2019-04-05 02:23:40 +07:00
|
|
|
/**
|
|
|
|
* API Mocks for WebUI
|
|
|
|
*/
|
|
|
|
import logo from '../store/logo';
|
|
|
|
import login from '../store/login';
|
|
|
|
import { packageMeta } from '../store/packageMeta';
|
|
|
|
import { packageInformation } from '../store/package';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register mock api endpoints
|
|
|
|
* @param {string} endpoint
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
|
|
|
const register = (url, method = 'get', options = {}) => {
|
|
|
|
if (url === 'login' && method.toLocaleLowerCase() === 'post') {
|
|
|
|
return login(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url === 'logo' && method.toLocaleLowerCase() === 'get') {
|
|
|
|
return logo();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url === 'sidebar/verdaccio' && method.toLocaleLowerCase() === 'get') {
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
resolve(packageMeta);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url === 'packages' && method.toLocaleLowerCase() === 'get') {
|
2019-06-20 19:37:28 +07:00
|
|
|
return new Promise(function(resolve) {
|
2019-04-05 02:23:40 +07:00
|
|
|
resolve(packageInformation);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Error(`URL not found: ${url}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind API methods
|
|
|
|
*/
|
|
|
|
class API {
|
2019-06-24 02:50:30 +07:00
|
|
|
public request() {
|
|
|
|
const rest = arguments;
|
|
|
|
return register.call(null, ...rest);
|
2019-04-05 02:23:40 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
export default new API();
|