@stackedapp/utils 2.15.0 → 2.17.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILevelCondition, ICurrencyCondition, IStakedTokensCondition, ITrustScoreCondition, IDaysInGameCondition, ILoginStreakCondition, IAchievementCondition, IMembershipCondition, IQuestCondition, IEntityLinkCondition, IDynamicConditionItem, IIdentifiersCondition, ITokenBalanceCondition, IStackedAccountCondition, IUserSettingsCondition, IBuyItemCondition, ISpendCurrencyCondition, IDepositCurrencyCondition, ISocialCondition, ILoginCondition, ICompletionContextCondition, ILinkedCompletionsCondition, IDynamicTrackerCondition, IContractInteractionCondition, ICompletionTrackers, ConditionDetail, StackedSnapshot, StackedBaseUserExtra } from '@stackedapp/types';
|
|
1
|
+
import { ILevelCondition, ICurrencyCondition, IStakedTokensCondition, ITrustScoreCondition, IDaysInGameCondition, ILoginStreakCondition, IAchievementCondition, IMembershipCondition, IQuestCondition, IEntityLinkCondition, IDynamicConditionItem, IIdentifiersCondition, ITokenBalanceCondition, IStackedAccountCondition, IUserSettingsCondition, IBuyItemCondition, ISpendCurrencyCondition, IDepositCurrencyCondition, ISocialCondition, ILoginCondition, ICompletionContextCondition, ILinkedCompletionsCondition, IDynamicTrackerCondition, IContractInteractionCondition, ISocialEngagementCondition, ICompletionTrackers, ConditionDetail, StackedSnapshot, StackedBaseUserExtra } from '@stackedapp/types';
|
|
2
2
|
export interface EvalContext {
|
|
3
3
|
snap: StackedSnapshot;
|
|
4
4
|
additionalData?: StackedBaseUserExtra;
|
|
@@ -38,4 +38,5 @@ export declare function evaluateSocial(cond: ISocialCondition, ctx: EvalContext)
|
|
|
38
38
|
export declare function evaluateLinkedCompletions(cond: ILinkedCompletionsCondition, ctx: EvalContext): EvalResult;
|
|
39
39
|
export declare function evaluateDynamicTracker(cond: IDynamicTrackerCondition, ctx: EvalContext): EvalResult;
|
|
40
40
|
export declare function evaluateContractInteraction(cond: IContractInteractionCondition, ctx: EvalContext): EvalResult;
|
|
41
|
+
export declare function evaluateSocialEngagement(cond: ISocialEngagementCondition, ctx: EvalContext): EvalResult;
|
|
41
42
|
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -24,6 +24,7 @@ exports.evaluateSocial = evaluateSocial;
|
|
|
24
24
|
exports.evaluateLinkedCompletions = evaluateLinkedCompletions;
|
|
25
25
|
exports.evaluateDynamicTracker = evaluateDynamicTracker;
|
|
26
26
|
exports.evaluateContractInteraction = evaluateContractInteraction;
|
|
27
|
+
exports.evaluateSocialEngagement = evaluateSocialEngagement;
|
|
27
28
|
const types_1 = require("@stackedapp/types");
|
|
28
29
|
const template_1 = require("../template");
|
|
29
30
|
const dynamic_1 = require("../dynamic");
|
|
@@ -468,6 +469,30 @@ function evaluateStackedAccount(cond, ctx) {
|
|
|
468
469
|
});
|
|
469
470
|
}
|
|
470
471
|
}
|
|
472
|
+
if (cond.hasUsername !== undefined) {
|
|
473
|
+
const hasCustomUsername = ctx.additionalData?.hasCustomDisplayName ?? false;
|
|
474
|
+
const met = cond.hasUsername === hasCustomUsername;
|
|
475
|
+
if (!met)
|
|
476
|
+
isMet = false;
|
|
477
|
+
details.push({
|
|
478
|
+
isMet: met, kind: 'stackedAccount',
|
|
479
|
+
trackerAmount: hasCustomUsername ? 1 : 0, trackerGoal: 1,
|
|
480
|
+
percentCompleted: met ? 100 : 0,
|
|
481
|
+
text: cond.hasUsername ? 'Set a custom username' : 'Must not have a custom username',
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
if (cond.hasProfilePic !== undefined) {
|
|
485
|
+
const hasCustomPic = ctx.additionalData?.hasCustomProfileImage ?? false;
|
|
486
|
+
const met = cond.hasProfilePic === hasCustomPic;
|
|
487
|
+
if (!met)
|
|
488
|
+
isMet = false;
|
|
489
|
+
details.push({
|
|
490
|
+
isMet: met, kind: 'stackedAccount',
|
|
491
|
+
trackerAmount: hasCustomPic ? 1 : 0, trackerGoal: 1,
|
|
492
|
+
percentCompleted: met ? 100 : 0,
|
|
493
|
+
text: cond.hasProfilePic ? 'Set a custom profile picture' : 'Must not have a custom profile picture',
|
|
494
|
+
});
|
|
495
|
+
}
|
|
471
496
|
return { isMet, details };
|
|
472
497
|
}
|
|
473
498
|
function evaluateUserSettings(cond, ctx) {
|
|
@@ -763,4 +788,24 @@ function evaluateContractInteraction(cond, ctx) {
|
|
|
763
788
|
maxClaims,
|
|
764
789
|
};
|
|
765
790
|
}
|
|
791
|
+
function evaluateSocialEngagement(cond, ctx) {
|
|
792
|
+
const tracker = ctx.completionTrackers?.socialEngagement?.[cond.id];
|
|
793
|
+
const isMet = tracker?.verified === true;
|
|
794
|
+
const actionTextMap = {
|
|
795
|
+
follow: `Follow @${cond.targetUsername || '?'} on X`,
|
|
796
|
+
retweet: 'Retweet a post on X',
|
|
797
|
+
quoteTweet: cond.requiredWords?.length
|
|
798
|
+
? `Quote tweet on X with ${cond.requiredWords.map((w) => `"${w}"`).join(', ')}`
|
|
799
|
+
: 'Quote tweet on X',
|
|
800
|
+
};
|
|
801
|
+
return {
|
|
802
|
+
isMet,
|
|
803
|
+
details: [{
|
|
804
|
+
isMet, kind: 'socialEngagement',
|
|
805
|
+
trackerAmount: isMet ? 1 : 0, trackerGoal: 1,
|
|
806
|
+
percentCompleted: isMet ? 100 : 0,
|
|
807
|
+
text: actionTextMap[cond.action] || 'Complete X/Twitter engagement',
|
|
808
|
+
}],
|
|
809
|
+
};
|
|
810
|
+
}
|
|
766
811
|
//# sourceMappingURL=handlers.js.map
|
package/dist/conditions/index.js
CHANGED
|
@@ -42,6 +42,7 @@ function evaluateCompletionOnlyCondition(cond, ctx) {
|
|
|
42
42
|
case 'linkedCompletions': return (0, handlers_1.evaluateLinkedCompletions)(cond, ctx);
|
|
43
43
|
case 'dynamicTracker': return (0, handlers_1.evaluateDynamicTracker)(cond, ctx);
|
|
44
44
|
case 'contractInteraction': return (0, handlers_1.evaluateContractInteraction)(cond, ctx);
|
|
45
|
+
case 'socialEngagement': return (0, handlers_1.evaluateSocialEngagement)(cond, ctx);
|
|
45
46
|
// base kinds handled by evaluateBaseCondition
|
|
46
47
|
case 'level':
|
|
47
48
|
case 'currency':
|
|
@@ -385,6 +386,7 @@ const meetsCompletionConditionsBeforeExpiry = ({ completionConditions, completio
|
|
|
385
386
|
case 'completionContext':
|
|
386
387
|
case 'linkedCompletions':
|
|
387
388
|
case 'contractInteraction':
|
|
389
|
+
case 'socialEngagement':
|
|
388
390
|
if (completionTrackers?.lastUpdated != null && wasUpdatedAfterExpiry(completionTrackers.lastUpdated)) {
|
|
389
391
|
return false;
|
|
390
392
|
}
|