@stackedapp/utils 1.23.2 → 1.23.3
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/handlers.d.ts +41 -0
- package/dist/conditions/handlers.js +763 -0
- package/dist/conditions/helpers.d.ts +11 -0
- package/dist/conditions/helpers.js +256 -0
- package/dist/conditions/index.d.ts +97 -0
- package/dist/conditions/index.js +338 -0
- package/dist/dynamic.d.ts +2 -2
- package/dist/template.d.ts +2 -2
- package/package.json +1 -1
- package/dist/conditions.d.ts +0 -130
- package/dist/conditions.js +0 -1746
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.meetsCompletionConditionsBeforeExpiry = exports.meetsCompletionConditions = exports.offerMeetsCompletionConditions = exports.meetsLinkedEntityOffersCondition = exports.hasCompletionConditions = exports.meetsBaseConditions = exports.getMaxClaimsForDynamicGroup = exports.getMaxClaimsForDynamicCondition = exports.meetsDynamicConditions = void 0;
|
|
4
|
+
exports.meetsClaimableConditions = meetsClaimableConditions;
|
|
5
|
+
const handlers_1 = require("./handlers");
|
|
6
|
+
var helpers_1 = require("./helpers");
|
|
7
|
+
Object.defineProperty(exports, "meetsDynamicConditions", { enumerable: true, get: function () { return helpers_1.meetsDynamicConditions; } });
|
|
8
|
+
Object.defineProperty(exports, "getMaxClaimsForDynamicCondition", { enumerable: true, get: function () { return helpers_1.getMaxClaimsForDynamicCondition; } });
|
|
9
|
+
Object.defineProperty(exports, "getMaxClaimsForDynamicGroup", { enumerable: true, get: function () { return helpers_1.getMaxClaimsForDynamicGroup; } });
|
|
10
|
+
function evaluateBaseCondition(cond, ctx) {
|
|
11
|
+
switch (cond.kind) {
|
|
12
|
+
case 'daysInGame': return (0, handlers_1.evaluateDaysInGame)(cond, ctx);
|
|
13
|
+
case 'trustScore': return (0, handlers_1.evaluateTrustScore)(cond, ctx);
|
|
14
|
+
case 'level': return (0, handlers_1.evaluateLevel)(cond, ctx);
|
|
15
|
+
case 'currency': return (0, handlers_1.evaluateCurrency)(cond, ctx);
|
|
16
|
+
case 'stakedTokens': return (0, handlers_1.evaluateStakedTokens)(cond, ctx);
|
|
17
|
+
case 'loginStreak': return (0, handlers_1.evaluateLoginStreak)(cond, ctx);
|
|
18
|
+
case 'achievement': return (0, handlers_1.evaluateAchievement)(cond, ctx);
|
|
19
|
+
case 'membership': return (0, handlers_1.evaluateMembership)(cond, ctx);
|
|
20
|
+
case 'quest': return (0, handlers_1.evaluateQuest)(cond, ctx);
|
|
21
|
+
case 'entityLink': return (0, handlers_1.evaluateEntityLink)(cond, ctx);
|
|
22
|
+
case 'dynamic': return (0, handlers_1.evaluateDynamic)(cond, ctx);
|
|
23
|
+
case 'identifiers': return (0, handlers_1.evaluateIdentifiers)(cond, ctx);
|
|
24
|
+
case 'tokenBalance': return (0, handlers_1.evaluateTokenBalance)(cond, ctx);
|
|
25
|
+
case 'stackedAccount': return (0, handlers_1.evaluateStackedAccount)(cond, ctx);
|
|
26
|
+
case 'userSettings': return (0, handlers_1.evaluateUserSettings)(cond, ctx);
|
|
27
|
+
default: {
|
|
28
|
+
const _ = cond;
|
|
29
|
+
return undefined;
|
|
30
|
+
} // trick to refuse to compile if we don't handle a new condition kind
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function evaluateCompletionOnlyCondition(cond, ctx) {
|
|
34
|
+
switch (cond.kind) {
|
|
35
|
+
case 'completionContext': return (0, handlers_1.evaluateCompletionContext)(cond, ctx);
|
|
36
|
+
case 'buyItem': return (0, handlers_1.evaluateBuyItem)(cond, ctx);
|
|
37
|
+
case 'spendCurrency': return (0, handlers_1.evaluateSpendCurrency)(cond, ctx);
|
|
38
|
+
case 'depositCurrency': return (0, handlers_1.evaluateDepositCurrency)(cond, ctx);
|
|
39
|
+
case 'login': return (0, handlers_1.evaluateLogin)(cond, ctx);
|
|
40
|
+
case 'social': return (0, handlers_1.evaluateSocial)(cond, ctx);
|
|
41
|
+
case 'linkedCompletions': return (0, handlers_1.evaluateLinkedCompletions)(cond, ctx);
|
|
42
|
+
case 'dynamicTracker': return (0, handlers_1.evaluateDynamicTracker)(cond, ctx);
|
|
43
|
+
case 'contractInteraction': return (0, handlers_1.evaluateContractInteraction)(cond, ctx);
|
|
44
|
+
// base kinds handled by evaluateBaseCondition
|
|
45
|
+
case 'level':
|
|
46
|
+
case 'currency':
|
|
47
|
+
case 'stakedTokens':
|
|
48
|
+
case 'trustScore':
|
|
49
|
+
case 'daysInGame':
|
|
50
|
+
case 'loginStreak':
|
|
51
|
+
case 'achievement':
|
|
52
|
+
case 'membership':
|
|
53
|
+
case 'quest':
|
|
54
|
+
case 'entityLink':
|
|
55
|
+
case 'dynamic':
|
|
56
|
+
case 'identifiers':
|
|
57
|
+
case 'tokenBalance':
|
|
58
|
+
case 'stackedAccount':
|
|
59
|
+
case 'userSettings':
|
|
60
|
+
case 'nested':
|
|
61
|
+
return undefined;
|
|
62
|
+
default: {
|
|
63
|
+
const _ = cond;
|
|
64
|
+
return undefined;
|
|
65
|
+
} // trick to refuse to compile if we don't handle a new condition kind
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const meetsBaseConditions = ({ conditions, playerSnap, addDetails, playerOffer, additionalData, }) => {
|
|
69
|
+
const conditionData = [];
|
|
70
|
+
let isValid = true;
|
|
71
|
+
const ctx = {
|
|
72
|
+
snap: playerSnap,
|
|
73
|
+
additionalData,
|
|
74
|
+
offerTrackers: playerOffer?.trackers,
|
|
75
|
+
claimMultiplier: 1,
|
|
76
|
+
shouldScale: false,
|
|
77
|
+
};
|
|
78
|
+
for (const cond of conditions) {
|
|
79
|
+
if (cond.kind === 'nested')
|
|
80
|
+
continue; // handled separately if needed
|
|
81
|
+
const result = evaluateBaseCondition(cond, ctx);
|
|
82
|
+
if (!result)
|
|
83
|
+
continue; // not a base kind, skip
|
|
84
|
+
if (addDetails) {
|
|
85
|
+
conditionData.push(...result.details);
|
|
86
|
+
if (!result.isMet)
|
|
87
|
+
isValid = false;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
if (!result.isMet)
|
|
91
|
+
return { isValid: false, isComplete: false, percentCompleted: 0 };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const percentCompleted = conditionData.length > 0
|
|
95
|
+
? conditionData.reduce((sum, c) => sum + c.percentCompleted, 0) / conditionData.length
|
|
96
|
+
: isValid ? 100 : 0;
|
|
97
|
+
return {
|
|
98
|
+
isValid,
|
|
99
|
+
isComplete: isValid,
|
|
100
|
+
percentCompleted,
|
|
101
|
+
conditionData: addDetails ? conditionData : undefined,
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
exports.meetsBaseConditions = meetsBaseConditions;
|
|
105
|
+
const hasCompletionConditions = (conditions) => {
|
|
106
|
+
return !!conditions && conditions.length > 0;
|
|
107
|
+
};
|
|
108
|
+
exports.hasCompletionConditions = hasCompletionConditions;
|
|
109
|
+
const meetsLinkedEntityOffersCondition = ({ linkedEntityOffers, matchingLinks, linkedPOfferMap, }) => {
|
|
110
|
+
if (!linkedPOfferMap)
|
|
111
|
+
return { isValid: false };
|
|
112
|
+
const linkedPlayerOffer_ids = [];
|
|
113
|
+
const targetOfferId = linkedEntityOffers.offerId || linkedEntityOffers.offer_id;
|
|
114
|
+
for (const link of matchingLinks) {
|
|
115
|
+
const key = `${link.playerId}:${targetOfferId}`;
|
|
116
|
+
const po = linkedPOfferMap.get(key);
|
|
117
|
+
if (po) {
|
|
118
|
+
linkedPlayerOffer_ids.push(po.instanceId.toString());
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (linkedPlayerOffer_ids.length > 0) {
|
|
122
|
+
return { isValid: true, linkedPlayerOffer_ids };
|
|
123
|
+
}
|
|
124
|
+
return { isValid: false };
|
|
125
|
+
};
|
|
126
|
+
exports.meetsLinkedEntityOffersCondition = meetsLinkedEntityOffersCondition;
|
|
127
|
+
const offerMeetsCompletionConditions = (offer, snapshot, additionalData) => {
|
|
128
|
+
return (0, exports.meetsCompletionConditions)({
|
|
129
|
+
completionConditions: offer.completionConditions || [],
|
|
130
|
+
completionTrackers: offer.completionTrackers,
|
|
131
|
+
playerSnap: snapshot,
|
|
132
|
+
playerOffer: offer,
|
|
133
|
+
addDetails: true,
|
|
134
|
+
maxClaimCount: offer.maxClaimCount,
|
|
135
|
+
additionalData,
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
exports.offerMeetsCompletionConditions = offerMeetsCompletionConditions;
|
|
139
|
+
const meetsCompletionConditions = ({ completionConditions, completionTrackers, playerSnap, playerOffer, addDetails = false, maxClaimCount, additionalData, }) => {
|
|
140
|
+
if (!completionConditions?.length) {
|
|
141
|
+
return { isValid: true, isComplete: true, percentCompleted: 100, conditionData: [], availableClaimsNow: -1 };
|
|
142
|
+
}
|
|
143
|
+
const shouldScale = maxClaimCount === -1 || (maxClaimCount != null && maxClaimCount > 1);
|
|
144
|
+
const claimMultiplier = shouldScale ? (playerOffer.trackers?.claimedCount || 0) + 1 : 1;
|
|
145
|
+
const conditionData = [];
|
|
146
|
+
let isValid = true;
|
|
147
|
+
let maxTotalClaimsFromScaling = Infinity;
|
|
148
|
+
const updateMax = (limit) => { maxTotalClaimsFromScaling = Math.min(maxTotalClaimsFromScaling, limit); };
|
|
149
|
+
const ctx = {
|
|
150
|
+
snap: playerSnap,
|
|
151
|
+
additionalData,
|
|
152
|
+
offerTrackers: playerOffer?.trackers,
|
|
153
|
+
completionTrackers,
|
|
154
|
+
claimMultiplier,
|
|
155
|
+
shouldScale,
|
|
156
|
+
offerCreatedAt: playerOffer?.createdAt,
|
|
157
|
+
};
|
|
158
|
+
for (const cond of completionConditions) {
|
|
159
|
+
if (cond.kind === 'nested')
|
|
160
|
+
continue; // TODO: handle nested
|
|
161
|
+
// Try completion-only handler first, then base handler
|
|
162
|
+
let result = evaluateCompletionOnlyCondition(cond, ctx);
|
|
163
|
+
if (!result)
|
|
164
|
+
result = evaluateBaseCondition(cond, ctx);
|
|
165
|
+
if (!result)
|
|
166
|
+
continue; // unknown kind
|
|
167
|
+
if (result.maxClaims !== undefined)
|
|
168
|
+
updateMax(result.maxClaims);
|
|
169
|
+
if (addDetails) {
|
|
170
|
+
conditionData.push(...result.details);
|
|
171
|
+
if (!result.isMet)
|
|
172
|
+
isValid = false;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
if (!result.isMet)
|
|
176
|
+
return { isValid: false, isComplete: false, percentCompleted: 0, availableClaimsNow: 0 };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (maxClaimCount && maxClaimCount > 0)
|
|
180
|
+
updateMax(maxClaimCount);
|
|
181
|
+
const claimedCount = playerOffer?.trackers?.claimedCount || 0;
|
|
182
|
+
const availableClaimsNow = !isValid
|
|
183
|
+
? 0
|
|
184
|
+
: maxTotalClaimsFromScaling === Infinity
|
|
185
|
+
? -1
|
|
186
|
+
: Math.max(0, maxTotalClaimsFromScaling - claimedCount);
|
|
187
|
+
const percentCompleted = conditionData.length > 0
|
|
188
|
+
? conditionData.reduce((sum, c) => sum + c.percentCompleted, 0) / conditionData.length
|
|
189
|
+
: isValid ? 100 : 0;
|
|
190
|
+
return {
|
|
191
|
+
isValid,
|
|
192
|
+
isComplete: isValid,
|
|
193
|
+
percentCompleted,
|
|
194
|
+
conditionData,
|
|
195
|
+
availableClaimsNow,
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
exports.meetsCompletionConditions = meetsCompletionConditions;
|
|
199
|
+
const meetsCompletionConditionsBeforeExpiry = ({ completionConditions, completionTrackers, playerSnap, playerOffer, maxClaimCount, }) => {
|
|
200
|
+
if (!completionConditions)
|
|
201
|
+
return false;
|
|
202
|
+
if (!(0, exports.hasCompletionConditions)(completionConditions))
|
|
203
|
+
return false;
|
|
204
|
+
const conditionsMet = (0, exports.meetsCompletionConditions)({
|
|
205
|
+
completionConditions,
|
|
206
|
+
completionTrackers,
|
|
207
|
+
playerOffer,
|
|
208
|
+
playerSnap,
|
|
209
|
+
maxClaimCount,
|
|
210
|
+
});
|
|
211
|
+
if (!conditionsMet.isValid)
|
|
212
|
+
return false;
|
|
213
|
+
if (!playerOffer.expiresAt)
|
|
214
|
+
return true;
|
|
215
|
+
const expiryTime = new Date(playerOffer.expiresAt).getTime();
|
|
216
|
+
const lastSnapshotUpdate = new Date(playerSnap.snapshotLastUpdated ?? new Date()).getTime();
|
|
217
|
+
function wasUpdatedAfterExpiry(data) {
|
|
218
|
+
let lastUpdated;
|
|
219
|
+
if (typeof data === 'object' && data !== null && !(data instanceof Date)) {
|
|
220
|
+
lastUpdated = data.lastUpdated ? new Date(data.lastUpdated).getTime() : lastSnapshotUpdate;
|
|
221
|
+
}
|
|
222
|
+
else if (data instanceof Date) {
|
|
223
|
+
lastUpdated = data.getTime();
|
|
224
|
+
}
|
|
225
|
+
else if (typeof data === 'string' || typeof data === 'number') {
|
|
226
|
+
lastUpdated = new Date(data).getTime();
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
lastUpdated = lastSnapshotUpdate;
|
|
230
|
+
}
|
|
231
|
+
return lastUpdated >= expiryTime;
|
|
232
|
+
}
|
|
233
|
+
for (const cond of completionConditions) {
|
|
234
|
+
switch (cond.kind) {
|
|
235
|
+
case 'currency':
|
|
236
|
+
if (playerSnap.currencies?.[cond.id] && wasUpdatedAfterExpiry(playerSnap.currencies[cond.id]))
|
|
237
|
+
return false;
|
|
238
|
+
break;
|
|
239
|
+
case 'level':
|
|
240
|
+
if (playerSnap.levels?.[cond.id] && wasUpdatedAfterExpiry(playerSnap.levels[cond.id]))
|
|
241
|
+
return false;
|
|
242
|
+
break;
|
|
243
|
+
case 'quest':
|
|
244
|
+
if (playerSnap.quests?.[cond.id] && wasUpdatedAfterExpiry(playerSnap.quests[cond.id]))
|
|
245
|
+
return false;
|
|
246
|
+
break;
|
|
247
|
+
case 'membership':
|
|
248
|
+
if (playerSnap.memberships?.[cond.id] && wasUpdatedAfterExpiry(playerSnap.memberships[cond.id]))
|
|
249
|
+
return false;
|
|
250
|
+
break;
|
|
251
|
+
case 'achievement':
|
|
252
|
+
if (playerSnap.achievements?.[cond.id] && wasUpdatedAfterExpiry(playerSnap.achievements[cond.id]))
|
|
253
|
+
return false;
|
|
254
|
+
break;
|
|
255
|
+
case 'stakedTokens': {
|
|
256
|
+
const stakedToken = playerSnap.stakedTokens?.[cond.id];
|
|
257
|
+
if (stakedToken) {
|
|
258
|
+
const lastStakeTime = new Date(stakedToken.lastStake ?? 0).getTime();
|
|
259
|
+
const lastUnstakeTime = new Date(stakedToken.lastUnstake ?? 0).getTime();
|
|
260
|
+
if (Math.max(lastStakeTime, lastUnstakeTime) >= expiryTime)
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
case 'trustScore':
|
|
266
|
+
if (wasUpdatedAfterExpiry(playerSnap.trustLastUpdated))
|
|
267
|
+
return false;
|
|
268
|
+
break;
|
|
269
|
+
case 'daysInGame':
|
|
270
|
+
if (cond.min != null && wasUpdatedAfterExpiry(playerSnap.daysInGameLastUpdated))
|
|
271
|
+
return false;
|
|
272
|
+
break;
|
|
273
|
+
case 'login':
|
|
274
|
+
case 'loginStreak':
|
|
275
|
+
if (wasUpdatedAfterExpiry())
|
|
276
|
+
return false;
|
|
277
|
+
break;
|
|
278
|
+
case 'dynamic':
|
|
279
|
+
if (cond.conditions?.length && wasUpdatedAfterExpiry())
|
|
280
|
+
return false;
|
|
281
|
+
break;
|
|
282
|
+
case 'identifiers':
|
|
283
|
+
if (cond.platforms?.length && wasUpdatedAfterExpiry())
|
|
284
|
+
return false;
|
|
285
|
+
break;
|
|
286
|
+
case 'social':
|
|
287
|
+
if (completionTrackers?.social?.lastChecked) {
|
|
288
|
+
if (wasUpdatedAfterExpiry(completionTrackers.social.lastChecked))
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
break;
|
|
292
|
+
case 'buyItem':
|
|
293
|
+
case 'spendCurrency':
|
|
294
|
+
case 'depositCurrency':
|
|
295
|
+
case 'completionContext':
|
|
296
|
+
case 'linkedCompletions':
|
|
297
|
+
case 'contractInteraction':
|
|
298
|
+
if (completionTrackers?.lastUpdated != null && wasUpdatedAfterExpiry(completionTrackers.lastUpdated)) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
break;
|
|
302
|
+
case 'dynamicTracker':
|
|
303
|
+
if (completionTrackers?.lastUpdated != null) {
|
|
304
|
+
for (const dc of cond.conditions) {
|
|
305
|
+
const perKeyTs = completionTrackers.dynamicTracker?.[dc.key]?.lastUpdated;
|
|
306
|
+
if (wasUpdatedAfterExpiry(perKeyTs ?? completionTrackers.lastUpdated))
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return true;
|
|
314
|
+
};
|
|
315
|
+
exports.meetsCompletionConditionsBeforeExpiry = meetsCompletionConditionsBeforeExpiry;
|
|
316
|
+
function meetsClaimableConditions({ claimableConditions, playerOfferTrackers, claimableTrackers, }) {
|
|
317
|
+
if (!claimableConditions?.length)
|
|
318
|
+
return { isValid: true };
|
|
319
|
+
for (const cond of claimableConditions) {
|
|
320
|
+
switch (cond.kind) {
|
|
321
|
+
case 'siblingCompletions': {
|
|
322
|
+
if (!cond.count)
|
|
323
|
+
break;
|
|
324
|
+
const siblingCount = playerOfferTrackers?.siblingPlayerOffer_ids?.length ?? 0;
|
|
325
|
+
let completedCount = claimableTrackers?.siblingCompletions ?? 0;
|
|
326
|
+
if (completedCount === -1)
|
|
327
|
+
completedCount = siblingCount;
|
|
328
|
+
if (siblingCount > 0 && completedCount < siblingCount) {
|
|
329
|
+
return { isValid: false };
|
|
330
|
+
}
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
// default: { const _: never = cond; break; } // trick to refuse to compile if we don't handle a new condition kind (when more cases)
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return { isValid: true };
|
|
337
|
+
}
|
|
338
|
+
//# sourceMappingURL=index.js.map
|
package/dist/dynamic.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const dynamicTrackerToPrimitive: (dynaTrack: Record<string,
|
|
1
|
+
import { ICompletionDynamicTracker } from '@stackedapp/types';
|
|
2
|
+
export declare const dynamicTrackerToPrimitive: (dynaTrack: Record<string, ICompletionDynamicTracker>) => Record<string, string | number | boolean>;
|
|
3
3
|
//# sourceMappingURL=dynamic.d.ts.map
|
package/dist/template.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IDynamicCondition } from '@stackedapp/types';
|
|
2
2
|
export declare function extractTemplateKeys(template: string | undefined): Set<string>;
|
|
3
3
|
/**
|
|
4
4
|
* This replaces {keyName} keys from the template with corresponding values from the dynamic object.
|
|
@@ -12,7 +12,7 @@ export declare function renderTemplate(template: string | undefined, dynamic: Re
|
|
|
12
12
|
*/
|
|
13
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<
|
|
15
|
+
export declare function replaceDynamicConditionKeys(conditions: Array<IDynamicCondition>, trackers: Record<string, any> | undefined): {
|
|
16
16
|
key: string;
|
|
17
17
|
compareTo: string | number | boolean;
|
|
18
18
|
operator: "==" | "!=" | ">" | ">=" | "<" | "<=" | "has" | "not_has" | "is_truthy" | "is_falsy" | "is_defined";
|
package/package.json
CHANGED
package/dist/conditions.d.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { StackedCompletionConditions, StackedOffer, StackedSnapshot, StackedBaseUserExtra, StackedBaseConditions, StackedClaimableConditions, StackedClaimableTrackers, StackedCompletionTrackers, StackedDynamicCondition, StackedDynamicGroup, StackedOfferTrackers, ConditionDetail } from '@stackedapp/types';
|
|
2
|
-
export declare const DEFAULT_ENTITY_KIND = "_default";
|
|
3
|
-
export declare const meetsBaseConditions: ({ conditions, playerSnap, addDetails, playerOffer, additionalData, }: {
|
|
4
|
-
conditions: StackedBaseConditions;
|
|
5
|
-
playerSnap: StackedSnapshot;
|
|
6
|
-
addDetails?: boolean;
|
|
7
|
-
playerOffer?: {
|
|
8
|
-
createdAt?: Date | number;
|
|
9
|
-
claimedCount?: number;
|
|
10
|
-
trackers?: Record<string, any>;
|
|
11
|
-
};
|
|
12
|
-
additionalData?: StackedBaseUserExtra;
|
|
13
|
-
}) => {
|
|
14
|
-
isValid: boolean;
|
|
15
|
-
isComplete: boolean;
|
|
16
|
-
percentCompleted: number;
|
|
17
|
-
conditionData?: undefined;
|
|
18
|
-
} | {
|
|
19
|
-
/** @deprecated Use isComplete instead */
|
|
20
|
-
isValid: boolean;
|
|
21
|
-
isComplete: boolean;
|
|
22
|
-
percentCompleted: number;
|
|
23
|
-
conditionData: ConditionDetail[] | undefined;
|
|
24
|
-
};
|
|
25
|
-
export declare const hasCompletionConditions: (conditions: StackedCompletionConditions) => boolean;
|
|
26
|
-
export declare const meetsLinkedEntityOffersCondition: ({ linkedEntityOffers, matchingLinks, linkedPOfferMap, }: {
|
|
27
|
-
linkedEntityOffers: {
|
|
28
|
-
kind?: string;
|
|
29
|
-
offer_id?: string;
|
|
30
|
-
link?: boolean;
|
|
31
|
-
};
|
|
32
|
-
matchingLinks: Array<{
|
|
33
|
-
playerId: string;
|
|
34
|
-
kind?: string;
|
|
35
|
-
}>;
|
|
36
|
-
linkedPOfferMap: Map<string, StackedOffer>;
|
|
37
|
-
}) => {
|
|
38
|
-
isValid: boolean;
|
|
39
|
-
linkedPlayerOffer_ids?: string[];
|
|
40
|
-
};
|
|
41
|
-
export declare const offerMeetsCompletionConditions: (offer: StackedOffer, snapshot: StackedSnapshot, additionalData?: StackedBaseUserExtra) => {
|
|
42
|
-
isValid: boolean;
|
|
43
|
-
isComplete: boolean;
|
|
44
|
-
percentCompleted: number;
|
|
45
|
-
availableClaimsNow: number;
|
|
46
|
-
conditionData?: undefined;
|
|
47
|
-
} | {
|
|
48
|
-
/** @deprecated Use isComplete instead */
|
|
49
|
-
isValid: boolean;
|
|
50
|
-
isComplete: boolean;
|
|
51
|
-
percentCompleted: number;
|
|
52
|
-
conditionData: ConditionDetail[];
|
|
53
|
-
availableClaimsNow: number;
|
|
54
|
-
};
|
|
55
|
-
export declare const meetsCompletionConditions: ({ completionConditions, completionTrackers, playerSnap, playerOffer, addDetails, maxClaimCount, additionalData, }: {
|
|
56
|
-
completionConditions: StackedCompletionConditions;
|
|
57
|
-
completionTrackers?: StackedCompletionTrackers;
|
|
58
|
-
playerSnap: StackedSnapshot;
|
|
59
|
-
playerOffer: {
|
|
60
|
-
createdAt?: Date | number;
|
|
61
|
-
trackers?: StackedOfferTrackers;
|
|
62
|
-
};
|
|
63
|
-
addDetails?: boolean;
|
|
64
|
-
maxClaimCount?: number;
|
|
65
|
-
additionalData?: StackedBaseUserExtra;
|
|
66
|
-
}) => {
|
|
67
|
-
isValid: boolean;
|
|
68
|
-
isComplete: boolean;
|
|
69
|
-
percentCompleted: number;
|
|
70
|
-
availableClaimsNow: number;
|
|
71
|
-
conditionData?: undefined;
|
|
72
|
-
} | {
|
|
73
|
-
/** @deprecated Use isComplete instead */
|
|
74
|
-
isValid: boolean;
|
|
75
|
-
isComplete: boolean;
|
|
76
|
-
percentCompleted: number;
|
|
77
|
-
conditionData: ConditionDetail[];
|
|
78
|
-
availableClaimsNow: number;
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* Checks if completion conditions were met before a specific expiry time.
|
|
82
|
-
* Returns true if all relevant condition fields were updated before expiryTime.
|
|
83
|
-
*
|
|
84
|
-
* @param completionConditions - The completion conditions to check
|
|
85
|
-
* @param completionTrackers - The completion trackers (for buyItem, spendCurrency, etc.)
|
|
86
|
-
* @param playerSnap - The player snapshot with field timestamps
|
|
87
|
-
* @returns true if all conditions were met before expiry, false otherwise
|
|
88
|
-
*/
|
|
89
|
-
export declare const meetsCompletionConditionsBeforeExpiry: ({ completionConditions, completionTrackers, playerSnap, playerOffer, maxClaimCount, }: {
|
|
90
|
-
completionConditions: StackedCompletionConditions;
|
|
91
|
-
completionTrackers?: StackedCompletionTrackers;
|
|
92
|
-
playerSnap: StackedSnapshot;
|
|
93
|
-
playerOffer: {
|
|
94
|
-
createdAt?: Date | number;
|
|
95
|
-
claimedCount?: number;
|
|
96
|
-
trackers?: Record<string, any>;
|
|
97
|
-
expiresAt?: Date | number | string;
|
|
98
|
-
};
|
|
99
|
-
maxClaimCount?: number;
|
|
100
|
-
}) => boolean;
|
|
101
|
-
/**
|
|
102
|
-
* Calculates the maximum number of claims supported by a single dynamic condition.
|
|
103
|
-
*/
|
|
104
|
-
export declare function getMaxClaimsForDynamicCondition(dynamicObj: Record<string, string | number | boolean>, cond: StackedDynamicCondition): number;
|
|
105
|
-
/**
|
|
106
|
-
* Calculates the maximum number of claims supported by a group of dynamic conditions.
|
|
107
|
-
*/
|
|
108
|
-
export declare function getMaxClaimsForDynamicGroup(dynamicObj: Record<string, string | number | boolean>, dynamicGroup: StackedDynamicGroup, currentClaimCount?: number): number;
|
|
109
|
-
/**
|
|
110
|
-
* Evaluates a group of dynamic conditions with logical links (AND, OR, AND NOT).
|
|
111
|
-
* @param dynamicObj - The player's dynamic object with any key and string or number value.
|
|
112
|
-
* @param dynamicGroup - The group of conditions and links to check.
|
|
113
|
-
* @param claimMultiplier - Multiplier to scale conditions (used for numeric comparisons).
|
|
114
|
-
* @returns true if the group evaluates to true, false otherwise.
|
|
115
|
-
*/
|
|
116
|
-
export declare function meetsDynamicConditions(dynamicObj: Record<string, string | number | boolean> | undefined | null, dynamicGroup: StackedDynamicGroup, claimMultiplier?: number): boolean;
|
|
117
|
-
/**
|
|
118
|
-
* Checks if a PlayerOffer meets its claimable conditions (completed -> claimable transition).
|
|
119
|
-
* @param claimableConditions - The offer's claimableConditions (from IOffer)
|
|
120
|
-
* @param claimableTrackers - The player offer's claimableTrackers
|
|
121
|
-
*/
|
|
122
|
-
export declare function meetsClaimableConditions({ claimableConditions, playerOfferTrackers, claimableTrackers, }: {
|
|
123
|
-
claimableConditions?: StackedClaimableConditions;
|
|
124
|
-
playerOfferTrackers?: StackedOfferTrackers;
|
|
125
|
-
claimableTrackers?: StackedClaimableTrackers;
|
|
126
|
-
}): {
|
|
127
|
-
isValid: boolean;
|
|
128
|
-
};
|
|
129
|
-
export declare function aggregateTokenBalances(data?: StackedBaseUserExtra): Record<string, number>;
|
|
130
|
-
//# sourceMappingURL=conditions.d.ts.map
|