Skip to content

Commit bc27ecd

Browse files
authored
fix: update and remove a bunch of security vulnerable deps (#623)
* fix: update and remove a bunch of security vulnerable deps * fix: rewrite package-lock.json
1 parent 5339d99 commit bc27ecd

File tree

4 files changed

+12919
-23895
lines changed

4 files changed

+12919
-23895
lines changed

app/routes/api.device.$deviceId.ts

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { json, type LoaderFunctionArgs } from '@remix-run/node'
2-
import { getDevice } from '~/models/device.server'
1+
import { type LoaderFunctionArgs } from "react-router";
2+
import { getDevice } from "~/models/device.server";
33

44
/**
55
* @openapi
@@ -62,40 +62,49 @@ import { getDevice } from '~/models/device.server'
6262
* description: Internal server error
6363
*/
6464
export async function loader({ params }: LoaderFunctionArgs) {
65-
const { deviceId } = params
65+
const { deviceId } = params;
6666

67-
if (!deviceId) {
68-
return new Response(JSON.stringify({ message: 'Device ID is required.' }), {
69-
status: 400,
70-
headers: {
71-
'content-type': 'application/json; charset=utf-8',
72-
},
73-
})
74-
}
67+
if (!deviceId) {
68+
return new Response(JSON.stringify({ message: "Device ID is required." }), {
69+
status: 400,
70+
headers: {
71+
"content-type": "application/json; charset=utf-8",
72+
},
73+
});
74+
}
7575

76-
try {
77-
const device = await getDevice({ id: deviceId })
76+
try {
77+
const device = await getDevice({ id: deviceId });
7878

79-
if (!device) {
80-
return new Response(JSON.stringify({ message: 'Device not found.' }), {
81-
status: 404,
82-
headers: {
83-
'content-type': 'application/json; charset=utf-8',
84-
},
85-
})
86-
}
79+
if (!device) {
80+
return new Response(JSON.stringify({ message: "Device not found." }), {
81+
status: 404,
82+
headers: {
83+
"content-type": "application/json; charset=utf-8",
84+
},
85+
});
86+
}
8787

88-
return json(device)
89-
} catch (error) {
90-
console.error('Error fetching box:', error)
88+
return new Response(JSON.stringify(device), {
89+
headers: {
90+
"Content-Type": "application/json; charset=utf-8",
91+
},
92+
});
93+
} catch (error) {
94+
console.error("Error fetching box:", error);
9195

92-
if (error instanceof Response) {
93-
throw error
94-
}
96+
if (error instanceof Response) {
97+
throw error;
98+
}
9599

96-
throw json(
97-
{ error: 'Internal server error while fetching box' },
98-
{ status: 500 },
99-
)
100-
}
100+
return new Response(
101+
JSON.stringify({ error: "Internal server error while fetching box" }),
102+
{
103+
status: 500,
104+
headers: {
105+
"Content-Type": "application/json; charset=utf-8",
106+
},
107+
},
108+
);
109+
}
101110
}

app/routes/api.devices.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { json, type LoaderFunctionArgs } from "@remix-run/node";
2-
import { type ActionFunctionArgs } from "react-router";
1+
import { type LoaderFunctionArgs, type ActionFunctionArgs } from "react-router";
32
import { BoxesQuerySchema, deleteDevice } from "~/lib/devices-service.server";
43
import { getUserFromJwt } from "~/lib/jwt";
54
import {
@@ -290,10 +289,16 @@ export async function loader({ request }: LoaderFunctionArgs) {
290289
if (!parseResult.success) {
291290
const { fieldErrors, formErrors } = parseResult.error.flatten();
292291
if (fieldErrors.format) {
293-
throw json({ error: "Invalid format parameter" }, { status: 422 });
292+
throw Response.json(
293+
{ error: "Invalid format parameter" },
294+
{ status: 422 },
295+
);
294296
}
295297

296-
throw json({ error: parseResult.error.flatten() }, { status: 422 });
298+
throw Response.json(
299+
{ error: parseResult.error.flatten() },
300+
{ status: 422 },
301+
);
297302
}
298303

299304
const params: FindDevicesOptions = parseResult.data;
@@ -363,19 +368,19 @@ async function del(request: Request, user: User, params: any) {
363368
const { deviceId } = params;
364369

365370
if (!deviceId) {
366-
throw json({ message: "Device ID is required" }, { status: 400 });
371+
throw Response.json({ message: "Device ID is required" }, { status: 400 });
367372
}
368373

369374
const device = (await getDevice({ id: deviceId })) as unknown as Device;
370375

371376
if (!device) {
372-
throw json({ message: "Device not found" }, { status: 404 });
377+
throw Response.json({ message: "Device not found" }, { status: 404 });
373378
}
374379

375380
const body = await request.json();
376381

377382
if (!body.password) {
378-
throw json(
383+
throw Response.json(
379384
{ message: "Password is required for device deletion" },
380385
{ status: 400 },
381386
);
@@ -408,7 +413,7 @@ async function post(request: Request, user: User) {
408413
const body = await request.json();
409414

410415
if (!body.location) {
411-
throw json(
416+
throw Response.json(
412417
{ message: "missing required parameter location" },
413418
{ status: 400 },
414419
);
@@ -419,7 +424,7 @@ async function post(request: Request, user: User) {
419424
if (Array.isArray(body.location)) {
420425
// Handle array format [lat, lng, height?]
421426
if (body.location.length < 2) {
422-
throw json(
427+
throw Response.json(
423428
{
424429
message: `Illegal value for parameter location. missing latitude or longitude in location [${body.location.join(",")}]`,
425430
},
@@ -432,7 +437,7 @@ async function post(request: Request, user: User) {
432437
} else if (typeof body.location === "object" && body.location !== null) {
433438
// Handle object format { lat, lng, height? }
434439
if (!("lat" in body.location) || !("lng" in body.location)) {
435-
throw json(
440+
throw Response.json(
436441
{
437442
message:
438443
"Illegal value for parameter location. missing latitude or longitude",
@@ -444,7 +449,7 @@ async function post(request: Request, user: User) {
444449
longitude = Number(body.location.lng);
445450
height = body.location.height ? Number(body.location.height) : undefined;
446451
} else {
447-
throw json(
452+
throw Response.json(
448453
{
449454
message:
450455
"Illegal value for parameter location. Expected array or object",
@@ -454,15 +459,18 @@ async function post(request: Request, user: User) {
454459
}
455460

456461
if (isNaN(latitude) || isNaN(longitude)) {
457-
throw json(
462+
throw Response.json(
458463
{ message: "Invalid latitude or longitude values" },
459464
{ status: 422 },
460465
);
461466
}
462467

463468
const rawAuthorizationHeader = request.headers.get("authorization");
464469
if (!rawAuthorizationHeader) {
465-
throw json({ message: "Authorization header required" }, { status: 401 });
470+
throw Response.json(
471+
{ message: "Authorization header required" },
472+
{ status: 401 },
473+
);
466474
}
467475
const [, jwtString] = rawAuthorizationHeader.split(" ");
468476

@@ -474,7 +482,7 @@ async function post(request: Request, user: User) {
474482

475483
const newDevice = await createDevice(deviceData, user.id);
476484

477-
return json(
485+
return Response.json(
478486
{
479487
data: {
480488
...newDevice,
@@ -490,6 +498,6 @@ async function post(request: Request, user: User) {
490498
throw error;
491499
}
492500

493-
throw json({ message: "Internal server error" }, { status: 500 });
501+
throw Response.json({ message: "Internal server error" }, { status: 500 });
494502
}
495503
}

0 commit comments

Comments
 (0)