rhythia-api 80.0.0 → 82.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/api/getProfile.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { geolocation } from "@vercel/edge";
1
2
  import { NextResponse } from "next/server";
2
3
  import z from "zod";
3
4
  import { Database } from "../types/database";
@@ -42,7 +43,8 @@ export async function POST(res: Response): Promise<NextResponse> {
42
43
  }
43
44
 
44
45
  export async function handler(
45
- data: (typeof Schema)["input"]["_type"]
46
+ data: (typeof Schema)["input"]["_type"],
47
+ req: Request
46
48
  ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
47
49
  let profiles: Database["public"]["Tables"]["profiles"]["Row"][] = [];
48
50
 
@@ -76,6 +78,7 @@ export async function handler(
76
78
 
77
79
  console.log(profiles, error);
78
80
  if (!queryData?.length) {
81
+ const geo = geolocation(req);
79
82
  const data = await supabase
80
83
  .from("profiles")
81
84
  .upsert({
@@ -84,7 +87,7 @@ export async function handler(
84
87
  avatar_url: user.user_metadata.avatar_url,
85
88
  badges: ["Early Bird"],
86
89
  username: user.user_metadata.full_name,
87
- flag: "",
90
+ flag: (geo.country || "US").toUpperCase(),
88
91
  created_at: Date.now(),
89
92
  })
90
93
  .select();
@@ -0,0 +1,36 @@
1
+ import { NextResponse } from "next/server";
2
+ import z from "zod";
3
+ import { protectedApi } from "../utils/requestUtils";
4
+
5
+ export const Schema = {
6
+ input: z.strictObject({
7
+ session: z.string(),
8
+ data: z.strictObject({
9
+ token: z.string(),
10
+ relayHwid: z.string(),
11
+ songId: z.string(),
12
+ noteResults: z.record(z.boolean()),
13
+ triggers: z.array(z.array(z.number())),
14
+ mapHash: z.string(),
15
+ mapTitle: z.string(),
16
+ }),
17
+ }),
18
+ output: z.object({
19
+ error: z.string().optional(),
20
+ }),
21
+ };
22
+
23
+ export async function POST(res: Response): Promise<NextResponse> {
24
+ return protectedApi({
25
+ response: res,
26
+ schema: Schema,
27
+ authorization: () => {},
28
+ activity: handler,
29
+ });
30
+ }
31
+
32
+ export async function handler(
33
+ data: (typeof Schema)["input"]["_type"]
34
+ ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
35
+ return NextResponse.json({});
36
+ }
package/handleApi.ts CHANGED
@@ -1,16 +1,18 @@
1
1
  import { z } from "zod";
2
-
2
+ let env = "development";
3
+ export function setEnvironment(
4
+ stage: "development" | "testing" | "production"
5
+ ) {
6
+ env = stage;
7
+ }
3
8
  export function handleApi<
4
9
  T extends { url: string; input: z.ZodObject<any>; output: z.ZodObject<any> }
5
10
  >(apiSchema: T) {
6
11
  return async (input: T["input"]["_type"]): Promise<T["output"]["_type"]> => {
7
- const response = await fetch(
8
- `https://${process.env.API_STAGE}.rhythia.com${apiSchema.url}`,
9
- {
10
- method: "POST",
11
- body: JSON.stringify(input),
12
- }
13
- );
12
+ const response = await fetch(`https://${env}.rhythia.com${apiSchema.url}`, {
13
+ method: "POST",
14
+ body: JSON.stringify(input),
15
+ });
14
16
  const output = await response.json();
15
17
  return output;
16
18
  };
package/index.ts CHANGED
@@ -19,4 +19,9 @@ export const getProfile = handleApi({url:"/api/getProfile",...GetProfile})
19
19
  import { Schema as SearchUsers } from "./api/searchUsers"
20
20
  export { Schema as SchemaSearchUsers } from "./api/searchUsers"
21
21
  export const searchUsers = handleApi({url:"/api/searchUsers",...SearchUsers})
22
+
23
+ // ./api/submitScore.ts API
24
+ import { Schema as SubmitScore } from "./api/submitScore"
25
+ export { Schema as SchemaSubmitScore } from "./api/submitScore"
26
+ export const submitScore = handleApi({url:"/api/submitScore",...SubmitScore})
22
27
  export { handleApi } from "./handleApi"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "80.0.0",
3
+ "version": "82.0.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "update": "bun ./scripts/update.ts",
@@ -18,6 +18,7 @@
18
18
  "@types/bun": "^1.1.6",
19
19
  "@types/lodash": "^4.17.7",
20
20
  "@types/node": "^22.2.0",
21
+ "@vercel/edge": "^1.1.2",
21
22
  "@vercel/node": "^3.2.8",
22
23
  "aws-lambda": "^1.0.7",
23
24
  "bufferutil": "^4.0.8",
@@ -26,7 +26,7 @@ export async function protectedApi({
26
26
  return authorizationReponse;
27
27
  }
28
28
 
29
- return await activity(data);
29
+ return await activity(data, response);
30
30
  }
31
31
 
32
32
  export async function validUser(data) {