@stackedapp/utils 2.38.0 → 2.38.2

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.
@@ -42,7 +42,10 @@ function evaluateDaysInGame(cond, ctx) {
42
42
  if (!met)
43
43
  isMet = false;
44
44
  details.push({
45
- isMet: met, kind: 'daysInGame', trackerAmount, trackerGoal,
45
+ isMet: met,
46
+ kind: 'daysInGame',
47
+ trackerAmount,
48
+ trackerGoal,
46
49
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, met),
47
50
  text: `More than ${trackerGoal} Days in Game`,
48
51
  });
@@ -53,7 +56,10 @@ function evaluateDaysInGame(cond, ctx) {
53
56
  if (!met)
54
57
  isMet = false;
55
58
  details.push({
56
- isMet: met, kind: 'daysInGame', trackerAmount, trackerGoal: cond.max,
59
+ isMet: met,
60
+ kind: 'daysInGame',
61
+ trackerAmount,
62
+ trackerGoal: cond.max,
57
63
  percentCompleted: met ? 100 : 0,
58
64
  text: `Less than ${cond.max} Days in Game`,
59
65
  });
@@ -70,7 +76,10 @@ function evaluateTrustScore(cond, ctx) {
70
76
  if (!met)
71
77
  isMet = false;
72
78
  details.push({
73
- isMet: met, kind: 'trustScore', trackerAmount, trackerGoal,
79
+ isMet: met,
80
+ kind: 'trustScore',
81
+ trackerAmount,
82
+ trackerGoal,
74
83
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, met),
75
84
  text: `More than ${trackerGoal} Rep`,
76
85
  });
@@ -81,7 +90,10 @@ function evaluateTrustScore(cond, ctx) {
81
90
  if (!met)
82
91
  isMet = false;
83
92
  details.push({
84
- isMet: met, kind: 'trustScore', trackerAmount, trackerGoal: cond.max,
93
+ isMet: met,
94
+ kind: 'trustScore',
95
+ trackerAmount,
96
+ trackerGoal: cond.max,
85
97
  percentCompleted: met ? 100 : 0,
86
98
  text: `Less than ${cond.max} Rep`,
87
99
  });
@@ -99,7 +111,10 @@ function evaluateLevel(cond, ctx) {
99
111
  if (!met)
100
112
  isMet = false;
101
113
  details.push({
102
- isMet: met, kind: 'level', trackerAmount, trackerGoal,
114
+ isMet: met,
115
+ kind: 'level',
116
+ trackerAmount,
117
+ trackerGoal,
103
118
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, met),
104
119
  text: `Be above level ${trackerGoal} ${cond.name}`,
105
120
  });
@@ -110,7 +125,10 @@ function evaluateLevel(cond, ctx) {
110
125
  if (!met)
111
126
  isMet = false;
112
127
  details.push({
113
- isMet: met, kind: 'level', trackerAmount, trackerGoal: cond.max,
128
+ isMet: met,
129
+ kind: 'level',
130
+ trackerAmount,
131
+ trackerGoal: cond.max,
114
132
  percentCompleted: met ? 100 : 0,
115
133
  text: `Be under level ${cond.max} ${cond.name}`,
116
134
  });
@@ -128,7 +146,10 @@ function evaluateCurrency(cond, ctx) {
128
146
  if (!met)
129
147
  isMet = false;
130
148
  details.push({
131
- isMet: met, kind: 'currency', trackerAmount, trackerGoal,
149
+ isMet: met,
150
+ kind: 'currency',
151
+ trackerAmount,
152
+ trackerGoal,
132
153
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, met),
133
154
  text: `Have more than ${trackerGoal} ${cond.name}`,
134
155
  });
@@ -139,7 +160,10 @@ function evaluateCurrency(cond, ctx) {
139
160
  if (!met)
140
161
  isMet = false;
141
162
  details.push({
142
- isMet: met, kind: 'currency', trackerAmount, trackerGoal: cond.max,
163
+ isMet: met,
164
+ kind: 'currency',
165
+ trackerAmount,
166
+ trackerGoal: cond.max,
143
167
  percentCompleted: met ? 100 : 0,
144
168
  text: `Have less than ${cond.max} ${cond.name}`,
145
169
  });
@@ -151,7 +175,10 @@ function evaluateCurrency(cond, ctx) {
151
175
  if (!met)
152
176
  isMet = false;
153
177
  details.push({
154
- isMet: met, kind: 'currency', trackerAmount, trackerGoal,
178
+ isMet: met,
179
+ kind: 'currency',
180
+ trackerAmount,
181
+ trackerGoal,
155
182
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, met),
156
183
  text: `Deposit at least ${trackerGoal} ${cond.name}`,
157
184
  });
@@ -163,7 +190,10 @@ function evaluateCurrency(cond, ctx) {
163
190
  if (!met)
164
191
  isMet = false;
165
192
  details.push({
166
- isMet: met, kind: 'currency', trackerAmount, trackerGoal,
193
+ isMet: met,
194
+ kind: 'currency',
195
+ trackerAmount,
196
+ trackerGoal,
167
197
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, met),
168
198
  text: `Withdraw at least ${trackerGoal} ${cond.name}`,
169
199
  });
@@ -181,7 +211,10 @@ function evaluateStakedTokens(cond, ctx) {
181
211
  if (!met)
182
212
  isMet = false;
183
213
  details.push({
184
- isMet: met, kind: 'stakedTokens', trackerAmount, trackerGoal,
214
+ isMet: met,
215
+ kind: 'stakedTokens',
216
+ trackerAmount,
217
+ trackerGoal,
185
218
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, met),
186
219
  text: `Have at least ${trackerGoal} ${cond.name} staked`,
187
220
  });
@@ -202,11 +235,16 @@ function evaluateLoginStreak(cond, ctx) {
202
235
  const isMet = trackerAmount >= trackerGoal;
203
236
  return {
204
237
  isMet,
205
- details: [{
206
- isMet, kind: 'loginStreak', trackerAmount, trackerGoal,
238
+ details: [
239
+ {
240
+ isMet,
241
+ kind: 'loginStreak',
242
+ trackerAmount,
243
+ trackerGoal,
207
244
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, isMet),
208
245
  text: `Login streak of ${trackerGoal || 0} days`,
209
- }],
246
+ },
247
+ ],
210
248
  };
211
249
  }
212
250
  function evaluateAchievement(cond, ctx) {
@@ -216,7 +254,10 @@ function evaluateAchievement(cond, ctx) {
216
254
  if (!playerAchData) {
217
255
  isMet = false;
218
256
  details.push({
219
- isMet: false, kind: 'achievement', trackerAmount: 0, trackerGoal: 1,
257
+ isMet: false,
258
+ kind: 'achievement',
259
+ trackerAmount: 0,
260
+ trackerGoal: 1,
220
261
  percentCompleted: 0,
221
262
  text: `Have the achievement ${cond.name}`,
222
263
  });
@@ -228,7 +269,10 @@ function evaluateAchievement(cond, ctx) {
228
269
  if (!met)
229
270
  isMet = false;
230
271
  details.push({
231
- isMet: met, kind: 'achievement', trackerAmount, trackerGoal,
272
+ isMet: met,
273
+ kind: 'achievement',
274
+ trackerAmount,
275
+ trackerGoal,
232
276
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, met),
233
277
  text: `Have the achievement ${cond.name} more than ${trackerGoal} times`,
234
278
  });
@@ -246,7 +290,10 @@ function evaluateMembership(cond, ctx) {
246
290
  if (!met)
247
291
  isMet = false;
248
292
  details.push({
249
- isMet: met, kind: 'membership', trackerAmount, trackerGoal,
293
+ isMet: met,
294
+ kind: 'membership',
295
+ trackerAmount,
296
+ trackerGoal,
250
297
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, met),
251
298
  text: trackerGoal > 1 ? `Have at least ${trackerGoal} ${cond.name} memberships` : `Have a ${cond.name} membership`,
252
299
  });
@@ -257,7 +304,10 @@ function evaluateMembership(cond, ctx) {
257
304
  if (!met)
258
305
  isMet = false;
259
306
  details.push({
260
- isMet: met, kind: 'membership', trackerAmount, trackerGoal: cond.maxCount,
307
+ isMet: met,
308
+ kind: 'membership',
309
+ trackerAmount,
310
+ trackerGoal: cond.maxCount,
261
311
  percentCompleted: met ? 100 : 0,
262
312
  text: `Have less than ${cond.maxCount} ${cond.name} memberships`,
263
313
  });
@@ -270,7 +320,10 @@ function evaluateMembership(cond, ctx) {
270
320
  if (!met)
271
321
  isMet = false;
272
322
  details.push({
273
- isMet: met, kind: 'membership', trackerAmount, trackerGoal,
323
+ isMet: met,
324
+ kind: 'membership',
325
+ trackerAmount,
326
+ trackerGoal,
274
327
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, met),
275
328
  text: `Own ${cond.name} membership for at least ${trackerGoal} days`,
276
329
  });
@@ -281,7 +334,9 @@ function evaluateMembership(cond, ctx) {
281
334
  if (!met)
282
335
  isMet = false;
283
336
  details.push({
284
- isMet: met, kind: 'membership', trackerAmount,
337
+ isMet: met,
338
+ kind: 'membership',
339
+ trackerAmount,
285
340
  trackerGoal: Number((cond.maxMs / (1000 * 60 * 60 * 24)).toFixed(1)),
286
341
  percentCompleted: met ? 100 : 0,
287
342
  text: `Own ${cond.name} membership for less than ${(cond.maxMs / (1000 * 60 * 60 * 24)).toFixed(1)} days`,
@@ -296,15 +351,20 @@ function evaluateQuest(cond, ctx) {
296
351
  const isMet = playerQuestData ? trackerAmount >= (cond.completions || 0) : false;
297
352
  return {
298
353
  isMet,
299
- details: [{
300
- isMet, kind: 'quest', trackerAmount, trackerGoal,
354
+ details: [
355
+ {
356
+ isMet,
357
+ kind: 'quest',
358
+ trackerAmount,
359
+ trackerGoal,
301
360
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, isMet),
302
361
  text: cond.completions === 1
303
362
  ? `Complete the quest ${cond.name}`
304
363
  : (cond.completions || 0) < 1
305
364
  ? `Start the quest ${cond.name}`
306
365
  : `Complete the quest ${cond.name} ${cond.completions} times`,
307
- }],
366
+ },
367
+ ],
308
368
  };
309
369
  }
310
370
  function evaluateEntityLink(cond, ctx) {
@@ -313,7 +373,10 @@ function evaluateEntityLink(cond, ctx) {
313
373
  let isMet = true;
314
374
  const makeText = (fallback) => cond.template
315
375
  ? (0, template_1.renderTemplate)(cond.template, {
316
- current: linkCount, min: cond.min ?? 0, max: cond.max ?? 0, type: cond.linkKind,
376
+ current: linkCount,
377
+ min: cond.min ?? 0,
378
+ max: cond.max ?? 0,
379
+ type: cond.linkKind,
317
380
  })
318
381
  : fallback;
319
382
  if (cond.min !== undefined) {
@@ -321,7 +384,10 @@ function evaluateEntityLink(cond, ctx) {
321
384
  if (!met)
322
385
  isMet = false;
323
386
  details.push({
324
- isMet: met, kind: 'entityLink', trackerAmount: linkCount, trackerGoal: cond.min,
387
+ isMet: met,
388
+ kind: 'entityLink',
389
+ trackerAmount: linkCount,
390
+ trackerGoal: cond.min,
325
391
  percentCompleted: (0, helpers_1.calculatePercent)(linkCount, cond.min, met),
326
392
  text: makeText(`At least ${cond.min} ${cond.linkKind} link(s)`),
327
393
  });
@@ -331,7 +397,10 @@ function evaluateEntityLink(cond, ctx) {
331
397
  if (!met)
332
398
  isMet = false;
333
399
  details.push({
334
- isMet: met, kind: 'entityLink', trackerAmount: linkCount, trackerGoal: cond.max,
400
+ isMet: met,
401
+ kind: 'entityLink',
402
+ trackerAmount: linkCount,
403
+ trackerGoal: cond.max,
335
404
  percentCompleted: met ? 100 : 0,
336
405
  text: makeText(`At most ${cond.max} ${cond.linkKind} link(s)`),
337
406
  });
@@ -354,29 +423,46 @@ function evaluateDynamic(cond, ctx) {
354
423
  const percentCompleted = (0, helpers_1.calculateDynamicGroupPercent)(dynamicObj, { ...cond, conditions: resolvedConditions });
355
424
  return {
356
425
  isMet: dynamicResult,
357
- details: [{
358
- isMet: dynamicResult, kind: 'dynamic', trackerAmount, trackerGoal, percentCompleted,
359
- text: (0, template_1.renderTemplate)((0, template_1.replaceDynamicConditionKey)(cond.template || '', ctx.offerTrackers || {}), dynamicObj) || 'Dynamic conditions',
360
- }],
426
+ details: [
427
+ {
428
+ isMet: dynamicResult,
429
+ kind: 'dynamic',
430
+ trackerAmount,
431
+ trackerGoal,
432
+ percentCompleted,
433
+ text: (0, template_1.renderTemplate)((0, template_1.replaceDynamicConditionKey)(cond.template || '', ctx.offerTrackers || {}), dynamicObj) ||
434
+ 'Dynamic conditions',
435
+ },
436
+ ],
361
437
  };
362
438
  }
363
439
  const AUTH_PLATFORM_DISPLAY_NAMES = {
364
- sms: 'SMS', email: 'Email', apple: 'Apple', google: 'Google',
365
- tiktok: 'TikTok', twitter: 'X/Twitter', moca: 'Moca',
440
+ sms: 'SMS',
441
+ email: 'Email',
442
+ apple: 'Apple',
443
+ google: 'Google',
444
+ tiktok: 'TikTok',
445
+ twitter: 'X/Twitter',
446
+ moca: 'Moca',
366
447
  };
448
+ function formatAuthPlatform(platform) {
449
+ const mappedPlatform = AUTH_PLATFORM_DISPLAY_NAMES[platform.toLowerCase()];
450
+ if (mappedPlatform)
451
+ return mappedPlatform;
452
+ return platform.charAt(0).toUpperCase() + platform.slice(1);
453
+ }
367
454
  function evaluateIdentifiers(cond, ctx) {
368
455
  const playerPlatforms = new Set(ctx.snap.identifiers?.map((i) => i.platform.toLowerCase()) || []);
369
456
  const platformsToCheck = cond.platforms;
370
457
  const metPlatforms = platformsToCheck.filter((p) => playerPlatforms.has(p.toLowerCase()));
371
- const platforms = platformsToCheck.map((p) => AUTH_PLATFORM_DISPLAY_NAMES[p.toLowerCase()] ?? p);
458
+ const platforms = platformsToCheck.map((p) => formatAuthPlatform(p));
372
459
  let isMet;
373
460
  let displayText;
374
461
  let percentCompleted;
375
462
  if (cond.behaviour === 'AND') {
376
463
  isMet = metPlatforms.length === platformsToCheck.length;
377
- displayText = platformsToCheck.length > 1
378
- ? `Link your ${(0, helpers_1.formatList)(platforms)} accounts`
379
- : `Link your ${platforms[0]} account`;
464
+ displayText =
465
+ platformsToCheck.length > 1 ? `Link your ${(0, helpers_1.formatList)(platforms)} accounts` : `Link your ${platforms[0]} account`;
380
466
  percentCompleted = (0, helpers_1.calculatePercent)(metPlatforms.length, platformsToCheck.length, isMet);
381
467
  }
382
468
  else if (cond.behaviour === 'NOT') {
@@ -391,12 +477,16 @@ function evaluateIdentifiers(cond, ctx) {
391
477
  }
392
478
  return {
393
479
  isMet,
394
- details: [{
395
- isMet, kind: 'identifiers',
396
- trackerAmount: isMet ? 1 : 0, trackerGoal: 1,
480
+ details: [
481
+ {
482
+ isMet,
483
+ kind: 'identifiers',
484
+ trackerAmount: isMet ? 1 : 0,
485
+ trackerGoal: 1,
397
486
  percentCompleted,
398
487
  text: displayText,
399
- }],
488
+ },
489
+ ],
400
490
  };
401
491
  }
402
492
  function evaluateTokenBalance(cond, ctx) {
@@ -414,7 +504,10 @@ function evaluateTokenBalance(cond, ctx) {
414
504
  if (!met)
415
505
  isMet = false;
416
506
  details.push({
417
- isMet: met, kind: 'tokenBalance', trackerAmount: totalBalance, trackerGoal: cond.min,
507
+ isMet: met,
508
+ kind: 'tokenBalance',
509
+ trackerAmount: totalBalance,
510
+ trackerGoal: cond.min,
418
511
  percentCompleted: (0, helpers_1.calculatePercent)(totalBalance, cond.min, met),
419
512
  text: `Have at least ${cond.min} ${cond.name || 'tokens'}`,
420
513
  });
@@ -424,7 +517,10 @@ function evaluateTokenBalance(cond, ctx) {
424
517
  if (!met)
425
518
  isMet = false;
426
519
  details.push({
427
- isMet: met, kind: 'tokenBalance', trackerAmount: totalBalance, trackerGoal: cond.max,
520
+ isMet: met,
521
+ kind: 'tokenBalance',
522
+ trackerAmount: totalBalance,
523
+ trackerGoal: cond.max,
428
524
  percentCompleted: met ? 100 : 0,
429
525
  text: `Have at most ${cond.max} ${cond.name || 'tokens'}`,
430
526
  });
@@ -440,8 +536,10 @@ function evaluateStackedAccount(cond, ctx) {
440
536
  if (!met)
441
537
  isMet = false;
442
538
  details.push({
443
- isMet: met, kind: 'stackedAccount',
444
- trackerAmount: playerHasAccount ? 1 : 0, trackerGoal: 1,
539
+ isMet: met,
540
+ kind: 'stackedAccount',
541
+ trackerAmount: playerHasAccount ? 1 : 0,
542
+ trackerGoal: 1,
445
543
  percentCompleted: met ? 100 : 0,
446
544
  text: cond.hasLinkedAccount ? 'Link a Stacked account' : 'Must not have Stacked account linked',
447
545
  });
@@ -453,8 +551,10 @@ function evaluateStackedAccount(cond, ctx) {
453
551
  if (!met)
454
552
  isMet = false;
455
553
  details.push({
456
- isMet: met, kind: 'stackedAccount',
457
- trackerAmount: walletCount, trackerGoal: cond.cryptoWallets.min,
554
+ isMet: met,
555
+ kind: 'stackedAccount',
556
+ trackerAmount: walletCount,
557
+ trackerGoal: cond.cryptoWallets.min,
458
558
  percentCompleted: (0, helpers_1.calculatePercent)(walletCount, cond.cryptoWallets.min, met),
459
559
  text: `Link at least ${cond.cryptoWallets.min} crypto wallet${cond.cryptoWallets.min === 1 ? '' : 's'}`,
460
560
  });
@@ -464,8 +564,10 @@ function evaluateStackedAccount(cond, ctx) {
464
564
  if (!met)
465
565
  isMet = false;
466
566
  details.push({
467
- isMet: met, kind: 'stackedAccount',
468
- trackerAmount: walletCount, trackerGoal: cond.cryptoWallets.max,
567
+ isMet: met,
568
+ kind: 'stackedAccount',
569
+ trackerAmount: walletCount,
570
+ trackerGoal: cond.cryptoWallets.max,
469
571
  percentCompleted: met ? 100 : 0,
470
572
  text: `Have at most ${cond.cryptoWallets.max} crypto wallet${cond.cryptoWallets.max === 1 ? '' : 's'}`,
471
573
  });
@@ -477,8 +579,10 @@ function evaluateStackedAccount(cond, ctx) {
477
579
  if (!met)
478
580
  isMet = false;
479
581
  details.push({
480
- isMet: met, kind: 'stackedAccount',
481
- trackerAmount: hasCustomUsername ? 1 : 0, trackerGoal: 1,
582
+ isMet: met,
583
+ kind: 'stackedAccount',
584
+ trackerAmount: hasCustomUsername ? 1 : 0,
585
+ trackerGoal: 1,
482
586
  percentCompleted: met ? 100 : 0,
483
587
  text: cond.hasUsername ? 'Set a custom username' : 'Must not have a custom username',
484
588
  });
@@ -489,8 +593,10 @@ function evaluateStackedAccount(cond, ctx) {
489
593
  if (!met)
490
594
  isMet = false;
491
595
  details.push({
492
- isMet: met, kind: 'stackedAccount',
493
- trackerAmount: hasCustomPic ? 1 : 0, trackerGoal: 1,
596
+ isMet: met,
597
+ kind: 'stackedAccount',
598
+ trackerAmount: hasCustomPic ? 1 : 0,
599
+ trackerGoal: 1,
494
600
  percentCompleted: met ? 100 : 0,
495
601
  text: cond.hasProfilePic ? 'Set a custom profile picture' : 'Must not have a custom profile picture',
496
602
  });
@@ -499,15 +605,16 @@ function evaluateStackedAccount(cond, ctx) {
499
605
  const playerPlatforms = new Set((ctx.additionalData?.linkedPlatforms || []).map((p) => p.toLowerCase()));
500
606
  const platformsToCheck = cond.authPlatforms.platforms;
501
607
  const metPlatforms = platformsToCheck.filter((p) => playerPlatforms.has(p.toLowerCase()));
502
- const platforms = platformsToCheck.map((p) => AUTH_PLATFORM_DISPLAY_NAMES[p.toLowerCase()] ?? p);
608
+ const platforms = platformsToCheck.map((p) => formatAuthPlatform(p));
503
609
  let met;
504
610
  let displayText;
505
611
  let percentCompleted;
506
612
  if (cond.authPlatforms.behaviour === 'AND') {
507
613
  met = metPlatforms.length === platformsToCheck.length;
508
- displayText = platformsToCheck.length > 1
509
- ? `Link your ${(0, helpers_1.formatList)(platforms)} accounts in Stacked`
510
- : `Link your ${platforms[0]} account in Stacked`;
614
+ displayText =
615
+ platformsToCheck.length > 1
616
+ ? `Link your ${(0, helpers_1.formatList)(platforms)} accounts in Stacked`
617
+ : `Link your ${platforms[0]} account in Stacked`;
511
618
  percentCompleted = (0, helpers_1.calculatePercent)(metPlatforms.length, platformsToCheck.length, met);
512
619
  }
513
620
  else if (cond.authPlatforms.behaviour === 'NOT') {
@@ -523,8 +630,10 @@ function evaluateStackedAccount(cond, ctx) {
523
630
  if (!met)
524
631
  isMet = false;
525
632
  details.push({
526
- isMet: met, kind: 'stackedAccount',
527
- trackerAmount: met ? 1 : 0, trackerGoal: 1,
633
+ isMet: met,
634
+ kind: 'stackedAccount',
635
+ trackerAmount: met ? 1 : 0,
636
+ trackerGoal: 1,
528
637
  percentCompleted,
529
638
  text: displayText,
530
639
  });
@@ -540,8 +649,10 @@ function evaluateUserSettings(cond, ctx) {
540
649
  if (!met)
541
650
  isMet = false;
542
651
  details.push({
543
- isMet: met, kind: 'userSettings',
544
- trackerAmount: playerHasNewsletter ? 1 : 0, trackerGoal: 1,
652
+ isMet: met,
653
+ kind: 'userSettings',
654
+ trackerAmount: playerHasNewsletter ? 1 : 0,
655
+ trackerGoal: 1,
545
656
  percentCompleted: met ? 100 : 0,
546
657
  text: cond.emailNewsletter ? 'Subscribe to email newsletter' : 'Must not be subscribed to email newsletter',
547
658
  });
@@ -554,12 +665,16 @@ function evaluateCompletionContext(cond, ctx) {
554
665
  const isMet = !!hasTrackedContext;
555
666
  return {
556
667
  isMet,
557
- details: [{
558
- isMet, kind: 'completionContext',
559
- trackerAmount: isMet ? 1 : 0, trackerGoal: 1,
668
+ details: [
669
+ {
670
+ isMet,
671
+ kind: 'completionContext',
672
+ trackerAmount: isMet ? 1 : 0,
673
+ trackerGoal: 1,
560
674
  percentCompleted: isMet ? 100 : 0,
561
675
  text: cond.name,
562
- }],
676
+ },
677
+ ],
563
678
  };
564
679
  }
565
680
  function evaluateBuyItem(cond, ctx) {
@@ -569,11 +684,16 @@ function evaluateBuyItem(cond, ctx) {
569
684
  const isMet = trackerValue >= scaledAmount;
570
685
  return {
571
686
  isMet,
572
- details: [{
573
- isMet, kind: 'buyItem', trackerAmount: trackerValue, trackerGoal: scaledAmount,
687
+ details: [
688
+ {
689
+ isMet,
690
+ kind: 'buyItem',
691
+ trackerAmount: trackerValue,
692
+ trackerGoal: scaledAmount,
574
693
  percentCompleted: (0, helpers_1.calculatePercent)(trackerValue, scaledAmount, isMet),
575
694
  text: `Buy ${scaledAmount} ${cond.name}`,
576
- }],
695
+ },
696
+ ],
577
697
  maxClaims: ctx.shouldScale && baseAmount > 0 ? Math.floor(trackerValue / baseAmount) : undefined,
578
698
  };
579
699
  }
@@ -584,11 +704,16 @@ function evaluateSpendCurrency(cond, ctx) {
584
704
  const isMet = trackerValue >= scaledAmount;
585
705
  return {
586
706
  isMet,
587
- details: [{
588
- isMet, kind: 'spendCurrency', trackerAmount: trackerValue, trackerGoal: scaledAmount,
707
+ details: [
708
+ {
709
+ isMet,
710
+ kind: 'spendCurrency',
711
+ trackerAmount: trackerValue,
712
+ trackerGoal: scaledAmount,
589
713
  percentCompleted: (0, helpers_1.calculatePercent)(trackerValue, scaledAmount, isMet),
590
714
  text: `Spend ${scaledAmount} ${cond.name}`,
591
- }],
715
+ },
716
+ ],
592
717
  maxClaims: ctx.shouldScale && baseAmount > 0 ? Math.floor(trackerValue / baseAmount) : undefined,
593
718
  };
594
719
  }
@@ -599,11 +724,16 @@ function evaluateDepositCurrency(cond, ctx) {
599
724
  const isMet = trackerValue >= scaledAmount;
600
725
  return {
601
726
  isMet,
602
- details: [{
603
- isMet, kind: 'depositCurrency', trackerAmount: trackerValue, trackerGoal: scaledAmount,
727
+ details: [
728
+ {
729
+ isMet,
730
+ kind: 'depositCurrency',
731
+ trackerAmount: trackerValue,
732
+ trackerGoal: scaledAmount,
604
733
  percentCompleted: (0, helpers_1.calculatePercent)(trackerValue, scaledAmount, isMet),
605
734
  text: `Deposit ${scaledAmount} ${cond.name}`,
606
- }],
735
+ },
736
+ ],
607
737
  maxClaims: ctx.shouldScale && baseAmount > 0 ? Math.floor(trackerValue / baseAmount) : undefined,
608
738
  };
609
739
  }
@@ -611,12 +741,16 @@ function evaluateLogin(_cond, ctx) {
611
741
  const isMet = new Date(ctx.snap.snapshotLastUpdated || 0).getTime() > new Date(ctx.offerCreatedAt || 0).getTime();
612
742
  return {
613
743
  isMet,
614
- details: [{
615
- isMet, kind: 'login',
616
- trackerAmount: isMet ? 1 : 0, trackerGoal: 1,
744
+ details: [
745
+ {
746
+ isMet,
747
+ kind: 'login',
748
+ trackerAmount: isMet ? 1 : 0,
749
+ trackerGoal: 1,
617
750
  percentCompleted: isMet ? 100 : 0,
618
751
  text: 'Login to the game',
619
- }],
752
+ },
753
+ ],
620
754
  };
621
755
  }
622
756
  function evaluateSocial(cond, ctx) {
@@ -660,7 +794,9 @@ function evaluateSocial(cond, ctx) {
660
794
  socialPercentages.push(0);
661
795
  const socialPercent = socialPercentages.length > 0
662
796
  ? socialPercentages.reduce((a, b) => a + b, 0) / socialPercentages.length
663
- : hasContent ? 100 : 0;
797
+ : hasContent
798
+ ? 100
799
+ : 0;
664
800
  const platformMap = { tiktok: 'TikTok', instagram: 'Instagram', youtube: 'YouTube' };
665
801
  const platformText = cond.platforms.map((p) => platformMap[p] || p).join(' | ');
666
802
  const requiredWords = cond.requiredWords ?? [];
@@ -671,7 +807,10 @@ function evaluateSocial(cond, ctx) {
671
807
  if (mode === 'accumulate') {
672
808
  const matchCount = tSocialAccumulate?.matchCount || 0;
673
809
  details.push({
674
- isMet: hasContent && isMet, kind: 'social', trackerAmount: matchCount, trackerGoal: 1,
810
+ isMet: hasContent && isMet,
811
+ kind: 'social',
812
+ trackerAmount: matchCount,
813
+ trackerGoal: 1,
675
814
  percentCompleted: socialPercent,
676
815
  text: hasContent
677
816
  ? `Found ${matchCount} matching ${platformText} post${matchCount !== 1 ? 's' : ''}`
@@ -683,8 +822,10 @@ function evaluateSocial(cond, ctx) {
683
822
  else {
684
823
  const title = tSocialAttach?.title;
685
824
  details.push({
686
- isMet: hasContent && isMet, kind: 'social',
687
- trackerAmount: hasContent ? 1 : 0, trackerGoal: 1,
825
+ isMet: hasContent && isMet,
826
+ kind: 'social',
827
+ trackerAmount: hasContent ? 1 : 0,
828
+ trackerGoal: 1,
688
829
  percentCompleted: socialPercent,
689
830
  text: !hasContent
690
831
  ? requiredWords.length > 0
@@ -695,24 +836,30 @@ function evaluateSocial(cond, ctx) {
695
836
  }
696
837
  if (minLikes > 0) {
697
838
  details.push({
698
- isMet: hasContent && likes >= minLikes, kind: 'social',
699
- trackerAmount: likes, trackerGoal: minLikes,
839
+ isMet: hasContent && likes >= minLikes,
840
+ kind: 'social',
841
+ trackerAmount: likes,
842
+ trackerGoal: minLikes,
700
843
  percentCompleted: (0, helpers_1.calculatePercent)(likes, minLikes, hasContent && likes >= minLikes),
701
844
  text: mode === 'accumulate' ? `Combined ${minLikes} Likes` : `Reach ${minLikes} Likes`,
702
845
  });
703
846
  }
704
847
  if (minViews > 0) {
705
848
  details.push({
706
- isMet: hasContent && views >= minViews, kind: 'social',
707
- trackerAmount: views, trackerGoal: minViews,
849
+ isMet: hasContent && views >= minViews,
850
+ kind: 'social',
851
+ trackerAmount: views,
852
+ trackerGoal: minViews,
708
853
  percentCompleted: (0, helpers_1.calculatePercent)(views, minViews, hasContent && views >= minViews),
709
854
  text: mode === 'accumulate' ? `Combined ${minViews} Views` : `Reach ${minViews} Views`,
710
855
  });
711
856
  }
712
857
  if (minComments > 0) {
713
858
  details.push({
714
- isMet: hasContent && comments >= minComments, kind: 'social',
715
- trackerAmount: comments, trackerGoal: minComments,
859
+ isMet: hasContent && comments >= minComments,
860
+ kind: 'social',
861
+ trackerAmount: comments,
862
+ trackerGoal: minComments,
716
863
  percentCompleted: (0, helpers_1.calculatePercent)(comments, minComments, hasContent && comments >= minComments),
717
864
  text: mode === 'accumulate' ? `Combined ${minComments} Comments` : `Reach ${minComments} Comments`,
718
865
  });
@@ -726,13 +873,18 @@ function evaluateLinkedCompletions(cond, ctx) {
726
873
  const isMet = trackerAmount >= trackerGoal;
727
874
  return {
728
875
  isMet,
729
- details: [{
730
- isMet, kind: 'linkedCompletions', trackerAmount, trackerGoal,
876
+ details: [
877
+ {
878
+ isMet,
879
+ kind: 'linkedCompletions',
880
+ trackerAmount,
881
+ trackerGoal,
731
882
  percentCompleted: (0, helpers_1.calculatePercent)(trackerAmount, trackerGoal, isMet),
732
883
  text: cond.template
733
884
  ? (0, template_1.renderTemplate)(cond.template, { current: trackerAmount, required: trackerGoal })
734
885
  : `Wait for ${trackerGoal} linked ${trackerGoal === 1 ? 'entity' : 'entities'} to complete`,
735
- }],
886
+ },
887
+ ],
736
888
  maxClaims: ctx.shouldScale && baseMin > 0 ? Math.floor(trackerAmount / baseMin) : undefined,
737
889
  };
738
890
  }
@@ -754,14 +906,22 @@ function evaluateDynamicTracker(cond, ctx) {
754
906
  trackerAmount = typeof val === 'number' ? val : 0;
755
907
  }
756
908
  const percentCompleted = (0, helpers_1.calculateDynamicGroupPercent)(primitiveTrackers, {
757
- ...cond, conditions: resolvedConditions,
909
+ ...cond,
910
+ conditions: resolvedConditions,
758
911
  });
759
912
  return {
760
913
  isMet: dynamicResult,
761
- details: [{
762
- isMet: dynamicResult, kind: 'dynamicTracker', trackerAmount, trackerGoal, percentCompleted,
763
- text: (0, template_1.renderTemplate)((0, template_1.replaceDynamicConditionKey)(cond.template || '', ctx.offerTrackers || {}), primitiveTrackers) || 'Dynamic conditions',
764
- }],
914
+ details: [
915
+ {
916
+ isMet: dynamicResult,
917
+ kind: 'dynamicTracker',
918
+ trackerAmount,
919
+ trackerGoal,
920
+ percentCompleted,
921
+ text: (0, template_1.renderTemplate)((0, template_1.replaceDynamicConditionKey)(cond.template || '', ctx.offerTrackers || {}), primitiveTrackers) ||
922
+ 'Dynamic conditions',
923
+ },
924
+ ],
765
925
  maxClaims,
766
926
  };
767
927
  }
@@ -812,15 +972,22 @@ function evaluateContractInteraction(cond, ctx) {
812
972
  }
813
973
  return {
814
974
  isMet,
815
- details: [{
816
- isMet, kind: 'contractInteraction', trackerAmount,
975
+ details: [
976
+ {
977
+ isMet,
978
+ kind: 'contractInteraction',
979
+ trackerAmount,
817
980
  percentCompleted: percent,
818
981
  text: (0, template_1.renderTemplate)(cond.template, {
819
- currentAmount: trackerAmount || 0, currentCount: trackerCount || 0,
820
- minAmount: minAmount || 0, maxAmount: maxAmount || 0,
821
- minCount: minCount || 0, maxCount: maxCount || 0,
982
+ currentAmount: trackerAmount || 0,
983
+ currentCount: trackerCount || 0,
984
+ minAmount: minAmount || 0,
985
+ maxAmount: maxAmount || 0,
986
+ minCount: minCount || 0,
987
+ maxCount: maxCount || 0,
822
988
  }),
823
- }],
989
+ },
990
+ ],
824
991
  maxClaims,
825
992
  };
826
993
  }
@@ -836,12 +1003,16 @@ function evaluateTwitterVerification(cond, ctx) {
836
1003
  };
837
1004
  return {
838
1005
  isMet,
839
- details: [{
840
- isMet, kind: 'twitterVerification',
841
- trackerAmount: isMet ? 1 : 0, trackerGoal: 1,
1006
+ details: [
1007
+ {
1008
+ isMet,
1009
+ kind: 'twitterVerification',
1010
+ trackerAmount: isMet ? 1 : 0,
1011
+ trackerGoal: 1,
842
1012
  percentCompleted: isMet ? 100 : 0,
843
1013
  text: actionTextMap[cond.action] || 'Complete action on X',
844
- }],
1014
+ },
1015
+ ],
845
1016
  };
846
1017
  }
847
1018
  function evaluateMocaCredential(cond, ctx) {
@@ -849,12 +1020,16 @@ function evaluateMocaCredential(cond, ctx) {
849
1020
  const isMet = tracker?.verified === true;
850
1021
  return {
851
1022
  isMet,
852
- details: [{
853
- isMet, kind: 'mocaCredential',
854
- trackerAmount: isMet ? 1 : 0, trackerGoal: 1,
1023
+ details: [
1024
+ {
1025
+ isMet,
1026
+ kind: 'mocaCredential',
1027
+ trackerAmount: isMet ? 1 : 0,
1028
+ trackerGoal: 1,
855
1029
  percentCompleted: isMet ? 100 : 0,
856
1030
  text: cond.template || 'Verify Moca credential',
857
- }],
1031
+ },
1032
+ ],
858
1033
  };
859
1034
  }
860
1035
  //# sourceMappingURL=handlers.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackedapp/utils",
3
- "version": "2.38.0",
3
+ "version": "2.38.2",
4
4
  "description": "Public utilities for Stacked platform SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",