@foxnose/sdk 0.8.0 → 0.9.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 +98 -0
- package/dist/index.cjs +1173 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +693 -4
- package/dist/index.d.ts +693 -4
- package/dist/index.js +1160 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -488,6 +488,104 @@ These errors are subclasses of `FoxnoseAPIError`:
|
|
|
488
488
|
|
|
489
489
|
A rejected request body is a `400` `FoxnoseAPIError`: `errorCode` is the code (`invalid_url`, `unknown_event_type`, `unknown_collection`, ...) and `detail` says what is wrong when there is something to say: `field`, and for example `unknown` or `reason`.
|
|
490
490
|
|
|
491
|
+
## Tenant Tokens
|
|
492
|
+
|
|
493
|
+
Your backend signs a short-lived token per end user; it reaches only that user's records and the shared collections its signing key allows. Make the key pair on your side and register the public key, so the private key never leaves your backend:
|
|
494
|
+
|
|
495
|
+
```typescript
|
|
496
|
+
import { ManagementClient, generateTenantSigningKey } from '@foxnose/sdk';
|
|
497
|
+
|
|
498
|
+
const pair = generateTenantSigningKey();
|
|
499
|
+
storeSecret(pair.privateKey); // base64 PKCS#8 DER; not enumerable, so JSON.stringify(pair) leaves it out
|
|
500
|
+
|
|
501
|
+
const key = await management.createTenantSigningKey({
|
|
502
|
+
parent_key: 'dw2qC5qRwxuZ', // the parent Flux API key
|
|
503
|
+
anchor_collections: ['a8Lq3vNm2xKp'], // owner collections (keys, not aliases)
|
|
504
|
+
apis: { support: ['read'] },
|
|
505
|
+
public_key: pair.publicKey,
|
|
506
|
+
});
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
`generate: true` has FoxNose generate the pair instead; the response carries `private_key` once.
|
|
510
|
+
|
|
511
|
+
Sign tokens and send them with the Flux client:
|
|
512
|
+
|
|
513
|
+
```typescript
|
|
514
|
+
import { FluxClient, TenantTokenAuth, signTenantToken } from '@foxnose/sdk';
|
|
515
|
+
|
|
516
|
+
const mint = () =>
|
|
517
|
+
signTenantToken(privateKey, {
|
|
518
|
+
kid: 'tsk_Q7m2xPz9aLwK',
|
|
519
|
+
environmentKey: '7c9h4pwu',
|
|
520
|
+
sub: 'user-4821', // your id for the end user
|
|
521
|
+
anchors: [['a8Lq3vNm2xKp', 'cust-4821']], // [collection key, record key]
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
const flux = new FluxClient({
|
|
525
|
+
baseUrl: 'https://7c9h4pwu.fxns.io',
|
|
526
|
+
apiPrefix: 'support',
|
|
527
|
+
auth: new TenantTokenAuth(mint),
|
|
528
|
+
});
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
`TenantTokenAuth` mints a new token 60 seconds before expiry, and when Flux answers `401` with `error="invalid_token"` it mints again and sends the request once more. One instance serves one end user: a token for another signing key, environment, `sub`, anchors or narrowing claims is refused. Do not let `mint` read the user from global or request-local state.
|
|
532
|
+
|
|
533
|
+
With the MCP TypeScript SDK, pass `tenantTokenFetch` as the transport's `fetch`:
|
|
534
|
+
|
|
535
|
+
```typescript
|
|
536
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
537
|
+
import { tenantTokenFetch } from '@foxnose/sdk';
|
|
538
|
+
|
|
539
|
+
const transport = new StreamableHTTPClientTransport(
|
|
540
|
+
new URL('https://7c9h4pwu.fxns.io/support/_mcp'),
|
|
541
|
+
{ fetch: tenantTokenFetch(mint) },
|
|
542
|
+
);
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
`mint` may be async here. Flux keeps an MCP session across new tokens with the same scope.
|
|
546
|
+
|
|
547
|
+
| Call | What it does |
|
|
548
|
+
|---|---|
|
|
549
|
+
| `listTenantSigningKeys` / `createTenantSigningKey` / `getTenantSigningKey` | Signing keys of the environment, revoked ones included |
|
|
550
|
+
| `updateTenantSigningKey` | Label, per-key limits, or the `not_before` cutoff (`'now'`) |
|
|
551
|
+
| `deleteTenantSigningKey` | Revoke the key |
|
|
552
|
+
| `addTenantTokenRevocation` | Refuse one token (`jti`) or one end user's tokens (`sub`) |
|
|
553
|
+
| `getTenantLimits` / `updateTenantLimits` | Per-user and per-owner rate limits |
|
|
554
|
+
|
|
555
|
+
## Guardrails
|
|
556
|
+
|
|
557
|
+
```typescript
|
|
558
|
+
import { getUntrustedFields } from '@foxnose/sdk';
|
|
559
|
+
|
|
560
|
+
await management.updateGuardrailsPolicy('tickets', {
|
|
561
|
+
mode: 'screened',
|
|
562
|
+
overrides: { prompt_attack: 'block' },
|
|
563
|
+
});
|
|
564
|
+
const held = await management.listHeldRevisions('tickets', { status: 'needs_review' });
|
|
565
|
+
await management.releaseHeldRevision('tickets', held.results[0].resource_key, held.results[0].revision_key);
|
|
566
|
+
await management.markResourceReviewed('tickets', 'refund-4821');
|
|
567
|
+
|
|
568
|
+
// On Flux reads: the fields written by end users or agents.
|
|
569
|
+
const record = await flux.getResource('tickets', 'refund-4821');
|
|
570
|
+
const untrusted = getUntrustedFields(record); // e.g. ['body']
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
`getRecordTrust(record)` reads `_sys.trust` (present when the collection's guardrails mode is `provenance` or `screened` and the Flux API's `trust_delivery` is `metadata`); `getFileTrust(record)` reads a files record's `data.trust`; a record counts as a files record when `data` holds a file block (`file` with `processing`, an object under the collection's own key with `uuid`, `processing` and `tainted_paths`, or an object with `processing` whose `uuid` is `data.trust.upload`) or a `trust` object with source `end_user_upload`. `upload` is the file block's `uuid` and `processing` is `agent_ready` exactly when the block's is (a files record without its file block is malformed), a region's `boxes` are `[x0, y0, x1, y1]` fractions of the page, and a flag's `scope` is `line`, `page` or `region`. `_sys.trust` carries `verdict` and `reasons` together or neither, and lists no paths when its `provenance` is `unknown`. A record without trust metadata says nothing about trust. Trust metadata that is present but malformed, or missing a field the server always sends, throws `MalformedTrustMetadataError`: treat that record as untrusted. Pass untrusted fields to a model as data, never as instructions.
|
|
574
|
+
|
|
575
|
+
A write can declare untrusted fields: `flux.createResource('tickets', data, { provenance: { untrusted_fields: ['body'], source: 'support-inbox' } })`.
|
|
576
|
+
|
|
577
|
+
| Call | What it does |
|
|
578
|
+
|---|---|
|
|
579
|
+
| `getGuardrailsPolicy` / `updateGuardrailsPolicy` | The collection's policy; only set fields are sent, unknown fields throw |
|
|
580
|
+
| `listHeldRevisions` | Retained held revisions, by `status` |
|
|
581
|
+
| `releaseHeldRevision` / `rejectHeldRevision` | Decide on one held revision |
|
|
582
|
+
| `rejectHeldRevisions` / `rescreenHeldRevisions` | Up to 50 at once; each item reports its own outcome |
|
|
583
|
+
| `getGuardrailsUsage` | Review backlog and this hour's screening budget |
|
|
584
|
+
| `listGuardrailsReviewQueue` | Everything waiting for a person in the environment |
|
|
585
|
+
| `getRevisionGuardrails` | The team view of a revision |
|
|
586
|
+
| `markResourceReviewed` | Vouch for a record's published content |
|
|
587
|
+
| `getGuardrailsCatalog` | The wording of findings, states and writers |
|
|
588
|
+
|
|
491
589
|
## Authentication
|
|
492
590
|
|
|
493
591
|
The SDK supports four authentication strategies:
|