@scalar/asyncapi-to-markdown 0.2.5 → 0.2.7
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/CHANGELOG.md +9 -0
- package/README.md +17 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/load-document.d.ts +3 -1
- package/dist/load-document.d.ts.map +1 -1
- package/dist/load-document.js +7 -24
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @scalar/asyncapi-to-markdown
|
|
2
2
|
|
|
3
|
+
## 0.2.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#10904](https://github.com/scalar/scalar/pull/10904): Block private-network document requests by default and require an explicit basePath for local files. Apply the same permissions to external references, with an opt-in for trusted private-network inputs.
|
|
8
|
+
- [#10904](https://github.com/scalar/scalar/pull/10904): Share confined document loading between Markdown converters and include HTTP status codes in load errors.
|
|
9
|
+
|
|
10
|
+
## 0.2.6
|
|
11
|
+
|
|
3
12
|
## 0.2.5
|
|
4
13
|
|
|
5
14
|
## 0.2.4
|
package/README.md
CHANGED
|
@@ -12,10 +12,14 @@ import {
|
|
|
12
12
|
createMarkdownFromAsyncApi,
|
|
13
13
|
} from '@scalar/asyncapi-to-markdown'
|
|
14
14
|
|
|
15
|
-
const markdown = await createMarkdownFromAsyncApi('./asyncapi.yaml'
|
|
15
|
+
const markdown = await createMarkdownFromAsyncApi('./asyncapi.yaml', {
|
|
16
|
+
documentLoading: { basePath: process.cwd() },
|
|
17
|
+
})
|
|
16
18
|
|
|
17
19
|
// Load, upgrade and bundle references once for a documentation build.
|
|
18
|
-
const renderer = await createAsyncApiMarkdownRenderer('./asyncapi.yaml'
|
|
20
|
+
const renderer = await createAsyncApiMarkdownRenderer('./asyncapi.yaml', {
|
|
21
|
+
basePath: process.cwd(),
|
|
22
|
+
})
|
|
19
23
|
await renderer.render() // Complete description
|
|
20
24
|
await renderer.render({ introduction: true })
|
|
21
25
|
await renderer.render({ channel: 'orders' })
|
|
@@ -35,6 +39,17 @@ inputs use Scalar's upgrader to produce a 3.1 document. The original version sta
|
|
|
35
39
|
in the introduction. Input objects are not modified. Create a new renderer to pick up
|
|
36
40
|
source changes; rendering pages does not fetch the source again.
|
|
37
41
|
|
|
42
|
+
Private-network requests are blocked by default for both the source URL and external
|
|
43
|
+
references. Local file access is disabled unless `basePath` names an approved directory;
|
|
44
|
+
source files and references, including symlink targets, must remain inside it. Prefer the
|
|
45
|
+
smallest directory containing the files you intend to expose.
|
|
46
|
+
|
|
47
|
+
For trusted private-network descriptions, pass `allowPrivateNetworks: true` to
|
|
48
|
+
`createAsyncApiMarkdownRenderer`, or use
|
|
49
|
+
`{ documentLoading: { allowPrivateNetworks: true } }` with `createMarkdownFromAsyncApi`.
|
|
50
|
+
Only enable this option for trusted input. Loading permissions apply to all nested
|
|
51
|
+
references and are separate from page-rendering options.
|
|
52
|
+
|
|
38
53
|
Choose at most one selector per call. Strings identify exact, case-sensitive map keys:
|
|
39
54
|
channels, operations, component messages, or component schemas. Channel addresses and
|
|
40
55
|
human-readable titles are not selectors. Every map selector also accepts an exact JSON
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { type DocumentLoadOptions } from './load-document.js';
|
|
1
2
|
import type { AsyncApiInput, AsyncApiMarkdownRenderer, AsyncApiRenderOptions } from './types.js';
|
|
3
|
+
export type { DocumentLoadOptions } from './load-document.js';
|
|
2
4
|
export type { AsyncApiInput, AsyncApiMarkdownRenderer, AsyncApiRenderOptions, AsyncApiSelector } from './types.js';
|
|
3
5
|
/** Prepare an immutable document snapshot once for a complete export or multiple pages. */
|
|
4
|
-
export declare const createAsyncApiMarkdownRenderer: (input: AsyncApiInput) => Promise<AsyncApiMarkdownRenderer>;
|
|
6
|
+
export declare const createAsyncApiMarkdownRenderer: (input: AsyncApiInput, options?: DocumentLoadOptions) => Promise<AsyncApiMarkdownRenderer>;
|
|
5
7
|
/** Generate LLM-friendly Markdown from an AsyncAPI description or one of its reference pages. */
|
|
6
|
-
export declare const createMarkdownFromAsyncApi: (input: AsyncApiInput, options?: AsyncApiRenderOptions
|
|
8
|
+
export declare const createMarkdownFromAsyncApi: (input: AsyncApiInput, options?: AsyncApiRenderOptions & {
|
|
9
|
+
documentLoading?: DocumentLoadOptions;
|
|
10
|
+
}) => Promise<string>;
|
|
7
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAgB,MAAM,iBAAiB,CAAA;AAExE,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAE7F,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,YAAY,EAAE,aAAa,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/G,2FAA2F;AAC3F,eAAO,MAAM,8BAA8B,GACzC,OAAO,aAAa,EACpB,UAAU,mBAAmB,KAC5B,OAAO,CAAC,wBAAwB,CAAuD,CAAA;AAE1F,iGAAiG;AACjG,eAAO,MAAM,0BAA0B,GACrC,OAAO,aAAa,EACpB,UAAU,qBAAqB,GAAG;IAAE,eAAe,CAAC,EAAE,mBAAmB,CAAA;CAAE,KAC1E,OAAO,CAAC,MAAM,CAIhB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { loadDocument } from './load-document.js';
|
|
2
2
|
import { createRenderer } from './render-document.js';
|
|
3
3
|
/** Prepare an immutable document snapshot once for a complete export or multiple pages. */
|
|
4
|
-
export const createAsyncApiMarkdownRenderer = async (input) => createRenderer(await loadDocument(input));
|
|
4
|
+
export const createAsyncApiMarkdownRenderer = async (input, options) => createRenderer(await loadDocument(input, options));
|
|
5
5
|
/** Generate LLM-friendly Markdown from an AsyncAPI description or one of its reference pages. */
|
|
6
|
-
export const createMarkdownFromAsyncApi = async (input, options) =>
|
|
6
|
+
export const createMarkdownFromAsyncApi = async (input, options) => {
|
|
7
|
+
const { documentLoading, ...renderOptions } = options ?? {};
|
|
8
|
+
const renderer = await createAsyncApiMarkdownRenderer(input, documentLoading);
|
|
9
|
+
return renderer.render(renderOptions);
|
|
10
|
+
};
|
package/dist/load-document.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { type DocumentLoadOptions } from '@scalar/json-magic/bundle/plugins/node';
|
|
1
2
|
import type { AsyncApiInput } from './types.js';
|
|
3
|
+
export type { DocumentLoadOptions } from '@scalar/json-magic/bundle/plugins/node';
|
|
2
4
|
/** Load once, preserving the source location for relative external references. */
|
|
3
|
-
export declare const loadDocument: (input: AsyncApiInput) => Promise<Record<string, unknown>>;
|
|
5
|
+
export declare const loadDocument: (input: AsyncApiInput, options?: DocumentLoadOptions) => Promise<Record<string, unknown>>;
|
|
4
6
|
//# sourceMappingURL=load-document.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-document.d.ts","sourceRoot":"","sources":["../src/load-document.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"load-document.d.ts","sourceRoot":"","sources":["../src/load-document.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,mBAAmB,EAAwB,MAAM,wCAAwC,CAAA;AAMvG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,YAAY,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAEjF,kFAAkF;AAClF,eAAO,MAAM,YAAY,GACvB,OAAO,aAAa,EACpB,UAAS,mBAAwB,KAChC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA4CjC,CAAA"}
|
package/dist/load-document.js
CHANGED
|
@@ -1,34 +1,17 @@
|
|
|
1
1
|
import { upgrade } from '@scalar/asyncapi-upgrader';
|
|
2
2
|
import { isObject } from '@scalar/helpers/object/is-object';
|
|
3
3
|
import { bundle } from '@scalar/json-magic/bundle';
|
|
4
|
-
import {
|
|
5
|
-
import { normalize } from '@scalar/json-magic/helpers/normalize';
|
|
4
|
+
import { createDocumentLoader } from '@scalar/json-magic/bundle/plugins/node';
|
|
6
5
|
import { createMagicProxy, getRaw } from '@scalar/json-magic/magic-proxy';
|
|
7
6
|
import { deepClone } from '@scalar/workspace-store/helpers/deep-clone';
|
|
8
7
|
import { object } from './document.js';
|
|
9
8
|
import { preserveData } from './preserve-data.js';
|
|
10
9
|
/** Load once, preserving the source location for relative external references. */
|
|
11
|
-
export const loadDocument = async (input) => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
const parsed = normalize(input);
|
|
17
|
-
if (isObject(parsed)) {
|
|
18
|
-
return { value: parsed };
|
|
19
|
-
}
|
|
20
|
-
if (/^https?:\/\//i.test(input)) {
|
|
21
|
-
const response = await fetch(input);
|
|
22
|
-
if (!response.ok) {
|
|
23
|
-
throw new Error(`Failed to load AsyncAPI document (HTTP ${response.status})`);
|
|
24
|
-
}
|
|
25
|
-
return { value: normalize(await response.text()), origin: input };
|
|
26
|
-
}
|
|
27
|
-
const [{ resolve }, { readFile }] = await Promise.all([import('node:path'), import('node:fs/promises')]);
|
|
28
|
-
const origin = resolve(input);
|
|
29
|
-
return { value: normalize(await readFile(origin, 'utf8')), origin };
|
|
30
|
-
};
|
|
31
|
-
const { value, origin } = await source();
|
|
10
|
+
export const loadDocument = async (input, options = {}) => {
|
|
11
|
+
const loader = createDocumentLoader(options);
|
|
12
|
+
const { value, origin } = typeof input === 'string'
|
|
13
|
+
? await loader.load(input, 'AsyncAPI')
|
|
14
|
+
: { value: deepClone(getRaw(input)), origin: undefined };
|
|
32
15
|
if (!isObject(value) || typeof value.asyncapi !== 'string') {
|
|
33
16
|
throw new Error('Expected an AsyncAPI document with an asyncapi version');
|
|
34
17
|
}
|
|
@@ -39,7 +22,7 @@ export const loadDocument = async (input) => {
|
|
|
39
22
|
const errors = [];
|
|
40
23
|
const bundled = await bundle(value, {
|
|
41
24
|
origin,
|
|
42
|
-
plugins: [
|
|
25
|
+
plugins: [...loader.plugins, preserveData()],
|
|
43
26
|
treeShake: false,
|
|
44
27
|
hooks: { onResolveError: (node) => errors.push(`Failed to resolve ${node.$ref}`) },
|
|
45
28
|
});
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"markdown",
|
|
16
16
|
"llm"
|
|
17
17
|
],
|
|
18
|
-
"version": "0.2.
|
|
18
|
+
"version": "0.2.7",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=22"
|
|
21
21
|
},
|
|
@@ -39,18 +39,18 @@
|
|
|
39
39
|
"CHANGELOG.md"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@scalar/asyncapi-upgrader": "0.1.
|
|
43
|
-
"@scalar/helpers": "0.
|
|
44
|
-
"@scalar/json-magic": "0.
|
|
45
|
-
"@scalar/openapi-to-markdown": "1.7.
|
|
46
|
-
"@scalar/types": "0.
|
|
47
|
-
"@scalar/workspace-store": "0.
|
|
42
|
+
"@scalar/asyncapi-upgrader": "0.1.20",
|
|
43
|
+
"@scalar/helpers": "0.17.1",
|
|
44
|
+
"@scalar/json-magic": "0.19.0",
|
|
45
|
+
"@scalar/openapi-to-markdown": "1.7.5",
|
|
46
|
+
"@scalar/types": "0.28.0",
|
|
47
|
+
"@scalar/workspace-store": "0.71.0",
|
|
48
48
|
"remark-gfm": "^4.0.1",
|
|
49
49
|
"remark-stringify": "^11.0.0",
|
|
50
50
|
"unified": "^11.0.5"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@scalar/components": "0.
|
|
53
|
+
"@scalar/components": "0.34.0",
|
|
54
54
|
"@scalar/themes": "0.20.0",
|
|
55
55
|
"@tailwindcss/vite": "^4.3.3",
|
|
56
56
|
"@types/mdast": "^4.0.4",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"tailwindcss": "^4.3.3",
|
|
63
63
|
"tsx": "4.23.15",
|
|
64
64
|
"vite": "8.3.4",
|
|
65
|
-
"vitest": "
|
|
65
|
+
"vitest": "5.0.5",
|
|
66
66
|
"vue": "^3.5.44",
|
|
67
67
|
"vue-tsc": "3.3.11"
|
|
68
68
|
},
|