@stackedapp/utils 1.12.0 → 1.13.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.
- package/dist/conditions.js +4 -2
- package/dist/template.d.ts +2 -2
- package/dist/template.js +6 -2
- package/package.json +1 -1
package/dist/conditions.js
CHANGED
|
@@ -543,7 +543,7 @@ additionalData, }) => {
|
|
|
543
543
|
trackerAmount,
|
|
544
544
|
trackerGoal,
|
|
545
545
|
percentCompleted,
|
|
546
|
-
text: (0, template_1.renderTemplate)(conditions.dynamic.template, dynamicObj) || 'Dynamic conditions',
|
|
546
|
+
text: (0, template_1.renderTemplate)((0, template_1.replaceDynamicConditionKey)(conditions.dynamic.template || '', playerOffer?.trackers || {}), dynamicObj) || 'Dynamic conditions',
|
|
547
547
|
});
|
|
548
548
|
if (!dynamicResult)
|
|
549
549
|
isValid = false;
|
|
@@ -1067,7 +1067,9 @@ const meetsCompletionConditions = ({ completionConditions, completionTrackers, p
|
|
|
1067
1067
|
trackerAmount,
|
|
1068
1068
|
trackerGoal,
|
|
1069
1069
|
percentCompleted,
|
|
1070
|
-
text: (0, template_1.renderTemplate)(
|
|
1070
|
+
text: (0, template_1.renderTemplate)(
|
|
1071
|
+
// First resolve {{}} placeholders (e.g., {{surfacerPlayerId}}) using offer trackers
|
|
1072
|
+
(0, template_1.replaceDynamicConditionKey)(conditions.dynamicTracker.template || '', playerOffer?.trackers || {}), primitiveTrackers) || 'Dynamic conditions',
|
|
1071
1073
|
});
|
|
1072
1074
|
if (!dynamicResult)
|
|
1073
1075
|
isValid = false;
|
package/dist/template.d.ts
CHANGED
|
@@ -10,9 +10,9 @@ export declare function renderTemplate(template: string | undefined, dynamic: Re
|
|
|
10
10
|
*
|
|
11
11
|
* eg. a condition high_score_pet-{{surfacerPlayerId}} with high_score_pet-12345
|
|
12
12
|
*/
|
|
13
|
-
export declare function replaceDynamicConditionKey(key: string, trackers: Record<string, any>): string;
|
|
13
|
+
export declare function replaceDynamicConditionKey(key: string, trackers: Record<string, any> | undefined): string;
|
|
14
14
|
/** this replaces all of the dynamic conditions.keys by calling replaceDynamicConditionKey */
|
|
15
|
-
export declare function replaceDynamicConditionKeys(conditions: Array<StackedDynamicCondition>, trackers: Record<string, any>): {
|
|
15
|
+
export declare function replaceDynamicConditionKeys(conditions: Array<StackedDynamicCondition>, trackers: Record<string, any> | undefined): {
|
|
16
16
|
key: string;
|
|
17
17
|
compareTo: string | number | boolean;
|
|
18
18
|
operator: "==" | "!=" | ">" | ">=" | "<" | "<=" | "has" | "not_has";
|
package/dist/template.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.extractTemplateKeys = extractTemplateKeys;
|
|
|
4
4
|
exports.renderTemplate = renderTemplate;
|
|
5
5
|
exports.replaceDynamicConditionKey = replaceDynamicConditionKey;
|
|
6
6
|
exports.replaceDynamicConditionKeys = replaceDynamicConditionKeys;
|
|
7
|
-
const keyPattern = /\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;
|
|
7
|
+
const keyPattern = /\{([a-zA-Z_][a-zA-Z0-9_-]*)\}/g;
|
|
8
8
|
// extract {key} placeholders from template string
|
|
9
9
|
// e.g. "Hello {playerName}, you have {coins} coins!" → Set { "playerName", "coins" }
|
|
10
10
|
function extractTemplateKeys(template) {
|
|
@@ -39,7 +39,11 @@ function renderTemplate(template, dynamic) {
|
|
|
39
39
|
* eg. a condition high_score_pet-{{surfacerPlayerId}} with high_score_pet-12345
|
|
40
40
|
*/
|
|
41
41
|
function replaceDynamicConditionKey(key, trackers) {
|
|
42
|
-
|
|
42
|
+
if (!key)
|
|
43
|
+
return '';
|
|
44
|
+
if (!trackers)
|
|
45
|
+
return key;
|
|
46
|
+
return key.replace(/\{\{([a-zA-Z_][a-zA-Z0-9_]*)\}\}/g, (match, p1) => {
|
|
43
47
|
const value = trackers[p1];
|
|
44
48
|
return value !== undefined ? String(value) : match;
|
|
45
49
|
});
|