rhythia-api 59.0.0 → 63.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/getUser.ts ADDED
@@ -0,0 +1,60 @@
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
10
+ .object({
11
+ about_me: z.string().nullable(),
12
+ avatar_url: z.string().nullable(),
13
+ badges: z.any().nullable(),
14
+ created_at: z.number().nullable(),
15
+ flag: z.string().nullable(),
16
+ id: z.number(),
17
+ uid: z.string().nullable(),
18
+ username: z.string().nullable(),
19
+ verified: z.boolean().nullable(),
20
+ })
21
+ .or(
22
+ z.object({
23
+ error: z.string(),
24
+ })
25
+ ),
26
+ };
27
+
28
+ const supabase = createClient<Database>(
29
+ `https://pfkajngbllcbdzoylrvp.supabase.co`,
30
+ process.env.ADMIN_KEY!,
31
+ {
32
+ auth: {
33
+ autoRefreshToken: false,
34
+ persistSession: false,
35
+ },
36
+ }
37
+ );
38
+
39
+ export async function GET(
40
+ res: Response
41
+ ): Promise<(typeof Schema)["output"]["_type"]> {
42
+ const toParse = await res.json();
43
+ const data = Schema.input.parse(toParse);
44
+
45
+ let { data: profiles, error } = await supabase
46
+ .from("profiles")
47
+ .select("*")
48
+ .eq("column", data.id);
49
+
50
+ if (!profiles?.length) {
51
+ return {
52
+ error: "User not found",
53
+ };
54
+ }
55
+
56
+ const user = profiles[0];
57
+ return {
58
+ ...user,
59
+ };
60
+ }
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/getUser.ts API
9
+ import { Schema as GetUser } from "./api/getUser"
10
+ export { Schema as SchemaGetUser } from "./api/getUser"
11
+ export const getUser = handleApi({url:"/api/getUser",...GetUser})
7
12
  export { handleApi } from "./handleApi"
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "59.0.0",
3
+ "version": "63.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,76 @@
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
+
6
+ // Set up the repository URL
7
+ const repoUrl = `https://${process.env.GIT_KEY}@github.com/cunev/rhythia-api.git`;
8
+
9
+ const sourceBranch = process.env.SOURCE_BRANCH!;
10
+ const targetBranch = process.env.TARGET_BRANCH!;
11
+
12
+ async function cloneBranch() {
13
+ const dir = path.join("/tmp", "repo");
14
+
15
+ try {
16
+ // Ensure the directory is clean before cloning
17
+ if (fs.existsSync(dir)) {
18
+ fs.rmdirSync(dir, { recursive: true });
19
+ console.log(`Deleted existing directory: ${dir}`);
20
+ }
21
+
22
+ // Clone the repository into a temporary directory
23
+ await git.clone({
24
+ fs,
25
+ http,
26
+ dir,
27
+ url: repoUrl,
28
+ ref: sourceBranch,
29
+ singleBranch: true,
30
+ depth: 1,
31
+ });
32
+ console.log(`Cloned ${sourceBranch} branch from remote repository.`);
33
+
34
+ // Check out the source branch
35
+ await git.checkout({ fs, dir, ref: sourceBranch });
36
+ console.log(`Checked out to branch: ${sourceBranch}`);
37
+
38
+ // Pull the latest changes from the source branch
39
+ await git.pull({
40
+ fs,
41
+ http,
42
+ dir,
43
+ ref: sourceBranch,
44
+ singleBranch: true,
45
+ author: {
46
+ name: process.env.GIT_USER,
47
+ email: "you@example.com", // Replace with the actual email
48
+ },
49
+ });
50
+ console.log(`Pulled latest changes from branch: ${sourceBranch}`);
51
+
52
+ // Create and checkout the target branch from the source branch
53
+ await git.branch({ fs, dir, ref: targetBranch });
54
+ await git.checkout({ fs, dir, ref: targetBranch });
55
+ console.log(`Created and checked out to branch: ${targetBranch}`);
56
+
57
+ // Push the new branch to the remote repository
58
+ await git.push({
59
+ fs,
60
+ http,
61
+ dir,
62
+ remote: "origin",
63
+ ref: targetBranch,
64
+ force: true,
65
+ onAuth: () => ({
66
+ username: process.env.GIT_KEY, // GitHub token or password
67
+ password: "",
68
+ }),
69
+ });
70
+ console.log(`Pushed new branch to remote: ${targetBranch}`);
71
+ } catch (error) {
72
+ console.error("Error performing Git operations:", error.message);
73
+ }
74
+ }
75
+
76
+ cloneBranch();
package/scripts/update.ts CHANGED
@@ -44,6 +44,6 @@ exports.push(`export { handleApi } from "./handleApi"`);
44
44
 
45
45
  writeFileSync("./index.ts", exports.join("\n"));
46
46
 
47
- const conf = readFileSync("./.cred", "utf-8");
48
- await $`npm logout`.nothrow();
49
- await $`npm config set ${conf.split("$").join("")} && yarn publish`;
47
+ // const conf = readFileSync("./.cred", "utf-8");
48
+ // await $`npm logout`.nothrow();
49
+ await $`yarn publish`;