@foxnose/sdk 0.3.0 → 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 +103 -5
- package/dist/index.cjs +522 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +282 -8
- package/dist/index.d.ts +282 -8
- package/dist/index.js +517 -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
|
|
@@ -233,7 +289,7 @@ All API errors are thrown as typed exceptions:
|
|
|
233
289
|
import { FoxnoseAPIError, FoxnoseTransportError } from '@foxnose/sdk';
|
|
234
290
|
|
|
235
291
|
try {
|
|
236
|
-
await client.getResource('
|
|
292
|
+
await client.getResource('collection', 'nonexistent-key');
|
|
237
293
|
} catch (err) {
|
|
238
294
|
if (err instanceof FoxnoseAPIError) {
|
|
239
295
|
console.error(err.statusCode); // 404
|
|
@@ -245,6 +301,48 @@ try {
|
|
|
245
301
|
}
|
|
246
302
|
```
|
|
247
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
|
+
|
|
248
346
|
## Batch Operations
|
|
249
347
|
|
|
250
348
|
Efficiently upsert multiple resources with concurrency control:
|