apiblaze 0.18.6 → 0.18.8

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 (3) hide show
  1. package/README.md +45 -62
  2. package/dist/index.js +9 -2
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,67 +1,6 @@
1
1
  # apiblaze
2
2
 
3
- CLI for [APIblaze](https://apiblaze.com) — Chat with your APIs, Manage your API keys, users and groups through APIblaze's serverless proxy
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.
3
+ CLI for [APIblaze](https://apiblaze.com) — chat with your APIs, run them as serverless proxies, and let your customers self-serve keys, users & groups from your own site.
65
4
 
66
5
  ---
67
6
 
@@ -103,10 +42,44 @@ npx apiblaze tenant
103
42
  # Access your localhost through a proxied URL
104
43
  npx apiblaze dev 3000
105
44
 
45
+ # Route a Next.js app's outbound fetch() through APIblaze
46
+ npx apiblaze sidecar
47
+
106
48
  # Sign in to manage APIs under your team
107
49
  npx apiblaze login
108
50
  ```
109
51
 
52
+ ## Embeddable widgets (React)
53
+
54
+ Let your customers self-serve from **your** site — **API keys** (`<ApiKeyWidget/>`) and
55
+ **users, groups & admins** (`<UsersGroupsWidget/>`). Each is one server route holding your
56
+ **Widget key** (Dashboard → Developers) plus one component; the browser only ever talks to
57
+ your backend — no secrets in the client. One `getUser` maps your session
58
+ (`{ tenant, userId, email }`); **both widgets share the same key**.
59
+
60
+ ```ts
61
+ // app/api/apiblaze/keys/route.ts → <ApiKeyWidget/>
62
+ import { createApiblazeKeys } from 'apiblaze/server';
63
+ const keys = createApiblazeKeys({ cpKey: process.env.APIBLAZE_CP_KEY!, getUser });
64
+ export const GET = keys.handler, POST = keys.handler;
65
+
66
+ // app/api/apiblaze/groups/route.ts → <UsersGroupsWidget/> (same key)
67
+ import { createApiblazeGroups } from 'apiblaze/server';
68
+ const groups = createApiblazeGroups({ cpKey: process.env.APIBLAZE_CP_KEY!, getUser });
69
+ export const GET = groups.handler, POST = groups.handler;
70
+ ```
71
+
72
+ ```tsx
73
+ 'use client';
74
+ import { ApiKeyWidget, UsersGroupsWidget } from 'apiblaze/react';
75
+
76
+ <ApiKeyWidget theme={{ accent: '#7C3AED' }} />; // keys: create · rotate · revoke
77
+ <UsersGroupsWidget theme={{ accent: '#7C3AED' }} />; // users · nested groups · co-admins · seen-in-traffic
78
+ ```
79
+
80
+ Every color and font is a `theme` token — white-label to any brand. Eligibility and admin
81
+ rights are decided on **your** server from your session, never the browser.
82
+
110
83
  ## Help
111
84
 
112
85
  ```bash
@@ -162,6 +135,16 @@ Every chat turn shows its cost.
162
135
  | `apiblaze tenant cors --tenant <slug> --origins <a,b>` | Set which websites can call it |
163
136
  | `apiblaze tenant list / delete <slug>` | List / delete tenants |
164
137
 
138
+ ### Producer — users, groups & authorization
139
+
140
+ | Command | What it does |
141
+ |---|---|
142
+ | `apiblaze group create / list / delete <name>` | Manage a tenant's groups (also `<UsersGroupsWidget/>`) |
143
+ | `apiblaze group add-user / remove-user <user> <group>` | Put a user in a group (or take them out) |
144
+ | `apiblaze group add-group / remove-group <child> <parent>` | Nest a group inside a group |
145
+ | `apiblaze rule "<plain english>" <project> [--enforce]` | Author an object-level access rule in one shot (shadow, then `--enforce`) |
146
+ | `apiblaze agent authz <project>` | Design & turn on authorization interactively (chat) |
147
+
165
148
  ### Producer — change a proxy's config
166
149
 
167
150
  | Command | What it does |
package/dist/index.js CHANGED
@@ -703,7 +703,7 @@ var import_commander = require("commander");
703
703
  var import_chalk41 = __toESM(require("chalk"));
704
704
 
705
705
  // package.json
706
- var version = "0.18.6";
706
+ var version = "0.18.8";
707
707
 
708
708
  // src/index.ts
709
709
  init_types();
@@ -5613,6 +5613,7 @@ function renderToolEvents(events, dpKey) {
5613
5613
  }
5614
5614
  function billingLine(billing) {
5615
5615
  if (!billing || typeof billing.cents !== "number") return null;
5616
+ if (typeof billing.free_turns_remaining === "number") return null;
5616
5617
  const usd = (billing.cents / 100).toFixed(Math.abs(billing.cents - Math.round(billing.cents)) < 1e-9 ? 2 : 4);
5617
5618
  let line = import_chalk36.default.magenta(` \u{1F4B3} $${usd}`) + import_chalk36.default.dim(billing.model ? ` \xB7 ${billing.model}` : "");
5618
5619
  if (typeof billing.credits_remaining === "number") {
@@ -5621,7 +5622,13 @@ function billingLine(billing) {
5621
5622
  return line;
5622
5623
  }
5623
5624
  function freeBudgetWarning(billing, anon) {
5624
- if (!anon || !billing || typeof billing.free_remaining_cents !== "number") return null;
5625
+ if (!anon || !billing) return null;
5626
+ if (typeof billing.free_turns_remaining === "number") {
5627
+ const left2 = billing.free_turns_remaining;
5628
+ if (left2 <= 0) return import_chalk36.default.yellow(" Free chats used up \u2014 `npx apiblaze login` (free) to keep going.");
5629
+ return import_chalk36.default.dim(` ${left2} free chat${left2 === 1 ? "" : "s"} left`);
5630
+ }
5631
+ if (typeof billing.free_remaining_cents !== "number") return null;
5625
5632
  const perTurn = Math.max(billing.cents || 0, 0.02);
5626
5633
  const left = Math.floor(billing.free_remaining_cents / perTurn);
5627
5634
  if (left > 8) return null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "apiblaze",
3
- "version": "0.18.6",
4
- "description": "APIblaze CLI Chat with your APIs, Manage your API keys, users and groups with the APIblaze serverless proxy",
3
+ "version": "0.18.8",
4
+ "description": "APIblaze CLI \u2014 Chat with your APIs, Manage your API keys, users and groups with the APIblaze serverless proxy",
5
5
  "keywords": [
6
6
  "apiblaze",
7
7
  "dev-tunnel",