@wral/resource-deref
Version:
A Library for dereferencing $ref references in Javascript objects
64 lines (44 loc) • 1.21 kB
Markdown
# `@wral/resource-deref`
A Library for dereferencing $ref references in Javascript objects
## Installation
```bash
npm install @wral/resource-deref
```
## Usage
### `deref`
```js
import { deref } from '@wral/resource-deref';
deref({ $ref: 'https://example.com' }, {
}).then(console.log);
```
### `compile`
```js
import { compile } from '@wral/resource-deref';
const doDeref = compile({
trustedDomains: ['example.com'],
auth: {
headers: {
Authorization: 'Basic ABCDEFG',
},
},
});
doDeref({ $ref: 'https://example.com' }, {
headers: {
UserAgent: 'Your script name',
},
}).then(console.log);
```
## Options
- `trustedDomains` - array of domains to trust with credentials
- `auth` - object containing credentials (`headers`)
- `fetchOptions` - additional options to pass to `fetch`
### `trustedFetch`
A wrapper around `fetch` that trusts a list of domains for credentials.
```js
import { trustedFetch } from '@wral/resource-deref';
trustedDomains = {
'example.com': 'some-api-key',
};
trustedFetch(trustedDomains, 'https://example.com', {}).then(console.log);
```
Arguments: {object} trustedDomains, {string} url, {object} fetchOptions