@smartico/public-api 0.0.322 → 0.0.323
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/Missions/BadgesTimeLimitStates.d.ts +14 -0
- package/dist/Missions/MissionsUtils.d.ts +2 -0
- package/dist/Missions/UserAchievement.d.ts +3 -0
- package/dist/Missions/index.d.ts +2 -0
- package/dist/SmarticoLib/index.d.ts +2 -0
- package/dist/WSAPI/WSAPITypes.d.ts +3 -1
- package/dist/index.js +60 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +62 -2
- package/dist/index.modern.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Missions/BadgesTimeLimitStates.ts +15 -0
- package/src/Missions/MissionsUtils.ts +38 -0
- package/src/Missions/UserAchievement.ts +12 -0
- package/src/Missions/index.ts +3 -1
- package/src/SmarticoAPI.ts +2 -0
- package/src/SmarticoLib/index.ts +3 -0
- package/src/WSAPI/WSAPITypes.ts +4 -1
package/package.json
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export enum BadgesTimeLimitStates {
|
|
2
|
+
/** Before Start Date */
|
|
3
|
+
BeforeStartDate = 0,
|
|
4
|
+
/** After Start Date but before earned */
|
|
5
|
+
AfterStartDateNoProgress = 1,
|
|
6
|
+
/** After Start Date but before started (no progress) + End date */
|
|
7
|
+
AfterStartDateNoProgressAndEndDate = 2,
|
|
8
|
+
/** After Start Date, but with some progress + End date */
|
|
9
|
+
AfterStartDateWithProgressAndEndDate = 3,
|
|
10
|
+
/** After End Date (not started) */
|
|
11
|
+
AfterEndDateNotStarted = 4,
|
|
12
|
+
/** After End Date (player has some progress, but not completed) */
|
|
13
|
+
AfterEndDateWithProgress = 5,
|
|
14
|
+
}
|
|
15
|
+
|
|
@@ -3,6 +3,7 @@ import { AchievementAvailabilityStatus } from "./AchievementAvailabilityStatus";
|
|
|
3
3
|
import { AchievementStatus } from "./AchievementStatus";
|
|
4
4
|
import { UserAchievement } from "./UserAchievement";
|
|
5
5
|
import { UserAchievementTask } from "./UserAchievementTask";
|
|
6
|
+
import { BadgesTimeLimitStates } from "./BadgesTimeLimitStates";
|
|
6
7
|
|
|
7
8
|
export class MissionUtils {
|
|
8
9
|
|
|
@@ -246,4 +247,41 @@ export class MissionUtils {
|
|
|
246
247
|
|
|
247
248
|
return task;
|
|
248
249
|
}
|
|
250
|
+
|
|
251
|
+
public static determineBadgeState = (badge: UserAchievement): BadgesTimeLimitStates => {
|
|
252
|
+
const now = Date.now();
|
|
253
|
+
const { active_from_ts, active_till_ts, progress } = badge;
|
|
254
|
+
|
|
255
|
+
// 1. BEFORE START
|
|
256
|
+
if (active_from_ts > now) {
|
|
257
|
+
return BadgesTimeLimitStates.BeforeStartDate;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// 2. AFTER START, NO END DATE (infinite badge)
|
|
261
|
+
// → grey, no locked, no date chip
|
|
262
|
+
if (!active_till_ts) {
|
|
263
|
+
if (progress === 0) {
|
|
264
|
+
return BadgesTimeLimitStates.AfterStartDateNoProgress;
|
|
265
|
+
}
|
|
266
|
+
// If infinite and with progress → this state does not exist in enum
|
|
267
|
+
// (but if needed we can add one)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// 3. AFTER START, BEFORE END DATE
|
|
271
|
+
if (now < active_till_ts) {
|
|
272
|
+
if (progress === 0) {
|
|
273
|
+
// now < end + has end date → must show chip
|
|
274
|
+
return BadgesTimeLimitStates.AfterStartDateNoProgressAndEndDate;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return BadgesTimeLimitStates.AfterStartDateWithProgressAndEndDate;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// 4. AFTER END DATE
|
|
281
|
+
if (progress === 0) {
|
|
282
|
+
return BadgesTimeLimitStates.AfterEndDateNotStarted;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return BadgesTimeLimitStates.AfterEndDateWithProgress;
|
|
286
|
+
}
|
|
249
287
|
}
|
|
@@ -8,6 +8,7 @@ import { AchievementType } from './AchievementType';
|
|
|
8
8
|
import { MissionUtils } from './MissionsUtils';
|
|
9
9
|
import { ScheduledMissionType } from './ScheduledMissionType';
|
|
10
10
|
import { UserAchievementTask } from './UserAchievementTask';
|
|
11
|
+
import { BadgesTimeLimitStates } from './BadgesTimeLimitStates';
|
|
11
12
|
|
|
12
13
|
export interface UserAchievement {
|
|
13
14
|
ach_id?: number;
|
|
@@ -45,8 +46,18 @@ export interface UserAchievement {
|
|
|
45
46
|
completed_this_week?: boolean;
|
|
46
47
|
completed_this_month?: boolean;
|
|
47
48
|
custom_section_type_id?: number;
|
|
49
|
+
badgeTimeLimitState?: BadgesTimeLimitStates;
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
export const enrichUserAchievementsWithBadgeState = (items: UserAchievement[]): UserAchievement[] => {
|
|
53
|
+
return items.map((item) => {
|
|
54
|
+
if (item.ach_type_id === AchievementType.Badge && (item.active_from_ts || item.active_till_ts)) {
|
|
55
|
+
item.badgeTimeLimitState = MissionUtils.determineBadgeState(item);
|
|
56
|
+
}
|
|
57
|
+
return item;
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
50
61
|
export const UserAchievementTransform = (items: UserAchievement[]): TMissionOrBadge[] => {
|
|
51
62
|
return items
|
|
52
63
|
.filter((r) => r.ach_id >= 1)
|
|
@@ -142,6 +153,7 @@ export const UserAchievementTransform = (items: UserAchievement[]): TMissionOrBa
|
|
|
142
153
|
availability_status: MissionUtils.getAvailabilityStatus(r),
|
|
143
154
|
claim_button_title: r.ach_public_meta.claim_button_title,
|
|
144
155
|
claim_button_action: r.ach_public_meta.claim_button_action,
|
|
156
|
+
badgeTimeLimitState: r.badgeTimeLimitState,
|
|
145
157
|
};
|
|
146
158
|
|
|
147
159
|
if (r.ach_status_id === AchievementStatus.Recurring) {
|
package/src/Missions/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from './GetAchievementMapRequest';
|
|
|
9
9
|
export * from './GetAchievementMapResponse';
|
|
10
10
|
export * from './ReloadAchievementsEvent';
|
|
11
11
|
export * from './UserAchievement';
|
|
12
|
+
export { enrichUserAchievementsWithBadgeState } from './UserAchievement';
|
|
12
13
|
export * from './UserAchievementTask';
|
|
13
14
|
export * from './ScheduledMissionType';
|
|
14
15
|
export * from './AchCategoryPublicMeta';
|
|
@@ -21,4 +22,5 @@ export * from './AchievementAvailabilityStatus';
|
|
|
21
22
|
export * from './GetRelatedAchTourResponse';
|
|
22
23
|
export * from './MissionsUtils';
|
|
23
24
|
export * from './MissionCategory';
|
|
24
|
-
export * from './UserAchievementTaskAffectsProgress'
|
|
25
|
+
export * from './UserAchievementTaskAffectsProgress';
|
|
26
|
+
export * from './BadgesTimeLimitStates';
|
package/src/SmarticoAPI.ts
CHANGED
|
@@ -64,6 +64,7 @@ import {
|
|
|
64
64
|
GetAchievementMapRequest,
|
|
65
65
|
GetAchievementMapResponse,
|
|
66
66
|
UserAchievementTransform,
|
|
67
|
+
enrichUserAchievementsWithBadgeState,
|
|
67
68
|
} from './Missions';
|
|
68
69
|
import {
|
|
69
70
|
GetTournamentInfoRequest,
|
|
@@ -878,6 +879,7 @@ class SmarticoAPI {
|
|
|
878
879
|
|
|
879
880
|
if (responseClone.achievements) {
|
|
880
881
|
responseClone.achievements = responseClone.achievements.filter((a) => a.ach_type_id === AchievementType.Badge);
|
|
882
|
+
responseClone.achievements = enrichUserAchievementsWithBadgeState(responseClone.achievements);
|
|
881
883
|
}
|
|
882
884
|
return responseClone;
|
|
883
885
|
}
|
package/src/SmarticoLib/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
+
import { BadgesTimeLimitStates } from "src/Missions";
|
|
4
|
+
|
|
3
5
|
declare enum CJMActivityType {
|
|
4
6
|
Root = 0,
|
|
5
7
|
Journey_Started = 1,
|
|
@@ -1561,6 +1563,7 @@ export interface UserAchievement {
|
|
|
1561
1563
|
completed_this_week?: boolean;
|
|
1562
1564
|
completed_this_month?: boolean;
|
|
1563
1565
|
custom_section_type_id?: number;
|
|
1566
|
+
badgeTimeLimitState?: BadgesTimeLimitStates;
|
|
1564
1567
|
}
|
|
1565
1568
|
export interface GetAchievementMapResponse extends ProtocolResponse {
|
|
1566
1569
|
achievements?: UserAchievement[];
|
package/src/WSAPI/WSAPITypes.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BuyStoreItemErrorCode } from '../Store';
|
|
2
2
|
import { MiniGamePrizeTypeName, SAWAcknowledgeTypeName, SAWAskForUsername, SAWBuyInTypeName, SAWGameLayout, SAWGameTypeName, SAWSpinErrorCode, SAWTemplate, SAWTemplateUI } from '../MiniGames';
|
|
3
3
|
import { TournamentRegistrationError, TournamentRegistrationStatusName, TournamentRegistrationTypeName } from '../Tournaments';
|
|
4
|
-
import { AchievementAvailabilityStatus } from '../Missions';
|
|
4
|
+
import { AchievementAvailabilityStatus, BadgesTimeLimitStates } from '../Missions';
|
|
5
5
|
import { LeaderBoardPeriodType } from '../Leaderboard';
|
|
6
6
|
import { AchCustomLayoutTheme, AchCustomSectionType, AchMissionsTabsOptions, AchOverviewMissionsFilter, LiquidEntityData } from '../CustomSections';
|
|
7
7
|
import { PrizeModifiers } from '../MiniGames/PrizeModifiers';
|
|
@@ -677,6 +677,9 @@ export interface TMissionOrBadge {
|
|
|
677
677
|
|
|
678
678
|
/** Action for the claim reward button */
|
|
679
679
|
claim_button_action?: string;
|
|
680
|
+
|
|
681
|
+
/** Badge time limit state for badges with time restrictions */
|
|
682
|
+
badgeTimeLimitState?: BadgesTimeLimitStates;
|
|
680
683
|
}
|
|
681
684
|
|
|
682
685
|
export interface AchRelatedGame {
|