Skip to content

Commit 41f8605

Browse files
committed
feat(packages): add klesia-sdk
1 parent f54eec6 commit 41f8605

File tree

12 files changed

+100
-14
lines changed

12 files changed

+100
-14
lines changed

apps/klesia/docs/index.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
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.
2+
3+
## TypeScript SDK
4+
5+
There is a TypeScript SDK available for Klesia RPC. It is available on npm as `@mina-js/klesia-sdk`.

apps/klesia/src/docs.md renamed to apps/klesia/docs/rpc.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Klesia RPC
2-
3-
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.
4-
51
## Methods
62

73
### mina_getTransactionCount

apps/klesia/package.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
{
22
"name": "@mina-js/klesia",
33
"type": "module",
4+
"module": "dist/index.js",
5+
"types": "dist/index.d.ts",
6+
"exports": {
7+
".": {
8+
"types": "./dist/index.d.ts",
9+
"default": "./dist/index.cjs",
10+
"import": "./dist/index.js"
11+
}
12+
},
413
"scripts": {
5-
"build": "tsc --noEmit && bun build src/index.ts --outdir dist",
6-
"dev": "bun run --hot src/index.ts",
7-
"start": "bun dist/index.js"
14+
"build": "tsup-node",
15+
"dev": "tsup-node --watch --onSuccess \"node dist/index.js\"",
16+
"start": "node dist/index.js"
817
},
918
"dependencies": {
10-
"@mina-js/shared": "workspace:*",
19+
"@hono/node-server": "^1.12.2",
1120
"@hono/zod-openapi": "^0.16.0",
21+
"@mina-js/shared": "workspace:*",
1222
"@scalar/hono-api-reference": "^0.5.143",
1323
"@urql/core": "^5.0.6",
1424
"dayjs": "^1.11.13",
25+
"dotenv": "^16.4.5",
1526
"hono": "^4.5.10",
1627
"hono-rate-limiter": "^0.4.0",
1728
"nanoid": "^5.0.7",

apps/klesia/src/custom.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
declare module "*.md";
1+
declare module "*.txt";

apps/klesia/src/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import "dotenv/config";
2+
import { serve } from "@hono/node-server";
3+
import { getConnInfo } from "@hono/node-server/conninfo";
14
import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
25
import { PublicKeySchema } from "@mina-js/shared";
36
import { apiReference } from "@scalar/hono-api-reference";
47
import { rateLimiter } from "hono-rate-limiter";
5-
import { getConnInfo } from "hono/bun";
68
import { logger } from "hono/logger";
79
import { nanoid } from "nanoid";
810
import { match } from "ts-pattern";
9-
import rpcDocs from "./docs.md" with { type: "text" };
11+
import mainDocs from "../docs/index.txt";
12+
import rpcDocs from "../docs/rpc.txt";
1013
import { mina } from "./methods/mina";
1114
import { RpcMethodSchema, RpcResponseSchema } from "./schema";
1215
import { buildResponse } from "./utils/build-response";
@@ -25,7 +28,8 @@ api.doc("/api/openapi", {
2528
openapi: "3.0.0",
2629
info: {
2730
version: "1.0.0",
28-
title: "Klesia API",
31+
title: "Klesia RPC",
32+
description: mainDocs,
2933
},
3034
});
3135

@@ -50,7 +54,7 @@ const rpcRoute = createRoute({
5054

5155
api.get("/", ({ redirect }) => redirect("/api", 301));
5256

53-
api.openapi(rpcRoute, async ({ req, json }) => {
57+
const klesiaRpcRoute = api.openapi(rpcRoute, async ({ req, json }) => {
5458
const body = req.valid("json");
5559
return match(body)
5660
.with({ method: "mina_getTransactionCount" }, async ({ params }) => {
@@ -93,4 +97,6 @@ api.get(
9397
}),
9498
);
9599

96-
export default api;
100+
serve(api);
101+
102+
export type KlesiaRpc = typeof klesiaRpcRoute;

apps/klesia/tsup.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import sharedConfig from "../../packages/shared/tsup.config";
2+
3+
export default sharedConfig;

bun.lockb

1.21 KB
Binary file not shown.

packages/klesia-sdk/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# klesia-sdk
2+
3+
To install dependencies:
4+
5+
```bash
6+
bun install
7+
```
8+
9+
To run:
10+
11+
```bash
12+
bun run index.ts
13+
```
14+
15+
This project was created using `bun init` in bun v1.1.27. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

packages/klesia-sdk/package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "@mina-js/klesia-sdk",
3+
"type": "module",
4+
"module": "dist/index.js",
5+
"types": "dist/index.d.ts",
6+
"exports": {
7+
".": {
8+
"types": "./dist/index.d.ts",
9+
"default": "./dist/index.cjs",
10+
"import": "./dist/index.js"
11+
}
12+
},
13+
"scripts": {
14+
"build": "tsup",
15+
"test": "bun test",
16+
"cleanup": "rimraf dist .turbo"
17+
},
18+
"devDependencies": {
19+
"@mina-js/klesia": "workspace:*"
20+
},
21+
"peerDependencies": {
22+
"typescript": "^5.0.0"
23+
},
24+
"dependencies": {
25+
"hono": "^4.5.10",
26+
"ts-pattern": "^5.3.1",
27+
"zod": "^3.23.8"
28+
}
29+
}

packages/klesia-sdk/src/client.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { KlesiaRpc } from "@mina-js/klesia";
2+
import { hc } from "hono/client";
3+
import { match } from "ts-pattern";
4+
import { z } from "zod";
5+
6+
const NetworkMatcher = z.enum(["mainnet", "devnet"]);
7+
8+
export const createClient = ({ network }: { network: 'mainnet' | 'devnet' }) => {
9+
return match(NetworkMatcher.parse(network))
10+
.with("devnet", () =>
11+
hc<KlesiaRpc>("https://devnet.klesia.palladians.xyz/api"),
12+
)
13+
.with("mainnet", () =>
14+
hc<KlesiaRpc>("https://mainnet.klesia.palladians.xyz/api"),
15+
)
16+
.exhaustive();
17+
};

0 commit comments

Comments
 (0)