Skip to content

Commit fdc78cf

Browse files
committed
Add README with installation and usage guide
1 parent eea0656 commit fdc78cf

1 file changed

Lines changed: 213 additions & 0 deletions

File tree

README.md

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# @foxnose/sdk
2+
3+
[![npm version](https://img.shields.io/npm/v/@foxnose/sdk)](https://www.npmjs.com/package/@foxnose/sdk)
4+
[![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
5+
[![Node.js](https://img.shields.io/badge/node-%3E%3D18-green)](https://nodejs.org)
6+
7+
Official TypeScript SDK for the [FoxNose](https://foxnose.net/?utm_source=github&utm_medium=repository&utm_campaign=foxnose-typescript) platform — a managed knowledge layer for RAG and AI agents.
8+
9+
## Features
10+
11+
- **Type-safe clients** with full TypeScript interfaces for all API responses
12+
- **Async-only API** built on native `fetch` (Node 18+)
13+
- **Automatic retries** with exponential backoff and Retry-After support
14+
- **Four auth strategies** — Anonymous, JWT, Simple key, and Secure (ECDSA P-256)
15+
- **Zero dependencies** — uses only Node.js built-in modules
16+
- **Dual output** — ESM and CommonJS builds with full `.d.ts` declarations
17+
18+
## Documentation
19+
20+
- [FoxNose Platform Documentation](https://foxnose.net/docs?utm_source=github&utm_medium=repository&utm_campaign=foxnose-typescript)
21+
- [Management API Reference](https://foxnose.net/docs/management-api/v1/get-started?utm_source=github&utm_medium=repository&utm_campaign=foxnose-typescript)
22+
- [Flux API Reference](https://foxnose.net/docs/flux-api/v1/get-started?utm_source=github&utm_medium=repository&utm_campaign=foxnose-typescript)
23+
24+
## Installation
25+
26+
```bash
27+
npm install @foxnose/sdk
28+
# or
29+
pnpm add @foxnose/sdk
30+
# or
31+
yarn add @foxnose/sdk
32+
```
33+
34+
## Quick Start
35+
36+
### Management Client
37+
38+
```typescript
39+
import { ManagementClient, JWTAuth } from '@foxnose/sdk';
40+
41+
const auth = JWTAuth.fromStaticToken('your-access-token');
42+
43+
const client = new ManagementClient({
44+
baseUrl: 'https://api.foxnose.net',
45+
environmentKey: 'your-environment-key',
46+
auth,
47+
});
48+
49+
// List folders
50+
const folders = await client.listFolders();
51+
console.log(folders.results);
52+
53+
// Create a resource
54+
const resource = await client.createResource('my-folder-key', {
55+
data: { title: 'Hello World' },
56+
});
57+
console.log(resource.key);
58+
59+
// Clean up
60+
client.close();
61+
```
62+
63+
### Flux Client
64+
65+
```typescript
66+
import { FluxClient, SimpleKeyAuth } from '@foxnose/sdk';
67+
68+
const auth = new SimpleKeyAuth('your-public-key', 'your-secret-key');
69+
70+
const client = new FluxClient({
71+
baseUrl: 'https://your-env.fxns.io',
72+
apiPrefix: 'v1',
73+
auth,
74+
});
75+
76+
// List resources from a folder
77+
const resources = await client.listResources('articles');
78+
console.log(resources.results);
79+
80+
// Get a single resource
81+
const article = await client.getResource('articles', 'resource-key');
82+
console.log(article);
83+
84+
// Search
85+
const results = await client.search('articles', {
86+
query: { match_all: {} },
87+
size: 10,
88+
});
89+
90+
client.close();
91+
```
92+
93+
## Authentication
94+
95+
The SDK supports four authentication strategies:
96+
97+
### JWT Auth
98+
99+
Best for server-side applications with user tokens.
100+
101+
```typescript
102+
import { JWTAuth } from '@foxnose/sdk';
103+
104+
// From a static token
105+
const auth = JWTAuth.fromStaticToken('your-access-token');
106+
107+
// With a custom token provider
108+
const auth = new JWTAuth({
109+
getToken() {
110+
return fetchTokenFromSomewhere();
111+
},
112+
});
113+
```
114+
115+
### Simple Key Auth
116+
117+
For development and Flux API access.
118+
119+
```typescript
120+
import { SimpleKeyAuth } from '@foxnose/sdk';
121+
122+
const auth = new SimpleKeyAuth('public-key', 'secret-key');
123+
```
124+
125+
### Secure Key Auth
126+
127+
ECDSA P-256 signature-based authentication (Node.js only).
128+
129+
```typescript
130+
import { SecureKeyAuth } from '@foxnose/sdk';
131+
132+
const auth = new SecureKeyAuth('public-key', 'base64-der-private-key');
133+
```
134+
135+
### Anonymous Auth
136+
137+
For unauthenticated endpoints.
138+
139+
```typescript
140+
import { AnonymousAuth } from '@foxnose/sdk';
141+
142+
const auth = new AnonymousAuth();
143+
```
144+
145+
## Error Handling
146+
147+
All API errors are thrown as typed exceptions:
148+
149+
```typescript
150+
import { FoxnoseAPIError, FoxnoseTransportError } from '@foxnose/sdk';
151+
152+
try {
153+
await client.getResource('folder', 'nonexistent-key');
154+
} catch (err) {
155+
if (err instanceof FoxnoseAPIError) {
156+
console.error(err.statusCode); // 404
157+
console.error(err.errorCode); // "not_found"
158+
console.error(err.detail); // Additional error details
159+
} else if (err instanceof FoxnoseTransportError) {
160+
console.error('Network error:', err.message);
161+
}
162+
}
163+
```
164+
165+
## Batch Operations
166+
167+
Efficiently upsert multiple resources with concurrency control:
168+
169+
```typescript
170+
const items = [
171+
{ external_id: 'article-1', payload: { data: { title: 'First' } } },
172+
{ external_id: 'article-2', payload: { data: { title: 'Second' } } },
173+
];
174+
175+
const result = await client.batchUpsertResources('folder-key', items, {
176+
maxConcurrency: 5,
177+
onProgress: (completed, total) => {
178+
console.log(`${completed}/${total}`);
179+
},
180+
});
181+
182+
console.log(result.succeeded.length); // Successfully upserted
183+
console.log(result.failed.length); // Failed items with errors
184+
```
185+
186+
## Development
187+
188+
```bash
189+
# Install dependencies
190+
pnpm install
191+
192+
# Build
193+
pnpm build
194+
195+
# Run tests
196+
pnpm test
197+
198+
# Run tests with coverage
199+
pnpm test:coverage
200+
201+
# Lint
202+
pnpm lint
203+
204+
# Type check
205+
pnpm typecheck
206+
207+
# Format
208+
pnpm format
209+
```
210+
211+
## License
212+
213+
[Apache-2.0](LICENSE)

0 commit comments

Comments
 (0)