kyro-connect 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +242 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,242 @@
1
+ # kyro-connect
2
+
3
+ Universal SDK for [Kyro CMS](https://kyro.dev). Type-safe client for any platform — Node.js, browser, Deno, Bun.
4
+
5
+ ```bash
6
+ npm install kyro-connect
7
+ ```
8
+
9
+ ---
10
+
11
+ ## Quick Start
12
+
13
+ ### 1. Generate types
14
+
15
+ ```bash
16
+ npx kyro-codegen --url http://localhost:4321/api --api-key kyro_xxx
17
+ ```
18
+
19
+ Fetches your CMS schema and generates `kyro.generated.d.ts` with full type definitions for every collection, global, and procedure.
20
+
21
+ ### 2. Use the client
22
+
23
+ ```ts
24
+ import { createClient } from "kyro-connect";
25
+ import type { AppRouter } from "./kyro.generated";
26
+
27
+ const api = createClient<AppRouter>({
28
+ url: "http://localhost:4321/api/trpc",
29
+ apiKey: "kyro_xxx",
30
+ });
31
+ ```
32
+
33
+ ---
34
+
35
+ ## API
36
+
37
+ ### `createClient(options)`
38
+
39
+ Creates a proxy-based client for your Kyro CMS tRPC endpoint.
40
+
41
+ ```ts
42
+ const api = createClient<AppRouter>({
43
+ url: "http://localhost:4321/api/trpc",
44
+ apiKey: "kyro_xxx",
45
+ fetch: globalThis.fetch,
46
+ });
47
+ ```
48
+
49
+ | Option | Type | Default | Description |
50
+ |---|---|---|---|
51
+ | `url` | `string` | — | Base URL of the tRPC endpoint |
52
+ | `apiKey` | `string` | — | API key for authenticated requests |
53
+ | `fetch` | `typeof globalThis.fetch` | `globalThis.fetch` | Custom fetch implementation |
54
+
55
+ #### Query procedures (GET)
56
+
57
+ ```ts
58
+ const { docs } = await api["posts"].find({ page: 1, limit: 10 });
59
+ // docs: Post[]
60
+
61
+ const post = await api["posts"].findByID({ id: "abc123" });
62
+ // post: Post
63
+
64
+ const { totalDocs } = await api["posts"].count({
65
+ where: { status: { equals: "published" } },
66
+ });
67
+ // totalDocs: number
68
+ ```
69
+
70
+ #### Mutation procedures (POST)
71
+
72
+ ```ts
73
+ const { doc } = await api["posts"].create({
74
+ data: { title: "Hello", slug: "hello" },
75
+ });
76
+ // doc: Post
77
+
78
+ const { doc } = await api["posts"].update({
79
+ id: "abc",
80
+ data: { title: "Updated" },
81
+ });
82
+ // doc: Post
83
+
84
+ const { doc, message } = await api["posts"].delete({ id: "abc" });
85
+ // doc: Post, message: string
86
+ ```
87
+
88
+ #### Globals
89
+
90
+ ```ts
91
+ const settings = await api["_globals_site-settings"].get();
92
+ // settings: SiteSettingsGlobal
93
+
94
+ await api["_globals_site-settings"].update({
95
+ data: { siteName: "New Name" },
96
+ });
97
+ ```
98
+
99
+ ---
100
+
101
+ ## Codegen
102
+
103
+ ### CLI
104
+
105
+ ```bash
106
+ # Basic
107
+ npx kyro-codegen --url http://localhost:4321/api --api-key kyro_xxx
108
+
109
+ # Custom output path
110
+ npx kyro-codegen --url http://localhost:4321/api --api-key kyro_xxx --output src/types/kyro.d.ts
111
+ ```
112
+
113
+ ### Generated types
114
+
115
+ Running codegen produces `kyro.generated.d.ts` containing:
116
+
117
+ - **Doc types** — TypeScript interfaces for each collection and global, derived from field definitions
118
+ - **Input types** — typed inputs for every procedure (`PostsFindInput`, `PostsCreateInput`, etc.)
119
+ - **Output types** — typed outputs for every procedure (`PostsFindOutput`, etc.)
120
+ - **AppRouter** — mapped type linking all collection/global procedures to their input/output types
121
+
122
+ ### Slugs with hyphens
123
+
124
+ Use bracket notation when accessing collections with hyphens in their slug:
125
+
126
+ ```ts
127
+ const data = await api["my-collection"].find({ page: 1 });
128
+ ```
129
+
130
+ ### Without codegen
131
+
132
+ The client works without types — everything is `any`:
133
+
134
+ ```ts
135
+ const api = createClient({ url: "...", apiKey: "..." });
136
+ const posts = await api.posts.find({ page: 1 });
137
+ // posts: any
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Transport
143
+
144
+ ### Request format
145
+
146
+ | Procedure type | HTTP method | URL | Body |
147
+ |---|---|---|---|
148
+ | `find`, `findByID`, `count` | GET | `/api/trpc/{slug}.{proc}?input={json}` | — |
149
+ | `create`, `update`, `delete` | POST | `/api/trpc/{slug}.{proc}` | JSON body |
150
+
151
+ ### Authentication
152
+
153
+ API key is sent as the `x-api-key` header on every request. If the server session cookie is already present (browser environment), the `apiKey` option can be omitted.
154
+
155
+ ---
156
+
157
+ ## Errors
158
+
159
+ ### `KyroConnectError`
160
+
161
+ Thrown when the server responds with a non-2xx status code.
162
+
163
+ ```ts
164
+ import { createClient, KyroConnectError } from "kyro-connect";
165
+
166
+ try {
167
+ await api["posts"].find({ page: 1 });
168
+ } catch (err) {
169
+ if (err instanceof KyroConnectError) {
170
+ console.error(err.message); // Server error message
171
+ console.error(err.status); // HTTP status code
172
+ console.error(err.code); // tRPC error code
173
+ }
174
+ }
175
+ ```
176
+
177
+ ### Error scenarios
178
+
179
+ | Scenario | Error type | Cause |
180
+ |---|---|---|
181
+ | Network failure | `TypeError` | DNS, connection refused, timeout |
182
+ | Server error response | `KyroConnectError` | 4xx or 5xx status with JSON body |
183
+ | Invalid response body | `SyntaxError` | Non-JSON response |
184
+ | Access denied | `KyroConnectError` with `status: 403` | Missing or invalid API key |
185
+ | Not found | `KyroConnectError` with `status: 404` | Collection or document not found |
186
+
187
+ ---
188
+
189
+ ## Platform support
190
+
191
+ | Platform | Native fetch | Status |
192
+ |---|---|---|
193
+ | Node.js 18+ | ✅ | Full support |
194
+ | Browser | ✅ | Full support |
195
+ | Deno | ✅ | Full support |
196
+ | Bun | ✅ | Full support |
197
+ | Cloudflare Workers | ✅ | Full support |
198
+ | Vercel Edge Runtime | ✅ | Full support |
199
+ | Node.js 16-17 | ⚠️ | Requires polyfill or `--experimental-fetch` |
200
+
201
+ ---
202
+
203
+ ## TypeScript configuration
204
+
205
+ Ensure the generated types are visible to the TypeScript compiler:
206
+
207
+ ```json
208
+ // tsconfig.json
209
+ {
210
+ "include": ["src", "kyro.generated.d.ts"]
211
+ }
212
+ ```
213
+
214
+ Or place `kyro.generated.d.ts` inside your `src/` directory.
215
+
216
+ ---
217
+
218
+ ## Development
219
+
220
+ ```bash
221
+ git clone <repo>
222
+ cd packages/kyro-connect
223
+ pnpm install
224
+ pnpm build
225
+ ```
226
+
227
+ ### Local testing
228
+
229
+ ```bash
230
+ # Link the package globally
231
+ pnpm link --global
232
+
233
+ # In your consumer project
234
+ pnpm link kyro-connect
235
+ npx kyro-codegen --url http://localhost:4321/api --api-key kyro_xxx
236
+ ```
237
+
238
+ ---
239
+
240
+ ## License
241
+
242
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kyro-connect",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Universal SDK for Kyro CMS. Type-safe client + codegen for any platform.",
5
5
  "type": "module",
6
6
  "exports": {