From 920df83cad4851d8d8f6b6f62c0b29079e4ef33e Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Tue, 10 Jan 2023 11:01:08 +0000 Subject: [PATCH] add lint:functions script and make it pass --- functions/ap/users/[id]/followers/page.ts | 4 ---- functions/ap/users/[id]/following/page.ts | 4 ---- functions/ap/users/[id]/inbox.ts | 1 - functions/ap/users/[id]/outbox.ts | 5 +---- functions/ap/users/[id]/outbox/page.ts | 1 + functions/api/v1/accounts/[id].ts | 1 - functions/api/v1/accounts/[id]/statuses.ts | 5 +++-- functions/api/v1/accounts/relationships.ts | 2 +- functions/api/v1/accounts/update_credentials.ts | 2 +- functions/api/v1/apps.ts | 4 +--- functions/api/v1/notifications.ts | 3 --- functions/api/v1/notifications/[id].ts | 1 - functions/api/v1/push/subscription.ts | 4 ---- functions/api/v1/statuses.ts | 5 +---- functions/api/v1/statuses/[id].ts | 6 +----- functions/api/v1/statuses/[id]/favourite.ts | 4 +--- functions/api/v1/statuses/[id]/reblog.ts | 4 +--- functions/api/v1/timelines/home.ts | 7 +------ functions/api/v1/timelines/public.ts | 3 ++- functions/first-login.ts | 4 +--- functions/oauth/authorize.ts | 4 +--- functions/oauth/token.ts | 2 +- functions/start-instance-test-access.ts | 11 +++++------ functions/start-instance.ts | 6 ++---- package.json | 1 + 25 files changed, 26 insertions(+), 68 deletions(-) diff --git a/functions/ap/users/[id]/followers/page.ts b/functions/ap/users/[id]/followers/page.ts index a77cc82..4b52f49 100644 --- a/functions/ap/users/[id]/followers/page.ts +++ b/functions/ap/users/[id]/followers/page.ts @@ -1,13 +1,9 @@ import { parseHandle } from 'wildebeest/backend/src/utils/parse' import { getFollowers } from 'wildebeest/backend/src/mastodon/follow' -import * as objects from 'wildebeest/backend/src/activitypub/objects' -import type { Activity } from 'wildebeest/backend/src/activitypub/activities' import { getPersonById } from 'wildebeest/backend/src/activitypub/actors' import { actorURL } from 'wildebeest/backend/src/activitypub/actors' import type { ContextData } from 'wildebeest/backend/src/types/context' import type { Env } from 'wildebeest/backend/src/types/env' -import type { Note } from 'wildebeest/backend/src/activitypub/objects/note' -import * as activityCreate from 'wildebeest/backend/src/activitypub/activities/create' export const onRequest: PagesFunction = async ({ request, env, params }) => { const domain = new URL(request.url).hostname diff --git a/functions/ap/users/[id]/following/page.ts b/functions/ap/users/[id]/following/page.ts index 43164c2..c4a44da 100644 --- a/functions/ap/users/[id]/following/page.ts +++ b/functions/ap/users/[id]/following/page.ts @@ -1,13 +1,9 @@ import { parseHandle } from 'wildebeest/backend/src/utils/parse' import { getFollowingId } from 'wildebeest/backend/src/mastodon/follow' -import * as objects from 'wildebeest/backend/src/activitypub/objects' -import type { Activity } from 'wildebeest/backend/src/activitypub/activities' import { getPersonById } from 'wildebeest/backend/src/activitypub/actors' import { actorURL } from 'wildebeest/backend/src/activitypub/actors' import type { ContextData } from 'wildebeest/backend/src/types/context' import type { Env } from 'wildebeest/backend/src/types/env' -import type { Note } from 'wildebeest/backend/src/activitypub/objects/note' -import * as activityCreate from 'wildebeest/backend/src/activitypub/activities/create' export const onRequest: PagesFunction = async ({ request, env, params }) => { const domain = new URL(request.url).hostname diff --git a/functions/ap/users/[id]/inbox.ts b/functions/ap/users/[id]/inbox.ts index b283851..d9b8acf 100644 --- a/functions/ap/users/[id]/inbox.ts +++ b/functions/ap/users/[id]/inbox.ts @@ -3,7 +3,6 @@ import * as activityHandler from 'wildebeest/backend/src/activitypub/activities/ import type { Env } from 'wildebeest/backend/src/types/env' import * as actors from 'wildebeest/backend/src/activitypub/actors' import type { Activity } from 'wildebeest/backend/src/activitypub/activities' -import * as activities from 'wildebeest/backend/src/activitypub/activities' import { actorURL } from 'wildebeest/backend/src/activitypub/actors' import { parseRequest } from 'wildebeest/backend/src/utils/httpsigjs/parser' import { fetchKey, verifySignature } from 'wildebeest/backend/src/utils/httpsigjs/verifier' diff --git a/functions/ap/users/[id]/outbox.ts b/functions/ap/users/[id]/outbox.ts index 811a7c7..a6be63a 100644 --- a/functions/ap/users/[id]/outbox.ts +++ b/functions/ap/users/[id]/outbox.ts @@ -1,12 +1,8 @@ import { parseHandle } from 'wildebeest/backend/src/utils/parse' -import * as objects from 'wildebeest/backend/src/activitypub/objects' -import type { Activity } from 'wildebeest/backend/src/activitypub/activities' import { getPersonById } from 'wildebeest/backend/src/activitypub/actors' import { actorURL } from 'wildebeest/backend/src/activitypub/actors' import type { ContextData } from 'wildebeest/backend/src/types/context' import type { Env } from 'wildebeest/backend/src/types/env' -import type { Note } from 'wildebeest/backend/src/activitypub/objects/note' -import * as activityCreate from 'wildebeest/backend/src/activitypub/activities/create' export const onRequest: PagesFunction = async ({ request, env, params }) => { const domain = new URL(request.url).hostname @@ -17,6 +13,7 @@ const headers = { 'content-type': 'application/json; charset=utf-8', } +// eslint-disable-next-line @typescript-eslint/no-unused-vars -- TODO: use userKEK export async function handleRequest(domain: string, db: D1Database, id: string, userKEK: string): Promise { const handle = parseHandle(id) diff --git a/functions/ap/users/[id]/outbox/page.ts b/functions/ap/users/[id]/outbox/page.ts index bbd265f..543f7a9 100644 --- a/functions/ap/users/[id]/outbox/page.ts +++ b/functions/ap/users/[id]/outbox/page.ts @@ -21,6 +21,7 @@ const headers = { const DEFAULT_LIMIT = 20 +// eslint-disable-next-line @typescript-eslint/no-unused-vars -- TODO: use userKEK export async function handleRequest(domain: string, db: D1Database, id: string, userKEK: string): Promise { const handle = parseHandle(id) diff --git a/functions/api/v1/accounts/[id].ts b/functions/api/v1/accounts/[id].ts index 85db96a..3489894 100644 --- a/functions/api/v1/accounts/[id].ts +++ b/functions/api/v1/accounts/[id].ts @@ -4,7 +4,6 @@ import { actorURL } from 'wildebeest/backend/src/activitypub/actors' import { getPersonById } from 'wildebeest/backend/src/activitypub/actors' import type { ContextData } from 'wildebeest/backend/src/types/context' import type { Env } from 'wildebeest/backend/src/types/env' -import type { MastodonAccount } from 'wildebeest/backend/src/types/account' import { parseHandle } from 'wildebeest/backend/src/utils/parse' import type { Handle } from 'wildebeest/backend/src/utils/parse' import { queryAcct } from 'wildebeest/backend/src/webfinger/index' diff --git a/functions/api/v1/accounts/[id]/statuses.ts b/functions/api/v1/accounts/[id]/statuses.ts index 22d009d..49d91ee 100644 --- a/functions/api/v1/accounts/[id]/statuses.ts +++ b/functions/api/v1/accounts/[id]/statuses.ts @@ -2,13 +2,12 @@ import type { Env } from 'wildebeest/backend/src/types/env' import type { Activity } from 'wildebeest/backend/src/activitypub/activities' import type { Note } from 'wildebeest/backend/src/activitypub/objects/note' import { loadExternalMastodonAccount } from 'wildebeest/backend/src/mastodon/account' -import type { Object } from 'wildebeest/backend/src/activitypub/objects' import { getPersonById } from 'wildebeest/backend/src/activitypub/actors' import { makeGetActorAsId, makeGetObjectAsId } from 'wildebeest/backend/src/activitypub/activities/handle' import { parseHandle } from 'wildebeest/backend/src/utils/parse' import type { Handle } from 'wildebeest/backend/src/utils/parse' import type { ContextData } from 'wildebeest/backend/src/types/context' -import type { MastodonAccount, MastodonStatus } from 'wildebeest/backend/src/types' +import type { MastodonStatus } from 'wildebeest/backend/src/types' import { toMastodonStatusFromObject } from 'wildebeest/backend/src/mastodon/status' import * as objects from 'wildebeest/backend/src/activitypub/objects' import { actorURL } from 'wildebeest/backend/src/activitypub/actors' @@ -41,6 +40,7 @@ export async function handleRequest(request: Request, db: D1Database, id: string } } +// eslint-disable-next-line @typescript-eslint/no-unused-vars -- TODO: use userKEK async function getRemoteStatuses(request: Request, handle: Handle, db: D1Database, userKEK: string): Promise { const url = new URL(request.url) const domain = url.hostname @@ -61,6 +61,7 @@ async function getRemoteStatuses(request: Request, handle: Handle, db: D1Databas const activities = await outbox.get(actor) + // eslint-disable-next-line @typescript-eslint/no-unused-vars -- TODO: use account const account = await loadExternalMastodonAccount(acct, actor) const promises = activities.items.map(async (activity: Activity) => { diff --git a/functions/api/v1/accounts/relationships.ts b/functions/api/v1/accounts/relationships.ts index 4f74737..6f61e5e 100644 --- a/functions/api/v1/accounts/relationships.ts +++ b/functions/api/v1/accounts/relationships.ts @@ -5,7 +5,7 @@ import type { Env } from 'wildebeest/backend/src/types/env' import type { ContextData } from 'wildebeest/backend/src/types/context' import { getFollowingAcct, getFollowingRequestedAcct } from 'wildebeest/backend/src/mastodon/follow' -export const onRequest: PagesFunction = async ({ request, env, params, data }) => { +export const onRequest: PagesFunction = async ({ request, env, data }) => { return handleRequest(request, env.DATABASE, data.connectedActor) } diff --git a/functions/api/v1/accounts/update_credentials.ts b/functions/api/v1/accounts/update_credentials.ts index f29837f..02dcf1e 100644 --- a/functions/api/v1/accounts/update_credentials.ts +++ b/functions/api/v1/accounts/update_credentials.ts @@ -9,7 +9,7 @@ import * as images from 'wildebeest/backend/src/media/image' import type { Env } from 'wildebeest/backend/src/types/env' import type { Actor } from 'wildebeest/backend/src/activitypub/actors' import { updateActorProperty } from 'wildebeest/backend/src/activitypub/actors' -import type { CredentialAccount, MastodonAccount } from 'wildebeest/backend/src/types/account' +import type { CredentialAccount } from 'wildebeest/backend/src/types/account' import type { ContextData } from 'wildebeest/backend/src/types/context' import { loadLocalMastodonAccount } from 'wildebeest/backend/src/mastodon/account' diff --git a/functions/api/v1/apps.ts b/functions/api/v1/apps.ts index 828aa0b..de7e186 100644 --- a/functions/api/v1/apps.ts +++ b/functions/api/v1/apps.ts @@ -1,6 +1,4 @@ import { ContextData } from 'wildebeest/backend/src/types/context' -import { b64ToUrlEncoded, exportPublicKeyPair } from 'wildebeest/backend/src/webpush/util' -import type { JWK } from 'wildebeest/backend/src/webpush/jwk' import { Env } from 'wildebeest/backend/src/types/env' import { createClient } from 'wildebeest/backend/src/mastodon/client' import { getVAPIDKeys, VAPIDPublicKey } from 'wildebeest/backend/src/mastodon/subscription' @@ -12,7 +10,7 @@ type AppsPost = { scopes: string } -export const onRequest: PagesFunction = async ({ request, env, data }) => { +export const onRequest: PagesFunction = async ({ request, env }) => { return handleRequest(env.DATABASE, request) } diff --git a/functions/api/v1/notifications.ts b/functions/api/v1/notifications.ts index 8aaf6db..6c1195e 100644 --- a/functions/api/v1/notifications.ts +++ b/functions/api/v1/notifications.ts @@ -1,11 +1,8 @@ // https://docs.joinmastodon.org/methods/notifications/#get import type { Env } from 'wildebeest/backend/src/types/env' -import * as objects from 'wildebeest/backend/src/activitypub/objects' import type { Person } from 'wildebeest/backend/src/activitypub/actors' import type { ContextData } from 'wildebeest/backend/src/types/context' -import { getNotifications } from 'wildebeest/backend/src/mastodon/notification' -import type { MastodonStatus } from 'wildebeest/backend/src/types' export const onRequest: PagesFunction = async ({ request, env, data }) => { return handleRequest(request, env.KV_CACHE, data.connectedActor) diff --git a/functions/api/v1/notifications/[id].ts b/functions/api/v1/notifications/[id].ts index d4b05a7..c698826 100644 --- a/functions/api/v1/notifications/[id].ts +++ b/functions/api/v1/notifications/[id].ts @@ -4,7 +4,6 @@ import type { Notification } from 'wildebeest/backend/src/types/notification' import { urlToHandle } from 'wildebeest/backend/src/utils/handle' import { getPersonById } from 'wildebeest/backend/src/activitypub/actors' import { loadExternalMastodonAccount } from 'wildebeest/backend/src/mastodon/account' -import * as objects from 'wildebeest/backend/src/activitypub/objects' import type { Person } from 'wildebeest/backend/src/activitypub/actors' import type { Env } from 'wildebeest/backend/src/types/env' import type { ContextData } from 'wildebeest/backend/src/types/context' diff --git a/functions/api/v1/push/subscription.ts b/functions/api/v1/push/subscription.ts index 99f71da..8dc85fa 100644 --- a/functions/api/v1/push/subscription.ts +++ b/functions/api/v1/push/subscription.ts @@ -5,10 +5,6 @@ import type { CreateRequest } from 'wildebeest/backend/src/mastodon/subscription import { ContextData } from 'wildebeest/backend/src/types/context' import { Env } from 'wildebeest/backend/src/types/env' import * as errors from 'wildebeest/backend/src/errors' -import type { JWK } from 'wildebeest/backend/src/webpush/jwk' -import type { WebPushInfos, WebPushMessage, WebPushResult } from 'wildebeest/backend/src/webpush/webpushinfos' -import { b64ToUrlEncoded, exportPublicKeyPair } from 'wildebeest/backend/src/webpush/util' -import { generateWebPushMessage } from 'wildebeest/backend/src/webpush' import { getVAPIDKeys, VAPIDPublicKey } from 'wildebeest/backend/src/mastodon/subscription' export const onRequestGet: PagesFunction = async ({ request, env, data }) => { diff --git a/functions/api/v1/statuses.ts b/functions/api/v1/statuses.ts index 6abc4b3..bc46a29 100644 --- a/functions/api/v1/statuses.ts +++ b/functions/api/v1/statuses.ts @@ -1,7 +1,6 @@ // https://docs.joinmastodon.org/methods/statuses/#create import { loadLocalMastodonAccount } from 'wildebeest/backend/src/mastodon/account' -import type { MediaAttachment } from 'wildebeest/backend/src/types/media' import { createPublicNote } from 'wildebeest/backend/src/activitypub/objects/note' import type { Document } from 'wildebeest/backend/src/activitypub/objects' import { getObjectByMastodonId } from 'wildebeest/backend/src/activitypub/objects' @@ -9,8 +8,6 @@ import { getMentions } from 'wildebeest/backend/src/mastodon/status' import * as activities from 'wildebeest/backend/src/activitypub/activities/create' import type { Env } from 'wildebeest/backend/src/types/env' import type { ContextData } from 'wildebeest/backend/src/types/context' -import type { MastodonAccount } from 'wildebeest/backend/src/types/account' -import type { MastodonStatus } from 'wildebeest/backend/src/types/status' import { queryAcct } from 'wildebeest/backend/src/webfinger' import { deliverFollowers, deliverToActor } from 'wildebeest/backend/src/activitypub/deliver' import { addObjectInOutbox } from 'wildebeest/backend/src/activitypub/actors/outbox' @@ -47,7 +44,7 @@ export async function handleRequest( return new Response('', { status: 400 }) } - let mediaAttachments: Array = [] + const mediaAttachments: Array = [] if (body.media_ids && body.media_ids.length > 0) { for (let i = 0, len = body.media_ids.length; i < len; i++) { const id = body.media_ids[i] diff --git a/functions/api/v1/statuses/[id].ts b/functions/api/v1/statuses/[id].ts index 00f1e1b..e9e4b1d 100644 --- a/functions/api/v1/statuses/[id].ts +++ b/functions/api/v1/statuses/[id].ts @@ -1,15 +1,11 @@ // https://docs.joinmastodon.org/methods/statuses/#get import type { UUID } from 'wildebeest/backend/src/types' -import { urlToHandle } from 'wildebeest/backend/src/utils/handle' -import { parseHandle } from 'wildebeest/backend/src/utils/parse' -import type { Person } from 'wildebeest/backend/src/activitypub/actors' import type { ContextData } from 'wildebeest/backend/src/types/context' -import { getFollowers } from 'wildebeest/backend/src/mastodon/follow' import { getMastodonStatusById } from 'wildebeest/backend/src/mastodon/status' import type { Env } from 'wildebeest/backend/src/types/env' -export const onRequest: PagesFunction = async ({ params, request, env, data }) => { +export const onRequest: PagesFunction = async ({ params, env }) => { return handleRequest(env.DATABASE, params.id as UUID) } diff --git a/functions/api/v1/statuses/[id]/favourite.ts b/functions/api/v1/statuses/[id]/favourite.ts index 17cb920..36f7ea8 100644 --- a/functions/api/v1/statuses/[id]/favourite.ts +++ b/functions/api/v1/statuses/[id]/favourite.ts @@ -1,7 +1,6 @@ // https://docs.joinmastodon.org/methods/statuses/#favourite import type { Env } from 'wildebeest/backend/src/types/env' -import { parseHandle } from 'wildebeest/backend/src/utils/parse' import { insertLike } from 'wildebeest/backend/src/mastodon/like' import { getSigningKey } from 'wildebeest/backend/src/mastodon/account' import { deliverToActor } from 'wildebeest/backend/src/activitypub/deliver' @@ -11,10 +10,9 @@ import * as like from 'wildebeest/backend/src/activitypub/activities/like' import { getObjectByMastodonId } from 'wildebeest/backend/src/activitypub/objects' import type { Note } from 'wildebeest/backend/src/activitypub/objects/note' import type { ContextData } from 'wildebeest/backend/src/types/context' -import { queryAcct } from 'wildebeest/backend/src/webfinger' import { toMastodonStatusFromObject } from 'wildebeest/backend/src/mastodon/status' -export const onRequest: PagesFunction = async ({ request, env, data, params }) => { +export const onRequest: PagesFunction = async ({ env, data, params }) => { return handleRequest(env.DATABASE, params.id as string, data.connectedActor, env.userKEK) } diff --git a/functions/api/v1/statuses/[id]/reblog.ts b/functions/api/v1/statuses/[id]/reblog.ts index 3ba7090..fe89945 100644 --- a/functions/api/v1/statuses/[id]/reblog.ts +++ b/functions/api/v1/statuses/[id]/reblog.ts @@ -1,7 +1,6 @@ // https://docs.joinmastodon.org/methods/statuses/#boost import type { Env } from 'wildebeest/backend/src/types/env' -import { parseHandle } from 'wildebeest/backend/src/utils/parse' import { addObjectInOutbox } from 'wildebeest/backend/src/activitypub/actors/outbox' import { insertReblog } from 'wildebeest/backend/src/mastodon/reblog' import { getSigningKey } from 'wildebeest/backend/src/mastodon/account' @@ -12,10 +11,9 @@ import * as announce from 'wildebeest/backend/src/activitypub/activities/announc import { getObjectByMastodonId } from 'wildebeest/backend/src/activitypub/objects' import type { Note } from 'wildebeest/backend/src/activitypub/objects/note' import type { ContextData } from 'wildebeest/backend/src/types/context' -import { queryAcct } from 'wildebeest/backend/src/webfinger' import { toMastodonStatusFromObject } from 'wildebeest/backend/src/mastodon/status' -export const onRequest: PagesFunction = async ({ request, env, data, params }) => { +export const onRequest: PagesFunction = async ({ env, data, params }) => { return handleRequest(env.DATABASE, params.id as string, data.connectedActor, env.userKEK) } diff --git a/functions/api/v1/timelines/home.ts b/functions/api/v1/timelines/home.ts index 5f8209e..7296a01 100644 --- a/functions/api/v1/timelines/home.ts +++ b/functions/api/v1/timelines/home.ts @@ -1,11 +1,6 @@ import type { Env } from 'wildebeest/backend/src/types/env' import type { ContextData } from 'wildebeest/backend/src/types/context' import type { Actor } from 'wildebeest/backend/src/activitypub/actors/' -import * as objects from 'wildebeest/backend/src/activitypub/objects/' -import { urlToHandle } from 'wildebeest/backend/src/utils/handle' -import { getHomeTimeline } from 'wildebeest/backend/src/mastodon/timeline' -import { getPersonById } from 'wildebeest/backend/src/activitypub/actors' -import type { MastodonAccount, MastodonStatus } from 'wildebeest/backend/src/types/' import * as errors from 'wildebeest/backend/src/errors' const headers = { @@ -14,7 +9,7 @@ const headers = { 'content-type': 'application/json; charset=utf-8', } -export const onRequest: PagesFunction = async ({ request, env, params, data }) => { +export const onRequest: PagesFunction = async ({ request, env, data }) => { return handleRequest(request, env.KV_CACHE, data.connectedActor) } diff --git a/functions/api/v1/timelines/public.ts b/functions/api/v1/timelines/public.ts index ada9e62..d68249d 100644 --- a/functions/api/v1/timelines/public.ts +++ b/functions/api/v1/timelines/public.ts @@ -8,7 +8,7 @@ const headers = { 'content-type': 'application/json; charset=utf-8', } -export const onRequest: PagesFunction = async ({ request, env, params, data }) => { +export const onRequest: PagesFunction = async ({ request, env }) => { const { searchParams } = new URL(request.url) const local = searchParams.get('local') === 'true' const remote = searchParams.get('remote') === 'true' @@ -21,6 +21,7 @@ export const onRequest: PagesFunction = async ({ request, export async function handleRequest( domain: string, db: D1Database, + // eslint-disable-next-line @typescript-eslint/no-unused-vars -- TODO: use only_media { local = false, remote = false, only_media = false, offset = 0 } = {} ): Promise { let localParam = LocalPreference.NotSet diff --git a/functions/first-login.ts b/functions/first-login.ts index bef2a96..f53e603 100644 --- a/functions/first-login.ts +++ b/functions/first-login.ts @@ -2,11 +2,9 @@ // especially) import type { Env } from 'wildebeest/backend/src/types/env' import type { ContextData } from 'wildebeest/backend/src/types/context' -import type { Person } from 'wildebeest/backend/src/activitypub/actors' import { createPerson } from 'wildebeest/backend/src/activitypub/actors' -import * as errors from 'wildebeest/backend/src/errors' -export const onRequestPost: PagesFunction = async ({ request, env, data }) => { +export const onRequestPost: PagesFunction = async ({ request, env }) => { return handlePostRequest(request, env.DATABASE, env.userKEK) } diff --git a/functions/oauth/authorize.ts b/functions/oauth/authorize.ts index 32201db..e707ad6 100644 --- a/functions/oauth/authorize.ts +++ b/functions/oauth/authorize.ts @@ -10,7 +10,7 @@ import { getPersonByEmail } from 'wildebeest/backend/src/activitypub/actors' // Extract the JWT token sent by Access (running before us). const extractJWTFromRequest = (request: Request) => request.headers.get('Cf-Access-Jwt-Assertion') || '' -export const onRequest: PagesFunction = async ({ data, request, env }) => { +export const onRequest: PagesFunction = async ({ request, env }) => { return handleRequest(request, env.DATABASE, env.userKEK, env.ACCESS_AUTH_DOMAIN, env.ACCESS_AUD) } @@ -58,8 +58,6 @@ export async function handleRequest( return new Response('', { status: 403 }) } - const scope = url.searchParams.get('scope') || '' - const jwt = extractJWTFromRequest(request) const validate = access.generateValidator({ jwt, domain: accessDomain, aud: accessAud }) await validate(request) diff --git a/functions/oauth/token.ts b/functions/oauth/token.ts index 5b00d31..ca84436 100644 --- a/functions/oauth/token.ts +++ b/functions/oauth/token.ts @@ -9,7 +9,7 @@ type Body = { code: string | null } -export const onRequest: PagesFunction = async ({ params, request, env }) => { +export const onRequest: PagesFunction = async ({ request, env }) => { return handleRequest(env.DATABASE, request) } diff --git a/functions/start-instance-test-access.ts b/functions/start-instance-test-access.ts index eaee63e..c2c182a 100644 --- a/functions/start-instance-test-access.ts +++ b/functions/start-instance-test-access.ts @@ -3,15 +3,14 @@ import * as access from 'wildebeest/backend/src/access' import * as errors from 'wildebeest/backend/src/errors' import { parse } from 'cookie' import type { ContextData } from 'wildebeest/backend/src/types/context' -import type { InstanceConfig } from 'wildebeest/backend/src/config' -import { configure } from 'wildebeest/backend/src/config' -export const onRequestGet: PagesFunction = async ({ request, data, env }) => { - return handleGetRequest(env.DATABASE, request) +export const onRequestGet: PagesFunction = async ({ request, env }) => { + return handleGetRequest(env, request) } // Route to test if Access has been configured properly -export async function handleGetRequest(db: D1Database, request: Request): Promise { +export async function handleGetRequest(env: Env, request: Request): Promise { + const db = env.DATABASE const query = ` SELECT * FROM instance_config WHERE key IN ('accessDomain', 'accessAud') ` @@ -37,7 +36,7 @@ export async function handleGetRequest(db: D1Database, request: Request): Promis const domain = env.ACCESS_AUTH_DOMAIN const validator = access.generateValidator({ jwt, domain, aud: env.ACCESS_AUD }) - const { payload } = await validator(request) + await validator(request) const identity = await access.getIdentity({ jwt, domain }) if (!identity) { diff --git a/functions/start-instance.ts b/functions/start-instance.ts index 803adac..e9172f6 100644 --- a/functions/start-instance.ts +++ b/functions/start-instance.ts @@ -3,7 +3,6 @@ import type { Env } from 'wildebeest/backend/src/types/env' import * as errors from 'wildebeest/backend/src/errors' import * as access from 'wildebeest/backend/src/access' import { parse } from 'cookie' -import type { ContextData } from 'wildebeest/backend/src/types/context' import type { InstanceConfig } from 'wildebeest/backend/src/config' import * as config from 'wildebeest/backend/src/config' @@ -12,11 +11,10 @@ export const onRequestPost: PagesFunction = async ({ request, env }) = } export const onRequestGet: PagesFunction = async (ctx) => { - const { request, env, next } = ctx + const { request, env } = ctx const cookie = parse(request.headers.get('Cookie') || '') const jwt = cookie['CF_Authorization'] if (!jwt) { - const { hostname } = new URL(request.url) const url = access.generateLoginURL({ redirectURL: new URL('/start-instance', 'https://' + env.DOMAIN), domain: env.ACCESS_AUTH_DOMAIN, @@ -44,7 +42,7 @@ export async function handlePostRequest( } const validator = access.generateValidator({ jwt, domain: accessDomain, aud: accessAud }) - const { payload } = await validator(request) + await validator(request) const identity = await access.getIdentity({ jwt, domain: accessDomain }) if (!identity) { diff --git a/package.json b/package.json index b8ee622..f46d554 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "test": "NODE_OPTIONS=--experimental-vm-modules yarn jest", "lint": "npx eslint .", "lint:be": "npx eslint backend", + "lint:functions": "npx eslint functions", "build": "yarn --cwd frontend install && yarn --cwd frontend build", "d1": "NO_D1_WARNING=true wrangler d1", "pages": "NO_D1_WARNING=true wrangler pages",