Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable strict types mode #362

Merged
merged 25 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = {
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/require-await": "warn",
"@typescript-eslint/prefer-ts-expect-error": "error",
"no-nested-ternary": "warn",
eqeqeq: "error",
"no-duplicate-imports": "warn",
"promise/always-return": "error",
Expand Down
2 changes: 2 additions & 0 deletions components/2016/legacyContractHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const legacyContractRouter = Router()
legacyContractRouter.post(
"/GetForPlay",
jsonMiddleware(),
// @ts-expect-error Has jwt props.
(req: RequestWithJwt, res) => {
if (!uuidRegex.test(req.body.id)) {
res.status(400).end()
Expand Down Expand Up @@ -130,6 +131,7 @@ legacyContractRouter.post(
legacyContractRouter.post(
"/Start",
jsonMiddleware(),
// @ts-expect-error Has jwt props.
(req: RequestWithJwt, res) => {
if (req.body.profileId !== req.jwt.unique_name) {
res.status(400).end() // requested for different user id
Expand Down
2 changes: 2 additions & 0 deletions components/2016/legacyMenuData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const legacyMenuDataRouter = Router()

legacyMenuDataRouter.get(
"/debriefingchallenges",
// @ts-expect-error Has jwt props.
(
req: RequestWithJwt<{ contractSessionId: string; contractId: string }>,
res,
Expand Down Expand Up @@ -55,6 +56,7 @@ legacyMenuDataRouter.get(

legacyMenuDataRouter.get(
"/MasteryLocation",
// @ts-expect-error Has jwt props.
(req: RequestWithJwt<{ locationId: string; difficulty: string }>, res) => {
const masteryData =
controller.masteryService.getMasteryDataForDestination(
Expand Down
25 changes: 15 additions & 10 deletions components/2016/legacyProfileRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const legacyProfileRouter = Router()
legacyProfileRouter.post(
"/ChallengesService/GetActiveChallenges",
jsonMiddleware(),
// @ts-expect-error Has jwt props.
(req: RequestWithJwt, res) => {
if (!uuidRegex.test(req.body.contractId)) {
return res.status(404).send("invalid contract")
Expand Down Expand Up @@ -93,7 +94,13 @@ legacyProfileRouter.post(
legacyProfileRouter.post(
"/ChallengesService/GetProgression",
jsonMiddleware(),
// @ts-expect-error Has jwt props.
(req: RequestWithJwt<never, LegacyGetProgressionBody>, res) => {
if (!Array.isArray(req.body.challengeids)) {
res.status(400).send("invalid body")
return
}

const legacyGlobalChallenges = getConfig<CompiledChallengeIngameData[]>(
"LegacyGlobalChallenges",
false,
Expand All @@ -114,10 +121,11 @@ legacyProfileRouter.post(
MustBeSaved: false,
}))

/*
for (const challengeId of req.body.challengeids) {
const challenge =
controller.challengeService.getChallengeById(challengeId)
const challenge = controller.challengeService.getChallengeById(
challengeId,
"h1",
)

if (!challenge) {
log(
Expand All @@ -128,7 +136,7 @@ legacyProfileRouter.post(
}

const progression =
controller.challengeService.getChallengeProgression(
controller.challengeService.getPersistentChallengeProgression(
req.jwt.unique_name,
challengeId,
req.gameVersion,
Expand All @@ -138,19 +146,16 @@ legacyProfileRouter.post(
ChallengeId: challengeId,
ProfileId: req.jwt.unique_name,
Completed: progression.Completed,
Ticked: progression.Ticked,
State: progression.State,
ETag: `W/"datetime'${encodeURIComponent(
new Date().toISOString(),
)}'"`,
CompletedAt: progression.CompletedAt,
MustBeSaved: false,
MustBeSaved: progression.MustBeSaved,
})
}
*/
// TODO: atampy broke this - please fix
// update(RD) nov 18 '22: fixed but still missing challenges in
// 2016 engine (e.g. showstopper is missing 9, 5 of which are the
// classics I think, not sure about the other 4)
// TODO: HELP! Please DM rdil if you see this

res.json(challenges)
},
Expand Down
29 changes: 8 additions & 21 deletions components/candle/challengeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import {
ChallengeProgressionData,
CompiledChallengeRewardData,
CompiledChallengeRuntimeData,
InclusionData,
MissionManifest,
Expand All @@ -28,19 +27,6 @@ import { SavedChallengeGroup } from "../types/challenges"
import { controller } from "../controller"
import { gameDifficulty, isSniperLocation } from "../utils"

// TODO: unused?
export function compileScoringChallenge(
challenge: RegistryChallenge,
): CompiledChallengeRewardData {
return {
ChallengeId: challenge.Id,
ChallengeName: challenge.Name,
ChallengeDescription: challenge.Description,
ChallengeImageUrl: challenge.ImageName,
XPGain: challenge.Rewards?.MasteryXP || 0,
}
}

export function compileRuntimeChallenge(
challenge: RegistryChallenge,
progression: ChallengeProgressionData,
Expand Down Expand Up @@ -106,8 +92,8 @@ export type ChallengeFilterOptions =
* @returns A boolean as the result.
*/
export function inclusionDataCheck(
incData: InclusionData,
contract: MissionManifest,
incData: InclusionData | undefined,
contract: MissionManifest | undefined,
): boolean {
if (!incData) return true
if (!contract) return false
Expand Down Expand Up @@ -174,24 +160,25 @@ function isChallengeInContract(
: {
...challenge.InclusionData,
ContractTypes:
challenge.InclusionData.ContractTypes.filter(
challenge.InclusionData?.ContractTypes?.filter(
(type) => type !== "tutorial",
),
) || [],
Comment on lines -177 to +165
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible behavior change

},
contract,
)
}

// Is this for the current contract or group contract?
const isForContract = (challenge.InclusionData?.ContractIds || []).includes(
contract.Metadata.Id,
contract?.Metadata.Id || "",
)

// Is this for the current contract type?
// As of v6.1.0, this is only used for ET challenges.
// We have to resolve the non-group contract, `contract` is the group contract
const isForContractType = (
challenge.InclusionData?.ContractTypes || []
).includes(controller.resolveContract(contractId).Metadata.Type)
).includes(controller.resolveContract(contractId)!.Metadata.Type)

// Is this a location-wide challenge?
// "location" is more widely used, but "parentlocation" is used in Ambrose and Berlin, as well as some "Discover XX" challenges.
Expand Down Expand Up @@ -287,7 +274,7 @@ export function filterChallenge(
*/
export function mergeSavedChallengeGroups(
g1: SavedChallengeGroup,
g2: SavedChallengeGroup,
g2?: SavedChallengeGroup,
): SavedChallengeGroup {
return {
...g1,
Expand Down
Loading