@builtwith/sdk 1.3.0 → 1.4.1

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 +39 -0
  2. package/package.json +1 -1
  3. package/src/index.js +33 -0
package/README.md CHANGED
@@ -63,6 +63,8 @@ if (result.ok) {
63
63
  | `payment_discovery()` | — | Agent Payment API: credit balance |
64
64
  | `payment_configuration()` | — | Agent Payment API: spending limits |
65
65
  | `payment_purchase({ credits })` | Integer ≥ 2000 | Agent Payment API: purchase credits |
66
+ | `BuiltWithClient.agent_auth_start()` | — | Start Device-Code Authorization (static, no key required) |
67
+ | `BuiltWithClient.agent_auth_token(device_code)` | Device code string | Poll for auth result and access token (static, no key required) |
66
68
 
67
69
  ### Response Format
68
70
 
@@ -132,6 +134,8 @@ All methods accept a `CancellationToken` as an optional last parameter.
132
134
  | `payment_discovery()` | — | Agent Payment API: credit balance |
133
135
  | `payment_configuration()` | — | Agent Payment API: spending limits |
134
136
  | `payment_purchase(credits)` | `int` ≥ 2000 | Agent Payment API: purchase credits |
137
+ | `BuiltWithClient.agent_auth_start()` | — | Start Device-Code Authorization (static, no key required) |
138
+ | `BuiltWithClient.agent_auth_token(deviceCode)` | `string` | Poll for auth result and access token (static, no key required) |
135
139
 
136
140
  ### Response Format
137
141
 
@@ -154,6 +158,41 @@ BUILTWITH_API_KEY=your-key dotnet run
154
158
 
155
159
  ---
156
160
 
161
+ ## Agent Device-Code Authorization
162
+
163
+ Agents can obtain a temporary `bw-` prefixed API token without the user pasting their key. These are **static methods** — no API key or client instance required.
164
+
165
+ ```js
166
+ // Node.js
167
+ const { BuiltWithClient } = require('@builtwith/sdk');
168
+
169
+ // Step 1: start the flow
170
+ const start = await BuiltWithClient.agent_auth_start();
171
+ // start.data => { device_code, verification_uri }
172
+
173
+ console.log(`Open in browser: ${start.data.verification_uri}`);
174
+
175
+ // Step 2: poll every 5 seconds
176
+ const token = await BuiltWithClient.agent_auth_token(start.data.device_code);
177
+ // token.data => { status: 'pending' | 'approved' | 'denied', access_token? }
178
+
179
+ if (token.data.status === 'approved') {
180
+ const client = new BuiltWithClient(token.data.access_token);
181
+ // use client normally
182
+ }
183
+ ```
184
+
185
+ ```csharp
186
+ // C#
187
+ var start = await BuiltWithClient.agent_auth_start();
188
+ // start.Data => { device_code, verification_uri }
189
+
190
+ var token = await BuiltWithClient.agent_auth_token(deviceCode);
191
+ // token.Data => { status, access_token }
192
+ ```
193
+
194
+ ---
195
+
157
196
  ## Agent Payment API
158
197
 
159
198
  The payment methods let AI agents check credit balances, view spending configuration, and purchase credits. They route through the standard MCP endpoint using your existing API key. Configure billing at [payments.builtwith.com/agent-payment-api-config](https://payments.builtwith.com/agent-payment-api-config).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builtwith/sdk",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "BuiltWith AI-first SDK for Node.js",
5
5
  "main": "src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -393,6 +393,39 @@ class BuiltWithClient {
393
393
  _validate_domain(domain);
394
394
  return { mcp_prompt: 'check-domain-trust', arguments: { domain } };
395
395
  }
396
+
397
+ // ── Agent Device-Code Authorization (no API key required) ─────────────────
398
+
399
+ static async agent_auth_start() {
400
+ try {
401
+ const res = await _http_post('https://api.builtwith.com/agent-auth-start', {}, {}, 30000);
402
+ if (res.status < 200 || res.status >= 300) {
403
+ return _err(new BuiltWithError('HTTP_ERROR', `HTTP ${res.status}: ${res.body.substring(0, 200)}`, res.status), 'agent-auth-start');
404
+ }
405
+ let data;
406
+ try { data = JSON.parse(res.body); } catch (_) {
407
+ return _err(new BuiltWithError('PARSE_ERROR', 'Failed to parse agent-auth-start response.', res.status), 'agent-auth-start');
408
+ }
409
+ return _ok(data, data, 'agent-auth-start');
410
+ } catch (err) {
411
+ return _err(new BuiltWithError('NETWORK_ERROR', err.message, 0, null, 'Check network connectivity.'), 'agent-auth-start');
412
+ }
413
+ }
414
+
415
+ static async agent_auth_token(device_code) {
416
+ _validate_string('device_code', device_code);
417
+ try {
418
+ const res = await _http_post('https://api.builtwith.com/agent-auth-token', { device_code }, {}, 30000);
419
+ let data;
420
+ try { data = JSON.parse(res.body); } catch (_) {
421
+ return _err(new BuiltWithError('PARSE_ERROR', 'Failed to parse agent-auth-token response.', res.status), 'agent-auth-token');
422
+ }
423
+ // Pass through body even on 4xx — error field carries meaningful status (access_denied, expired_token)
424
+ return _ok(data, data, 'agent-auth-token');
425
+ } catch (err) {
426
+ return _err(new BuiltWithError('NETWORK_ERROR', err.message, 0, null, 'Check network connectivity.'), 'agent-auth-token');
427
+ }
428
+ }
396
429
  }
397
430
 
398
431
  module.exports = { BuiltWithClient, BuiltWithError };