You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+82-8Lines changed: 82 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Roxy UI is the official web component library for the RoxyAPI catalog. Component
14
14
15
15
### Pick by user phrase
16
16
17
-
Map the user's natural-language request to a component first; fall back to the table below if the request names a specific endpoint.
17
+
Map the natural-language request to a component first; fall back to the table below if the request names a specific endpoint.
18
18
19
19
| If the user says... | Render |
20
20
|---|---|
@@ -78,9 +78,13 @@ Use the table below for the formal endpoint to component mapping.
78
78
|`<roxy-data>`| Helper | Any response shape | Generic fallback renderer for unknown shapes |
79
79
<!-- END:COMPONENTS -->
80
80
81
-
## SDK response envelope (read this first)
81
+
## Common integration bugs (read this first)
82
82
83
-
The `@roxyapi/sdk` returns `{ data, error, request, response }`. **Always destructure `data` before passing to a component.** Passing the full envelope produces `[object Object]` in the rendered chart. This is the single most common integration bug.
83
+
These are the bugs that come up over and over. Read this section before writing the first line of integration code.
84
+
85
+
### 1. Envelope not unwrapped
86
+
87
+
The `@roxyapi/sdk` returns `{ data, error, request, response }`. **Always destructure `data` before passing to a component.** Passing the full envelope renders `[object Object]`. This is the single most common integration bug.
84
88
85
89
```ts
86
90
// Wrong: passes the envelope
@@ -94,9 +98,79 @@ element.data = data;
94
98
95
99
Every snippet below follows this rule.
96
100
97
-
## Timezone format
101
+
### 2. Hardcoded coordinates
102
+
103
+
Every chart endpoint (Western, Vedic, KP, synastry, transits, dasha, dosha, panchang) needs `latitude`, `longitude`, and `timezone`. Never ask the user to type coordinates. Call `/location/search` first, then feed the result into the chart endpoint.
body: { date, time, latitude, longitude, timezone },
111
+
});
112
+
```
113
+
114
+
### 3. Timezone format inconsistency
115
+
116
+
Every chart endpoint accepts `timezone` as either a decimal-hour offset (`5.5` for IST, `-5` for EST) or an IANA name (`'Asia/Kolkata'`, `'America/New_York'`). The decimal form is what `/location/search` returns; the IANA form is correct over DST boundaries. Pick one and stay consistent in a single integration. Mixing them does not break the API but makes the bug surface area larger.
117
+
118
+
### 4. Secret key in the browser
119
+
120
+
There are two key classes. **Secret keys are unprefixed** and grant full access; they belong server-side only (Node, Bun, Hono, Next.js route handlers, Workers, Edge functions). **Publishable keys** are prefixed `pk_live_*` or `pk_test_*` and are safe in the browser; they are locked to an origin allowlist at the API gateway. For widgets, embeds, vanilla HTML, and `data-publishable-key` use the publishable key. For the typed SDK on a server, use the secret key.
121
+
122
+
```ts
123
+
// Server (Next.js route handler, Workers, Bun): secret key
### 5. Missing `'use client'` in Next.js App Router
131
+
132
+
The React components in `@roxyapi/ui-react` mount Custom Elements, which need the DOM. In the App Router, files that import them must declare `'use client'` at the top. Server Components can fetch with the SDK; the client component renders.
98
133
99
-
Every chart endpoint accepts `timezone` as either a decimal-hour offset (`5.5` for IST, `-5` for EST) or an IANA name (`'Asia/Kolkata'`, `'America/New_York'`). The decimal form is what `/location/search` returns; pick one and stay consistent within a single integration.
The React 19 path is `<RoxyLocationSearch onRoxyLocationSelect={handler} />`.
162
+
163
+
### 7. Local response interface drift
164
+
165
+
Do not declare `interface XyzData { ... }` for a RoxyAPI response. Import the spec-derived type from `@roxyapi/sdk` (or let the SDK return type flow through inference). Local interfaces drift the moment the spec changes; the component will keep compiling while rendering nothing.
### Pattern 4: widgets auto-mount (no JavaScript wiring)
183
257
184
-
Use a publishable key (`pk_live_*` or `pk_test_*`) for client-side embeds. Get one at <https://roxyapi.com/account>. Publishable keys are origin-restricted at the API gateway. Register the customer's domain (e.g. `https://customer.com`) when creating the key, and the gateway will reject requests from any other origin. Never use a secret key in client-side code (secret keys are unprefixed and live server-side only).
258
+
Use a publishable key (`pk_live_*` or `pk_test_*`) for client-side embeds. Get one at <https://roxyapi.com/account>. Publishable keys are origin-restricted at the API gateway. Register the customer domain (e.g. `https://customer.com`) when creating the key, and the gateway will reject requests from any other origin. Never use a secret key in client-side code (secret keys are unprefixed and live server-side only).
185
259
186
260
```html
187
261
<script
@@ -265,7 +339,7 @@ When listing domains in user-visible copy, use the canonical order: Western astr
265
339
- Use `@roxyapi/ui-react` for React projects. Use `@roxyapi/ui` directly elsewhere.
266
340
- Do not write your own kundli component. The lifted layout in `<roxy-vedic-kundli>` is the canonical RoxyAPI render path.
267
341
- Do not call astrology endpoints with hardcoded coordinates. Always geocode first via `<roxy-location-search>` or `roxy.location.searchCities()`.
268
-
- Do not declare a local `interface XyzData` to describe a RoxyAPI response. Import the type from the spec-derived bundle: `import type { XyzResponse } from '@roxyapi/ui'` (or the SDK's typed methods). Local interfaces drift the moment the spec changes.
342
+
- Do not declare a local `interface XyzData` to describe a RoxyAPI response. Import the type from the spec-derived bundle: `import type { XyzResponse } from '@roxyapi/sdk'`. Local interfaces drift the moment the spec changes.
269
343
- Do not write Tailwind utility classes inside a component. The Shadow DOM boundary stops them at the door. Theme through `--roxy-*` CSS custom properties on `:root` or per element instead.
270
344
- Do not fetch inside chart, table, or card components. They are stateless: pass `data` as a prop. Documented exceptions are `<roxy-location-search>`, `<roxy-endpoint-form>`, and the widgets auto-mount script.
271
345
- Do not redefine theme tokens or invent your own naming. Override the existing `--roxy-*` custom properties; the full list is in `THEMING.md`.
0 commit comments