@foxnose/sdk 0.2.3 → 0.4.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 +161 -5
- package/dist/index.cjs +802 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +394 -8
- package/dist/index.d.ts +394 -8
- package/dist/index.js +795 -21
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -48,12 +48,12 @@ const client = new ManagementClient({
|
|
|
48
48
|
auth,
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
// List
|
|
52
|
-
const
|
|
53
|
-
console.log(
|
|
51
|
+
// List collections
|
|
52
|
+
const collections = await client.listCollections();
|
|
53
|
+
console.log(collections.results);
|
|
54
54
|
|
|
55
55
|
// Create a resource
|
|
56
|
-
const resource = await client.createResource('my-
|
|
56
|
+
const resource = await client.createResource('my-collection-key', {
|
|
57
57
|
data: { title: 'Hello World' },
|
|
58
58
|
});
|
|
59
59
|
console.log(resource.key);
|
|
@@ -62,6 +62,62 @@ console.log(resource.key);
|
|
|
62
62
|
client.close();
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
> **Note (0.4.0):** Folder-named methods (`listFolders`, `createFolder`,
|
|
66
|
+
> `addApiFolder`, `listFolderVersions`, `listFolderFields`, etc.) remain as
|
|
67
|
+
> `@deprecated` aliases that emit a one-shot `console.warn` on first use per
|
|
68
|
+
> process. They keep their original wire behaviour (hitting the legacy
|
|
69
|
+
> `/folders/...` URL alias on the server) and will be removed in **1.0**.
|
|
70
|
+
> Prefer the `*Collection*` names in new code.
|
|
71
|
+
|
|
72
|
+
### Components on Collections
|
|
73
|
+
|
|
74
|
+
Collections can embed Components as nested fields with explicit pin
|
|
75
|
+
semantics (`component`, `component_version`, `auto_update`). The
|
|
76
|
+
`nestedFieldMeta` helper builds the `meta` block with camelCase
|
|
77
|
+
ergonomics, and `syncCollectionComponent` advances pinned fields to a
|
|
78
|
+
target Component version on demand.
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { ManagementClient, JWTAuth, nestedFieldMeta } from '@foxnose/sdk';
|
|
82
|
+
|
|
83
|
+
const client = new ManagementClient({
|
|
84
|
+
config: { baseUrl: 'https://api.foxnose.com' },
|
|
85
|
+
environmentKey: 'prod',
|
|
86
|
+
auth: new JWTAuth('ACCESS_TOKEN'),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Embed a Component as a pinned nested field on a Collection draft.
|
|
90
|
+
await client.createCollectionField('articles', 'v2-draft', {
|
|
91
|
+
key: 'seo',
|
|
92
|
+
name: 'SEO',
|
|
93
|
+
type: 'nested',
|
|
94
|
+
required: true,
|
|
95
|
+
meta: nestedFieldMeta({
|
|
96
|
+
component: 'cmp-seo-metadata',
|
|
97
|
+
componentVersion: 'ver-abc12345',
|
|
98
|
+
autoUpdate: false, // default — pin until explicit sync
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Later, advance every pinned nested field to its Component's
|
|
103
|
+
// current version (empty body = sync all pinned).
|
|
104
|
+
const result = await client.syncCollectionComponent('articles');
|
|
105
|
+
console.log(result.synced_paths, result.schema_version);
|
|
106
|
+
|
|
107
|
+
// Advance specific paths to a chosen Component version.
|
|
108
|
+
await client.syncCollectionComponent('articles', {
|
|
109
|
+
fieldPaths: ['seo'],
|
|
110
|
+
toVersions: { seo: 'ver-def67890' },
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`syncCollectionComponent` returns a `SyncComponentResponse` with
|
|
115
|
+
`synced_paths`, `skipped` (per-path reasons), and `schema_version`
|
|
116
|
+
(UID of the newly published Collection schema version, or `null` if no
|
|
117
|
+
field needed advancing). On compatibility conflict the server returns
|
|
118
|
+
409 `component_sync_conflict`; quota exhaustion returns 422
|
|
119
|
+
`too_many_versions`. Both surface as `FoxnoseAPIError`.
|
|
120
|
+
|
|
65
121
|
### Flux Client
|
|
66
122
|
|
|
67
123
|
```typescript
|
|
@@ -100,6 +156,64 @@ console.log(schema.searchable_fields);
|
|
|
100
156
|
client.close();
|
|
101
157
|
```
|
|
102
158
|
|
|
159
|
+
### Vector Search
|
|
160
|
+
|
|
161
|
+
The Flux client provides typed convenience methods for all vector search modes:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { FluxClient, SearchMode, buildSearchBody } from '@foxnose/sdk';
|
|
165
|
+
|
|
166
|
+
// Semantic search (auto-generated embeddings)
|
|
167
|
+
const results = await client.vectorSearch('articles', {
|
|
168
|
+
query: 'machine learning in healthcare',
|
|
169
|
+
top_k: 10,
|
|
170
|
+
similarity_threshold: 0.7,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Custom embedding search
|
|
174
|
+
const results = await client.vectorFieldSearch('articles', {
|
|
175
|
+
field: 'content_embedding',
|
|
176
|
+
query_vector: [0.012, -0.034, 0.056 /* ... */],
|
|
177
|
+
top_k: 20,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Hybrid text + vector search
|
|
181
|
+
const results = await client.hybridSearch('articles', {
|
|
182
|
+
query: 'ML applications',
|
|
183
|
+
find_text: { query: 'machine learning' },
|
|
184
|
+
vector_weight: 0.7,
|
|
185
|
+
text_weight: 0.3,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Boosted search (keywords boosted by vector similarity)
|
|
189
|
+
const results = await client.boostedSearch('articles', {
|
|
190
|
+
find_text: { query: 'python tutorial' },
|
|
191
|
+
query: 'beginner programming guide',
|
|
192
|
+
boost_factor: 1.5,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Extra parameters (where, sort) are forwarded to the API
|
|
196
|
+
const results = await client.vectorSearch('articles', {
|
|
197
|
+
query: 'climate change',
|
|
198
|
+
limit: 5,
|
|
199
|
+
sort: '-published_at',
|
|
200
|
+
where: { category: 'science' },
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
You can also use `buildSearchBody()` for full control with the raw `search()` method:
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
const body = buildSearchBody({
|
|
208
|
+
search_mode: SearchMode.HYBRID,
|
|
209
|
+
find_text: { query: 'python' },
|
|
210
|
+
vector_search: { query: 'programming tutorials', top_k: 10 },
|
|
211
|
+
hybrid_config: { vector_weight: 0.6, text_weight: 0.4 },
|
|
212
|
+
limit: 20,
|
|
213
|
+
});
|
|
214
|
+
const results = await client.search('articles', body);
|
|
215
|
+
```
|
|
216
|
+
|
|
103
217
|
### API Folder Route Descriptions
|
|
104
218
|
|
|
105
219
|
You can configure per-route descriptions when connecting a folder to an API.
|
|
@@ -175,7 +289,7 @@ All API errors are thrown as typed exceptions:
|
|
|
175
289
|
import { FoxnoseAPIError, FoxnoseTransportError } from '@foxnose/sdk';
|
|
176
290
|
|
|
177
291
|
try {
|
|
178
|
-
await client.getResource('
|
|
292
|
+
await client.getResource('collection', 'nonexistent-key');
|
|
179
293
|
} catch (err) {
|
|
180
294
|
if (err instanceof FoxnoseAPIError) {
|
|
181
295
|
console.error(err.statusCode); // 404
|
|
@@ -187,6 +301,48 @@ try {
|
|
|
187
301
|
}
|
|
188
302
|
```
|
|
189
303
|
|
|
304
|
+
### Billing errors
|
|
305
|
+
|
|
306
|
+
Billing-related responses are thrown as typed subclasses of `FoxnoseAPIError`,
|
|
307
|
+
so an existing `catch (err) { if (err instanceof FoxnoseAPIError) ... }` keeps
|
|
308
|
+
working. Narrow to a subclass to read its typed fields:
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
import {
|
|
312
|
+
FoxnoseAPIError,
|
|
313
|
+
SpendCapExceededError,
|
|
314
|
+
PlanExhaustedError,
|
|
315
|
+
PlanLimitExceededError,
|
|
316
|
+
RateLimitExceededError,
|
|
317
|
+
} from '@foxnose/sdk';
|
|
318
|
+
|
|
319
|
+
try {
|
|
320
|
+
await client.createResource('collection', payload);
|
|
321
|
+
} catch (err) {
|
|
322
|
+
if (err instanceof SpendCapExceededError) {
|
|
323
|
+
// HTTP 402
|
|
324
|
+
console.error(err.capUsd); // Spend cap in USD (or null)
|
|
325
|
+
console.error(err.cycleResetsAt); // ISO timestamp
|
|
326
|
+
console.error(err.raiseCapUrl); // Where to raise the cap
|
|
327
|
+
} else if (err instanceof PlanExhaustedError) {
|
|
328
|
+
// HTTP 402
|
|
329
|
+
console.error(err.axis); // e.g. "retrievals", "writes"
|
|
330
|
+
console.error(err.windowResetsAt); // ISO timestamp
|
|
331
|
+
console.error(err.upgradeUrl);
|
|
332
|
+
} else if (err instanceof PlanLimitExceededError) {
|
|
333
|
+
// HTTP 403
|
|
334
|
+
console.error(err.entity); // e.g. "collections"
|
|
335
|
+
console.error(err.current, err.limit);
|
|
336
|
+
console.error(err.upgradeUrl); // May be undefined
|
|
337
|
+
} else if (err instanceof RateLimitExceededError) {
|
|
338
|
+
// HTTP 429
|
|
339
|
+
console.error(err.retryAfter); // Seconds to wait (from Retry-After)
|
|
340
|
+
} else if (err instanceof FoxnoseAPIError) {
|
|
341
|
+
console.error(err.statusCode, err.errorCode);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
```
|
|
345
|
+
|
|
190
346
|
## Batch Operations
|
|
191
347
|
|
|
192
348
|
Efficiently upsert multiple resources with concurrency control:
|