
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@kano/api-client
Advanced tools
Provides a js API for browsers to communicate with our set of microservices.
import { AccountClient } from '@kano/api-client/index.js';
const account = new AccountClient({
// Where to find the API
url: 'https://my-api.stuff.me',
// Default headers will be sent with all requests. Has default for json
defaultHeaders: {
'X-Special': 'Value',
},
});
account.login('me', 'my-password').then(session => console.log(session));
You can share options across clients by giving another client to the contructor:
import { AccountClient, UserClient } from '@kano/api-client/index.js';
const account = new AccountClient({
// Where to find the API
url: 'https://my-api.stuff.me',
});
// Same options here
const user = new UserClient(account);
Implemented clients:
AccountClient
:
UserClient
:
More to come
You can add plugin to a client. A plugin is a set of methods called during the lifecycle of a request.
Example:
account.addPlugin({
// Will be called before fetch. The endpoint about to be called will be provided
// You can change any of its values. Adding a response property will cancel the call
// to fetch and return the response right away
beforeFetch(endpoint) {
// Hi-jack the login endpoint and return static content
// You can use this to provide offline features
if (endpoint.name === 'login') {
endpoint.response = {
data: {
user: {
id: 'Hello',
},
},
};
}
// Alwasy return a Promise
return Promise.resolve(endpoint);
},
onError(endpoint, error) {
if (error === 'fetch failed') {
/* Silently spoof cached response */
endpoint.response = ResponseCache.lookup(endponint),
return Promise.resolve(endpoint);
} else {
/* Log and rethrow */
console.log(error);
throw error;
}
},
// Will return raw data as received from the API before processing
// Use this to cache raw responses
afterDataReceived(endpoint, data) {
if (name === 'login') {
console.log(data);
}
return Promise.resolve(data);
},
// Will be called after the data was received but before it is resolved to the client user
// Use this to reformat the data, or for logging
afterDataProcessed(endpoint, data) {
if (name === 'login') {
console.log(data);
}
return Promise.resolve(data);
},
});
This is an npm package and published publicly on npm. To do this, change the version number in the package.json (eg: 2.0.3 => 2.0.4), run yarn
, then push and merge to master then run the following command from the root of the repo:
npm publish --access public
It will require you to have an account with npm and to be logged into npm in your terminal.
FAQs
Intercept calls between the server and the client try to minimise them
The npm package @kano/api-client receives a total of 6 weekly downloads. As such, @kano/api-client popularity was classified as not popular.
We found that @kano/api-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.