Socket
Socket
Sign inDemoInstall

@mocks-server/admin-api-client

Package Overview
Dependencies
9
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.0 to 6.1.0

dist-tsc/entities.d.ts

471

dist/index.cjs.js

@@ -12,228 +12,283 @@ 'use strict';

function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}
return keys;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isUndefined(value) {
return typeof value === "undefined";
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
function handleResponse(res) {
if (res.status > 199 && res.status < 300) {
return res.json().catch(() => Promise.resolve());
}
return res.json().then((data) => {
return Promise.reject(new Error(data.message));
});
}
return target;
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
class ApiClient {
constructor() {
Object.defineProperty(this, "_host", {
enumerable: true,
configurable: true,
writable: true,
value: adminApiPaths.DEFAULT_CLIENT_HOST
});
Object.defineProperty(this, "_port", {
enumerable: true,
configurable: true,
writable: true,
value: adminApiPaths.DEFAULT_PORT
});
}
get _baseUrl() {
return `${adminApiPaths.DEFAULT_PROTOCOL}://${this._host}:${this._port}${adminApiPaths.BASE_PATH}`;
}
_fullUrl(apiPath) {
return `${this._baseUrl}${apiPath}`;
}
config(configuration = {}) {
if (!isUndefined(configuration.host)) {
this._host = configuration.host;
}
if (!isUndefined(configuration.port)) {
this._port = configuration.port;
}
}
read(apiPath) {
return crossFetch__default["default"](this._fullUrl(apiPath)).then(handleResponse);
}
patch(apiPath, data) {
return crossFetch__default["default"](this._fullUrl(apiPath), {
method: "PATCH",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json",
},
}).then(handleResponse);
}
delete(apiPath) {
return crossFetch__default["default"](this._fullUrl(apiPath), {
method: "DELETE",
}).then(handleResponse);
}
create(apiPath, data) {
return crossFetch__default["default"](this._fullUrl(apiPath), {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json",
},
}).then(handleResponse);
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
class ApiResource {
constructor(apiClient, apiPath, id) {
Object.defineProperty(this, "_apiPath", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_id", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_apiClient", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this._apiPath = apiPath;
this._id = id ? `/${encodeURIComponent(id)}` : "";
this._apiClient = apiClient;
}
get _fullApiPath() {
return `${this._apiPath}${this._id}`;
}
read() {
return this._apiClient.read(this._fullApiPath);
}
update(data) {
return this._apiClient.patch(this._fullApiPath, data);
}
delete() {
return this._apiClient.delete(this._fullApiPath);
}
create(data) {
return this._apiClient.create(this._fullApiPath, data);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
class BaseAdminApiClient {
constructor() {
Object.defineProperty(this, "_apiClient", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_about", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_config", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_alerts", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_collections", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_routes", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_variants", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_customRouteVariants", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this._apiClient = new ApiClient();
this._about = new ApiResource(this._apiClient, adminApiPaths.ABOUT);
this._config = new ApiResource(this._apiClient, adminApiPaths.CONFIG);
this._alerts = new ApiResource(this._apiClient, adminApiPaths.ALERTS);
this._collections = new ApiResource(this._apiClient, adminApiPaths.COLLECTIONS);
this._routes = new ApiResource(this._apiClient, adminApiPaths.ROUTES);
this._variants = new ApiResource(this._apiClient, adminApiPaths.VARIANTS);
this._customRouteVariants = new ApiResource(this._apiClient, adminApiPaths.CUSTOM_ROUTE_VARIANTS);
}
get about() {
return this._about;
}
get config() {
return this._config;
}
get alerts() {
return this._alerts;
}
alert(id) {
return new ApiResource(this._apiClient, adminApiPaths.ALERTS, id);
}
get collections() {
return this._collections;
}
collection(id) {
return new ApiResource(this._apiClient, adminApiPaths.COLLECTIONS, id);
}
get routes() {
return this._routes;
}
route(id) {
return new ApiResource(this._apiClient, adminApiPaths.ROUTES, id);
}
get variants() {
return this._variants;
}
variant(id) {
return new ApiResource(this._apiClient, adminApiPaths.VARIANTS, id);
}
get customRouteVariants() {
return this._customRouteVariants;
}
configClient(configuration) {
this._apiClient.config(configuration);
}
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
var DEFAULT_OPTIONS = {
port: 3110,
host: "127.0.0.1"
};
var clientConfiguration = _objectSpread2({}, DEFAULT_OPTIONS);
function handleResponse(res) {
if (res.status > 199 && res.status < 300) {
return res.json()["catch"](function () {
return Promise.resolve();
});
}
return res.json().then(function (data) {
return Promise.reject(new Error(data.message));
});
}
function configClient(options) {
clientConfiguration = _objectSpread2(_objectSpread2({}, clientConfiguration), options);
}
var Fetcher = /*#__PURE__*/function () {
function Fetcher(url, id) {
_classCallCheck(this, Fetcher);
this._url = url;
this._id = id ? "/".concat(encodeURIComponent(id)) : "";
}
_createClass(Fetcher, [{
key: "url",
get: function get() {
return "http://".concat(clientConfiguration.host, ":").concat(clientConfiguration.port).concat(adminApiPaths.BASE_PATH).concat(this._url).concat(this._id);
class AdminApiClient {
constructor() {
Object.defineProperty(this, "_adminApiClient", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this._adminApiClient = new BaseAdminApiClient();
}
}, {
key: "_read",
value: function _read() {
return crossFetch__default["default"](this.url).then(handleResponse);
readAbout() {
return this._adminApiClient.about.read();
}
}, {
key: "_patch",
value: function _patch(data) {
return crossFetch__default["default"](this.url, {
method: "PATCH",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
}
}).then(handleResponse);
readConfig() {
return this._adminApiClient.config.read();
}
}, {
key: "_delete",
value: function _delete() {
return crossFetch__default["default"](this.url, {
method: "DELETE"
}).then(handleResponse);
updateConfig(newConfig) {
return this._adminApiClient.config.update(newConfig);
}
}, {
key: "_create",
value: function _create(data) {
return crossFetch__default["default"](this.url, {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
}
}).then(handleResponse);
readAlerts() {
return this._adminApiClient.alerts.read();
}
}, {
key: "read",
value: function read() {
return this._read();
readAlert(id) {
return this._adminApiClient.alert(id).read();
}
}, {
key: "update",
value: function update(data) {
return this._patch(data);
readCollections() {
return this._adminApiClient.collections.read();
}
}, {
key: "delete",
value: function _delete() {
return this._delete();
readCollection(id) {
return this._adminApiClient.collection(id).read();
}
}, {
key: "create",
value: function create(data) {
return this._create(data);
readRoutes() {
return this._adminApiClient.routes.read();
}
}]);
return Fetcher;
}();
var about = new Fetcher(adminApiPaths.ABOUT);
var config = new Fetcher(adminApiPaths.CONFIG);
var alerts = new Fetcher(adminApiPaths.ALERTS);
var alert = function alert(id) {
return new Fetcher(adminApiPaths.ALERTS, id);
};
var collections = new Fetcher(adminApiPaths.COLLECTIONS);
var collection = function collection(id) {
return new Fetcher(adminApiPaths.COLLECTIONS, id);
};
var routes = new Fetcher(adminApiPaths.ROUTES);
var route = function route(id) {
return new Fetcher(adminApiPaths.ROUTES, id);
};
var variants = new Fetcher(adminApiPaths.VARIANTS);
var variant = function variant(id) {
return new Fetcher(adminApiPaths.VARIANTS, id);
};
var customRouteVariants = new Fetcher(adminApiPaths.CUSTOM_ROUTE_VARIANTS);
function readAbout() {
return about.read();
readRoute(id) {
return this._adminApiClient.route(id).read();
}
readVariants() {
return this._adminApiClient.variants.read();
}
readVariant(id) {
return this._adminApiClient.variant(id).read();
}
readCustomRouteVariants() {
return this._adminApiClient.customRouteVariants.read();
}
useRouteVariant(id) {
return this._adminApiClient.customRouteVariants.create({
id,
});
}
restoreRouteVariants() {
return this._adminApiClient.customRouteVariants.delete();
}
configClient(config) {
return this._adminApiClient.configClient(config);
}
}
function readConfig() {
return config.read();
}
function updateConfig(newConfig) {
return config.update(newConfig);
}
function readAlerts() {
return alerts.read();
}
function readAlert(id) {
return alert(id).read();
}
function readCollections() {
return collections.read();
}
function readCollection(id) {
return collection(id).read();
}
function readRoutes() {
return routes.read();
}
function readRoute(id) {
return route(id).read();
}
function readVariants() {
return variants.read();
}
function readVariant(id) {
return variant(id).read();
}
function readCustomRouteVariants() {
return customRouteVariants.read();
}
function useRouteVariant(id) {
return customRouteVariants.create({
id: id
});
}
function restoreRouteVariants() {
return customRouteVariants["delete"]();
}
const defaultClient = new AdminApiClient();
const readAbout = defaultClient.readAbout.bind(defaultClient);
const readConfig = defaultClient.readConfig.bind(defaultClient);
const updateConfig = defaultClient.updateConfig.bind(defaultClient);
const readAlerts = defaultClient.readAlerts.bind(defaultClient);
const readAlert = defaultClient.readAlert.bind(defaultClient);
const readCollections = defaultClient.readCollections.bind(defaultClient);
const readCollection = defaultClient.readCollection.bind(defaultClient);
const readRoutes = defaultClient.readRoutes.bind(defaultClient);
const readRoute = defaultClient.readRoute.bind(defaultClient);
const readVariants = defaultClient.readVariants.bind(defaultClient);
const readVariant = defaultClient.readVariant.bind(defaultClient);
const readCustomRouteVariants = defaultClient.readCustomRouteVariants.bind(defaultClient);
const useRouteVariant = defaultClient.useRouteVariant.bind(defaultClient);
const restoreRouteVariants = defaultClient.restoreRouteVariants.bind(defaultClient);
const configClient = defaultClient.configClient.bind(defaultClient);
exports.AdminApiClient = AdminApiClient;
exports.configClient = configClient;

@@ -240,0 +295,0 @@ exports.readAbout = readAbout;

import crossFetch from 'cross-fetch';
import { ABOUT, CONFIG, ALERTS, COLLECTIONS, ROUTES, VARIANTS, CUSTOM_ROUTE_VARIANTS, BASE_PATH } from '@mocks-server/admin-api-paths';
import { ABOUT, CONFIG, ALERTS, COLLECTIONS, ROUTES, VARIANTS, CUSTOM_ROUTE_VARIANTS, DEFAULT_CLIENT_HOST, DEFAULT_PORT, DEFAULT_PROTOCOL, BASE_PATH } from '@mocks-server/admin-api-paths';
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}
return keys;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isUndefined(value) {
return typeof value === "undefined";
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
function handleResponse(res) {
if (res.status > 199 && res.status < 300) {
return res.json().catch(() => Promise.resolve());
}
return res.json().then((data) => {
return Promise.reject(new Error(data.message));
});
}
return target;
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
class ApiClient {
constructor() {
Object.defineProperty(this, "_host", {
enumerable: true,
configurable: true,
writable: true,
value: DEFAULT_CLIENT_HOST
});
Object.defineProperty(this, "_port", {
enumerable: true,
configurable: true,
writable: true,
value: DEFAULT_PORT
});
}
get _baseUrl() {
return `${DEFAULT_PROTOCOL}://${this._host}:${this._port}${BASE_PATH}`;
}
_fullUrl(apiPath) {
return `${this._baseUrl}${apiPath}`;
}
config(configuration = {}) {
if (!isUndefined(configuration.host)) {
this._host = configuration.host;
}
if (!isUndefined(configuration.port)) {
this._port = configuration.port;
}
}
read(apiPath) {
return crossFetch(this._fullUrl(apiPath)).then(handleResponse);
}
patch(apiPath, data) {
return crossFetch(this._fullUrl(apiPath), {
method: "PATCH",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json",
},
}).then(handleResponse);
}
delete(apiPath) {
return crossFetch(this._fullUrl(apiPath), {
method: "DELETE",
}).then(handleResponse);
}
create(apiPath, data) {
return crossFetch(this._fullUrl(apiPath), {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json",
},
}).then(handleResponse);
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
class ApiResource {
constructor(apiClient, apiPath, id) {
Object.defineProperty(this, "_apiPath", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_id", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_apiClient", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this._apiPath = apiPath;
this._id = id ? `/${encodeURIComponent(id)}` : "";
this._apiClient = apiClient;
}
get _fullApiPath() {
return `${this._apiPath}${this._id}`;
}
read() {
return this._apiClient.read(this._fullApiPath);
}
update(data) {
return this._apiClient.patch(this._fullApiPath, data);
}
delete() {
return this._apiClient.delete(this._fullApiPath);
}
create(data) {
return this._apiClient.create(this._fullApiPath, data);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
class BaseAdminApiClient {
constructor() {
Object.defineProperty(this, "_apiClient", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_about", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_config", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_alerts", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_collections", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_routes", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_variants", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_customRouteVariants", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this._apiClient = new ApiClient();
this._about = new ApiResource(this._apiClient, ABOUT);
this._config = new ApiResource(this._apiClient, CONFIG);
this._alerts = new ApiResource(this._apiClient, ALERTS);
this._collections = new ApiResource(this._apiClient, COLLECTIONS);
this._routes = new ApiResource(this._apiClient, ROUTES);
this._variants = new ApiResource(this._apiClient, VARIANTS);
this._customRouteVariants = new ApiResource(this._apiClient, CUSTOM_ROUTE_VARIANTS);
}
get about() {
return this._about;
}
get config() {
return this._config;
}
get alerts() {
return this._alerts;
}
alert(id) {
return new ApiResource(this._apiClient, ALERTS, id);
}
get collections() {
return this._collections;
}
collection(id) {
return new ApiResource(this._apiClient, COLLECTIONS, id);
}
get routes() {
return this._routes;
}
route(id) {
return new ApiResource(this._apiClient, ROUTES, id);
}
get variants() {
return this._variants;
}
variant(id) {
return new ApiResource(this._apiClient, VARIANTS, id);
}
get customRouteVariants() {
return this._customRouteVariants;
}
configClient(configuration) {
this._apiClient.config(configuration);
}
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
var DEFAULT_OPTIONS = {
port: 3110,
host: "127.0.0.1"
};
var clientConfiguration = _objectSpread2({}, DEFAULT_OPTIONS);
function handleResponse(res) {
if (res.status > 199 && res.status < 300) {
return res.json()["catch"](function () {
return Promise.resolve();
});
}
return res.json().then(function (data) {
return Promise.reject(new Error(data.message));
});
}
function configClient(options) {
clientConfiguration = _objectSpread2(_objectSpread2({}, clientConfiguration), options);
}
var Fetcher = /*#__PURE__*/function () {
function Fetcher(url, id) {
_classCallCheck(this, Fetcher);
this._url = url;
this._id = id ? "/".concat(encodeURIComponent(id)) : "";
}
_createClass(Fetcher, [{
key: "url",
get: function get() {
return "http://".concat(clientConfiguration.host, ":").concat(clientConfiguration.port).concat(BASE_PATH).concat(this._url).concat(this._id);
class AdminApiClient {
constructor() {
Object.defineProperty(this, "_adminApiClient", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this._adminApiClient = new BaseAdminApiClient();
}
}, {
key: "_read",
value: function _read() {
return crossFetch(this.url).then(handleResponse);
readAbout() {
return this._adminApiClient.about.read();
}
}, {
key: "_patch",
value: function _patch(data) {
return crossFetch(this.url, {
method: "PATCH",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
}
}).then(handleResponse);
readConfig() {
return this._adminApiClient.config.read();
}
}, {
key: "_delete",
value: function _delete() {
return crossFetch(this.url, {
method: "DELETE"
}).then(handleResponse);
updateConfig(newConfig) {
return this._adminApiClient.config.update(newConfig);
}
}, {
key: "_create",
value: function _create(data) {
return crossFetch(this.url, {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
}
}).then(handleResponse);
readAlerts() {
return this._adminApiClient.alerts.read();
}
}, {
key: "read",
value: function read() {
return this._read();
readAlert(id) {
return this._adminApiClient.alert(id).read();
}
}, {
key: "update",
value: function update(data) {
return this._patch(data);
readCollections() {
return this._adminApiClient.collections.read();
}
}, {
key: "delete",
value: function _delete() {
return this._delete();
readCollection(id) {
return this._adminApiClient.collection(id).read();
}
}, {
key: "create",
value: function create(data) {
return this._create(data);
readRoutes() {
return this._adminApiClient.routes.read();
}
}]);
return Fetcher;
}();
var about = new Fetcher(ABOUT);
var config = new Fetcher(CONFIG);
var alerts = new Fetcher(ALERTS);
var alert = function alert(id) {
return new Fetcher(ALERTS, id);
};
var collections = new Fetcher(COLLECTIONS);
var collection = function collection(id) {
return new Fetcher(COLLECTIONS, id);
};
var routes = new Fetcher(ROUTES);
var route = function route(id) {
return new Fetcher(ROUTES, id);
};
var variants = new Fetcher(VARIANTS);
var variant = function variant(id) {
return new Fetcher(VARIANTS, id);
};
var customRouteVariants = new Fetcher(CUSTOM_ROUTE_VARIANTS);
function readAbout() {
return about.read();
readRoute(id) {
return this._adminApiClient.route(id).read();
}
readVariants() {
return this._adminApiClient.variants.read();
}
readVariant(id) {
return this._adminApiClient.variant(id).read();
}
readCustomRouteVariants() {
return this._adminApiClient.customRouteVariants.read();
}
useRouteVariant(id) {
return this._adminApiClient.customRouteVariants.create({
id,
});
}
restoreRouteVariants() {
return this._adminApiClient.customRouteVariants.delete();
}
configClient(config) {
return this._adminApiClient.configClient(config);
}
}
function readConfig() {
return config.read();
}
function updateConfig(newConfig) {
return config.update(newConfig);
}
function readAlerts() {
return alerts.read();
}
function readAlert(id) {
return alert(id).read();
}
function readCollections() {
return collections.read();
}
function readCollection(id) {
return collection(id).read();
}
function readRoutes() {
return routes.read();
}
function readRoute(id) {
return route(id).read();
}
function readVariants() {
return variants.read();
}
function readVariant(id) {
return variant(id).read();
}
function readCustomRouteVariants() {
return customRouteVariants.read();
}
function useRouteVariant(id) {
return customRouteVariants.create({
id: id
});
}
function restoreRouteVariants() {
return customRouteVariants["delete"]();
}
const defaultClient = new AdminApiClient();
const readAbout = defaultClient.readAbout.bind(defaultClient);
const readConfig = defaultClient.readConfig.bind(defaultClient);
const updateConfig = defaultClient.updateConfig.bind(defaultClient);
const readAlerts = defaultClient.readAlerts.bind(defaultClient);
const readAlert = defaultClient.readAlert.bind(defaultClient);
const readCollections = defaultClient.readCollections.bind(defaultClient);
const readCollection = defaultClient.readCollection.bind(defaultClient);
const readRoutes = defaultClient.readRoutes.bind(defaultClient);
const readRoute = defaultClient.readRoute.bind(defaultClient);
const readVariants = defaultClient.readVariants.bind(defaultClient);
const readVariant = defaultClient.readVariant.bind(defaultClient);
const readCustomRouteVariants = defaultClient.readCustomRouteVariants.bind(defaultClient);
const useRouteVariant = defaultClient.useRouteVariant.bind(defaultClient);
const restoreRouteVariants = defaultClient.restoreRouteVariants.bind(defaultClient);
const configClient = defaultClient.configClient.bind(defaultClient);
export { configClient, readAbout, readAlert, readAlerts, readCollection, readCollections, readConfig, readCustomRouteVariants, readRoute, readRoutes, readVariant, readVariants, restoreRouteVariants, updateConfig, useRouteVariant };
export { AdminApiClient, configClient, readAbout, readAlert, readAlerts, readCollection, readCollections, readConfig, readCustomRouteVariants, readRoute, readRoutes, readVariant, readVariants, restoreRouteVariants, updateConfig, useRouteVariant };

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@mocks-server/admin-api-paths")):"function"==typeof define&&define.amd?define(["exports","@mocks-server/admin-api-paths"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).mocksServerAdminApiClient={},t.pluginAdminApiPaths)}(this,(function(t,e){"use strict";function r(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function n(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?r(Object(n),!0).forEach((function(e){i(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function o(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function i(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function a(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var u={exports:{}};!function(t,e){var r="undefined"!=typeof self?self:s,n=function(){function t(){this.fetch=!1,this.DOMException=r.DOMException}return t.prototype=r,new t}();!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,o="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function f(t){return"string"!=typeof t&&(t=String(t)),t}function d(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function h(t){this.map={},t instanceof h?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function l(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=l(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:o&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&o&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var t=p(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,n=p(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=l(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(O)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(t,e){t=c(t),e=f(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},h.prototype.delete=function(t){delete this.map[c(t)]},h.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},h.prototype.set=function(t,e){this.map[c(t)]=f(e)},h.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},h.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),d(t)},h.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),d(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),d(t)},n&&(h.prototype[Symbol.iterator]=h.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(t,e){var r,n,o=(e=e||{}).body;if(t instanceof v){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new h(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new h(e.headers)),this.method=(r=e.method||this.method||"GET",n=r.toUpperCase(),w.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function O(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function E(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new h(e.headers),this.url=e.url||"",this._initBody(t)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},m.call(v.prototype),m.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},E.error=function(){var t=new E(null,{status:0,statusText:""});return t.type="error",t};var g=[301,302,303,307,308];E.redirect=function(t,e){if(-1===g.indexOf(e))throw new RangeError("Invalid status code");return new E(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function A(t,r){return new Promise((function(n,i){var s=new v(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;n(new E(o,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",u)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}A.polyfill=!0,t.fetch||(t.fetch=A,t.Headers=h,t.Request=v,t.Response=E),e.Headers=h,e.Request=v,e.Response=E,e.fetch=A,Object.defineProperty(e,"__esModule",{value:!0})}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var o=n;(e=o.fetch).default=o.fetch,e.fetch=o.fetch,e.Headers=o.Headers,e.Request=o.Request,e.Response=o.Response,t.exports=e}(u,u.exports);var c=a(u.exports),f=n({},{port:3110,host:"127.0.0.1"});function d(t){return t.status>199&&t.status<300?t.json().catch((function(){return Promise.resolve()})):t.json().then((function(t){return Promise.reject(new Error(t.message))}))}var h=function(){function t(e,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this._url=e,this._id=r?"/".concat(encodeURIComponent(r)):""}var r,n,i;return r=t,(n=[{key:"url",get:function(){return"http://".concat(f.host,":").concat(f.port).concat(e.BASE_PATH).concat(this._url).concat(this._id)}},{key:"_read",value:function(){return c(this.url).then(d)}},{key:"_patch",value:function(t){return c(this.url,{method:"PATCH",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}}).then(d)}},{key:"_delete",value:function(){return c(this.url,{method:"DELETE"}).then(d)}},{key:"_create",value:function(t){return c(this.url,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}}).then(d)}},{key:"read",value:function(){return this._read()}},{key:"update",value:function(t){return this._patch(t)}},{key:"delete",value:function(){return this._delete()}},{key:"create",value:function(t){return this._create(t)}}])&&o(r.prototype,n),i&&o(r,i),Object.defineProperty(r,"prototype",{writable:!1}),t}(),p=new h(e.ABOUT),l=new h(e.CONFIG),y=new h(e.ALERTS),b=new h(e.COLLECTIONS),m=new h(e.ROUTES),w=new h(e.VARIANTS),v=new h(e.CUSTOM_ROUTE_VARIANTS);t.configClient=function(t){f=n(n({},f),t)},t.readAbout=function(){return p.read()},t.readAlert=function(t){return function(t){return new h(e.ALERTS,t)}(t).read()},t.readAlerts=function(){return y.read()},t.readCollection=function(t){return function(t){return new h(e.COLLECTIONS,t)}(t).read()},t.readCollections=function(){return b.read()},t.readConfig=function(){return l.read()},t.readCustomRouteVariants=function(){return v.read()},t.readRoute=function(t){return function(t){return new h(e.ROUTES,t)}(t).read()},t.readRoutes=function(){return m.read()},t.readVariant=function(t){return function(t){return new h(e.VARIANTS,t)}(t).read()},t.readVariants=function(){return w.read()},t.restoreRouteVariants=function(){return v.delete()},t.updateConfig=function(t){return l.update(t)},t.useRouteVariant=function(t){return v.create({id:t})},Object.defineProperty(t,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@mocks-server/admin-api-paths")):"function"==typeof define&&define.amd?define(["exports","@mocks-server/admin-api-paths"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).mocksServerAdminApiClient={},e.pluginAdminApiPaths)}(this,(function(e,t){"use strict";var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(e,t){var i="undefined"!=typeof self?self:r,n=function(){function e(){this.fetch=!1,this.DOMException=i.DOMException}return e.prototype=i,new e}();!function(e){!function(t){var r="URLSearchParams"in e,i="Symbol"in e&&"iterator"in Symbol,n="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),o="FormData"in e,a="ArrayBuffer"in e;if(a)var s=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(e){return e&&s.indexOf(Object.prototype.toString.call(e))>-1};function l(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function d(e){return"string"!=typeof e&&(e=String(e)),e}function h(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return i&&(t[Symbol.iterator]=function(){return t}),t}function c(e){this.map={},e instanceof c?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function f(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function p(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function b(e){var t=new FileReader,r=p(t);return t.readAsArrayBuffer(e),r}function y(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function _(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:n&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:o&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&n&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=y(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||u(e))?this._bodyArrayBuffer=y(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},n&&(this.blob=function(){var e=f(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(b)}),this.text=function(){var e,t,r,i=f(this);if(i)return i;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=p(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),i=0;i<t.length;i++)r[i]=String.fromCharCode(t[i]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},o&&(this.formData=function(){return this.text().then(A)}),this.json=function(){return this.text().then(JSON.parse)},this}c.prototype.append=function(e,t){e=l(e),t=d(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},c.prototype.delete=function(e){delete this.map[l(e)]},c.prototype.get=function(e){return e=l(e),this.has(e)?this.map[e]:null},c.prototype.has=function(e){return this.map.hasOwnProperty(l(e))},c.prototype.set=function(e,t){this.map[l(e)]=d(t)},c.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},c.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),h(e)},c.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),h(e)},c.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),h(e)},i&&(c.prototype[Symbol.iterator]=c.prototype.entries);var m=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(e,t){var r,i,n=(t=t||{}).body;if(e instanceof w){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new c(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,n||null==e._bodyInit||(n=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new c(t.headers)),this.method=(r=t.method||this.method||"GET",i=r.toUpperCase(),m.indexOf(i)>-1?i:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function A(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),i=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(i),decodeURIComponent(n))}})),t}function v(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new c(t.headers),this.url=t.url||"",this._initBody(e)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},_.call(w.prototype),_.call(v.prototype),v.prototype.clone=function(){return new v(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},v.error=function(){var e=new v(null,{status:0,statusText:""});return e.type="error",e};var g=[301,302,303,307,308];v.redirect=function(e,t){if(-1===g.indexOf(t))throw new RangeError("Invalid status code");return new v(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function C(e,r){return new Promise((function(i,o){var a=new w(e,r);if(a.signal&&a.signal.aborted)return o(new t.DOMException("Aborted","AbortError"));var s=new XMLHttpRequest;function u(){s.abort()}s.onload=function(){var e,t,r={status:s.status,statusText:s.statusText,headers:(e=s.getAllResponseHeaders()||"",t=new c,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var r=e.split(":"),i=r.shift().trim();if(i){var n=r.join(":").trim();t.append(i,n)}})),t)};r.url="responseURL"in s?s.responseURL:r.headers.get("X-Request-URL");var n="response"in s?s.response:s.responseText;i(new v(n,r))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.onabort=function(){o(new t.DOMException("Aborted","AbortError"))},s.open(a.method,a.url,!0),"include"===a.credentials?s.withCredentials=!0:"omit"===a.credentials&&(s.withCredentials=!1),"responseType"in s&&n&&(s.responseType="blob"),a.headers.forEach((function(e,t){s.setRequestHeader(t,e)})),a.signal&&(a.signal.addEventListener("abort",u),s.onreadystatechange=function(){4===s.readyState&&a.signal.removeEventListener("abort",u)}),s.send(void 0===a._bodyInit?null:a._bodyInit)}))}C.polyfill=!0,e.fetch||(e.fetch=C,e.Headers=c,e.Request=w,e.Response=v),t.Headers=c,t.Request=w,t.Response=v,t.fetch=C,Object.defineProperty(t,"__esModule",{value:!0})}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var o=n;(t=o.fetch).default=o.fetch,t.fetch=o.fetch,t.Headers=o.Headers,t.Request=o.Request,t.Response=o.Response,e.exports=t}(n,n.exports);var o=i(n.exports);function a(e){return void 0===e}function s(e){return e.status>199&&e.status<300?e.json().catch((()=>Promise.resolve())):e.json().then((e=>Promise.reject(new Error(e.message))))}class u{constructor(){Object.defineProperty(this,"_host",{enumerable:!0,configurable:!0,writable:!0,value:t.DEFAULT_CLIENT_HOST}),Object.defineProperty(this,"_port",{enumerable:!0,configurable:!0,writable:!0,value:t.DEFAULT_PORT})}get _baseUrl(){return`${t.DEFAULT_PROTOCOL}://${this._host}:${this._port}${t.BASE_PATH}`}_fullUrl(e){return`${this._baseUrl}${e}`}config(e={}){a(e.host)||(this._host=e.host),a(e.port)||(this._port=e.port)}read(e){return o(this._fullUrl(e)).then(s)}patch(e,t){return o(this._fullUrl(e),{method:"PATCH",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}}).then(s)}delete(e){return o(this._fullUrl(e),{method:"DELETE"}).then(s)}create(e,t){return o(this._fullUrl(e),{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}}).then(s)}}class l{constructor(e,t,r){Object.defineProperty(this,"_apiPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_apiClient",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._apiPath=t,this._id=r?`/${encodeURIComponent(r)}`:"",this._apiClient=e}get _fullApiPath(){return`${this._apiPath}${this._id}`}read(){return this._apiClient.read(this._fullApiPath)}update(e){return this._apiClient.patch(this._fullApiPath,e)}delete(){return this._apiClient.delete(this._fullApiPath)}create(e){return this._apiClient.create(this._fullApiPath,e)}}class d{constructor(){Object.defineProperty(this,"_apiClient",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_about",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_alerts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_collections",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_routes",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_variants",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_customRouteVariants",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._apiClient=new u,this._about=new l(this._apiClient,t.ABOUT),this._config=new l(this._apiClient,t.CONFIG),this._alerts=new l(this._apiClient,t.ALERTS),this._collections=new l(this._apiClient,t.COLLECTIONS),this._routes=new l(this._apiClient,t.ROUTES),this._variants=new l(this._apiClient,t.VARIANTS),this._customRouteVariants=new l(this._apiClient,t.CUSTOM_ROUTE_VARIANTS)}get about(){return this._about}get config(){return this._config}get alerts(){return this._alerts}alert(e){return new l(this._apiClient,t.ALERTS,e)}get collections(){return this._collections}collection(e){return new l(this._apiClient,t.COLLECTIONS,e)}get routes(){return this._routes}route(e){return new l(this._apiClient,t.ROUTES,e)}get variants(){return this._variants}variant(e){return new l(this._apiClient,t.VARIANTS,e)}get customRouteVariants(){return this._customRouteVariants}configClient(e){this._apiClient.config(e)}}class h{constructor(){Object.defineProperty(this,"_adminApiClient",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._adminApiClient=new d}readAbout(){return this._adminApiClient.about.read()}readConfig(){return this._adminApiClient.config.read()}updateConfig(e){return this._adminApiClient.config.update(e)}readAlerts(){return this._adminApiClient.alerts.read()}readAlert(e){return this._adminApiClient.alert(e).read()}readCollections(){return this._adminApiClient.collections.read()}readCollection(e){return this._adminApiClient.collection(e).read()}readRoutes(){return this._adminApiClient.routes.read()}readRoute(e){return this._adminApiClient.route(e).read()}readVariants(){return this._adminApiClient.variants.read()}readVariant(e){return this._adminApiClient.variant(e).read()}readCustomRouteVariants(){return this._adminApiClient.customRouteVariants.read()}useRouteVariant(e){return this._adminApiClient.customRouteVariants.create({id:e})}restoreRouteVariants(){return this._adminApiClient.customRouteVariants.delete()}configClient(e){return this._adminApiClient.configClient(e)}}const c=new h,f=c.readAbout.bind(c),p=c.readConfig.bind(c),b=c.updateConfig.bind(c),y=c.readAlerts.bind(c),_=c.readAlert.bind(c),m=c.readCollections.bind(c),w=c.readCollection.bind(c),A=c.readRoutes.bind(c),v=c.readRoute.bind(c),g=c.readVariants.bind(c),C=c.readVariant.bind(c),O=c.readCustomRouteVariants.bind(c),T=c.useRouteVariant.bind(c),E=c.restoreRouteVariants.bind(c),P=c.configClient.bind(c);e.AdminApiClient=h,e.configClient=P,e.readAbout=f,e.readAlert=_,e.readAlerts=y,e.readCollection=w,e.readCollections=m,e.readConfig=p,e.readCustomRouteVariants=O,e.readRoute=v,e.readRoutes=A,e.readVariant=C,e.readVariants=g,e.restoreRouteVariants=E,e.updateConfig=b,e.useRouteVariant=T,Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "@mocks-server/admin-api-client",
"version": "6.0.0",
"version": "6.1.0",
"description": "Client of @mocks-server/plugin-admin-api",

@@ -26,8 +26,10 @@ "keywords": [

"files": [
"dist"
"dist",
"dist-tsc"
],
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"types": "dist-tsc/index.d.ts",
"dependencies": {
"@mocks-server/admin-api-paths": "4.0.0",
"@mocks-server/admin-api-paths": "4.1.0",
"cross-fetch": "3.1.5"

@@ -39,8 +41,8 @@ },

"scripts": {
"build": "rollup --config",
"build": "tsc && rollup --config",
"mocks:ci": "pnpm -w run nx start admin-api-client-unit-mocks",
"test": "jest",
"test": "jest --runInBand",
"test:unit": "start-server-and-test mocks:ci tcp:127.0.0.1:3200 test"
},
"readme": "<p align=\"center\"><a href=\"https://mocks-server.org\" target=\"_blank\" rel=\"noopener noreferrer\"><img width=\"120\" src=\"https://www.mocks-server.org/img/logo_120.png\" alt=\"Mocks Server logo\"></a></p>\n\n<p align=\"center\">\n <a href=\"https://github.com/mocks-server/main/actions?query=workflow%3Abuild+branch%3Amaster\"><img src=\"https://github.com/mocks-server/main/workflows/build/badge.svg?branch=master\" alt=\"Build Status\"></a>\n <a href=\"https://codecov.io/gh/mocks-server/main\"><img src=\"https://codecov.io/gh/mocks-server/main/branch/master/graph/badge.svg?token=2S8ZR55AJV\" alt=\"Coverage\"></a>\n <a href=\"https://sonarcloud.io/project/overview?id=mocks-server_main_admin-api-client\"><img src=\"https://sonarcloud.io/api/project_badges/measure?project=mocks-server_main_admin-api-client&metric=alert_status\" alt=\"Quality Gate\"></a>\n <a href=\"https://www.npmjs.com/package/@mocks-server/admin-api-client\"><img src=\"https://img.shields.io/npm/dm/@mocks-server/admin-api-client.svg\" alt=\"Downloads\"></a>\n <a href=\"https://renovatebot.com\"><img src=\"https://img.shields.io/badge/renovate-enabled-brightgreen.svg\" alt=\"Renovate\"></a>\n <a href=\"https://github.com/mocks-server/main/blob/master/packages/admin-api-client/LICENSE\"><img src=\"https://img.shields.io/npm/l/@mocks-server/admin-api-client.svg\" alt=\"License\"></a>\n</p>\n\n---\n\n# Mocks-server administration api client\n\nThis package provides an API client for administrating Mocks Server through HTTP requests to the [Admin API plugin][plugin-admin-api-url].\n\nRequests to the Mocks Server administration API are made using [`cross-fetch`](https://www.npmjs.com/package/cross-fetch), which makes this package compatible with browsers and Node.js environments, but, if you are going to build a browser application, you'll probably prefer to use the [`@mocks-server/admin-api-client-data-provider` package](https://www.npmjs.com/package/@mocks-server/admin-api-client-data-provider), which uses [Data Provider](https://www.data-provider.org), and works well with Redux, React, etc.\n\n## Install\n\n```bash\nnpm install --save @mocks-server/admin-api-client\n```\n\nThe UMD build is also available on unpkg. When UMD package is loaded, it creates a `mocksServerAdminApiClient` global object containing all of the methods.\n\n```html\n<script src=\"https://unpkg.com/@mocks-server/admin-api-paths/dist/index.umd.js\"></script>\n<script src=\"https://unpkg.com/@mocks-server/admin-api-client/dist/index.umd.js\"></script>\n```\n\n> The umd distribution is bundled with the `cross-env` dependency, but requires the `@mocks-server/admin-api-paths` dependency to be added separately.\n\n## Usage\n\nAll methods described in the [Api](#api) return Promises when executed (except the `configClient` method):\n\n```js\nimport { readAbout, readConfig, updateConfig } from \"@mocks-server/admin-api-client\";\n\nconst example = async () => {\n const { version } = await readAbout();\n console.log(`Current Admin API plugin version is ${versions.adminApi}`);\n\n const currentConfig = await readConfig();\n console.log(\"Current Mocks Server config is\", JSON.stringify(currentConfig));\n\n await updateConfig({\n mock: {\n collections: {\n selected: \"user-super-admin\"\n },\n routes: {\n delay: 1000\n },\n },\n });\n console.log(\"Collection and delay changed\");\n};\n\nexample();\n```\n\n## Api\n\n* `readAbout()` - Returns info about the Admin API plugin, such as current version.\n* `readConfig()` - Returns current configuration.\n* `updateConfig(configObject)` - Updates Mocks Server configuration. A configuration object has to be provided. Read the [Mocks Server configuration docs](https://www.mocks-server.org/docs/configuration/options) for further info.\n* `readAlerts()` - Returns array of current alerts.\n* `readAlert(alertId)` - Returns an specific alert.\n* `readCollections()` - Returns available collections.\n* `readCollection(id)` - Returns a collection by ID.\n* `readRoutes()` - Returns available routes.\n* `readRoute(id)` - Returns a route by ID.\n* `readVariants()` - Returns available route variants.\n* `readVariant(id)` - Returns a route variant by ID.\n* `readCustomRouteVariants()` - Returns current custom route variants of the current collection.\n* `useRouteVariant(id)` - Sets a custom route variant to be used by current collection.\n* `restoreRouteVariants()` - Restore route variants to those defined in current collection.\n\n## Configuration\n\nBy default, the client is configured to request to `http://127.0.0.1:3110/api`, based in the [default options of Mocks Server](https://www.mocks-server.org/docs/configuration/options)\n\nYou can change both the the host and port of the administration API:\n\n```js\nimport { configClient } from \"@mocks-server/admin-api-client\";\n\nconfigClient({\n host: \"localhost\",\n port: 3500\n});\n```\n\n## Release notes\n\nCurrent major release is compatible only with `@mocks-server/main` versions upper or equal than `3.6`. Use prior releases for lower versions. If you don't want to update to the latest major version of this package yet but you want to update `@mocks-server/main`, you can also use any `5.x` version of this package with any `@mocks-server/main@3.x` version.\n\n## Contributing\n\nContributors are welcome.\nPlease read the [contributing guidelines](.github/CONTRIBUTING.md) and [code of conduct](.github/CODE_OF_CONDUCT.md).\n\n[plugin-admin-api-url]: https://github.com/mocks-server/main/blob/master/packages/admin-api-client\n"
"readme": "<p align=\"center\"><a href=\"https://mocks-server.org\" target=\"_blank\" rel=\"noopener noreferrer\"><img width=\"120\" src=\"https://www.mocks-server.org/img/logo_120.png\" alt=\"Mocks Server logo\"></a></p>\n\n<p align=\"center\">\n <a href=\"https://github.com/mocks-server/main/actions?query=workflow%3Abuild+branch%3Amaster\"><img src=\"https://github.com/mocks-server/main/workflows/build/badge.svg?branch=master\" alt=\"Build Status\"></a>\n <a href=\"https://codecov.io/gh/mocks-server/main\"><img src=\"https://codecov.io/gh/mocks-server/main/branch/master/graph/badge.svg?token=2S8ZR55AJV\" alt=\"Coverage\"></a>\n <a href=\"https://sonarcloud.io/project/overview?id=mocks-server_main_admin-api-client\"><img src=\"https://sonarcloud.io/api/project_badges/measure?project=mocks-server_main_admin-api-client&metric=alert_status\" alt=\"Quality Gate\"></a>\n <a href=\"https://www.npmjs.com/package/@mocks-server/admin-api-client\"><img src=\"https://img.shields.io/npm/dm/@mocks-server/admin-api-client.svg\" alt=\"Downloads\"></a>\n <a href=\"https://renovatebot.com\"><img src=\"https://img.shields.io/badge/renovate-enabled-brightgreen.svg\" alt=\"Renovate\"></a>\n <a href=\"https://github.com/mocks-server/main/blob/master/packages/admin-api-client/LICENSE\"><img src=\"https://img.shields.io/npm/l/@mocks-server/admin-api-client.svg\" alt=\"License\"></a>\n</p>\n\n---\n\n# Mocks-server administration api client\n\nThis package provides an API client for administrating Mocks Server through HTTP requests to the [Admin API plugin][plugin-admin-api-url].\n\nRequests to the Mocks Server administration API are made using [`cross-fetch`](https://www.npmjs.com/package/cross-fetch), which makes this package compatible with browsers and Node.js environments, but, if you are going to build a browser application, you'll probably prefer to use the [`@mocks-server/admin-api-client-data-provider` package](https://www.npmjs.com/package/@mocks-server/admin-api-client-data-provider), which uses [Data Provider](https://www.data-provider.org), and works well with Redux, React, etc.\n\n## Installation\n\n```bash\nnpm install --save @mocks-server/admin-api-client\n```\n\nThe UMD build is also available on unpkg. When UMD package is loaded, it creates a `mocksServerAdminApiClient` global object containing all methods and classes.\n\n```html\n<script src=\"https://unpkg.com/@mocks-server/admin-api-paths/dist/index.umd.js\"></script>\n<script src=\"https://unpkg.com/@mocks-server/admin-api-client/dist/index.umd.js\"></script>\n```\n\n> NOTE: The umd distribution is bundled with the `cross-fetch` dependency, but it requires the `@mocks-server/admin-api-paths` dependency to be added separately.\n\n## Usage\n\nImport and create a new `AdminApiClient` class. All methods described in the [Api](#api) return Promises when executed (except the `configClient` method):\n\n```js\nimport { AdminApiClient } from \"@mocks-server/admin-api-client\";\n\nconst example = async () => {\n const adminApiClient = new AdminApiClient();\n\n const { version } = await adminApiClient.readAbout();\n console.log(`Current Admin API plugin version is ${versions.adminApi}`);\n\n const currentConfig = await adminApiClient.readConfig();\n console.log(\"Current Mocks Server config is\", JSON.stringify(currentConfig));\n\n await adminApiClient.updateConfig({\n mock: {\n collections: {\n selected: \"user-super-admin\"\n },\n routes: {\n delay: 1000\n },\n },\n });\n console.log(\"Collection and delay changed\");\n};\n\nexample();\n```\n\n## Api\n\n### new AdminApiClient()\n\nReturns an instance containing next methods:\n\n* `readAbout()` - Returns info about the Admin API plugin, such as current version.\n* `readConfig()` - Returns current configuration.\n* `updateConfig(configObject)` - Updates Mocks Server configuration. A configuration object has to be provided. Read the [Mocks Server configuration docs](https://www.mocks-server.org/docs/configuration/options) for further info.\n* `readAlerts()` - Returns array of current alerts.\n* `readAlert(alertId)` - Returns an specific alert.\n* `readCollections()` - Returns available collections.\n* `readCollection(id)` - Returns a collection by ID.\n* `readRoutes()` - Returns available routes.\n* `readRoute(id)` - Returns a route by ID.\n* `readVariants()` - Returns available route variants.\n* `readVariant(id)` - Returns a route variant by ID.\n* `readCustomRouteVariants()` - Returns current custom route variants of the current collection.\n* `useRouteVariant(id)` - Sets a custom route variant to be used by current collection.\n* `restoreRouteVariants()` - Restore route variants to those defined in current collection.\n* `configClient(clientConfig)` - Changes the client configuration.\n * `clientConfig` _`<Object>`_ - It should be an object containing any of next properties:\n * `port` - Changes the client port. \n * `host` - Changes the client host.\n\n## Configuration\n\nBy default, clients are configured to request to `http://127.0.0.1:3110/api`, based in the [default options of Mocks Server Plugin Admin API](https://www.mocks-server.org/docs/configuration/options)\n\nYou can change both the the host and port of the administration API using the `configClient` method:\n\n```js\n\nimport { AdminApiClient } from \"@mocks-server/admin-api-client\";\n\nconst apiClient = new AdminApiClient();\napiClient.configClient({\n host: \"localhost\",\n port: 3500\n});\n```\n\n## Release notes\n\n* Due to backward compatibility reasons, the package also creates a default `AdminApiClient` automatically and exports all of its methods as functions available at first level. Usage of these \"global\" functions is discouraged, as they will be removed in next major version. \n* Current major release is compatible only with `@mocks-server/main` versions upper or equal than `3.6`. Use prior releases for lower versions. If you don't want to update to the latest major version of this package yet but you want to update `@mocks-server/main`, you can also use any `5.x` version of this package with any `@mocks-server/main@3.x` version.\n\n## Contributing\n\nContributors are welcome.\nPlease read the [contributing guidelines](.github/CONTRIBUTING.md) and [code of conduct](.github/CODE_OF_CONDUCT.md).\n\n[plugin-admin-api-url]: https://github.com/mocks-server/main/blob/master/packages/admin-api-client\n"
}

@@ -20,3 +20,3 @@ <p align="center"><a href="https://mocks-server.org" target="_blank" rel="noopener noreferrer"><img width="120" src="https://www.mocks-server.org/img/logo_120.png" alt="Mocks Server logo"></a></p>

## Install
## Installation

@@ -27,3 +27,3 @@ ```bash

The UMD build is also available on unpkg. When UMD package is loaded, it creates a `mocksServerAdminApiClient` global object containing all of the methods.
The UMD build is also available on unpkg. When UMD package is loaded, it creates a `mocksServerAdminApiClient` global object containing all methods and classes.

@@ -35,19 +35,21 @@ ```html

> The umd distribution is bundled with the `cross-env` dependency, but requires the `@mocks-server/admin-api-paths` dependency to be added separately.
> NOTE: The umd distribution is bundled with the `cross-fetch` dependency, but it requires the `@mocks-server/admin-api-paths` dependency to be added separately.
## Usage
All methods described in the [Api](#api) return Promises when executed (except the `configClient` method):
Import and create a new `AdminApiClient` class. All methods described in the [Api](#api) return Promises when executed (except the `configClient` method):
```js
import { readAbout, readConfig, updateConfig } from "@mocks-server/admin-api-client";
import { AdminApiClient } from "@mocks-server/admin-api-client";
const example = async () => {
const { version } = await readAbout();
const adminApiClient = new AdminApiClient();
const { version } = await adminApiClient.readAbout();
console.log(`Current Admin API plugin version is ${versions.adminApi}`);
const currentConfig = await readConfig();
const currentConfig = await adminApiClient.readConfig();
console.log("Current Mocks Server config is", JSON.stringify(currentConfig));
await updateConfig({
await adminApiClient.updateConfig({
mock: {

@@ -70,2 +72,6 @@ collections: {

### new AdminApiClient()
Returns an instance containing next methods:
* `readAbout()` - Returns info about the Admin API plugin, such as current version.

@@ -85,13 +91,19 @@ * `readConfig()` - Returns current configuration.

* `restoreRouteVariants()` - Restore route variants to those defined in current collection.
* `configClient(clientConfig)` - Changes the client configuration.
* `clientConfig` _`<Object>`_ - It should be an object containing any of next properties:
* `port` - Changes the client port.
* `host` - Changes the client host.
## Configuration
By default, the client is configured to request to `http://127.0.0.1:3110/api`, based in the [default options of Mocks Server](https://www.mocks-server.org/docs/configuration/options)
By default, clients are configured to request to `http://127.0.0.1:3110/api`, based in the [default options of Mocks Server Plugin Admin API](https://www.mocks-server.org/docs/configuration/options)
You can change both the the host and port of the administration API:
You can change both the the host and port of the administration API using the `configClient` method:
```js
import { configClient } from "@mocks-server/admin-api-client";
configClient({
import { AdminApiClient } from "@mocks-server/admin-api-client";
const apiClient = new AdminApiClient();
apiClient.configClient({
host: "localhost",

@@ -104,3 +116,4 @@ port: 3500

Current major release is compatible only with `@mocks-server/main` versions upper or equal than `3.6`. Use prior releases for lower versions. If you don't want to update to the latest major version of this package yet but you want to update `@mocks-server/main`, you can also use any `5.x` version of this package with any `@mocks-server/main@3.x` version.
* Due to backward compatibility reasons, the package also creates a default `AdminApiClient` automatically and exports all of its methods as functions available at first level. Usage of these "global" functions is discouraged, as they will be removed in next major version.
* Current major release is compatible only with `@mocks-server/main` versions upper or equal than `3.6`. Use prior releases for lower versions. If you don't want to update to the latest major version of this package yet but you want to update `@mocks-server/main`, you can also use any `5.x` version of this package with any `@mocks-server/main@3.x` version.

@@ -107,0 +120,0 @@ ## Contributing

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc