@amritk/resolve-refs 0.4.3 → 0.4.4
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/AI.md +45 -0
- package/dist/resolve-refs.d.ts +8 -0
- package/package.json +3 -2
package/AI.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @amritk/resolve-refs — notes for AI coding agents
|
|
2
|
+
|
|
3
|
+
Resolve and inline JSON Schema / OpenAPI `$ref`s (internal, cross-file, remote)
|
|
4
|
+
into a single dereferenced document, with session caching and a default-deny
|
|
5
|
+
SSRF guard. Full reference is [README.md](./README.md).
|
|
6
|
+
|
|
7
|
+
> Pre-alpha: APIs change in **minor** versions.
|
|
8
|
+
|
|
9
|
+
## Minimal example
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { resolveRefs, resolveRefsFromFile } from '@amritk/resolve-refs'
|
|
13
|
+
|
|
14
|
+
// In-memory, INTERNAL refs only:
|
|
15
|
+
const { resolved, errors } = resolveRefs(myDocument)
|
|
16
|
+
|
|
17
|
+
// From disk (cross-file + remote):
|
|
18
|
+
const result = await resolveRefsFromFile('./schema.json')
|
|
19
|
+
|
|
20
|
+
// Remote requires host allow-listing:
|
|
21
|
+
const remote = await resolveRefsFromFile('https://api.example.com/schema.json', {
|
|
22
|
+
allowedHosts: ['api.example.com'],
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Gotchas — where agents fail
|
|
27
|
+
|
|
28
|
+
1. **`resolveRefs` is in-memory only.** It does NOT load other files/URLs —
|
|
29
|
+
external refs stay in place and are pushed to `errors` (the ref becomes `{}`).
|
|
30
|
+
Use `resolveRefsFromFile` for cross-file/remote.
|
|
31
|
+
2. **Errors are collected, never thrown.** A missing file, refused host, or bad
|
|
32
|
+
URL lands on `result.errors` while the rest still resolves. Always check it.
|
|
33
|
+
3. **Default-deny SSRF guard.** Remote refs to loopback / private / link-local /
|
|
34
|
+
`169.254.169.254` are refused unless `allowPrivateHosts: true` or an explicit
|
|
35
|
+
`allowedHosts` entry.
|
|
36
|
+
4. **JSON-only by default** (`JSON.parse`). For YAML pass a custom
|
|
37
|
+
`parse: (content, location) => …` (e.g. wrapping `@amritk/yaml`).
|
|
38
|
+
5. **`origins` exists only with `trackOrigins: true`.** Cycles are preserved (the
|
|
39
|
+
cycle point stays a `$ref`), so output is not always fully flat. The remote
|
|
40
|
+
cache is process-wide — `clearRemoteCache()` or `cache: false` when a schema
|
|
41
|
+
may have changed.
|
|
42
|
+
|
|
43
|
+
Exports: `resolveRefs`, `resolveRefsFromFile`, `clearRemoteCache`,
|
|
44
|
+
`getByPointer`, `pointerToPath`, `isPrivateHost` + types. Only the `.` entry.
|
|
45
|
+
Install: `bun add @amritk/resolve-refs`.
|
package/dist/resolve-refs.d.ts
CHANGED
|
@@ -17,5 +17,13 @@ export type ResolveRefsOptions = {
|
|
|
17
17
|
* can't load other documents — use `resolveRefsFromFile` for those). Cycles are
|
|
18
18
|
* broken by keeping the original reference node, so recursive schemas keep
|
|
19
19
|
* their recursive branch.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const { resolved, errors } = resolveRefs(document)
|
|
24
|
+
* // Errors are COLLECTED, never thrown — always check `errors`.
|
|
25
|
+
* // External ($ref to another file/URL) refs stay in place; use
|
|
26
|
+
* // resolveRefsFromFile('./schema.json', { allowedHosts: [...] }) for those.
|
|
27
|
+
* ```
|
|
20
28
|
*/
|
|
21
29
|
export declare const resolveRefs: (data: unknown, options?: ResolveRefsOptions) => ResolveResult;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/resolve-refs",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Resolve and inline JSON Schema / OpenAPI $refs — internal, cross-file, and remote — with session caching and a default-deny SSRF guard.",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"url": "https://github.com/amritk/mjst/issues"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
|
-
"dist"
|
|
29
|
+
"dist",
|
|
30
|
+
"AI.md"
|
|
30
31
|
],
|
|
31
32
|
"publishConfig": {
|
|
32
33
|
"access": "public"
|