@sparted/shared-library 1.7.34 → 1.7.36
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 type { Content } from './content';
|
|
1
|
+
import type { Content, GameType } from './content';
|
|
2
2
|
import type { Image } from './media';
|
|
3
3
|
import type { MultilingualLabel } from './multilingual';
|
|
4
4
|
import type { Points } from './score';
|
|
@@ -33,12 +33,15 @@ export type Campaign = {
|
|
|
33
33
|
scheduling: CampaignScheduling;
|
|
34
34
|
type: 'campaign';
|
|
35
35
|
};
|
|
36
|
-
export type
|
|
36
|
+
export type BaseCampaignCardDetails = {
|
|
37
37
|
id: number;
|
|
38
38
|
coverImage: string;
|
|
39
39
|
title: MultilingualLabel;
|
|
40
|
+
description: MultilingualLabel;
|
|
40
41
|
utcStartDate: string;
|
|
41
42
|
utcEndDate: string;
|
|
43
|
+
};
|
|
44
|
+
export type WikiCardDetails = BaseCampaignCardDetails & {
|
|
42
45
|
contentCount: number;
|
|
43
46
|
};
|
|
44
47
|
export type WikiCardPlayerInteraction = {
|
|
@@ -46,7 +49,7 @@ export type WikiCardPlayerInteraction = {
|
|
|
46
49
|
favorite: boolean;
|
|
47
50
|
};
|
|
48
51
|
export type WikiCard = {
|
|
49
|
-
|
|
52
|
+
details: WikiCardDetails;
|
|
50
53
|
playerInteraction: WikiCardPlayerInteraction;
|
|
51
54
|
};
|
|
52
55
|
export type WikiContentCardDetails = {
|
|
@@ -59,20 +62,28 @@ export type WikiContentCard = {
|
|
|
59
62
|
contentDetails: WikiContentCardDetails;
|
|
60
63
|
points: Points;
|
|
61
64
|
};
|
|
65
|
+
export type CampaignCardScheduling = {
|
|
66
|
+
type: 'flexible' | 'intense';
|
|
67
|
+
extraDays: number;
|
|
68
|
+
enabledWeekDays: number[];
|
|
69
|
+
disabledDates: string[];
|
|
70
|
+
sessionCount: number;
|
|
71
|
+
};
|
|
72
|
+
export type LiveCampaignCardDetails = BaseCampaignCardDetails & CampaignCardScheduling;
|
|
62
73
|
export type CampaignCardAchievement = {
|
|
63
|
-
|
|
64
|
-
playable: boolean;
|
|
74
|
+
lastSessionPlayed: number;
|
|
65
75
|
points: Points;
|
|
66
76
|
};
|
|
67
77
|
export type SessionInsight = {
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
sessionNumber: number;
|
|
79
|
+
gameTypes: GameType[];
|
|
70
80
|
};
|
|
71
81
|
export type LiveCampaignCard = {
|
|
72
|
-
|
|
82
|
+
details: LiveCampaignCardDetails;
|
|
73
83
|
achievement: CampaignCardAchievement;
|
|
74
|
-
|
|
84
|
+
sessionInsights: SessionInsight[];
|
|
75
85
|
};
|
|
76
86
|
export declare const isCampaignSchedulingRandom: (scheduling: CampaignScheduling) => scheduling is RandomCampaignScheduling;
|
|
77
87
|
export declare const isCampaignSchedulingManual: (scheduling: CampaignScheduling) => scheduling is ManualCampaignScheduling;
|
|
78
88
|
export declare const isWikiCard: (item: unknown) => item is WikiCard;
|
|
89
|
+
export declare const computeCurrentSession: (card: LiveCampaignCard) => number;
|
|
@@ -4,8 +4,31 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const isCampaignSchedulingRandom = (scheduling) => scheduling.mode === 'random';
|
|
6
6
|
const isCampaignSchedulingManual = (scheduling) => scheduling.mode === 'manual';
|
|
7
|
-
const isWikiCard = (item) => typeof item === 'object' && item !== null && 'activityDetails' in item && 'playerInteraction' in item;
|
|
7
|
+
const isWikiCard = (item) => typeof item === 'object' && item !== null && 'activityDetails' in item && 'playerInteraction' in item;
|
|
8
|
+
const computeCurrentSession = (card) => {
|
|
9
|
+
const { details, achievement } = card;
|
|
10
|
+
if (details.type === 'flexible') {
|
|
11
|
+
return Math.min(achievement.lastSessionPlayed + 1, details.sessionCount);
|
|
12
|
+
}
|
|
13
|
+
const today = new Date();
|
|
14
|
+
const startDate = new Date(details.utcStartDate);
|
|
15
|
+
const endData = new Date(details.utcEndDate);
|
|
16
|
+
const calculateCurrentSessionAux = (date, currentSession) => {
|
|
17
|
+
if (date >= today || (endData && date >= endData) || currentSession >= details.sessionCount) {
|
|
18
|
+
return currentSession;
|
|
19
|
+
}
|
|
20
|
+
const jsDay = date.getDay();
|
|
21
|
+
const day = jsDay === 0 ? 7 : jsDay;
|
|
22
|
+
const isEnabledDay = details.enabledWeekDays.includes(day);
|
|
23
|
+
const isNotDisabledDate = !details.disabledDates.includes(date.toISOString().slice(0, 10));
|
|
24
|
+
const nextSession = isEnabledDay && isNotDisabledDate ? currentSession + 1 : currentSession;
|
|
25
|
+
date.setDate(date.getDate() + 1);
|
|
26
|
+
return calculateCurrentSessionAux(date, nextSession);
|
|
27
|
+
};
|
|
28
|
+
return calculateCurrentSessionAux(startDate, 1);
|
|
29
|
+
};
|
|
8
30
|
|
|
31
|
+
exports.computeCurrentSession = computeCurrentSession;
|
|
9
32
|
exports.isCampaignSchedulingManual = isCampaignSchedulingManual;
|
|
10
33
|
exports.isCampaignSchedulingRandom = isCampaignSchedulingRandom;
|
|
11
34
|
exports.isWikiCard = isWikiCard;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaign.js","sources":["../../../src/business/types/campaign.ts"],"sourcesContent":["import type { Content } from './content';\nimport type { Image } from './media';\nimport type { MultilingualLabel } from './multilingual';\nimport type { Points } from './score';\n\nexport type CampaignInformations = {\n coverImage: Image;\n name: MultilingualLabel;\n description: MultilingualLabel;\n disclaimer?: MultilingualLabel;\n lastSave: Date;\n};\n\nexport type BaseCampaignScheduling = {\n type: 'flexible' | 'intense';\n launchDate: string;\n endDate?: string;\n extraDays: number;\n enabledWeekDays: number[];\n disabledDates: string[];\n};\n\nexport type ManualCampaignScheduling = BaseCampaignScheduling & {\n mode: 'manual';\n orderedSessions: Content[][];\n};\n\nexport type RandomCampaignScheduling = BaseCampaignScheduling & {\n mode: 'random';\n nbSessions: number;\n contents: Content[];\n};\n\nexport type CampaignScheduling = ManualCampaignScheduling | RandomCampaignScheduling;\n\nexport type Campaign = {\n id: number;\n informations: CampaignInformations;\n scheduling: CampaignScheduling;\n type: 'campaign';\n};\n\nexport type
|
|
1
|
+
{"version":3,"file":"campaign.js","sources":["../../../src/business/types/campaign.ts"],"sourcesContent":["import type { Content, GameType } from './content';\nimport type { Image } from './media';\nimport type { MultilingualLabel } from './multilingual';\nimport type { Points } from './score';\n\nexport type CampaignInformations = {\n coverImage: Image;\n name: MultilingualLabel;\n description: MultilingualLabel;\n disclaimer?: MultilingualLabel;\n lastSave: Date;\n};\n\nexport type BaseCampaignScheduling = {\n type: 'flexible' | 'intense';\n launchDate: string;\n endDate?: string;\n extraDays: number;\n enabledWeekDays: number[];\n disabledDates: string[];\n};\n\nexport type ManualCampaignScheduling = BaseCampaignScheduling & {\n mode: 'manual';\n orderedSessions: Content[][];\n};\n\nexport type RandomCampaignScheduling = BaseCampaignScheduling & {\n mode: 'random';\n nbSessions: number;\n contents: Content[];\n};\n\nexport type CampaignScheduling = ManualCampaignScheduling | RandomCampaignScheduling;\n\nexport type Campaign = {\n id: number;\n informations: CampaignInformations;\n scheduling: CampaignScheduling;\n type: 'campaign';\n};\n\nexport type BaseCampaignCardDetails = {\n id: number;\n coverImage: string;\n title: MultilingualLabel;\n description: MultilingualLabel;\n utcStartDate: string;\n utcEndDate: string;\n};\n\nexport type WikiCardDetails = BaseCampaignCardDetails & {\n contentCount: number;\n};\n\nexport type WikiCardPlayerInteraction = {\n contentPlayedCount: number;\n favorite: boolean;\n};\n\nexport type WikiCard = {\n details: WikiCardDetails;\n playerInteraction: WikiCardPlayerInteraction;\n};\n\nexport type WikiContentCardDetails = {\n id: number;\n coverImage: string;\n title: MultilingualLabel;\n session: number;\n};\n\nexport type WikiContentCard = {\n contentDetails: WikiContentCardDetails;\n points: Points;\n};\n\nexport type CampaignCardScheduling = {\n type: 'flexible' | 'intense';\n extraDays: number;\n enabledWeekDays: number[];\n disabledDates: string[];\n sessionCount: number;\n};\n\nexport type LiveCampaignCardDetails = BaseCampaignCardDetails & CampaignCardScheduling;\n\nexport type CampaignCardAchievement = {\n lastSessionPlayed: number;\n points: Points;\n};\n\nexport type SessionInsight = {\n sessionNumber: number;\n gameTypes: GameType[];\n};\n\nexport type LiveCampaignCard = {\n details: LiveCampaignCardDetails;\n achievement: CampaignCardAchievement;\n sessionInsights: SessionInsight[];\n};\n\nexport const isCampaignSchedulingRandom = (scheduling: CampaignScheduling): scheduling is RandomCampaignScheduling =>\n scheduling.mode === 'random';\n\nexport const isCampaignSchedulingManual = (scheduling: CampaignScheduling): scheduling is ManualCampaignScheduling =>\n scheduling.mode === 'manual';\n\nexport const isWikiCard = (item: unknown): item is WikiCard =>\n typeof item === 'object' && item !== null && 'activityDetails' in item && 'playerInteraction' in item;\n\nexport const computeCurrentSession = (card: LiveCampaignCard): number => {\n const { details, achievement } = card;\n\n if (details.type === 'flexible') {\n return Math.min(achievement.lastSessionPlayed + 1, details.sessionCount);\n }\n\n const today = new Date();\n const startDate = new Date(details.utcStartDate);\n const endData = new Date(details.utcEndDate);\n\n const calculateCurrentSessionAux = (date: Date, currentSession: number): number => {\n if (date >= today || (endData && date >= endData) || currentSession >= details.sessionCount) {\n return currentSession;\n }\n\n const jsDay = date.getDay();\n const day = jsDay === 0 ? 7 : jsDay;\n\n const isEnabledDay = details.enabledWeekDays.includes(day);\n const isNotDisabledDate = !details.disabledDates.includes(date.toISOString().slice(0, 10));\n\n const nextSession = isEnabledDay && isNotDisabledDate ? currentSession + 1 : currentSession;\n\n date.setDate(date.getDate() + 1);\n\n return calculateCurrentSessionAux(date, nextSession);\n };\n\n return calculateCurrentSessionAux(startDate, 1);\n};\n"],"names":[],"mappings":";;;;AAuGO,MAAM,0BAA0B,GAAG,CAAC,UAA8B,KACvE,UAAU,CAAC,IAAI,KAAK,SAAS;AAExB,MAAM,0BAA0B,GAAG,CAAC,UAA8B,KACvE,UAAU,CAAC,IAAI,KAAK,SAAS;AAElB,MAAA,UAAU,GAAG,CAA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AG,YAAY,IAAI,iBAAiB,GAAG,cAAc,GAAG,CAAC,GAAG,cAAc,CAAC;QAE5F,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;AAEjC,QAAA,OAAO,0BAA0B,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AACvD,KAAC,CAAC;AAEF,IAAA,OAAO,0BAA0B,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;AAClD;;;;;;;"}
|
package/business/types/index.js
CHANGED
|
@@ -13,6 +13,7 @@ var score = require('./score.js');
|
|
|
13
13
|
exports.ACTIVITY_STATUS = activity.ACTIVITY_STATUS;
|
|
14
14
|
exports.isActivityBreakingNews = activity.isActivityBreakingNews;
|
|
15
15
|
exports.isActivityCampaign = activity.isActivityCampaign;
|
|
16
|
+
exports.computeCurrentSession = campaign.computeCurrentSession;
|
|
16
17
|
exports.isCampaignSchedulingManual = campaign.isCampaignSchedulingManual;
|
|
17
18
|
exports.isCampaignSchedulingRandom = campaign.isCampaignSchedulingRandom;
|
|
18
19
|
exports.isWikiCard = campaign.isWikiCard;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|