apiblaze 0.17.22 → 0.17.23
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.
- package/README.md +63 -0
- package/dist/index.js +451 -217
- package/dist/react/index.d.mts +34 -1
- package/dist/react/index.d.ts +34 -1
- package/dist/react/index.js +480 -53
- package/dist/react/index.mjs +479 -53
- package/dist/server/index.d.mts +139 -25
- package/dist/server/index.d.ts +139 -25
- package/dist/server/index.js +165 -24
- package/dist/server/index.mjs +162 -25
- package/package.json +26 -8
package/README.md
CHANGED
|
@@ -2,6 +2,69 @@
|
|
|
2
2
|
|
|
3
3
|
CLI for [APIblaze](https://apiblaze.com) — Chat with your APIs, Manage your API keys, users and groups through APIblaze's serverless proxy
|
|
4
4
|
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Drop-in API-key widget (React)
|
|
8
|
+
|
|
9
|
+
Let your users create and manage their API keys on your own site, in ~3 files. Your
|
|
10
|
+
server holds one control-plane key; the browser only ever talks to your own backend —
|
|
11
|
+
no secrets in the client, no cross-domain cookies.
|
|
12
|
+
|
|
13
|
+
**1. Install**
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install apiblaze react
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**2. One backend route** — it holds the key and reads your session (`app/api/apiblaze/keys/route.ts`):
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { createApiblazeKeys } from 'apiblaze/server';
|
|
23
|
+
import { auth } from '@/auth'; // NextAuth, Clerk, Auth0 — anything
|
|
24
|
+
|
|
25
|
+
const keys = createApiblazeKeys({
|
|
26
|
+
cpKey: process.env.APIBLAZE_CP_KEY!, // from Dashboard → Developers → "Widget key"
|
|
27
|
+
getUser: async () => {
|
|
28
|
+
const s = await auth();
|
|
29
|
+
if (!s?.user) return null; // not logged in → 401
|
|
30
|
+
return {
|
|
31
|
+
tenant: s.user.orgId ?? s.user.id, // the customer COMPANY → isolation
|
|
32
|
+
userId: s.user.id, // the PERSON → owns their keys
|
|
33
|
+
// Which key types this person may create. Decided HERE, on your server:
|
|
34
|
+
// omit → ['call-only'] (default) list → those (widget shows a picker) false → no access
|
|
35
|
+
keyTypes: s.user.isEngineer ? ['manager', 'call-only'] : undefined,
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const GET = keys.handler;
|
|
41
|
+
export const POST = keys.handler;
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**3. One component** — anywhere in your app:
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
'use client';
|
|
48
|
+
import { ApiKeyWidget } from 'apiblaze/react';
|
|
49
|
+
|
|
50
|
+
export default function Settings() {
|
|
51
|
+
return <ApiKeyWidget theme={{ accent: '#e11d48' }} />;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
That's it. The widget calls `/api/apiblaze/keys` (same-origin, your session cookie rides
|
|
56
|
+
along); your route adds the control-plane key and talks to apiblaze server-to-server.
|
|
57
|
+
|
|
58
|
+
**White-label it.** Every font and color is a `theme` token (`accent`, `surface`,
|
|
59
|
+
`headerBackground`, `text`, `muted`, `border`, `danger`, `success`, `radius`,
|
|
60
|
+
`fontFamily`, `monoFontFamily`) — match any brand without forking the component.
|
|
61
|
+
|
|
62
|
+
**Security.** Eligibility is decided on your server from your session, never the browser —
|
|
63
|
+
a crafted request can't mint a type the user isn't allowed. Use a **Widget key** (Dashboard
|
|
64
|
+
→ Developers), not a full admin key, so the platform's subset rule is a real backstop.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
5
68
|
## Install
|
|
6
69
|
|
|
7
70
|
```bash
|