Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@clevercloud/client
Advanced tools
This project contains a REST client for Clever Cloud's API and some utils.
First, you need to install the node module:
npm install @clevercloud/client
All API REST paths are accessible as "functions" organized in "services". A call to a function of a service will just prepare the HTTP request and return the request params in an object via a promise. It won't authenticate the request and it won't send it.
You will need to chain some helpers to the function call to:
Those helpers are ready to use for browsers or node and for oAuth v1 signature auth. The recommanded way is to wrap those helpers in one place of your app and to reuse it everywhere you need to send API calls.
Here's a example for a browser based project using ECMAScript modules with oAuth v1 signature and using the fetch
API to send requests.
In a file, expose this function:
import { addOauthHeader } from '@clevercloud/client/esm/oauth.browser.js';
import { prefixUrl } from '@clevercloud/client/esm/prefix-url.js';
import { request } from '@clevercloud/client/esm/request.fetch.js';
export function sendToApi (requestParams) {
// load and cache config and tokens
const API_HOST = 'https://api.clever-cloud.com/v2'
const tokens = {
OAUTH_CONSUMER_KEY: 'your OAUTH_CONSUMER_KEY',
OAUTH_CONSUMER_SECRET: 'your OAUTH_CONSUMER_SECRET',
API_OAUTH_TOKEN: 'your API_OAUTH_TOKEN',
API_OAUTH_TOKEN_SECRET: 'your API_OAUTH_TOKEN_SECRET',
}
return Promise.resolve(requestParams)
.then(prefixUrl(API_HOST))
.then(addOauthHeader(tokens))
.then(request);
// chain a .catch() call here if you need to handle some errors or maybe redirect to login
}
NOTE: If your project relies on a specific REST library (axios, jQuery...), you'll have to write your own request function to plug the params to your lib instead of using request.fetch.js
.
Then in any file of your app, import the function you need directly (it helps with tree shaking), call it and add a .then(sendToApi)
like this:
import { getAllEnvVars } from '@clevercloud/client/esm/api/application.js';
import { sendToApi } from '../send-to-api.js';
const envVars = await getAllEnvVars({ id: oid, appId }).then(sendToApi);
NOTE: It returns a promise, you may want to use await
with it.
Here's a example for a node based project using CommonJS modules with oAuth v1 signature and using the request
module to send requests.
In a file, expose this function:
const { addOauthHeader } = require('@clevercloud/client/cjs/oauth.node.js');
const { prefixUrl } = require('@clevercloud/client/cjs/prefix-url.js');
const { request } = require('@clevercloud/client/cjs/request.request.js');
module.exports.sendToApi = function sendToApi (requestParams) {
// load and cache config and tokens
const API_HOST = 'https://api.clever-cloud.com/v2'
const tokens = {
OAUTH_CONSUMER_KEY: 'your OAUTH_CONSUMER_KEY',
OAUTH_CONSUMER_SECRET: 'your OAUTH_CONSUMER_SECRET',
API_OAUTH_TOKEN: 'your API_OAUTH_TOKEN',
API_OAUTH_TOKEN_SECRET: 'your API_OAUTH_TOKEN_SECRET',
}
return Promise.resolve(requestParams)
.then(prefixUrl(API_HOST))
.then(addOauthHeader(tokens))
.then(request);
// chain a .catch() call here if you need to handle some errors or maybe redirect to login
}
NOTE: If your project relies on a specific REST library (axios, superagent...), you'll have to write your own request function to plug the params to your lib instead of using request.request.js
.
Then in any file of your app, require the service, call the function on it and add a .then(sendToApi)
like this:
const application = require('@clevercloud/client/cjs/api/application.js');
const { sendToApi } = require('../send-to-api.js');
const envVars = await application.getAllEnvVars({ id: oid, appId }).then(sendToApi);
NOTE: It returns a promise, you may want to use await
with it.
To generate a REST client from the API, run this command:
npm run generate-client
This command will:
To generate a REST client (ECMAScript modules) from the API, run this command:
npm run generate-client-from-openapi
This command will do the following steps:
.cache/openapi-clever.patched.json
(this step should disappear one day)/self
and /organisatio/{id}
)esm/api
esm/api/legacy-client.js
NOTE: The first step caches the Open API document locally for next calls, be sure to run this command to clear the content of .cache
if you want a clean build:
npm run clean-cache
If you want to generate a client for the preprod, you can change the config of OPEN_API_URL
in tasks/config.js
.
To generate a REST client for node (CommonJS modules) from the API, run this command:
npm run generate-cjs-modules
NOTE: This is based on the ECMAScript modules in esm
. Be sure to generate the ESM client before running this.
1.0.0-beta.0 (2019-07-22)
First public stable release
FAQs
JavaScript REST client and utils for Clever Cloud's API
The npm package @clevercloud/client receives a total of 1,587 weekly downloads. As such, @clevercloud/client popularity was classified as popular.
We found that @clevercloud/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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.