Skip to content

Commit 67413e2

Browse files
committed
sdk content
1 parent 497e307 commit 67413e2

File tree

4 files changed

+172
-12
lines changed

4 files changed

+172
-12
lines changed

astro.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default defineConfig({
101101
{ label: "Ecency wallets", slug: "developers/wallets" },
102102
{ label: "Ecency chats", slug: "developers/chats" },
103103
{ label: "Ecency analytics", slug: "developers/analytics" },
104-
{ label: "API Reference", slug: "developers/api" }, // if you later add this
104+
{ label: "Ecency SDK", slug: "developers/sdk" },
105105
{
106106
label: "Extra services",
107107
items: [

src/content/docs/developers/api.md

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
---
2+
title: Ecency SDK
3+
description: Framework-agnostic data layer for Hive apps with first-class React Query support.
4+
---
5+
6+
# Ecency SDK
7+
8+
The Ecency SDK is a framework-agnostic data layer for Hive applications with first-class
9+
**React Query** support. It provides composable query option builders, mutation hooks, and a
10+
shared configuration layer for Hive RPC and caching.
11+
12+
## What’s inside
13+
14+
- Query and mutation option builders powered by [@tanstack/react-query](https://tanstack.com/query)
15+
- Modular APIs: accounts, posts, communities, market, wallet, notifications, analytics,
16+
integrations, core, auth, bridge, games, hive-engine, operations, points, private-api,
17+
promotions, proposals, resource-credits, search, spk, witnesses
18+
- Central configuration via `CONFIG` / `ConfigManager` (RPC client, QueryClient)
19+
20+
## Installation
21+
22+
```sh
23+
yarn add @ecency/sdk
24+
# or
25+
npm install @ecency/sdk
26+
```
27+
28+
## Quick start (React Query)
29+
30+
```ts
31+
import { getAccountFullQueryOptions } from "@ecency/sdk";
32+
import { useQuery } from "@tanstack/react-query";
33+
34+
const { data, isLoading } = useQuery(getAccountFullQueryOptions("ecency"));
35+
```
36+
37+
## Configuration
38+
39+
The SDK uses a shared configuration singleton for the Hive RPC client and query client.
40+
41+
```ts
42+
import { ConfigManager, makeQueryClient } from "@ecency/sdk";
43+
44+
// Optional: provide your own QueryClient
45+
ConfigManager.setQueryClient(makeQueryClient());
46+
```
47+
48+
If your app sets up a custom Hive client, configure it at startup so all SDK modules
49+
share the same instance.
50+
51+
## Query options vs direct calls
52+
53+
Most APIs are exposed as **query option builders** to keep caching consistent:
54+
55+
```ts
56+
import { getPostsRankedQueryOptions } from "@ecency/sdk";
57+
58+
// Use in React Query hooks
59+
useQuery(getPostsRankedQueryOptions("trending", "", "", 20));
60+
```
61+
62+
Direct request helpers still exist for non-React contexts (e.g., server jobs).
63+
Prefer query options in UI code.
64+
65+
## Mutations
66+
67+
Mutations are provided as hooks that wrap `useMutation`:
68+
69+
```ts
70+
import { useAccountUpdate } from "@ecency/sdk";
71+
72+
const auth = {
73+
accessToken,
74+
postingKey,
75+
loginType,
76+
};
77+
78+
const { mutateAsync } = useAccountUpdate(username, auth);
79+
await mutateAsync({ metadata });
80+
```
81+
82+
`AuthContext` properties are optional. The example above works without an explicit
83+
`broadcast` function; the SDK will use `postingKey` or `accessToken` if provided. If your
84+
app needs custom broadcasting (Keychain, HiveAuth, mobile), add the optional `broadcast`
85+
function as shown below.
86+
87+
## Broadcasting and auth context
88+
89+
The SDK does not manage storage or platform-specific signers. Instead, it uses an
90+
`AuthContext` that you pass from the app:
91+
92+
```ts
93+
import type { AuthContext } from "@ecency/sdk";
94+
95+
const auth: AuthContext = {
96+
accessToken,
97+
postingKey,
98+
loginType,
99+
broadcast: async (operations, authority = "posting") => {
100+
// App-specific broadcaster (Keychain, HiveAuth, mobile wallet)
101+
return myBroadcaster(operations, authority);
102+
},
103+
};
104+
```
105+
106+
If `auth.broadcast` is provided, the SDK will call it for posting broadcasts and
107+
keychain/hiveauth flows. Otherwise it falls back to:
108+
109+
- `postingKey` (direct signing via dhive)
110+
- `accessToken` (Hivesigner)
111+
112+
## Active/owner key signing
113+
114+
For operations that must be signed with Active or Owner authority, use
115+
`useSignOperationByKey` and pass the appropriate private key:
116+
117+
```ts
118+
import { useSignOperationByKey } from "@ecency/sdk";
119+
120+
const { mutateAsync } = useSignOperationByKey(username);
121+
await mutateAsync({
122+
operation: ["account_update", { /* ... */ }],
123+
keyOrSeed: activeKey,
124+
});
125+
```
126+
127+
If you want the SDK to broadcast Active/Owner operations through an external signer
128+
(Keychain, HiveAuth, mobile), provide an `auth.broadcast` handler and use the
129+
`authority` argument:
130+
131+
```ts
132+
const auth = {
133+
broadcast: (ops, authority = "posting") => {
134+
return myBroadcaster(ops, authority);
135+
},
136+
};
137+
```
138+
139+
## Module layout
140+
141+
```text
142+
src/modules/
143+
accounts/ account data, relationships, mutations
144+
analytics/ activity tracking and stats
145+
auth/ login, tokens, and auth helpers
146+
bridge/ bridge API helpers
147+
communities/ community queries and utils
148+
core/ config, client, query manager, helpers
149+
games/ game-related endpoints
150+
hive-engine/ hive-engine data helpers
151+
integrations/ external integrations (hivesigner, 3speak, etc.)
152+
market/ market data and pricing
153+
notifications/ notification queries and enums
154+
operations/ operation signing helpers
155+
points/ points queries and mutations
156+
posts/ post queries, mutations, utils
157+
private-api/ private API helpers
158+
promotions/ promotion queries
159+
proposals/ proposal queries and mutations
160+
resource-credits/ RC stats helpers
161+
search/ search queries
162+
spk/ SPK data helpers
163+
wallet/ wallet-related queries and types
164+
witnesses/ witness queries and votes
165+
```
166+
167+
## SSR / RSC notes
168+
169+
- Query options are safe to use on the server, but hooks are client-only.
170+
- If you use Next.js App Router, keep hook usage in client components.

src/content/docs/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { Card, CardGrid } from "@astrojs/starlight/components";
3535
title="Developer Tools"
3636
icon="rocket"
3737
>
38-
<a href="/developers/api">Explore Ecency APIs and SDKs to build on Hive.</a>
38+
<a href="/developers/sdk">Explore the Ecency SDK and developer resources to build on Hive.</a>
3939
</Card>
4040

4141
<Card

0 commit comments

Comments
 (0)