rhythia-api 62.0.0 → 64.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.
@@ -0,0 +1,61 @@
1
+ import { createClient } from "@supabase/supabase-js";
2
+ import z from "zod";
3
+ import { Database } from "../types/supabase";
4
+
5
+ export const Schema = {
6
+ input: z.object({
7
+ id: z.string(),
8
+ }),
9
+ output: z.object({
10
+ error: z.string().optional(),
11
+ user: z
12
+ .object({
13
+ about_me: z.string().nullable(),
14
+ avatar_url: z.string().nullable(),
15
+ badges: z.any().nullable(),
16
+ created_at: z.number().nullable(),
17
+ flag: z.string().nullable(),
18
+ id: z.number(),
19
+ uid: z.string().nullable(),
20
+ username: z.string().nullable(),
21
+ verified: z.boolean().nullable(),
22
+ })
23
+ .optional(),
24
+ }),
25
+ };
26
+
27
+ const supabase = createClient<Database>(
28
+ `https://pfkajngbllcbdzoylrvp.supabase.co`,
29
+ process.env.ADMIN_KEY!,
30
+ {
31
+ auth: {
32
+ autoRefreshToken: false,
33
+ persistSession: false,
34
+ },
35
+ }
36
+ );
37
+
38
+ export async function GET(
39
+ res: Response
40
+ ): Promise<(typeof Schema)["output"]["_type"]> {
41
+ const toParse = await res.json();
42
+ const data = Schema.input.parse(toParse);
43
+
44
+ let { data: profiles, error } = await supabase
45
+ .from("profiles")
46
+ .select("*")
47
+ .eq("column", data.id);
48
+
49
+ if (!profiles?.length) {
50
+ return {
51
+ error: "User not found",
52
+ };
53
+ }
54
+
55
+ const user = profiles[0];
56
+ return {
57
+ user: {
58
+ ...user,
59
+ },
60
+ };
61
+ }
package/handleApi.ts CHANGED
@@ -4,13 +4,16 @@ export function handleApi<
4
4
  T extends { url: string; input: z.ZodObject<any>; output: z.ZodObject<any> }
5
5
  >(apiSchema: T) {
6
6
  return async (input: T["input"]["_type"]): Promise<T["output"]["_type"]> => {
7
- const response = await fetch(`https://test.com${apiSchema.url}`, {
8
- method: "POST",
9
- body: JSON.stringify(input),
10
- headers: {
11
- "Content-Type": "application/json",
12
- },
13
- });
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
+ headers: {
13
+ "Content-Type": "application/json",
14
+ },
15
+ }
16
+ );
14
17
  const output = await response.json();
15
18
  return output;
16
19
  };
package/index.html ADDED
@@ -0,0 +1,3 @@
1
+ <html>
2
+ <div>Rhythia API</div>
3
+ </html>
package/index.ts CHANGED
@@ -4,4 +4,9 @@ import { handleApi } from "./handleApi"
4
4
  import { Schema as EditUser } from "./api/editUser"
5
5
  export { Schema as SchemaEditUser } from "./api/editUser"
6
6
  export const editUser = handleApi({url:"/api/editUser",...EditUser})
7
+
8
+ // ./api/getProfile.ts API
9
+ import { Schema as GetProfile } from "./api/getProfile"
10
+ export { Schema as SchemaGetProfile } from "./api/getProfile"
11
+ export const getProfile = handleApi({url:"/api/getProfile",...GetProfile})
7
12
  export { handleApi } from "./handleApi"
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "62.0.0",
3
+ "version": "64.0.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "update": "bun ./scripts/update.ts",
7
+ "ci-deploy": "tsx ./scripts/ci-deploy.ts",
8
+ "test": "bun ./scripts/test.ts",
7
9
  "sync": "npx supabase gen types typescript --project-id \"pfkajngbllcbdzoylrvp\" --schema public > types/supabase.ts",
8
10
  "pipeline:build-api": "tsx ./scripts/build.ts",
9
11
  "pipeline:deploy-testing": "tsx ./scripts/build.ts"
@@ -20,7 +22,9 @@
20
22
  "bufferutil": "^4.0.8",
21
23
  "bun": "^1.1.22",
22
24
  "esbuild": "^0.23.0",
25
+ "isomorphic-git": "^1.27.1",
23
26
  "lodash": "^4.17.21",
27
+ "simple-git": "^3.25.0",
24
28
  "supabase": "^1.188.4",
25
29
  "tsx": "^4.17.0",
26
30
  "utf-8-validate": "^6.0.4",
@@ -0,0 +1,81 @@
1
+ import fs from "fs";
2
+ import * as git from "isomorphic-git";
3
+ import http from "isomorphic-git/http/node";
4
+ import path from "path";
5
+ import { getUser } from "..";
6
+
7
+ // Set up the repository URL
8
+ const repoUrl = `https://${process.env.GIT_KEY}@github.com/cunev/rhythia-api.git`;
9
+
10
+ const sourceBranch = process.env.SOURCE_BRANCH!;
11
+ const targetBranch = process.env.TARGET_BRANCH!;
12
+
13
+ async function cloneBranch() {
14
+ const dir = path.join("/tmp", "repo");
15
+
16
+ try {
17
+ // Ensure the directory is clean before cloning
18
+ if (fs.existsSync(dir)) {
19
+ fs.rmdirSync(dir, { recursive: true });
20
+ console.log(`Deleted existing directory: ${dir}`);
21
+ }
22
+
23
+ // Clone the repository into a temporary directory
24
+ await git.clone({
25
+ fs,
26
+ http,
27
+ dir,
28
+ url: repoUrl,
29
+ ref: sourceBranch,
30
+ singleBranch: true,
31
+ depth: 1,
32
+ });
33
+ console.log(`Cloned ${sourceBranch} branch from remote repository.`);
34
+
35
+ // Check out the source branch
36
+ await git.checkout({ fs, dir, ref: sourceBranch });
37
+ console.log(`Checked out to branch: ${sourceBranch}`);
38
+
39
+ // Pull the latest changes from the source branch
40
+ await git.pull({
41
+ fs,
42
+ http,
43
+ dir,
44
+ ref: sourceBranch,
45
+ singleBranch: true,
46
+ author: {
47
+ name: process.env.GIT_USER,
48
+ email: "you@example.com", // Replace with the actual email
49
+ },
50
+ });
51
+ console.log(`Pulled latest changes from branch: ${sourceBranch}`);
52
+
53
+ // Create and checkout the target branch from the source branch
54
+ await git.branch({ fs, dir, ref: targetBranch });
55
+ await git.checkout({ fs, dir, ref: targetBranch });
56
+ console.log(`Created and checked out to branch: ${targetBranch}`);
57
+
58
+ // Push the new branch to the remote repository
59
+ await git.push({
60
+ fs,
61
+ http,
62
+ dir,
63
+ remote: "origin",
64
+ ref: targetBranch,
65
+ force: true,
66
+ onAuth: () => ({
67
+ username: process.env.GIT_KEY, // GitHub token or password
68
+ password: "",
69
+ }),
70
+ });
71
+ console.log(`Pushed new branch to remote: ${targetBranch}`);
72
+ } catch (error) {
73
+ console.error("Error performing Git operations:", error.message);
74
+ }
75
+ }
76
+
77
+ cloneBranch();
78
+
79
+ const user = await getUser({ id: "0" });
80
+ if (user) {
81
+ }