@dupecom/botcha 0.9.0 → 0.11.0
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 +123 -5
- package/dist/lib/client/index.d.ts +69 -2
- package/dist/lib/client/index.d.ts.map +1 -1
- package/dist/lib/client/index.js +160 -1
- package/dist/lib/client/types.d.ts +37 -0
- package/dist/lib/client/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,7 +31,11 @@ Use cases:
|
|
|
31
31
|
- 🔄 AI-to-AI marketplaces
|
|
32
32
|
- 🎫 Bot verification systems
|
|
33
33
|
- 🔐 Autonomous agent authentication
|
|
34
|
-
- 🏢 Multi-tenant app isolation
|
|
34
|
+
- 🏢 Multi-tenant app isolation with email-tied accounts
|
|
35
|
+
- 📊 Per-app metrics dashboard at [botcha.ai/dashboard](https://botcha.ai/dashboard)
|
|
36
|
+
- 📧 Email verification, account recovery, and secret rotation
|
|
37
|
+
- 🤖 Agent-first dashboard auth (challenge-based login + device code handoff)
|
|
38
|
+
- 🆔 Persistent agent identities with registry
|
|
35
39
|
|
|
36
40
|
## Install
|
|
37
41
|
|
|
@@ -176,15 +180,25 @@ BOTCHA supports **multi-tenant isolation** — create separate apps with unique
|
|
|
176
180
|
### Creating an App
|
|
177
181
|
|
|
178
182
|
```bash
|
|
179
|
-
# Create a new app
|
|
180
|
-
curl -X POST https://botcha.ai/v1/apps
|
|
183
|
+
# Create a new app (email required)
|
|
184
|
+
curl -X POST https://botcha.ai/v1/apps \
|
|
185
|
+
-H "Content-Type: application/json" \
|
|
186
|
+
-d '{"email": "agent@example.com"}'
|
|
181
187
|
|
|
182
188
|
# Returns (save the secret - it's only shown once!):
|
|
183
189
|
{
|
|
184
190
|
"app_id": "app_abc123",
|
|
185
191
|
"app_secret": "sk_xyz789",
|
|
186
|
-
"
|
|
192
|
+
"email": "agent@example.com",
|
|
193
|
+
"email_verified": false,
|
|
194
|
+
"verification_required": true,
|
|
195
|
+
"warning": "Save your app_secret now — it cannot be retrieved again! Check your email for a verification code."
|
|
187
196
|
}
|
|
197
|
+
|
|
198
|
+
# Verify your email with the 6-digit code:
|
|
199
|
+
curl -X POST https://botcha.ai/v1/apps/app_abc123/verify-email \
|
|
200
|
+
-H "Content-Type: application/json" \
|
|
201
|
+
-d '{"code": "123456"}'
|
|
188
202
|
```
|
|
189
203
|
|
|
190
204
|
### Using Your App ID
|
|
@@ -224,6 +238,32 @@ async with BotchaClient(app_id="app_abc123") as client:
|
|
|
224
238
|
response = await client.fetch("https://api.example.com/agent-only")
|
|
225
239
|
```
|
|
226
240
|
|
|
241
|
+
### SDK App Lifecycle (v0.10.0+)
|
|
242
|
+
|
|
243
|
+
Both SDKs now include methods for the full app lifecycle:
|
|
244
|
+
|
|
245
|
+
**TypeScript:**
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
const client = new BotchaClient();
|
|
249
|
+
const app = await client.createApp('agent@example.com'); // auto-sets appId
|
|
250
|
+
await client.verifyEmail('123456'); // verify with email code
|
|
251
|
+
await client.resendVerification(); // resend code
|
|
252
|
+
await client.recoverAccount('agent@example.com'); // recovery device code via email
|
|
253
|
+
const rotated = await client.rotateSecret(); // rotate secret (auth required)
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**Python:**
|
|
257
|
+
|
|
258
|
+
```python
|
|
259
|
+
async with BotchaClient() as client:
|
|
260
|
+
app = await client.create_app("agent@example.com") # auto-sets app_id
|
|
261
|
+
await client.verify_email("123456") # verify with email code
|
|
262
|
+
await client.resend_verification() # resend code
|
|
263
|
+
await client.recover_account("agent@example.com") # recovery device code via email
|
|
264
|
+
rotated = await client.rotate_secret() # rotate secret (auth required)
|
|
265
|
+
```
|
|
266
|
+
|
|
227
267
|
### Rate Limiting
|
|
228
268
|
|
|
229
269
|
Each app gets its own rate limit bucket:
|
|
@@ -238,6 +278,84 @@ Each app gets its own rate limit bucket:
|
|
|
238
278
|
curl https://botcha.ai/v1/apps/app_abc123
|
|
239
279
|
```
|
|
240
280
|
|
|
281
|
+
## 📊 Per-App Metrics Dashboard
|
|
282
|
+
|
|
283
|
+
BOTCHA includes a built-in **metrics dashboard** at [`/dashboard`](https://botcha.ai/dashboard) showing per-app analytics with a terminal-inspired aesthetic.
|
|
284
|
+
|
|
285
|
+
### What You Get
|
|
286
|
+
|
|
287
|
+
- **Overview stats**: Challenges generated, verifications, success rate, avg solve time
|
|
288
|
+
- **Request volume**: Time-bucketed event charts
|
|
289
|
+
- **Challenge types**: Breakdown by speed/hybrid/reasoning/standard
|
|
290
|
+
- **Performance**: p50/p95 solve times, response latency
|
|
291
|
+
- **Errors & rate limits**: Failure tracking
|
|
292
|
+
- **Geographic distribution**: Top countries by request volume
|
|
293
|
+
|
|
294
|
+
### Access
|
|
295
|
+
|
|
296
|
+
Three ways to access — all require an AI agent:
|
|
297
|
+
|
|
298
|
+
1. **Agent Direct**: Your agent solves a speed challenge via `POST /v1/auth/dashboard` → gets a session token
|
|
299
|
+
2. **Device Code**: Agent solves challenge via `POST /v1/auth/device-code` → gets a `BOTCHA-XXXX` code → human enters it at `/dashboard/code`
|
|
300
|
+
3. **Legacy**: Login with `app_id` + `app_secret` at [botcha.ai/dashboard/login](https://botcha.ai/dashboard/login)
|
|
301
|
+
|
|
302
|
+
Session uses cookie-based auth (HttpOnly, Secure, SameSite=Lax, 1hr expiry).
|
|
303
|
+
|
|
304
|
+
### Email & Recovery
|
|
305
|
+
|
|
306
|
+
- Email is **required** at app creation (`POST /v1/apps` with `{"email": "..."}`)
|
|
307
|
+
- Verify email with a 6-digit code sent to your inbox
|
|
308
|
+
- Lost your secret? Use `POST /v1/auth/recover` to get a recovery device code emailed
|
|
309
|
+
- Rotate secrets via `POST /v1/apps/:id/rotate-secret` (auth required, sends notification)
|
|
310
|
+
|
|
311
|
+
### Period Filters
|
|
312
|
+
|
|
313
|
+
All metrics support `1h`, `24h`, `7d`, and `30d` time windows via htmx-powered buttons — no page reload required.
|
|
314
|
+
|
|
315
|
+
## 🤖 Agent Registry
|
|
316
|
+
|
|
317
|
+
BOTCHA now supports **persistent agent identities** — register your agent with a name, operator, and version to build a verifiable identity over time.
|
|
318
|
+
|
|
319
|
+
### Why Register an Agent?
|
|
320
|
+
|
|
321
|
+
- **Identity**: Get a persistent `agent_id` that survives across sessions
|
|
322
|
+
- **Attribution**: Track which agent made which API calls
|
|
323
|
+
- **Reputation**: Build trust over time (foundation for future reputation scoring)
|
|
324
|
+
- **Accountability**: Know who's operating each agent
|
|
325
|
+
|
|
326
|
+
### Registering an Agent
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
# Register a new agent (requires app_id)
|
|
330
|
+
curl -X POST "https://botcha.ai/v1/agents/register?app_id=app_abc123" \
|
|
331
|
+
-H "Content-Type: application/json" \
|
|
332
|
+
-d '{
|
|
333
|
+
"name": "my-assistant",
|
|
334
|
+
"operator": "Acme Corp",
|
|
335
|
+
"version": "1.0.0"
|
|
336
|
+
}'
|
|
337
|
+
|
|
338
|
+
# Returns:
|
|
339
|
+
{
|
|
340
|
+
"agent_id": "agent_xyz789",
|
|
341
|
+
"app_id": "app_abc123",
|
|
342
|
+
"name": "my-assistant",
|
|
343
|
+
"operator": "Acme Corp",
|
|
344
|
+
"version": "1.0.0",
|
|
345
|
+
"created_at": 1770936000000
|
|
346
|
+
}
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Agent Endpoints
|
|
350
|
+
|
|
351
|
+
| Endpoint | Description |
|
|
352
|
+
|----------|-------------|
|
|
353
|
+
| `POST /v1/agents/register` | Create a new agent identity (requires `app_id`) |
|
|
354
|
+
| `GET /v1/agents/:id` | Get agent info by ID (public, no auth) |
|
|
355
|
+
| `GET /v1/agents` | List all agents for authenticated app |
|
|
356
|
+
|
|
357
|
+
> **Note:** Agent Registry is the foundation for future features like delegation chains, capability attestation, and reputation scoring. See [ROADMAP.md](./ROADMAP.md) for details.
|
|
358
|
+
|
|
241
359
|
## 🔄 SSE Streaming Flow (AI-Native)
|
|
242
360
|
|
|
243
361
|
For AI agents that prefer a **conversational handshake**, BOTCHA offers **Server-Sent Events (SSE)** streaming:
|
|
@@ -315,7 +433,7 @@ BOTCHA is designed to be auto-discoverable by AI agents through multiple standar
|
|
|
315
433
|
All responses include these headers for agent discovery:
|
|
316
434
|
|
|
317
435
|
```http
|
|
318
|
-
X-Botcha-Version: 0.
|
|
436
|
+
X-Botcha-Version: 0.11.0
|
|
319
437
|
X-Botcha-Enabled: true
|
|
320
438
|
X-Botcha-Methods: hybrid-challenge,speed-challenge,reasoning-challenge,standard-challenge
|
|
321
439
|
X-Botcha-Docs: https://botcha.ai/openapi.json
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type { SpeedProblem, BotchaClientOptions, ChallengeResponse, StandardChallengeResponse, VerifyResponse, TokenResponse, StreamSession, StreamEvent, Problem, VerifyResult, StreamChallengeOptions, } from './types.js';
|
|
2
|
-
import type { BotchaClientOptions, VerifyResponse } from './types.js';
|
|
1
|
+
export type { SpeedProblem, BotchaClientOptions, ChallengeResponse, StandardChallengeResponse, VerifyResponse, TokenResponse, StreamSession, StreamEvent, Problem, VerifyResult, StreamChallengeOptions, CreateAppResponse, VerifyEmailResponse, ResendVerificationResponse, RecoverAccountResponse, RotateSecretResponse, } from './types.js';
|
|
2
|
+
import type { BotchaClientOptions, VerifyResponse, CreateAppResponse, VerifyEmailResponse, ResendVerificationResponse, RecoverAccountResponse, RotateSecretResponse } from './types.js';
|
|
3
3
|
export { BotchaStreamClient } from './stream.js';
|
|
4
4
|
/**
|
|
5
5
|
* BOTCHA Client SDK for AI Agents
|
|
@@ -87,6 +87,73 @@ export declare class BotchaClient {
|
|
|
87
87
|
* ```
|
|
88
88
|
*/
|
|
89
89
|
createHeaders(): Promise<Record<string, string>>;
|
|
90
|
+
/**
|
|
91
|
+
* Create a new BOTCHA app. Email is required.
|
|
92
|
+
*
|
|
93
|
+
* The returned `app_secret` is only shown once — save it securely.
|
|
94
|
+
* A 6-digit verification code will be sent to the provided email.
|
|
95
|
+
*
|
|
96
|
+
* @param email - Email address for the app owner
|
|
97
|
+
* @returns App creation response including app_id and app_secret
|
|
98
|
+
* @throws Error if app creation fails
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const app = await client.createApp('agent@example.com');
|
|
103
|
+
* console.log(app.app_id); // 'app_abc123'
|
|
104
|
+
* console.log(app.app_secret); // 'sk_...' (save this!)
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
createApp(email: string): Promise<CreateAppResponse>;
|
|
108
|
+
/**
|
|
109
|
+
* Verify the email address for an app using the 6-digit code sent via email.
|
|
110
|
+
*
|
|
111
|
+
* @param appId - The app ID (defaults to the client's appId)
|
|
112
|
+
* @param code - The 6-digit verification code from the email
|
|
113
|
+
* @returns Verification response
|
|
114
|
+
* @throws Error if verification fails
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const result = await client.verifyEmail('123456');
|
|
119
|
+
* console.log(result.email_verified); // true
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
verifyEmail(code: string, appId?: string): Promise<VerifyEmailResponse>;
|
|
123
|
+
/**
|
|
124
|
+
* Resend the email verification code.
|
|
125
|
+
*
|
|
126
|
+
* @param appId - The app ID (defaults to the client's appId)
|
|
127
|
+
* @returns Response with success status
|
|
128
|
+
* @throws Error if resend fails
|
|
129
|
+
*/
|
|
130
|
+
resendVerification(appId?: string): Promise<ResendVerificationResponse>;
|
|
131
|
+
/**
|
|
132
|
+
* Request account recovery via verified email.
|
|
133
|
+
* Sends a device code to the registered email address.
|
|
134
|
+
*
|
|
135
|
+
* Anti-enumeration: always returns the same response shape
|
|
136
|
+
* whether or not the email exists.
|
|
137
|
+
*
|
|
138
|
+
* @param email - The email address associated with the app
|
|
139
|
+
* @returns Recovery response (always success for anti-enumeration)
|
|
140
|
+
*/
|
|
141
|
+
recoverAccount(email: string): Promise<RecoverAccountResponse>;
|
|
142
|
+
/**
|
|
143
|
+
* Rotate the app secret. Requires an active dashboard session (Bearer token).
|
|
144
|
+
* The old secret is immediately invalidated.
|
|
145
|
+
*
|
|
146
|
+
* @param appId - The app ID (defaults to the client's appId)
|
|
147
|
+
* @returns New app_secret (save it — only shown once)
|
|
148
|
+
* @throws Error if rotation fails or auth is missing
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const result = await client.rotateSecret();
|
|
153
|
+
* console.log(result.app_secret); // 'sk_new_...' (save this!)
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
rotateSecret(appId?: string): Promise<RotateSecretResponse>;
|
|
90
157
|
}
|
|
91
158
|
/**
|
|
92
159
|
* Convenience function for one-off solves
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/client/index.ts"],"names":[],"mappings":"AAMA,YAAY,EACV,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,cAAc,EACd,aAAa,EACb,aAAa,EACb,WAAW,EACX,OAAO,EACP,YAAY,EACZ,sBAAsB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/client/index.ts"],"names":[],"mappings":"AAMA,YAAY,EACV,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,cAAc,EACd,aAAa,EACb,aAAa,EACb,WAAW,EACX,OAAO,EACP,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,EACnB,0BAA0B,EAC1B,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAEV,mBAAmB,EAGnB,cAAc,EAEd,iBAAiB,EACjB,mBAAmB,EACnB,0BAA0B,EAC1B,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAGpB,OAAO,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C,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAyB7E;;;;;;OAMG;IACG,kBAAkB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAwB7E;;;;;;;;;OASG;IACG,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAoBpE;;;;;;;;;;;;;OAaG;IACG,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;CA+BlE;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAIxD;AAED,eAAe,YAAY,CAAC"}
|
package/dist/lib/client/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
2
|
// SDK version - hardcoded since npm_package_version is unreliable when used as a library
|
|
3
|
-
const SDK_VERSION = '0.
|
|
3
|
+
const SDK_VERSION = '0.11.0';
|
|
4
4
|
// Export stream client
|
|
5
5
|
export { BotchaStreamClient } from './stream.js';
|
|
6
6
|
/**
|
|
@@ -335,6 +335,165 @@ export class BotchaClient {
|
|
|
335
335
|
}
|
|
336
336
|
return headers;
|
|
337
337
|
}
|
|
338
|
+
// ============ APP MANAGEMENT ============
|
|
339
|
+
/**
|
|
340
|
+
* Create a new BOTCHA app. Email is required.
|
|
341
|
+
*
|
|
342
|
+
* The returned `app_secret` is only shown once — save it securely.
|
|
343
|
+
* A 6-digit verification code will be sent to the provided email.
|
|
344
|
+
*
|
|
345
|
+
* @param email - Email address for the app owner
|
|
346
|
+
* @returns App creation response including app_id and app_secret
|
|
347
|
+
* @throws Error if app creation fails
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* const app = await client.createApp('agent@example.com');
|
|
352
|
+
* console.log(app.app_id); // 'app_abc123'
|
|
353
|
+
* console.log(app.app_secret); // 'sk_...' (save this!)
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
async createApp(email) {
|
|
357
|
+
const res = await fetch(`${this.baseUrl}/v1/apps`, {
|
|
358
|
+
method: 'POST',
|
|
359
|
+
headers: {
|
|
360
|
+
'Content-Type': 'application/json',
|
|
361
|
+
'User-Agent': this.agentIdentity,
|
|
362
|
+
},
|
|
363
|
+
body: JSON.stringify({ email }),
|
|
364
|
+
});
|
|
365
|
+
if (!res.ok) {
|
|
366
|
+
const body = await res.json().catch(() => ({}));
|
|
367
|
+
throw new Error(body.message || `App creation failed with status ${res.status}`);
|
|
368
|
+
}
|
|
369
|
+
const data = await res.json();
|
|
370
|
+
// Auto-set appId for subsequent requests
|
|
371
|
+
if (data.app_id) {
|
|
372
|
+
this.appId = data.app_id;
|
|
373
|
+
}
|
|
374
|
+
return data;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Verify the email address for an app using the 6-digit code sent via email.
|
|
378
|
+
*
|
|
379
|
+
* @param appId - The app ID (defaults to the client's appId)
|
|
380
|
+
* @param code - The 6-digit verification code from the email
|
|
381
|
+
* @returns Verification response
|
|
382
|
+
* @throws Error if verification fails
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* const result = await client.verifyEmail('123456');
|
|
387
|
+
* console.log(result.email_verified); // true
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
async verifyEmail(code, appId) {
|
|
391
|
+
const id = appId || this.appId;
|
|
392
|
+
if (!id) {
|
|
393
|
+
throw new Error('No app ID. Call createApp() first or pass appId.');
|
|
394
|
+
}
|
|
395
|
+
const res = await fetch(`${this.baseUrl}/v1/apps/${encodeURIComponent(id)}/verify-email`, {
|
|
396
|
+
method: 'POST',
|
|
397
|
+
headers: {
|
|
398
|
+
'Content-Type': 'application/json',
|
|
399
|
+
'User-Agent': this.agentIdentity,
|
|
400
|
+
},
|
|
401
|
+
body: JSON.stringify({ code }),
|
|
402
|
+
});
|
|
403
|
+
if (!res.ok) {
|
|
404
|
+
const body = await res.json().catch(() => ({}));
|
|
405
|
+
throw new Error(body.message || `Email verification failed with status ${res.status}`);
|
|
406
|
+
}
|
|
407
|
+
return await res.json();
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Resend the email verification code.
|
|
411
|
+
*
|
|
412
|
+
* @param appId - The app ID (defaults to the client's appId)
|
|
413
|
+
* @returns Response with success status
|
|
414
|
+
* @throws Error if resend fails
|
|
415
|
+
*/
|
|
416
|
+
async resendVerification(appId) {
|
|
417
|
+
const id = appId || this.appId;
|
|
418
|
+
if (!id) {
|
|
419
|
+
throw new Error('No app ID. Call createApp() first or pass appId.');
|
|
420
|
+
}
|
|
421
|
+
const res = await fetch(`${this.baseUrl}/v1/apps/${encodeURIComponent(id)}/resend-verification`, {
|
|
422
|
+
method: 'POST',
|
|
423
|
+
headers: {
|
|
424
|
+
'Content-Type': 'application/json',
|
|
425
|
+
'User-Agent': this.agentIdentity,
|
|
426
|
+
},
|
|
427
|
+
});
|
|
428
|
+
if (!res.ok) {
|
|
429
|
+
const body = await res.json().catch(() => ({}));
|
|
430
|
+
throw new Error(body.message || `Resend verification failed with status ${res.status}`);
|
|
431
|
+
}
|
|
432
|
+
return await res.json();
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Request account recovery via verified email.
|
|
436
|
+
* Sends a device code to the registered email address.
|
|
437
|
+
*
|
|
438
|
+
* Anti-enumeration: always returns the same response shape
|
|
439
|
+
* whether or not the email exists.
|
|
440
|
+
*
|
|
441
|
+
* @param email - The email address associated with the app
|
|
442
|
+
* @returns Recovery response (always success for anti-enumeration)
|
|
443
|
+
*/
|
|
444
|
+
async recoverAccount(email) {
|
|
445
|
+
const res = await fetch(`${this.baseUrl}/v1/auth/recover`, {
|
|
446
|
+
method: 'POST',
|
|
447
|
+
headers: {
|
|
448
|
+
'Content-Type': 'application/json',
|
|
449
|
+
'User-Agent': this.agentIdentity,
|
|
450
|
+
},
|
|
451
|
+
body: JSON.stringify({ email }),
|
|
452
|
+
});
|
|
453
|
+
if (!res.ok) {
|
|
454
|
+
const body = await res.json().catch(() => ({}));
|
|
455
|
+
throw new Error(body.message || `Account recovery failed with status ${res.status}`);
|
|
456
|
+
}
|
|
457
|
+
return await res.json();
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Rotate the app secret. Requires an active dashboard session (Bearer token).
|
|
461
|
+
* The old secret is immediately invalidated.
|
|
462
|
+
*
|
|
463
|
+
* @param appId - The app ID (defaults to the client's appId)
|
|
464
|
+
* @returns New app_secret (save it — only shown once)
|
|
465
|
+
* @throws Error if rotation fails or auth is missing
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* ```typescript
|
|
469
|
+
* const result = await client.rotateSecret();
|
|
470
|
+
* console.log(result.app_secret); // 'sk_new_...' (save this!)
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
async rotateSecret(appId) {
|
|
474
|
+
const id = appId || this.appId;
|
|
475
|
+
if (!id) {
|
|
476
|
+
throw new Error('No app ID. Call createApp() first or pass appId.');
|
|
477
|
+
}
|
|
478
|
+
// Rotate secret requires a dashboard session token
|
|
479
|
+
const headers = {
|
|
480
|
+
'Content-Type': 'application/json',
|
|
481
|
+
'User-Agent': this.agentIdentity,
|
|
482
|
+
};
|
|
483
|
+
// Use cached token if available (from dashboard auth)
|
|
484
|
+
if (this.cachedToken) {
|
|
485
|
+
headers['Authorization'] = `Bearer ${this.cachedToken}`;
|
|
486
|
+
}
|
|
487
|
+
const res = await fetch(`${this.baseUrl}/v1/apps/${encodeURIComponent(id)}/rotate-secret`, {
|
|
488
|
+
method: 'POST',
|
|
489
|
+
headers,
|
|
490
|
+
});
|
|
491
|
+
if (!res.ok) {
|
|
492
|
+
const body = await res.json().catch(() => ({}));
|
|
493
|
+
throw new Error(body.message || `Secret rotation failed with status ${res.status}`);
|
|
494
|
+
}
|
|
495
|
+
return await res.json();
|
|
496
|
+
}
|
|
338
497
|
}
|
|
339
498
|
/**
|
|
340
499
|
* Convenience function for one-off solves
|
|
@@ -94,4 +94,41 @@ export interface StreamChallengeOptions {
|
|
|
94
94
|
/** Timeout for the full verification flow in milliseconds (default: 30000) */
|
|
95
95
|
timeout?: number;
|
|
96
96
|
}
|
|
97
|
+
export interface CreateAppResponse {
|
|
98
|
+
success: boolean;
|
|
99
|
+
app_id: string;
|
|
100
|
+
app_secret: string;
|
|
101
|
+
email: string;
|
|
102
|
+
email_verified: boolean;
|
|
103
|
+
verification_required: boolean;
|
|
104
|
+
warning: string;
|
|
105
|
+
credential_advice: string;
|
|
106
|
+
created_at: string;
|
|
107
|
+
rate_limit: number;
|
|
108
|
+
next_step: string;
|
|
109
|
+
}
|
|
110
|
+
export interface VerifyEmailResponse {
|
|
111
|
+
success: boolean;
|
|
112
|
+
email_verified?: boolean;
|
|
113
|
+
error?: string;
|
|
114
|
+
message?: string;
|
|
115
|
+
}
|
|
116
|
+
export interface ResendVerificationResponse {
|
|
117
|
+
success: boolean;
|
|
118
|
+
message?: string;
|
|
119
|
+
error?: string;
|
|
120
|
+
}
|
|
121
|
+
export interface RecoverAccountResponse {
|
|
122
|
+
success: boolean;
|
|
123
|
+
message: string;
|
|
124
|
+
}
|
|
125
|
+
export interface RotateSecretResponse {
|
|
126
|
+
success: boolean;
|
|
127
|
+
app_id?: string;
|
|
128
|
+
app_secret?: string;
|
|
129
|
+
warning?: string;
|
|
130
|
+
rotated_at?: string;
|
|
131
|
+
error?: string;
|
|
132
|
+
message?: string;
|
|
133
|
+
}
|
|
97
134
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../lib/client/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,GAAG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