@barndoor-ai/sdk 0.2.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/.eslintignore +8 -0
- package/.eslintrc.cjs +102 -0
- package/.github/CODEOWNERS +4 -0
- package/.github/workflows/ci.yml +57 -0
- package/.prettierignore +6 -0
- package/.prettierrc +13 -0
- package/LICENSE +21 -0
- package/README.md +309 -0
- package/RELEASE.md +203 -0
- package/examples/README.md +92 -0
- package/examples/basic-mcp-client.js +134 -0
- package/examples/openai-integration.js +137 -0
- package/jest.config.js +16 -0
- package/openapi.yaml +681 -0
- package/package.json +87 -0
- package/rollup.config.js +63 -0
- package/scripts/dump-core-files.js +161 -0
- package/scripts/dump-typescript-only.js +150 -0
- package/src/auth/index.ts +26 -0
- package/src/auth/pkce.ts +346 -0
- package/src/auth/store.ts +809 -0
- package/src/client.ts +512 -0
- package/src/config.ts +402 -0
- package/src/exceptions/index.ts +205 -0
- package/src/http/client.ts +272 -0
- package/src/index.ts +92 -0
- package/src/logging.ts +111 -0
- package/src/models/index.ts +156 -0
- package/src/quickstart.ts +358 -0
- package/src/version.ts +41 -0
- package/test/client.test.js +381 -0
- package/test/config.test.js +202 -0
- package/test/exceptions.test.js +142 -0
- package/test/integration.test.js +147 -0
- package/test/models.test.js +177 -0
- package/test/token-management.test.js +81 -0
- package/test/token-validation.test.js +104 -0
- package/tsconfig.json +61 -0
package/.eslintignore
ADDED
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
parser: '@typescript-eslint/parser',
|
|
4
|
+
plugins: [
|
|
5
|
+
'@typescript-eslint',
|
|
6
|
+
'prettier'
|
|
7
|
+
],
|
|
8
|
+
extends: [
|
|
9
|
+
'eslint:recommended',
|
|
10
|
+
'plugin:@typescript-eslint/recommended',
|
|
11
|
+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
|
12
|
+
'prettier'
|
|
13
|
+
],
|
|
14
|
+
parserOptions: {
|
|
15
|
+
ecmaVersion: 2020,
|
|
16
|
+
sourceType: 'module',
|
|
17
|
+
project: './tsconfig.json',
|
|
18
|
+
tsconfigRootDir: __dirname,
|
|
19
|
+
},
|
|
20
|
+
env: {
|
|
21
|
+
node: true,
|
|
22
|
+
es2020: true,
|
|
23
|
+
jest: true
|
|
24
|
+
},
|
|
25
|
+
rules: {
|
|
26
|
+
// Prettier integration
|
|
27
|
+
'prettier/prettier': 'error',
|
|
28
|
+
|
|
29
|
+
// TypeScript specific rules (relaxed to reduce CI friction)
|
|
30
|
+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }],
|
|
31
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
32
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
33
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
34
|
+
'@typescript-eslint/no-non-null-assertion': 'warn',
|
|
35
|
+
'@typescript-eslint/prefer-nullish-coalescing': 'off',
|
|
36
|
+
'@typescript-eslint/prefer-optional-chain': 'off',
|
|
37
|
+
'@typescript-eslint/strict-boolean-expressions': 'off',
|
|
38
|
+
'@typescript-eslint/no-floating-promises': 'warn',
|
|
39
|
+
'@typescript-eslint/await-thenable': 'warn',
|
|
40
|
+
'@typescript-eslint/no-misused-promises': 'warn',
|
|
41
|
+
'@typescript-eslint/require-await': 'off',
|
|
42
|
+
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
43
|
+
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
44
|
+
'@typescript-eslint/no-unsafe-return': 'off',
|
|
45
|
+
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
46
|
+
'@typescript-eslint/no-unsafe-call': 'off',
|
|
47
|
+
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
|
|
48
|
+
'@typescript-eslint/restrict-template-expressions': 'off',
|
|
49
|
+
|
|
50
|
+
// General rules
|
|
51
|
+
'no-console': 'warn',
|
|
52
|
+
'prefer-const': 'error',
|
|
53
|
+
'no-var': 'error',
|
|
54
|
+
'object-shorthand': 'error',
|
|
55
|
+
'prefer-template': 'warn'
|
|
56
|
+
},
|
|
57
|
+
overrides: [
|
|
58
|
+
{
|
|
59
|
+
files: ['**/*.test.ts', '**/*.spec.ts'],
|
|
60
|
+
rules: {
|
|
61
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
62
|
+
'no-console': 'off'
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
files: ['test/**/*.js', 'examples/**/*.js'],
|
|
67
|
+
parser: 'espree',
|
|
68
|
+
parserOptions: {
|
|
69
|
+
ecmaVersion: 2020,
|
|
70
|
+
sourceType: 'module'
|
|
71
|
+
},
|
|
72
|
+
env: {
|
|
73
|
+
node: true,
|
|
74
|
+
jest: true,
|
|
75
|
+
es2020: true
|
|
76
|
+
},
|
|
77
|
+
rules: {
|
|
78
|
+
// JS files should not use TS type-aware rules
|
|
79
|
+
'@typescript-eslint/await-thenable': 'off',
|
|
80
|
+
'@typescript-eslint/no-floating-promises': 'off',
|
|
81
|
+
'@typescript-eslint/no-misused-promises': 'off',
|
|
82
|
+
'@typescript-eslint/require-await': 'off',
|
|
83
|
+
'@typescript-eslint/strict-boolean-expressions': 'off',
|
|
84
|
+
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
85
|
+
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
86
|
+
'@typescript-eslint/no-unsafe-return': 'off',
|
|
87
|
+
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
88
|
+
'@typescript-eslint/restrict-template-expressions': 'off',
|
|
89
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
90
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
91
|
+
'@typescript-eslint/no-explicit-any': 'off'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
files: ['examples/**/*.ts'],
|
|
96
|
+
rules: {
|
|
97
|
+
'no-console': 'off'
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
};
|
|
102
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
release:
|
|
9
|
+
types: [published]
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
build:
|
|
17
|
+
name: Build and test
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
- uses: actions/setup-node@v4
|
|
23
|
+
with:
|
|
24
|
+
node-version: 22
|
|
25
|
+
cache: npm
|
|
26
|
+
|
|
27
|
+
- run: npm ci
|
|
28
|
+
- run: npm run build
|
|
29
|
+
- run: npm test
|
|
30
|
+
- run: npm run lint
|
|
31
|
+
- run: npm run type-check
|
|
32
|
+
|
|
33
|
+
publish:
|
|
34
|
+
name: Publish
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
if: github.event_name == 'release'
|
|
37
|
+
environment: release
|
|
38
|
+
needs: build
|
|
39
|
+
|
|
40
|
+
permissions:
|
|
41
|
+
contents: read
|
|
42
|
+
id-token: write
|
|
43
|
+
|
|
44
|
+
steps:
|
|
45
|
+
- uses: actions/checkout@v4
|
|
46
|
+
- uses: actions/setup-node@v4
|
|
47
|
+
with:
|
|
48
|
+
node-version: 22
|
|
49
|
+
cache: npm
|
|
50
|
+
registry-url: 'https://registry.npmjs.org'
|
|
51
|
+
|
|
52
|
+
- run: npm ci
|
|
53
|
+
|
|
54
|
+
- run: npm publish --provenance --access public
|
|
55
|
+
env:
|
|
56
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
57
|
+
|
package/.prettierignore
ADDED
package/.prettierrc
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"semi": true,
|
|
3
|
+
"trailingComma": "es5",
|
|
4
|
+
"singleQuote": true,
|
|
5
|
+
"printWidth": 100,
|
|
6
|
+
"tabWidth": 2,
|
|
7
|
+
"useTabs": false,
|
|
8
|
+
"bracketSpacing": true,
|
|
9
|
+
"bracketSameLine": false,
|
|
10
|
+
"arrowParens": "avoid",
|
|
11
|
+
"endOfLine": "lf",
|
|
12
|
+
"quoteProps": "as-needed"
|
|
13
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Barndoor AI, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
# Barndoor TypeScript SDK
|
|
2
|
+
|
|
3
|
+
A lightweight, **framework-agnostic** TypeScript/JavaScript client for the Barndoor Platform REST APIs and Model Context Protocol (MCP) servers.
|
|
4
|
+
|
|
5
|
+
The SDK supports *lazy authentication*—you can build an SDK instance first, then inject a JWT later with `authenticate()`.
|
|
6
|
+
|
|
7
|
+
The SDK removes boiler-plate around:
|
|
8
|
+
|
|
9
|
+
* Secure, offline-friendly **authentication to Barndoor** (interactive PKCE flow + token caching).
|
|
10
|
+
* **Server registry** – list, inspect and connect third-party providers (Salesforce, Notion, Slack …).
|
|
11
|
+
* **Managed Connector Proxy** – build ready-to-use connection parameters for any LLM/agent framework (CrewAI, LangChain, custom code …) without importing Barndoor-specific adapters.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @barndoor/sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### Basic Usage
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { BarndoorSDK } from '@barndoor/sdk';
|
|
25
|
+
|
|
26
|
+
// ① token known at construction time (unchanged)
|
|
27
|
+
const sdk = new BarndoorSDK('https://your-org.mcp.barndoor.ai', {
|
|
28
|
+
token: 'your-jwt'
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
// ② deferred login (new)
|
|
34
|
+
const sdk = new BarndoorSDK('https://your-org.mcp.barndoor.ai');
|
|
35
|
+
await sdk.authenticate('your-jwt');
|
|
36
|
+
|
|
37
|
+
// List available MCP servers
|
|
38
|
+
const servers = await sdk.listServers();
|
|
39
|
+
console.log('Available servers:', servers);
|
|
40
|
+
|
|
41
|
+
// Get details for a specific server
|
|
42
|
+
const server = await sdk.getServer('server-uuid');
|
|
43
|
+
console.log('Server details:', server);
|
|
44
|
+
|
|
45
|
+
// Clean up
|
|
46
|
+
await sdk.close();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Interactive Login
|
|
50
|
+
|
|
51
|
+
For development and prototyping, use the interactive login helper:
|
|
52
|
+
|
|
53
|
+
`loginInteractive()` builds an SDK *without* requiring `token` in the ctor—it internally calls `sdk.authenticate()` for you.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { loginInteractive } from '@barndoor/sdk';
|
|
57
|
+
|
|
58
|
+
// Automatically handles OAuth flow and token caching
|
|
59
|
+
const sdk = await loginInteractive();
|
|
60
|
+
const servers = await sdk.listServers();
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Complete Workflow
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import {
|
|
67
|
+
loginInteractive,
|
|
68
|
+
ensureServerConnected,
|
|
69
|
+
makeMcpConnectionParams
|
|
70
|
+
} from '@barndoor/sdk';
|
|
71
|
+
|
|
72
|
+
async function main() {
|
|
73
|
+
// 1. Login (handles OAuth + caching)
|
|
74
|
+
const sdk = await loginInteractive();
|
|
75
|
+
|
|
76
|
+
// 2. Ensure server is connected (launches OAuth if needed)
|
|
77
|
+
await ensureServerConnected(sdk, 'notion'); // sdk.ensureServerConnected(...) is also available directly
|
|
78
|
+
|
|
79
|
+
// 3. Get connection parameters for your AI framework
|
|
80
|
+
const [params, publicUrl] = await makeMcpConnectionParams(sdk, 'notion');
|
|
81
|
+
|
|
82
|
+
// 4. Use with any MCP-compatible framework
|
|
83
|
+
console.log('MCP URL:', params.url);
|
|
84
|
+
console.log('Headers:', params.headers);
|
|
85
|
+
|
|
86
|
+
// 5. Disconnect when done (optional)
|
|
87
|
+
await sdk.disconnectServer('notion');
|
|
88
|
+
|
|
89
|
+
await sdk.close();
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Disconnecting from Servers
|
|
94
|
+
|
|
95
|
+
To disconnect from a server and clean up OAuth credentials:
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
// Disconnect using server ID or slug
|
|
99
|
+
await sdk.disconnectServer('notion');
|
|
100
|
+
// or
|
|
101
|
+
await sdk.disconnectServer('123e4567-e89b-12d3-a456-426614174000');
|
|
102
|
+
|
|
103
|
+
// The server will need to be reconnected before use
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Environment Configuration
|
|
107
|
+
|
|
108
|
+
The SDK automatically detects your environment and configures appropriate endpoints:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# Development
|
|
112
|
+
export MODE=development
|
|
113
|
+
export AGENT_CLIENT_ID=your_client_id
|
|
114
|
+
export AGENT_CLIENT_SECRET=your_client_secret
|
|
115
|
+
|
|
116
|
+
# Production
|
|
117
|
+
export MODE=production
|
|
118
|
+
export AGENT_CLIENT_ID=your_client_id
|
|
119
|
+
export AGENT_CLIENT_SECRET=your_client_secret
|
|
120
|
+
|
|
121
|
+
# Local development
|
|
122
|
+
export MODE=localdev
|
|
123
|
+
export BARNDOOR_API=http://localhost:8000
|
|
124
|
+
export BARNDOOR_URL=http://localhost:8000
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
If you run without a token at construction time the SDK will still read `AGENT_CLIENT_ID/SECRET` when `loginInteractive()` is invoked.
|
|
128
|
+
|
|
129
|
+
## API Reference
|
|
130
|
+
|
|
131
|
+
### BarndoorSDK
|
|
132
|
+
|
|
133
|
+
Main SDK class for API interactions.
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
const sdk = new BarndoorSDK(apiBaseUrl, options);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Parameters:**
|
|
140
|
+
- `apiBaseUrl` (string): Base URL of the Barndoor API
|
|
141
|
+
- `options.token?` (string): Initial JWT (pass later via authenticate() if omitted)
|
|
142
|
+
- `options.timeout` (number): Request timeout in seconds (default: 30)
|
|
143
|
+
- `options.maxRetries` (number): Maximum retry attempts (default: 3)
|
|
144
|
+
|
|
145
|
+
**Methods:**
|
|
146
|
+
|
|
147
|
+
#### `authenticate(jwtToken)`
|
|
148
|
+
Sets/validates token for the SDK instance.
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
await sdk.authenticate(jwtToken);
|
|
152
|
+
// Returns: Promise<void>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### `ensureServerConnected(serverSlug, options?)`
|
|
156
|
+
Ensure a server is connected, launching OAuth if needed – same behaviour as quick-start helper.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
await sdk.ensureServerConnected('notion', { pollSeconds: 2 });
|
|
160
|
+
// Returns: Promise<void>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### `listServers()`
|
|
164
|
+
List all MCP servers available to your organization.
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
const servers = await sdk.listServers();
|
|
168
|
+
// Returns: ServerSummary[]
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### `getServer(serverId)`
|
|
172
|
+
Get detailed information about a specific server.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
const server = await sdk.getServer('server-uuid');
|
|
176
|
+
// Returns: ServerDetail
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### `initiateConnection(serverId, returnUrl?)`
|
|
180
|
+
Initiate OAuth connection flow for a server.
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
const connection = await sdk.initiateConnection('server-uuid');
|
|
184
|
+
// Returns: { connection_id, auth_url, state }
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### `getConnectionStatus(serverId)`
|
|
188
|
+
Get connection status for a server.
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
const status = await sdk.getConnectionStatus('server-uuid');
|
|
192
|
+
// Returns: 'available' | 'pending' | 'connected'
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
#### `disconnectServer(serverId)`
|
|
196
|
+
Disconnect from a specific MCP server.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
await sdk.disconnectServer('server-uuid');
|
|
200
|
+
// Returns: Promise<void>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
This will remove the connection record and clean up any stored OAuth credentials. The user will need to reconnect to use this server again.
|
|
204
|
+
|
|
205
|
+
### Quick-start Helpers
|
|
206
|
+
|
|
207
|
+
#### `loginInteractive(options?)`
|
|
208
|
+
Perform interactive OAuth login and return initialized SDK.
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
const sdk = await loginInteractive({
|
|
212
|
+
authDomain: 'auth.barndoor.ai',
|
|
213
|
+
clientId: 'your-client-id',
|
|
214
|
+
clientSecret: 'your-client-secret',
|
|
215
|
+
port: 52765
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
#### `ensureServerConnected(sdk, serverSlug, options?)`
|
|
220
|
+
Ensure a server is connected, launching OAuth if needed.
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
await ensureServerConnected(sdk, 'notion', { timeout: 90 });
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### `makeMcpConnectionParams(sdk, serverSlug, options?)`
|
|
227
|
+
Generate MCP connection parameters for AI frameworks.
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
const [params, publicUrl] = await makeMcpConnectionParams(sdk, 'notion');
|
|
231
|
+
// params: { url, transport, headers }
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Error Handling
|
|
235
|
+
|
|
236
|
+
The SDK provides a comprehensive error hierarchy:
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import {
|
|
240
|
+
BarndoorError,
|
|
241
|
+
HTTPError,
|
|
242
|
+
ConnectionError,
|
|
243
|
+
TokenError,
|
|
244
|
+
ConfigurationError
|
|
245
|
+
} from '@barndoor/sdk';
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
await sdk.listServers();
|
|
249
|
+
} catch (error) {
|
|
250
|
+
if (error instanceof HTTPError) {
|
|
251
|
+
console.error('HTTP Error:', error.statusCode, error.message);
|
|
252
|
+
} else if (error instanceof TokenError) {
|
|
253
|
+
console.error('Token Error:', error.message);
|
|
254
|
+
// Re-authenticate
|
|
255
|
+
} else if (error instanceof ConnectionError) {
|
|
256
|
+
console.error('Connection Error:', error.message);
|
|
257
|
+
// Check network
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Browser Support
|
|
263
|
+
|
|
264
|
+
The SDK works in both Node.js and browser environments:
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
// Browser usage
|
|
268
|
+
import { BarndoorSDK } from '@barndoor/sdk';
|
|
269
|
+
|
|
270
|
+
// Token storage uses localStorage in browsers
|
|
271
|
+
const sdk = new BarndoorSDK('https://api.barndoor.ai', {
|
|
272
|
+
token: 'your-token'
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
When running in the browser you can also create the SDK first and later call `await sdk.authenticate(token)` once your SPA receives a JWT.
|
|
277
|
+
|
|
278
|
+
**Note:** Interactive login (`loginInteractive`) requires Node.js for the local callback server.
|
|
279
|
+
|
|
280
|
+
## Examples
|
|
281
|
+
|
|
282
|
+
See the `examples/` directory for complete working examples:
|
|
283
|
+
|
|
284
|
+
- `openai-integration.js` - OpenAI + MCP function calling integration
|
|
285
|
+
- `basic-mcp-client.js` - Direct MCP client without AI framework
|
|
286
|
+
|
|
287
|
+
## TypeScript Support
|
|
288
|
+
|
|
289
|
+
The SDK is written in TypeScript and includes full type definitions:
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
import { BarndoorSDK, ServerSummary } from '@barndoor/sdk';
|
|
293
|
+
|
|
294
|
+
const sdk = new BarndoorSDK('https://api.barndoor.ai', {
|
|
295
|
+
token: 'your-token'
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const servers: ServerSummary[] = await sdk.listServers();
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## Contributing
|
|
302
|
+
|
|
303
|
+
1. Clone the repository
|
|
304
|
+
2. Install node `nvm install 22 && nvm use 22`
|
|
305
|
+
3. Install dependencies: `npm install`
|
|
306
|
+
4. Build the project: `npm run build`
|
|
307
|
+
5. Run tests: `npm test`
|
|
308
|
+
6. Run linting: `npm run lint`
|
|
309
|
+
7. Run type checking: `npm run type-check`
|