Skip to content

Commit 67a6f04

Browse files
authored
Merge branch 'master' into fix/commandline-hotkey-custom-modals
2 parents 2ead7a7 + 994616b commit 67a6f04

60 files changed

Lines changed: 2028 additions & 2763 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/scripts/openapi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { generateOpenApi } from "@ts-rest/open-api";
2-
import { contract } from "@monkeytype/contracts/index";
2+
import { COMPATIBILITY_CHECK, contract } from "@monkeytype/contracts/index";
33
import { writeFileSync, mkdirSync } from "fs";
44
import { EndpointMetadata, PermissionId } from "@monkeytype/contracts/util/api";
55
import type { OpenAPIObject, OperationObject } from "openapi3-ts";
@@ -24,7 +24,7 @@ export function getOpenApi(): OpenAPIObject {
2424
title: "Monkeytype API",
2525
description:
2626
"Documentation for the endpoints provided by the Monkeytype API server.\n\nNote that authentication is performed with the Authorization HTTP header in the format `Authorization: ApeKey YOUR_APE_KEY`\n\nThere is a rate limit of `30 requests per minute` across all endpoints with some endpoints being more strict. Rate limit rates are shared across all ape keys.",
27-
version: "2.0.0",
27+
version: `2.${COMPATIBILITY_CHECK}.0`,
2828
termsOfService: "https://monkeytype.com/terms-of-service",
2929
contact: {
3030
name: "Support",

backend/src/api/controllers/result.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import {
4343
GetResultsResponse,
4444
UpdateResultTagsRequest,
4545
UpdateResultTagsResponse,
46-
ReportCompletedEventMismatchRequest,
4746
} from "@monkeytype/contracts/results";
4847
import {
4948
CompletedEvent,
@@ -185,48 +184,6 @@ export async function updateTags(
185184
});
186185
}
187186

188-
export async function reportCompletedEventMismatch(
189-
req: MonkeyRequest<undefined, ReportCompletedEventMismatchRequest>,
190-
): Promise<MonkeyResponse> {
191-
const { uid } = req.ctx.decodedToken;
192-
const {
193-
notMatching,
194-
mismatchedKeys,
195-
groupKey,
196-
language,
197-
mode,
198-
mode2,
199-
difficulty,
200-
duration,
201-
funboxes,
202-
version,
203-
eventLog,
204-
} = req.body;
205-
// Logger.warning(
206-
// `Completed event mismatch for uid ${uid}: ${notMatching.join(", ")}`,
207-
// );
208-
// Logger.warning(`Old CE: ${JSON.stringify(ce)}`);
209-
// Logger.warning(`New CE: ${JSON.stringify(ce2)}`);
210-
void addLog(
211-
"completed_event_mismatch",
212-
{
213-
notMatching,
214-
mismatchedKeys,
215-
groupKey,
216-
language,
217-
mode,
218-
mode2,
219-
difficulty,
220-
duration,
221-
funboxes,
222-
version,
223-
eventLog,
224-
},
225-
uid,
226-
);
227-
return new MonkeyResponse("Mismatch reported", null);
228-
}
229-
230187
export async function addResult(
231188
req: MonkeyRequest<undefined, AddResultRequest>,
232189
): Promise<AddResultResponse> {

backend/src/api/routes/results.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ export default s.router(resultsContract, {
1717
updateTags: {
1818
handler: async (r) => callController(ResultController.updateTags)(r),
1919
},
20-
reportCompletedEventMismatch: {
21-
handler: async (r) =>
22-
callController(ResultController.reportCompletedEventMismatch)(r),
23-
},
2420
deleteAll: {
2521
handler: async (r) => callController(ResultController.deleteAll)(r),
2622
},

backend/src/middlewares/rate-limit.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import MonkeyError from "../utils/error";
22
import type { Response, NextFunction, Request } from "express";
33
import { RateLimiterMemory } from "rate-limiter-flexible";
44
import {
5+
ipKeyGenerator,
56
rateLimit,
67
RateLimitRequestHandler,
78
type Options,
@@ -40,12 +41,13 @@ export const customHandler = (
4041
};
4142

4243
const getKey = (req: Request, _res: Response): string => {
43-
return (
44+
const ip =
4445
(req.headers["cf-connecting-ip"] as string) ||
4546
(req.headers["x-forwarded-for"] as string) ||
4647
(req.ip as string) ||
47-
"255.255.255.255"
48-
);
48+
"255.255.255.255";
49+
const key = ipKeyGenerator(ip);
50+
return key;
4951
};
5052

5153
const getKeyWithUid = (

frontend/__tests__/input/helpers/validation.spec.ts

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, it, expect, vi, beforeEach, afterAll } from "vitest";
22
import {
33
isCharCorrect,
4+
isWordCorrect,
45
shouldInsertSpaceCharacter,
56
} from "../../../src/ts/input/helpers/validation";
67
import { __testing } from "../../../src/ts/config/testing";
@@ -75,6 +76,29 @@ describe("isCharCorrect", () => {
7576
});
7677

7778
describe("Space Handling", () => {
79+
it.each([
80+
["returns false in the middle of a word", " ", "wor", "word", false],
81+
["returns false at the start of a word", " ", "", "word", false],
82+
[
83+
"returns false when longer than a word",
84+
" ",
85+
"wordwordword",
86+
"word",
87+
false,
88+
],
89+
])("%s", (_desc, char, input, word, expected) => {
90+
expect(
91+
isCharCorrect({
92+
data: char,
93+
inputValue: input,
94+
targetWord: word,
95+
correctShiftUsed: true,
96+
}),
97+
).toBe(expected);
98+
});
99+
});
100+
101+
describe("Space Handling at the end of a word", () => {
78102
it.each([
79103
["returns true at the end of a correct word", " ", "word", "word", true],
80104
[
@@ -84,18 +108,23 @@ describe("isCharCorrect", () => {
84108
"word",
85109
false,
86110
],
87-
["returns false in the middle of a word", " ", "wor", "word", false],
88-
["returns false at the start of a word", " ", "", "word", false],
89111
[
90-
"returns false when longer than a word",
91-
" ",
92-
"wordwordword",
112+
"returns true when committing a word with a newline",
113+
"\n",
93114
"word",
115+
"word\n",
116+
true,
117+
],
118+
[
119+
"returns false when committing an incorrect word with a newline",
120+
"\n",
121+
"xord",
122+
"word\n",
94123
false,
95124
],
96125
])("%s", (_desc, char, input, word, expected) => {
97126
expect(
98-
isCharCorrect({
127+
isWordCorrect({
99128
data: char,
100129
inputValue: input,
101130
targetWord: word,
@@ -124,17 +153,6 @@ describe("isCharCorrect", () => {
124153
},
125154
);
126155
});
127-
128-
it("throws error if data is undefined", () => {
129-
expect(() =>
130-
isCharCorrect({
131-
data: undefined as any,
132-
inputValue: "val",
133-
targetWord: "word",
134-
correctShiftUsed: true,
135-
}),
136-
).toThrow();
137-
});
138156
});
139157

140158
describe("shouldInsertSpaceCharacter", () => {

frontend/__tests__/test/events/data.spec.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function timerData(
5757
if (event === "step") {
5858
return { event, timer, drift: 0 };
5959
}
60-
return { event, timer };
60+
return { event, timer, date: 0 };
6161
}
6262

6363
describe("data.ts", () => {
@@ -285,18 +285,8 @@ describe("data.ts", () => {
285285
logTestEvent("input", 1010, inputData({ wordIndex: 0, charIndex: 0 }));
286286
logTestEvent("input", 1100, inputData({ wordIndex: 0, charIndex: 1 }));
287287

288-
const perWord = getEventsPerWord(getAllTestEvents(), undefined, 50);
289-
expect(perWord.get(0)).toHaveLength(1);
290-
});
291-
292-
it("respects startMs", () => {
293-
logTestEvent("input", 1010, inputData({ wordIndex: 0, charIndex: 0 }));
294-
logTestEvent("input", 1100, inputData({ wordIndex: 0, charIndex: 1 }));
295-
296288
const perWord = getEventsPerWord(getAllTestEvents(), 50);
297289
expect(perWord.get(0)).toHaveLength(1);
298-
const first = perWord.get(0)?.[0];
299-
expect(first?.type === "input" && first.data.charIndex).toBe(1);
300290
});
301291
});
302292

0 commit comments

Comments
 (0)