rhythia-api 83.0.0 → 85.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.json +6 -0
- package/api/editProfile.ts +74 -74
- package/api/getLeaderboard.ts +68 -68
- package/api/getProfile.ts +115 -115
- package/api/searchUsers.ts +44 -46
- package/api/submitScore.ts +106 -92
- package/handleApi.ts +19 -19
- package/index.html +2 -2
- package/index.ts +5 -5
- package/package.json +1 -1
- package/scripts/ci-deploy.ts +76 -76
- package/scripts/update.ts +49 -49
- package/types/database.ts +9 -3
- package/utils/requestUtils.ts +55 -51
- package/utils/supabase.ts +13 -13
- package/vercel.json +12 -12
package/utils/requestUtils.ts
CHANGED
|
@@ -1,51 +1,55 @@
|
|
|
1
|
-
import { NextResponse } from "next/server";
|
|
2
|
-
import { supabase } from "./supabase";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { supabase } from "./supabase";
|
|
3
|
+
import { ZodObject } from "zod";
|
|
4
|
+
|
|
5
|
+
interface Props<
|
|
6
|
+
K = (...args: any[]) => Promise<NextResponse<any>>,
|
|
7
|
+
T = ZodObject<any>
|
|
8
|
+
> {
|
|
9
|
+
request: Request;
|
|
10
|
+
schema: { input: T; output: T };
|
|
11
|
+
authorization?: Function;
|
|
12
|
+
activity: K;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function protectedApi({
|
|
16
|
+
request,
|
|
17
|
+
schema,
|
|
18
|
+
authorization,
|
|
19
|
+
activity,
|
|
20
|
+
}: Props) {
|
|
21
|
+
try {
|
|
22
|
+
const toParse = await request.json();
|
|
23
|
+
const data = schema.input.parse(toParse);
|
|
24
|
+
if (authorization) {
|
|
25
|
+
const authorizationResponse = await authorization(data);
|
|
26
|
+
if (authorizationResponse) {
|
|
27
|
+
return authorizationResponse;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return await activity(data, request);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return NextResponse.json({ error: error.toString() }, { status: 400 });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function validUser(data) {
|
|
37
|
+
if (!data.session) {
|
|
38
|
+
return NextResponse.json(
|
|
39
|
+
{
|
|
40
|
+
error: "Session is missing",
|
|
41
|
+
},
|
|
42
|
+
{ status: 501 }
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const user = await supabase.auth.getUser(data.session);
|
|
47
|
+
if (user.error || !user.data.user) {
|
|
48
|
+
return NextResponse.json(
|
|
49
|
+
{
|
|
50
|
+
error: "Invalid user session",
|
|
51
|
+
},
|
|
52
|
+
{ status: 400 }
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
package/utils/supabase.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { createClient } from "@supabase/supabase-js";
|
|
2
|
-
import { Database } from "../types/database";
|
|
3
|
-
|
|
4
|
-
export const supabase = createClient<Database>(
|
|
5
|
-
`https://pfkajngbllcbdzoylrvp.supabase.co`,
|
|
6
|
-
process.env.ADMIN_KEY || "key",
|
|
7
|
-
{
|
|
8
|
-
auth: {
|
|
9
|
-
autoRefreshToken: false,
|
|
10
|
-
persistSession: false,
|
|
11
|
-
},
|
|
12
|
-
}
|
|
13
|
-
);
|
|
1
|
+
import { createClient } from "@supabase/supabase-js";
|
|
2
|
+
import { Database } from "../types/database";
|
|
3
|
+
|
|
4
|
+
export const supabase = createClient<Database>(
|
|
5
|
+
`https://pfkajngbllcbdzoylrvp.supabase.co`,
|
|
6
|
+
process.env.ADMIN_KEY || "key",
|
|
7
|
+
{
|
|
8
|
+
auth: {
|
|
9
|
+
autoRefreshToken: false,
|
|
10
|
+
persistSession: false,
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
);
|
package/vercel.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"headers": [
|
|
3
|
-
{
|
|
4
|
-
"source": "/api/(.*)",
|
|
5
|
-
"headers": [
|
|
6
|
-
{ "key": "Access-Control-Allow-Credentials", "value": "true" },
|
|
7
|
-
{ "key": "Access-Control-Allow-Origin", "value": "*" },
|
|
8
|
-
{ "key": "Access-Control-Allow-Methods", "value": "GET,OPTIONS,PATCH,DELETE,POST,PUT" },
|
|
9
|
-
{ "key": "Access-Control-Allow-Headers", "value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" }
|
|
10
|
-
]
|
|
11
|
-
}
|
|
12
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"headers": [
|
|
3
|
+
{
|
|
4
|
+
"source": "/api/(.*)",
|
|
5
|
+
"headers": [
|
|
6
|
+
{ "key": "Access-Control-Allow-Credentials", "value": "true" },
|
|
7
|
+
{ "key": "Access-Control-Allow-Origin", "value": "*" },
|
|
8
|
+
{ "key": "Access-Control-Allow-Methods", "value": "GET,OPTIONS,PATCH,DELETE,POST,PUT" },
|
|
9
|
+
{ "key": "Access-Control-Allow-Headers", "value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" }
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
13
|
}
|