@eik/node-client
Advanced tools
Comparing version 1.0.0-next.6 to 1.0.0
161
CHANGELOG.md
@@ -0,4 +1,165 @@ | ||
# 1.0.0 (2021-11-02) | ||
* Next (#13) ([c7b2470](https://github.com/eik-lib/node-client/commit/c7b2470525b6def7ae4d506e2ba42ddef321e8c3)), closes [#13](https://github.com/eik-lib/node-client/issues/13) | ||
### BREAKING CHANGES | ||
* API is reworked to suite the current functionality of Eik | ||
* test: lint love | ||
* ci: fix ci tests | ||
* ci: Treat release config as a common.js file | ||
* chore(release): 1.0.0-next.1 [skip ci] | ||
# 1.0.0-next.1 (2021-03-10) | ||
### Features | ||
* Rework module to suite current functionality of Eik ([559294c](https://github.com/eik-lib/node-client/commit/559294cc8d1bd793873ba02000da6376312e0160)) | ||
### BREAKING CHANGES | ||
* API is reworked to suite the current functionality of Eik | ||
* chore: Rename module to @eik/node-client | ||
* Rename module to @eik/node-client | ||
* chore(release): 1.0.0-next.2 [skip ci] | ||
# [1.0.0-next.2](https://github.com/eik-lib/node-client/compare/v1.0.0-next.1...v1.0.0-next.2) (2021-03-10) | ||
### chore | ||
* Rename module to @eik/node-client ([f3d8c73](https://github.com/eik-lib/node-client/commit/f3d8c7325b90b345a79df731544f53ebb11c81bf)) | ||
### BREAKING CHANGES | ||
* Rename module to @eik/node-client | ||
* chore: Clean up the package structure | ||
* fix: Add CommonJS support | ||
* chore: Lint love | ||
* ci: Fix repo URL | ||
* chore(release): 1.0.0-next.3 [skip ci] | ||
# [1.0.0-next.3](https://github.com/eik-lib/node-client/compare/v1.0.0-next.2...v1.0.0-next.3) (2021-03-11) | ||
### Bug Fixes | ||
* Add CommonJS support ([b634537](https://github.com/eik-lib/node-client/commit/b6345378236d1bf60dc1ff6ceee1a285ca335e7f)) | ||
* docs: Document module | ||
* chore: lint love | ||
* Update README.md | ||
Co-authored-by: Richard Walker <digitalsadhu@gmail.com> | ||
* Update README.md | ||
Co-authored-by: Richard Walker <digitalsadhu@gmail.com> | ||
* Update README.md | ||
Co-authored-by: Richard Walker <digitalsadhu@gmail.com> | ||
* Update README.md | ||
Co-authored-by: Richard Walker <digitalsadhu@gmail.com> | ||
* Update README.md | ||
Co-authored-by: Richard Walker <digitalsadhu@gmail.com> | ||
* Update README.md | ||
Co-authored-by: Richard Walker <digitalsadhu@gmail.com> | ||
* Update README.md | ||
Co-authored-by: Richard Walker <digitalsadhu@gmail.com> | ||
* Update README.md | ||
Co-authored-by: Richard Walker <digitalsadhu@gmail.com> | ||
* Update README.md | ||
Co-authored-by: Richard Walker <digitalsadhu@gmail.com> | ||
* Update README.md | ||
Co-authored-by: Richard Walker <digitalsadhu@gmail.com> | ||
* Update README.md | ||
Co-authored-by: Richard Walker <digitalsadhu@gmail.com> | ||
* feat: Make .file() return an object | ||
* chore: Lint love | ||
* test: Add tests and documentation | ||
* doc: Fix example | ||
* chore(release): 1.0.0-next.4 [skip ci] | ||
# [1.0.0-next.4](https://github.com/eik-lib/node-client/compare/v1.0.0-next.3...v1.0.0-next.4) (2021-03-19) | ||
### Features | ||
* Make .file() return an object ([f53f15d](https://github.com/eik-lib/node-client/commit/f53f15dae288fda4b4527a3b4c69bab2e56f5169)) | ||
* fix: Do not use getters and setters on public data object | ||
* chore(release): 1.0.0-next.5 [skip ci] | ||
# [1.0.0-next.5](https://github.com/eik-lib/node-client/compare/v1.0.0-next.4...v1.0.0-next.5) (2021-03-23) | ||
### Bug Fixes | ||
* Do not use getters and setters on public data object ([0505dcb](https://github.com/eik-lib/node-client/commit/0505dcb25b2563b826d5806fc30a7d148c111c00)) | ||
* doc: Fixed spelling error | ||
* fix: Make default value of integrity to be undefined | ||
* chore(release): 1.0.0-next.6 [skip ci] | ||
# [1.0.0-next.6](https://github.com/eik-lib/node-client/compare/v1.0.0-next.5...v1.0.0-next.6) (2021-04-09) | ||
### Bug Fixes | ||
* Make default value of integrity to be undefined ([a679f73](https://github.com/eik-lib/node-client/commit/a679f733351413e5e59cbd0f71c86fef8a08042c)) | ||
* chore: Use private properties | ||
* test: run tests on node.js 16 instead of 15 | ||
* chore: Add tests | ||
* chore: lint love | ||
* doc: Update documentation | ||
* chore(deps): Updated dependencies | ||
Co-authored-by: Trygve Lie <trygve.lie@finn.no> | ||
Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net> | ||
Co-authored-by: Richard Walker <digitalsadhu@gmail.com> | ||
# [1.0.0-next.6](https://github.com/eik-lib/node-client/compare/v1.0.0-next.5...v1.0.0-next.6) (2021-04-09) | ||
### Bug Fixes | ||
@@ -5,0 +166,0 @@ |
{ | ||
"name": "@eik/node-client", | ||
"version": "1.0.0-next.6", | ||
"version": "1.0.0", | ||
"description": "A node.js client for interacting with a Eik server.", | ||
@@ -19,3 +19,3 @@ "type": "module", | ||
"scripts": { | ||
"test": "tap test/*.js --no-coverage", | ||
"test": "tap --no-coverage", | ||
"lint:fix": "eslint --fix .", | ||
@@ -41,24 +41,20 @@ "lint": "eslint .", | ||
"dependencies": { | ||
"@eik/common": "4.0.0-next.4", | ||
"@eik/common": "3.0.0", | ||
"abslog": "2.4.0", | ||
"node-fetch": "2.6.1" | ||
"undici": "4.9.3" | ||
}, | ||
"devDependencies": { | ||
"@semantic-release/changelog": "5.0.1", | ||
"@semantic-release/commit-analyzer": "8.0.1", | ||
"@semantic-release/git": "9.0.0", | ||
"@semantic-release/github": "7.2.0", | ||
"@semantic-release/npm": "7.0.10", | ||
"@semantic-release/release-notes-generator": "9.0.2", | ||
"@semantic-release/changelog": "6.0.1", | ||
"@semantic-release/git": "10.0.1", | ||
"babel-eslint": "10.1.0", | ||
"eslint": "7.21.0", | ||
"eslint": "7.32.0", | ||
"eslint-config-airbnb-base": "14.2.1", | ||
"eslint-config-prettier": "8.1.0", | ||
"eslint-plugin-import": "2.22.1", | ||
"eslint-plugin-prettier": "3.3.1", | ||
"prettier": "2.2.1", | ||
"rollup": "2.40.0", | ||
"semantic-release": "17.4.1", | ||
"tap": "15.0.2" | ||
"eslint-config-prettier": "8.3.0", | ||
"eslint-plugin-import": "2.25.2", | ||
"eslint-plugin-prettier": "4.0.0", | ||
"prettier": "2.4.1", | ||
"rollup": "2.59.0", | ||
"semantic-release": "18.0.0", | ||
"tap": "15.0.10" | ||
} | ||
} |
@@ -21,8 +21,5 @@ # @eik/node-client | ||
await client.load({ | ||
maps: true, | ||
}); | ||
await client.load(); | ||
client.file('/a-script-file.js') | ||
client.maps() | ||
const scriptPath = client.file('/a-script-file.js'); | ||
``` | ||
@@ -86,7 +83,8 @@ | ||
| option | default | type | required | details | | ||
| ----------- | --------------- | --------- | -------- | ----------------------------------------------------------------------------- | | ||
| option | default | type | required | details | | ||
| ----------- | --------------- | --------- | -------- | ------------------------------------------------------------------------------ | | ||
| path | `process.cwd()` | `string` | `false` | Path to directory containing an eik.json file or package.json with eik config. | | ||
| base | `null` | `string` | `false` | Base root to be used for returned asset files. | | ||
| development | `false` | `boolean` | `false` | Set the module in development mode or not. | | ||
| base | `null` | `string` | `false` | Base root to be used for returned asset files. | | ||
| development | `false` | `boolean` | `false` | Set the module in development mode or not. | | ||
| loadMaps | `false` | `boolean` | `false` | Specifies whether import maps defined in the config should be loaded from the Eik server or not. | | ||
@@ -105,2 +103,6 @@ #### path | ||
#### loadMaps | ||
Whether import maps defined in the config should be loaded from the Eik server or not. The import maps is loaded by calling the `.load()` method and loaded the maps can be retrieved with the `.maps()` method. The import maps will be cached in the module. | ||
## API | ||
@@ -110,15 +112,8 @@ | ||
### async .load(options) | ||
### async .load() | ||
Loads Eik config into the module. If `maps` is set to `true` and import maps are present in config, these will also be loaded. Once loaded both the config and import maps will be cached in the module. | ||
Loads Eik config into the module. The config will be cached in the module. If `loadMaps` is set to `true` on the constructor, the import maps defined in the config will be loaded from the Eik server | ||
#### options | ||
### .file(file) | ||
| option | default | type | required | details | | ||
| ----------- | --------------- | ---------- | -------- | -------------------------------------------------------------------------------- | | ||
| maps | `false` | `boolean` | `false` | Specifies whether import maps defined in the config should be loaded from the Eik server or not. | | ||
### .files(file) | ||
Constructs a full URL to an asset. The URL is built up by appending the value of the `file` argument to a `base` root. By default (production mode) the `base` root is built up from values in Eik config matching where the package for the config are located on the Eik server. If the module is in development mode, the value set for `base` on the constructor will be used as the `base` root. | ||
@@ -145,3 +140,3 @@ | ||
Returns the import maps defined in Eik config from the Eik server. For the maps to be returned they need to be loaded from the Eik server. This is done by setting the `maps` option on the `.load()` method to `true`. | ||
Returns the import maps defined in Eik config from the Eik server. For the maps to be returned they need to be loaded from the Eik server. This is done by setting the `loadMaps` option on the constructor to `true`. | ||
@@ -148,0 +143,0 @@ ## License |
import { helpers } from '@eik/common'; | ||
import { request } from 'undici'; | ||
import { join } from 'path'; | ||
import fetch from 'node-fetch'; | ||
import EikAsset from './asset.js'; | ||
import Asset from './asset.js'; | ||
@@ -9,13 +9,18 @@ const isUrl = (value = '') => value.startsWith('http'); | ||
const fetchImportMaps = async (urls = []) => { | ||
try { | ||
const maps = urls.map((map) => fetch(map).then((result) => { | ||
if (result.status === 404) { | ||
try{ | ||
const maps = urls.map(async (map) => { | ||
const { | ||
statusCode, | ||
body | ||
} = await request(map, { maxRedirections: 2 }); | ||
if (statusCode === 404) { | ||
throw new Error('Import map could not be found on server'); | ||
} else if (result.status >= 400 && result.status < 500) { | ||
} else if (statusCode >= 400 && statusCode < 500) { | ||
throw new Error('Server rejected client request'); | ||
} else if (result.status >= 500) { | ||
} else if (statusCode >= 500) { | ||
throw new Error('Server error'); | ||
} | ||
return result.json(); | ||
})); | ||
return body.json(); | ||
}); | ||
return await Promise.all(maps); | ||
@@ -27,23 +32,29 @@ } catch (err) { | ||
} | ||
}; | ||
} | ||
export default class EikNodeClient { | ||
export default class NodeClient { | ||
#development; | ||
#loadMaps; | ||
#config; | ||
#path; | ||
#base; | ||
#maps; | ||
constructor({ | ||
development = false, | ||
loadMaps = false, | ||
base = '', | ||
path = process.cwd(), | ||
} = {}) { | ||
this.pDevelopment = development; | ||
this.pConfig = {}; | ||
this.pPath = path; | ||
this.pBase = base; | ||
this.pMaps = []; | ||
this.#development = development; | ||
this.#loadMaps = loadMaps; | ||
this.#config = {}; | ||
this.#path = path; | ||
this.#base = base; | ||
this.#maps = []; | ||
} | ||
async load({ | ||
maps = false, | ||
} = {}) { | ||
this.pConfig = await helpers.getDefaults(this.pPath); | ||
if (maps) { | ||
this.pMaps = await fetchImportMaps(this.pConfig.map); | ||
async load() { | ||
this.#config = await helpers.getDefaults(this.#path); | ||
if (this.#loadMaps) { | ||
this.#maps = await fetchImportMaps(this.#config.map); | ||
} | ||
@@ -53,35 +64,36 @@ } | ||
get name() { | ||
if (this.pConfig.name) return this.pConfig.name; | ||
return ''; | ||
if (this.#config.name) return this.#config.name; | ||
throw new Error('Eik config was not loaded before calling .name'); | ||
} | ||
get version() { | ||
if (this.pConfig.version) return this.pConfig.version; | ||
return ''; | ||
if (this.#config.version) return this.#config.version; | ||
throw new Error('Eik config was not loaded before calling .version'); | ||
} | ||
get type() { | ||
if (this.pConfig.type && this.pConfig.type === 'package') return 'pkg'; | ||
if (this.pConfig.type) return this.pConfig.type; | ||
return ''; | ||
if (this.#config.type && this.#config.type === 'package') return 'pkg'; | ||
if (this.#config.type) return this.#config.type; | ||
throw new Error('Eik config was not loaded before calling .type'); | ||
} | ||
get server() { | ||
if (this.pConfig.server) return this.pConfig.server; | ||
return ''; | ||
if (this.#config.server) return this.#config.server; | ||
throw new Error('Eik config was not loaded before calling .server'); | ||
} | ||
get pathname() { | ||
return join('/', this.type, this.name, this.version); | ||
if (this.#config.type && this.#config.name && this.#config.version) return join('/', this.type, this.name, this.version); | ||
throw new Error('Eik config was not loaded before calling .pathname'); | ||
} | ||
file(file = '') { | ||
const asset = new EikAsset(); | ||
const asset = new Asset(); | ||
if (this.pDevelopment) { | ||
if (isUrl(this.pBase)) { | ||
const base = new URL(this.pBase); | ||
if (this.#development) { | ||
if (isUrl(this.#base)) { | ||
const base = new URL(this.#base); | ||
asset.value = new URL(join(base.pathname, file), base).href; | ||
} else { | ||
asset.value = join(this.pBase, file); | ||
asset.value = join(this.#base, file); | ||
} | ||
@@ -96,4 +108,5 @@ } else { | ||
maps() { | ||
return this.pMaps; | ||
if (this.#config.version && this.#loadMaps) return this.#maps; | ||
throw new Error('Eik config was not loaded or "loadMaps" is "false" when calling .maps()'); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
21506
12
205
0
0
159
+ Addedundici@4.9.3
+ Added@eik/common@3.0.0(transitive)
+ Addedajv@8.17.1(transitive)
+ Addedajv-formats@2.1.1(transitive)
+ Addedfast-uri@3.0.3(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedundici@4.9.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removednode-fetch@2.6.1
- Removed@eik/common@4.0.0-next.4(transitive)
- Removedajv@7.2.4(transitive)
- Removedajv-formats@1.6.1(transitive)
- Removednode-fetch@2.6.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removeduri-js@4.4.1(transitive)
Updated@eik/common@3.0.0