Skip to content

Commit

Permalink
routes: updated itty-router, fixed typing
Browse files Browse the repository at this point in the history
  • Loading branch information
denbeigh2000 committed Nov 6, 2023
1 parent c48ff64 commit 90eeb6f
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"cookie": "^0.5.0",
"discord-api-types": "^0.37.0",
"humanize-duration": "^3.30.0",
"itty-router": "^2.6.1",
"itty-router": "^4.0.23",
"simple-oauth2": "^4.3.0",
"toucan-js": "^3.3.0",
"workers-qb": "^1.1.1"
Expand Down
1 change: 0 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,3 @@ export function getUserRole(
validUserRoles.sort((a, b) => a - b);
return validUserRoles[0];
}

8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Router } from "itty-router";
import { Router, IRequest } from "itty-router";

import { Env } from "./env";
import { handler as handleJoin } from "./routes/join";
Expand All @@ -8,7 +8,9 @@ import { handler as handleRegister } from "./routes/register";
import { Sentry } from "./sentry";
import { respondNotFound, returnStatus } from "./util/http";

const ROUTER = Router();
type RequestType = [Env, ExecutionContext, Sentry];

const ROUTER = Router<IRequest, RequestType>();

ROUTER.get("/join", handleJoin);
ROUTER.get("/redirect", handleRedirect);
Expand All @@ -20,7 +22,7 @@ export default {
async fetch(
request: Request,
env: Env,
ctx: FetchEvent
ctx: ExecutionContext,
): Promise<Response> {
const sentry = new Sentry(request, env, ctx);
try {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/interaction/group/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function handler(
client: BotClient,
interaction: APIChatInputApplicationCommandGuildInteraction,
env: Env,
_ctx: FetchEvent,
_ctx: ExecutionContext,
sentry: Sentry
): Promise<RESTPostAPIWebhookWithTokenJSONBody> {
const manager = new GroupManager(
Expand Down
6 changes: 3 additions & 3 deletions src/routes/interaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { handler as handleHelp } from "./help";
export async function handler(
request: Request,
env: Env,
ctx: FetchEvent,
ctx: ExecutionContext,
sentry: Sentry
) {
const body = await request.text();
Expand Down Expand Up @@ -117,7 +117,7 @@ async function handleCommand(
commandType: CommandType,
interaction: APIChatInputApplicationCommandGuildInteraction,
env: Env,
ctx: FetchEvent,
ctx: ExecutionContext,
sentry: Sentry
): Promise<RESTPostAPIWebhookWithTokenJSONBody | null> {
const client = new BotClient(env.BOT_TOKEN, sentry);
Expand All @@ -140,7 +140,7 @@ async function handleCommand(
async function handleMessageComponent(
interaction: APIMessageComponentSelectMenuInteraction,
env: Env,
_ctx: FetchEvent,
_ctx: ExecutionContext,
sentry: Sentry
) {
const customId = interaction.data.custom_id;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/interaction/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function handler(
client: BotClient,
interaction: APIChatInputApplicationCommandGuildInteraction,
env: Env,
_ctx: FetchEvent,
_ctx: ExecutionContext,
sentry: Sentry
): Promise<RESTPostAPIWebhookWithTokenJSONBody> {
/* TODO: Most of this block should be factored out */
Expand Down
2 changes: 1 addition & 1 deletion src/routes/interaction/nowork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function handler(
client: BotClient,
interaction: APIChatInputApplicationCommandGuildInteraction,
env: Env,
_ctx: FetchEvent,
_ctx: ExecutionContext,
sentry: Sentry
): Promise<RESTPostAPIWebhookWithTokenJSONBody | null> {
const { options } = interaction.data;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/interaction/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function handler(
client: BotClient,
interaction: APIChatInputApplicationCommandGuildInteraction,
env: Env,
_ctx: FetchEvent,
_ctx: ExecutionContext,
sentry: Sentry
): Promise<RESTPostAPIWebhookWithTokenJSONBody> {
const ephFlags = { flags: MessageFlags.Ephemeral };
Expand Down
2 changes: 1 addition & 1 deletion src/routes/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { returnStatus } from "../util/http";
export async function handler(
req: Request,
env: Env,
_ctx: FetchEvent,
_ctx: ExecutionContext,
sentry: Sentry
): Promise<Response> {
const oauthClient = new OAuthClient(
Expand Down
2 changes: 1 addition & 1 deletion src/routes/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { respond400 } from "../util/http";
export async function handler(
req: Request,
env: Env,
_ctx: FetchEvent,
_ctx: ExecutionContext,
sentry: Sentry
): Promise<Response> {
const url = new URL(req.url);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ALL_COMMANDS = [
export async function handler(
req: Request,
env: Env,
_ctx: FetchEvent,
_ctx: ExecutionContext,
sentry: Sentry
) {
const oauthClient = new OAuthClient(
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1118,10 +1118,10 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==

itty-router@^2.6.1:
version "2.6.6"
resolved "https://registry.yarnpkg.com/itty-router/-/itty-router-2.6.6.tgz#78a08c3b7dc1bd90ce832cae8eff7e4cbfbf67ef"
integrity sha512-hIPHtXGymCX7Lzb2I4G6JgZFE4QEEQwst9GORK7sMYUpJvLfy4yZJr95r04e8DzoAnj6HcxM2m4TbK+juu+18g==
itty-router@^4.0.23:
version "4.0.23"
resolved "https://registry.yarnpkg.com/itty-router/-/itty-router-4.0.23.tgz#44bb79134567773d3356e9972913e8fd6ed8a7a0"
integrity sha512-tP1NI8PVK43vWlBnIPqj47ni5FDSczFviA4wgBznscndo8lEvBA+pO3DD1rNbIQPcZhprr775iUTunyGvQMcBw==

joi@^17.3.0:
version "17.11.0"
Expand Down

0 comments on commit 90eeb6f

Please sign in to comment.