Skip to content

Commit a452474

Browse files
authored
Merge pull request #2 from FoxNoseTech/feat/add-router-and-schema-introspection
Feat: Support Flux router and schema introspection endpoints
2 parents fabe93c + 377709b commit a452474

15 files changed

Lines changed: 250 additions & 153 deletions

File tree

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Official TypeScript SDK for the [FoxNose](https://foxnose.net/?utm_source=github
1212
- **Async-only API** built on native `fetch` (Node 18+)
1313
- **Automatic retries** with exponential backoff and Retry-After support
1414
- **Four auth strategies** — Anonymous, JWT, Simple key, and Secure (ECDSA P-256)
15+
- **Flux introspection** — discover route contracts with `/_router` and `/_schema`
1516
- **Zero dependencies** — uses only Node.js built-in modules
1617
- **Dual output** — ESM and CommonJS builds with full `.d.ts` declarations
1718

@@ -87,9 +88,32 @@ const results = await client.search('articles', {
8788
size: 10,
8889
});
8990

91+
// Discover available routes for this API prefix
92+
const router = await client.getRouter();
93+
console.log(router.routes.length);
94+
95+
// Get live schema metadata for a folder route
96+
const schema = await client.getSchema('articles');
97+
console.log(schema.searchable_fields);
98+
9099
client.close();
91100
```
92101

102+
### API Folder Route Descriptions
103+
104+
You can configure per-route descriptions when connecting a folder to an API.
105+
These descriptions are returned by Flux `/_router` introspection.
106+
107+
```typescript
108+
await managementClient.addApiFolder(api.key, folder.key, {
109+
allowedMethods: ['get_many', 'get_one'],
110+
descriptionGetOne: 'Get one article by key',
111+
descriptionGetMany: 'List published articles',
112+
descriptionSearch: 'Search published articles',
113+
descriptionSchema: 'Read article schema',
114+
});
115+
```
116+
93117
## Authentication
94118

95119
The SDK supports four authentication strategies:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@foxnose/sdk",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"description": "Official FoxNose SDK for TypeScript and JavaScript",
55
"license": "Apache-2.0",
66
"type": "module",

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const DEFAULT_RETRY_CONFIG: Readonly<RetryConfig> = {
1919
methods: ['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE'],
2020
};
2121

22-
export const SDK_VERSION = '0.1.1';
22+
export const SDK_VERSION = '0.2.0';
2323

2424
export const DEFAULT_USER_AGENT = `foxnose-sdk-js/${SDK_VERSION}`;
2525

src/flux/client.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ export class FluxClient {
7272
return this.transport.request('POST', path, { jsonBody: body });
7373
}
7474

75+
async getRouter<T = any>(): Promise<T> {
76+
const path = `/${this.apiPrefix}/_router`;
77+
return this.transport.request('GET', path);
78+
}
79+
80+
async getSchema<T = any>(folderPath: string): Promise<T> {
81+
const path = this.buildPath(folderPath, '/_schema');
82+
return this.transport.request('GET', path);
83+
}
84+
7585
close(): void {
7686
this.transport.close();
7787
}

src/http.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ export class HttpTransport {
1212
private readonly auth: AuthStrategy;
1313
private readonly retry: RetryConfig;
1414

15-
constructor(options: {
16-
config: FoxnoseConfig;
17-
auth?: AuthStrategy;
18-
retryConfig?: RetryConfig;
19-
}) {
15+
constructor(options: { config: FoxnoseConfig; auth?: AuthStrategy; retryConfig?: RetryConfig }) {
2016
this.config = options.config;
2117
this.auth = options.auth ?? new AnonymousAuth();
2218
this.retry = options.retryConfig ?? { ...DEFAULT_RETRY_CONFIG };

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ export { HttpTransport } from './http.js';
2525

2626
// Management Client
2727
export { ManagementClient } from './management/index.js';
28-
export type { ManagementClientOptions } from './management/index.js';
28+
export type {
29+
ApiFolderOptions,
30+
ApiFolderRouteDescriptionOptions,
31+
ManagementClientOptions,
32+
} from './management/index.js';
2933

3034
// Flux Client
3135
export { FluxClient } from './flux/index.js';

0 commit comments

Comments
 (0)