@stackedapp/utils 2.22.0 → 2.28.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,
|
|
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, ITwitterVerificationCondition, ICompletionTrackers, ConditionDetail, StackedSnapshot, StackedBaseUserExtra } from '@stackedapp/types';
|
|
2
2
|
export interface EvalContext {
|
|
3
3
|
snap: StackedSnapshot;
|
|
4
4
|
additionalData?: StackedBaseUserExtra;
|
|
@@ -38,5 +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
|
|
41
|
+
export declare function evaluateTwitterVerification(cond: ITwitterVerificationCondition, ctx: EvalContext): EvalResult;
|
|
42
42
|
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -24,7 +24,7 @@ exports.evaluateSocial = evaluateSocial;
|
|
|
24
24
|
exports.evaluateLinkedCompletions = evaluateLinkedCompletions;
|
|
25
25
|
exports.evaluateDynamicTracker = evaluateDynamicTracker;
|
|
26
26
|
exports.evaluateContractInteraction = evaluateContractInteraction;
|
|
27
|
-
exports.
|
|
27
|
+
exports.evaluateTwitterVerification = evaluateTwitterVerification;
|
|
28
28
|
const types_1 = require("@stackedapp/types");
|
|
29
29
|
const template_1 = require("../template");
|
|
30
30
|
const dynamic_1 = require("../dynamic");
|
|
@@ -359,14 +359,15 @@ function evaluateDynamic(cond, ctx) {
|
|
|
359
359
|
}],
|
|
360
360
|
};
|
|
361
361
|
}
|
|
362
|
+
const AUTH_PLATFORM_DISPLAY_NAMES = {
|
|
363
|
+
sms: 'SMS', email: 'Email', apple: 'Apple', google: 'Google',
|
|
364
|
+
tiktok: 'TikTok', twitter: 'X/Twitter',
|
|
365
|
+
};
|
|
362
366
|
function evaluateIdentifiers(cond, ctx) {
|
|
363
367
|
const playerPlatforms = new Set(ctx.snap.identifiers?.map((i) => i.platform.toLowerCase()) || []);
|
|
364
368
|
const platformsToCheck = cond.platforms;
|
|
365
|
-
const platformsMap = {
|
|
366
|
-
sms: 'SMS', email: 'Email', apple: 'Apple', google: 'Google', tiktok: 'TikTok',
|
|
367
|
-
};
|
|
368
369
|
const metPlatforms = platformsToCheck.filter((p) => playerPlatforms.has(p.toLowerCase()));
|
|
369
|
-
const platforms = platformsToCheck.map((p) =>
|
|
370
|
+
const platforms = platformsToCheck.map((p) => AUTH_PLATFORM_DISPLAY_NAMES[p.toLowerCase()] ?? p);
|
|
370
371
|
let isMet;
|
|
371
372
|
let displayText;
|
|
372
373
|
let percentCompleted;
|
|
@@ -493,6 +494,40 @@ function evaluateStackedAccount(cond, ctx) {
|
|
|
493
494
|
text: cond.hasProfilePic ? 'Set a custom profile picture' : 'Must not have a custom profile picture',
|
|
494
495
|
});
|
|
495
496
|
}
|
|
497
|
+
if (cond.authPlatforms && cond.authPlatforms.platforms.length > 0) {
|
|
498
|
+
const playerPlatforms = new Set((ctx.additionalData?.linkedPlatforms || []).map((p) => p.toLowerCase()));
|
|
499
|
+
const platformsToCheck = cond.authPlatforms.platforms;
|
|
500
|
+
const metPlatforms = platformsToCheck.filter((p) => playerPlatforms.has(p.toLowerCase()));
|
|
501
|
+
const platforms = platformsToCheck.map((p) => AUTH_PLATFORM_DISPLAY_NAMES[p.toLowerCase()] ?? p);
|
|
502
|
+
let met;
|
|
503
|
+
let displayText;
|
|
504
|
+
let percentCompleted;
|
|
505
|
+
if (cond.authPlatforms.behaviour === 'AND') {
|
|
506
|
+
met = metPlatforms.length === platformsToCheck.length;
|
|
507
|
+
displayText = platformsToCheck.length > 1
|
|
508
|
+
? `Link your ${(0, helpers_1.formatList)(platforms)} accounts in Stacked`
|
|
509
|
+
: `Link your ${platforms[0]} account in Stacked`;
|
|
510
|
+
percentCompleted = (0, helpers_1.calculatePercent)(metPlatforms.length, platformsToCheck.length, met);
|
|
511
|
+
}
|
|
512
|
+
else if (cond.authPlatforms.behaviour === 'NOT') {
|
|
513
|
+
met = metPlatforms.length === 0;
|
|
514
|
+
displayText = `Must not have ${(0, helpers_1.formatList)(platforms)} linked in Stacked`;
|
|
515
|
+
percentCompleted = met ? 100 : 0;
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
met = platformsToCheck.some((p) => playerPlatforms.has(p.toLowerCase()));
|
|
519
|
+
displayText = `Link any of your ${(0, helpers_1.formatList)(platforms)} accounts in Stacked`;
|
|
520
|
+
percentCompleted = met ? 100 : 0;
|
|
521
|
+
}
|
|
522
|
+
if (!met)
|
|
523
|
+
isMet = false;
|
|
524
|
+
details.push({
|
|
525
|
+
isMet: met, kind: 'stackedAccount',
|
|
526
|
+
trackerAmount: met ? 1 : 0, trackerGoal: 1,
|
|
527
|
+
percentCompleted,
|
|
528
|
+
text: displayText,
|
|
529
|
+
});
|
|
530
|
+
}
|
|
496
531
|
return { isMet, details };
|
|
497
532
|
}
|
|
498
533
|
function evaluateUserSettings(cond, ctx) {
|
|
@@ -788,8 +823,8 @@ function evaluateContractInteraction(cond, ctx) {
|
|
|
788
823
|
maxClaims,
|
|
789
824
|
};
|
|
790
825
|
}
|
|
791
|
-
function
|
|
792
|
-
const tracker = ctx.completionTrackers?.
|
|
826
|
+
function evaluateTwitterVerification(cond, ctx) {
|
|
827
|
+
const tracker = ctx.completionTrackers?.twitterVerification?.[cond.id];
|
|
793
828
|
const isMet = tracker?.verified === true;
|
|
794
829
|
const actionTextMap = {
|
|
795
830
|
follow: `Follow @${cond.targetUsername || '?'} on X`,
|
|
@@ -801,10 +836,10 @@ function evaluateSocialEngagement(cond, ctx) {
|
|
|
801
836
|
return {
|
|
802
837
|
isMet,
|
|
803
838
|
details: [{
|
|
804
|
-
isMet, kind: '
|
|
839
|
+
isMet, kind: 'twitterVerification',
|
|
805
840
|
trackerAmount: isMet ? 1 : 0, trackerGoal: 1,
|
|
806
841
|
percentCompleted: isMet ? 100 : 0,
|
|
807
|
-
text: actionTextMap[cond.action] || 'Complete X
|
|
842
|
+
text: actionTextMap[cond.action] || 'Complete action on X',
|
|
808
843
|
}],
|
|
809
844
|
};
|
|
810
845
|
}
|
package/dist/conditions/index.js
CHANGED
|
@@ -42,7 +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 '
|
|
45
|
+
case 'twitterVerification': return (0, handlers_1.evaluateTwitterVerification)(cond, ctx);
|
|
46
46
|
// base kinds handled by evaluateBaseCondition
|
|
47
47
|
case 'level':
|
|
48
48
|
case 'currency':
|
|
@@ -386,7 +386,7 @@ const meetsCompletionConditionsBeforeExpiry = ({ completionConditions, completio
|
|
|
386
386
|
case 'completionContext':
|
|
387
387
|
case 'linkedCompletions':
|
|
388
388
|
case 'contractInteraction':
|
|
389
|
-
case '
|
|
389
|
+
case 'twitterVerification':
|
|
390
390
|
if (completionTrackers?.lastUpdated != null && wasUpdatedAfterExpiry(completionTrackers.lastUpdated)) {
|
|
391
391
|
return false;
|
|
392
392
|
}
|