diff --git a/apps/klesia/docs/index.txt b/apps/klesia/docs/index.txt new file mode 100644 index 0000000..d26e16d --- /dev/null +++ b/apps/klesia/docs/index.txt @@ -0,0 +1,5 @@ +Klesia RPC is a JSON-RPC 2.0 wrapper over common Mina Protocol tools and services. The intention is to provide an outstanding Developer Experience for Mina Protocol's zkApp Developers. + +## TypeScript SDK + +There is a TypeScript SDK available for Klesia RPC. It is available on npm as `@mina-js/klesia-sdk`. diff --git a/apps/klesia/src/docs.md b/apps/klesia/docs/rpc.txt similarity index 80% rename from apps/klesia/src/docs.md rename to apps/klesia/docs/rpc.txt index 34a92ce..d332161 100644 --- a/apps/klesia/src/docs.md +++ b/apps/klesia/docs/rpc.txt @@ -1,7 +1,3 @@ -# Klesia RPC - -Klesia RPC is a JSON-RPC 2.0 wrapper over common Mina Protocol tools and services. The intention is to provide an outstanding Developer Experience for Mina Protocol's zkApp Developers. - ## Methods ### mina_getTransactionCount diff --git a/apps/klesia/package.json b/apps/klesia/package.json index 49d24a2..6d2c50c 100644 --- a/apps/klesia/package.json +++ b/apps/klesia/package.json @@ -1,17 +1,28 @@ { "name": "@mina-js/klesia", "type": "module", + "module": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.cjs", + "import": "./dist/index.js" + } + }, "scripts": { - "build": "tsc --noEmit && bun build src/index.ts --outdir dist", - "dev": "bun run --hot src/index.ts", - "start": "bun dist/index.js" + "build": "tsup-node", + "dev": "tsup-node --watch --onSuccess \"node dist/index.js\"", + "start": "node dist/index.js" }, "dependencies": { - "@mina-js/shared": "workspace:*", + "@hono/node-server": "^1.12.2", "@hono/zod-openapi": "^0.16.0", + "@mina-js/shared": "workspace:*", "@scalar/hono-api-reference": "^0.5.143", "@urql/core": "^5.0.6", "dayjs": "^1.11.13", + "dotenv": "^16.4.5", "hono": "^4.5.10", "hono-rate-limiter": "^0.4.0", "nanoid": "^5.0.7", diff --git a/apps/klesia/src/custom.d.ts b/apps/klesia/src/custom.d.ts index 18f423b..2ca0a44 100644 --- a/apps/klesia/src/custom.d.ts +++ b/apps/klesia/src/custom.d.ts @@ -1 +1 @@ -declare module "*.md"; +declare module "*.txt"; diff --git a/apps/klesia/src/index.ts b/apps/klesia/src/index.ts index 7793208..334e5c3 100644 --- a/apps/klesia/src/index.ts +++ b/apps/klesia/src/index.ts @@ -1,12 +1,15 @@ +import "dotenv/config"; +import { serve } from "@hono/node-server"; +import { getConnInfo } from "@hono/node-server/conninfo"; import { OpenAPIHono, createRoute } from "@hono/zod-openapi"; import { PublicKeySchema } from "@mina-js/shared"; import { apiReference } from "@scalar/hono-api-reference"; import { rateLimiter } from "hono-rate-limiter"; -import { getConnInfo } from "hono/bun"; import { logger } from "hono/logger"; import { nanoid } from "nanoid"; import { match } from "ts-pattern"; -import rpcDocs from "./docs.md" with { type: "text" }; +import mainDocs from "../docs/index.txt"; +import rpcDocs from "../docs/rpc.txt"; import { mina } from "./methods/mina"; import { RpcMethodSchema, RpcResponseSchema } from "./schema"; import { buildResponse } from "./utils/build-response"; @@ -25,7 +28,8 @@ api.doc("/api/openapi", { openapi: "3.0.0", info: { version: "1.0.0", - title: "Klesia API", + title: "Klesia RPC", + description: mainDocs, }, }); @@ -50,7 +54,7 @@ const rpcRoute = createRoute({ api.get("/", ({ redirect }) => redirect("/api", 301)); -api.openapi(rpcRoute, async ({ req, json }) => { +const klesiaRpcRoute = api.openapi(rpcRoute, async ({ req, json }) => { const body = req.valid("json"); return match(body) .with({ method: "mina_getTransactionCount" }, async ({ params }) => { @@ -93,4 +97,6 @@ api.get( }), ); -export default api; +serve(api); + +export type KlesiaRpc = typeof klesiaRpcRoute; diff --git a/apps/klesia/tsup.config.ts b/apps/klesia/tsup.config.ts new file mode 100644 index 0000000..33013ce --- /dev/null +++ b/apps/klesia/tsup.config.ts @@ -0,0 +1,3 @@ +import sharedConfig from "../../packages/shared/tsup.config"; + +export default sharedConfig; diff --git a/bun.lockb b/bun.lockb index b975fc1..423e4fb 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/klesia-sdk/README.md b/packages/klesia-sdk/README.md new file mode 100644 index 0000000..ac29d3f --- /dev/null +++ b/packages/klesia-sdk/README.md @@ -0,0 +1,15 @@ +# klesia-sdk + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.1.27. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/packages/klesia-sdk/package.json b/packages/klesia-sdk/package.json new file mode 100644 index 0000000..571c4c7 --- /dev/null +++ b/packages/klesia-sdk/package.json @@ -0,0 +1,29 @@ +{ + "name": "@mina-js/klesia-sdk", + "type": "module", + "module": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.cjs", + "import": "./dist/index.js" + } + }, + "scripts": { + "build": "tsup", + "test": "bun test", + "cleanup": "rimraf dist .turbo" + }, + "devDependencies": { + "@mina-js/klesia": "workspace:*" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "dependencies": { + "hono": "^4.5.10", + "ts-pattern": "^5.3.1", + "zod": "^3.23.8" + } +} diff --git a/packages/klesia-sdk/src/client.ts b/packages/klesia-sdk/src/client.ts new file mode 100644 index 0000000..2208505 --- /dev/null +++ b/packages/klesia-sdk/src/client.ts @@ -0,0 +1,17 @@ +import type { KlesiaRpc } from "@mina-js/klesia"; +import { hc } from "hono/client"; +import { match } from "ts-pattern"; +import { z } from "zod"; + +const NetworkMatcher = z.enum(["mainnet", "devnet"]); + +export const createClient = ({ network }: { network: 'mainnet' | 'devnet' }) => { + return match(NetworkMatcher.parse(network)) + .with("devnet", () => + hc("https://devnet.klesia.palladians.xyz/api"), + ) + .with("mainnet", () => + hc("https://mainnet.klesia.palladians.xyz/api"), + ) + .exhaustive(); +}; diff --git a/packages/klesia-sdk/src/index.ts b/packages/klesia-sdk/src/index.ts new file mode 100644 index 0000000..da6c2d5 --- /dev/null +++ b/packages/klesia-sdk/src/index.ts @@ -0,0 +1 @@ +export { createClient } from "./client"; diff --git a/packages/klesia-sdk/tsup.config.ts b/packages/klesia-sdk/tsup.config.ts new file mode 100644 index 0000000..6e9381b --- /dev/null +++ b/packages/klesia-sdk/tsup.config.ts @@ -0,0 +1,3 @@ +import sharedConfig from "../shared/tsup.config"; + +export default sharedConfig;