Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@eik/node-client
Advanced tools
The Eik Node.js client facilitates loading Eik config and providing URLs to assets on an Eik server or in local development plus loading import maps from the Eik server.
npm install @eik/node-client
import EikNodeClient from '@eik/node-client';
const client = new EikNodeClient({
development: false,
base: '/public'
});
await client.load();
const scriptPath = client.file('/a-script-file.js');
This module will load Eik config from either an eik.json
file or from values set in package.json
and then use these values to provide absolute URLs to assets on a Eik server. In addition to this it's possible to set a base
URL which will be used as the "base root" for files when this module is set in development mode. This makes it easy to retrieve absolute URLs to assets on a Eik server when an application is running in production but also get URLs to the same assets when in development.
In addition this module can also download the import maps defined in Eik config and provide these for inclusion in an application.
The following will use the information in Eik config and provide an absolute URL to a file on an Eik server:
import EikNodeClient from '@eik/node-client';
const client = new EikNodeClient({
development: false,
base: 'http://localhost:8080/public'
});
await client.load();
// Will, for example, output:
// {
// integrity: sha512-zHQjnDpMW7IKVyTpT9cOPT1+xhUSOcbgXj6qHCPSPu1CbQfgwDEsIniXU54zDIN71zqmxLSp3hfIljpt69ok0w==
// value: https://cdn.eik.dev/pkg/mymodue/2.4.1/path/script.js
// }
client.file('/path/script.js')
The following is the same as above but in development mode. The output will then be based on the vaule set for base
:
import EikNodeClient from '@eik/node-client';
const client = new EikNodeClient({
development: true,
base: 'http://localhost:8080/public'
});
await client.load();
// Will, for example, output:
// {
// integrity: null
// value: http://localhost:8080/public/path/script.js
// }
client.file('/path/script.js')
Create a new client instance.
const client = new EikNodeClient(options);
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. |
loadMaps | false | boolean | false | Specifies whether import maps defined in the config should be loaded from the Eik server or not. |
Path to directory containing a eik.json file or package.json with eik config.
Base root to be used for returned asset files. Can be either an absolute URL or relative URL. Will only be applied when the module is in development mode.
Set the module in development mode or not.
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.
This module has the following API
Loads Eik config from the Eik config into the object instance. If loadMaps
is set to true
on the constructor, the import maps defined in the config will be loaded from the Eik server.
Constructs a URL to the base of a package of assets. The returned value will differ depending on if development mode is set to true or not.
When in non development mode, the returned value will be built up by the values found in the loaded Eik config and provide a URL to where the files can be expected to be on the Eik server.
const client = new EikNodeClient({
development: false,
base: 'http://localhost:8080/assets'
});
await client.load();
client.base() // https://cdn.eik.dev/pkg/mymodue/2.4.1
When in development mode, the returned value will be equal to whats set on the base
argument on the constructor.
const client = new EikNodeClient({
development: true,
base: 'http://localhost:8080/assets'
});
await client.load();
client.base() // http://localhost:8080/assets
Constructs a full URL to an asset. The URL is built up by appending the value of the file
argument to a base
root. The returned value will differ depending on if development mode is set to true or not.
When in non development mode, the returned value will be built up by the values found in the loaded Eik config and provide a URL to where the files can be expected to be on the Eik server plus the provided value to the file
argument on the method.
const client = new EikNodeClient({
development: false,
base: 'http://localhost:8080/assets'
});
await client.load();
client.file('/js/script.js') // Returns an asset.value like: https://cdn.eik.dev/pkg/mymodue/2.4.1/js/script.js
When in development mode, the returned value will be equal to whats set on the base
argument on the constructor plus the provided value to the file
argument on the method.
const client = new EikNodeClient({
development: true,
base: 'http://localhost:8080/assets'
});
await client.load();
client.file('/js/script.js') // Returns an asset.value like: http://localhost:8080/assets/js/script.js
option | default | type | required | details |
---|---|---|---|---|
file | null | string | false | File to append to the base of a full URL to an asset |
Returns a object with as follow:
{
integrity: 'sha512-zHQjnDpMW7IKVyTpT9cOPT1+xhUSOcbgXj6qHCPSPu1CbQfgwDEsIniXU54zDIN71zqmxLSp3hfIljpt69ok0w==',
value: 'https://cdn.eik.dev/pkg/mymodue/2.4.1/path/script.js'
}
If integrity
of the file is not available, the value for integrity
will be null
. This will be the case when in development mode since integrity is calculated upon publish of a package to a Eik server.
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
.
Copyright (c) 2021 FINN.no
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Utilities for working with assets and import maps on an Eik server
The npm package @eik/node-client receives a total of 406 weekly downloads. As such, @eik/node-client popularity was classified as not popular.
We found that @eik/node-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.