Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
api-ref-bundler
Advanced tools
Bundle all external $ref in Json based API document into single document
This package provides utils to resolve all external/internal references in Json based API document and bundle/dereference into single document
npm install api-ref-bundler --save
import { promises as fs } from 'fs'
import { bundle, dereference } from 'api-ref-bundler'
const resolver = async (sourcePath) => {
const data = await fs.readFile(path.join(__dirname, "./", sourcePath), "utf8")
return sourcePath.slice(-3) === ".md" ? data : JSON.parse(data)
}
// bundle (convert all external refs to internal)
bundle("schema.json", resolver, { ignoreSibling: true }).then(schema => {
console.log(schema)
}).catch(errors => {
console.log(errors)
})
const onErrorHook = (msg: string) => {
throw new Error(msg)
}
// full dereference (remove all refs)
dereference("schema.json", resolver, { hooks: { onError: onErrorHook }}).then(schema => {
console.log(schema)
}).catch(errors => {
console.log(errors)
})
// partial dereference (remove all refs in path '/properties/foo')
dereference("schema.json#/properties/foo", resolver).then(foo => {
console.log(foo)
}).catch(errors => {
console.log(errors)
})
interface BundleOptions {
ignoreSibling?: boolean // ignore $ref sibling content
hooks?: {
onError?: (message: string, ctx: BundleContext) => void // error hook
onRef?: (ref: string, ctx: BundleContext) => void // ref hook
onCrawl?: (value: any, ctx: BundleContext) => void // node crawl hook
onExit?: (value: any, ctx: BundleContext) => void // node crawl exit hook
}
}
interface DereferenceOptions {
ignoreSibling?: boolean // ignore $ref sibling content
fullCrawl?: boolean // crawl all nodes includin cached
enableCircular?: boolean // convert circular $refs to nodes
hooks?: {
onError?: (message: string, ctx: DereferenceContext) => void // error hook
onRef?: (ref: string, ctx: DereferenceContext) => void // ref hook
onCrawl?: (value: any, ctx: DereferenceContext) => void // node crawl hook
onExit?: (value: any, ctx: DereferenceContext) => void // node crawl exit hook
onCycle?: (ref: string, ctx: DereferenceContext) => void // cycle refs hook
}
}
A browser version of api-ref-bundler
is also available via CDN:
<script src="https://cdn.jsdelivr.net/npm/api-ref-bundler@latest/browser/api-ref-bundler.es.js"></script>
<script src="https://cdn.jsdelivr.net/npm/api-ref-bundler@latest/browser/api-ref-bundler.umd.js"></script>
Reference api-ref-bundler.min.js
in your HTML and use the global variable ApiRefBundler
.
<script>
const resolver = async (sourcePath) => {
const data = await fetch(sourcePath)
return sourcePath.slice(-3) === ".md" ? data.text() : data.json()
}
ApiRefBundler.bundle("http://example.com/schema", resolver).then(schema => {
console.log(schema)
}).catch(errors => {
console.log(errors)
})
</script>
When contributing, keep in mind that it is an objective of api-ref-bundler
to have no package dependencies. This may change in the future, but for now, no-dependencies.
Please run the unit tests before submitting your PR: npm test
. Hopefully your PR includes additional unit tests to illustrate your change/modification!
MIT
FAQs
Bundle all external $ref in Json based API document into single document
We found that api-ref-bundler demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.