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 4.0.1 to 5.0.0

28

dist/index.cjs.js

@@ -191,13 +191,4 @@ 'use strict';

};
var mockCustomRoutesVariants = new Fetcher(adminApiPaths.MOCK_CUSTOM_ROUTES_VARIANTS); // legacy methods
var mockCustomRoutesVariants = new Fetcher(adminApiPaths.MOCK_CUSTOM_ROUTES_VARIANTS);
var behaviors = new Fetcher("".concat(adminApiPaths.LEGACY, "/").concat(adminApiPaths.BEHAVIORS));
var behavior = function behavior(name) {
return new Fetcher("".concat(adminApiPaths.LEGACY, "/").concat(adminApiPaths.BEHAVIORS), name);
};
var fixtures = new Fetcher("".concat(adminApiPaths.LEGACY, "/").concat(adminApiPaths.FIXTURES));
var fixture = function fixture(id) {
return new Fetcher("".concat(adminApiPaths.LEGACY, "/").concat(adminApiPaths.FIXTURES), id);
};
function readAbout() {

@@ -246,16 +237,3 @@ return about.read();

return mockCustomRoutesVariants["delete"]();
} // legacy
function readBehaviors() {
return behaviors.read();
}
function readBehavior(name) {
return behavior(name).read();
}
function readFixtures() {
return fixtures.read();
}
function readFixture(id) {
return fixture(id).read();
}

@@ -266,7 +244,3 @@ exports.config = config;

exports.readAlerts = readAlerts;
exports.readBehavior = readBehavior;
exports.readBehaviors = readBehaviors;
exports.readCustomRoutesVariants = readCustomRoutesVariants;
exports.readFixture = readFixture;
exports.readFixtures = readFixtures;
exports.readMock = readMock;

@@ -273,0 +247,0 @@ exports.readMocks = readMocks;

import fetch from 'cross-fetch';
import { ABOUT, SETTINGS, ALERTS, MOCKS, ROUTES, ROUTES_VARIANTS, MOCK_CUSTOM_ROUTES_VARIANTS, LEGACY, BEHAVIORS, FIXTURES, DEFAULT_BASE_PATH } from '@mocks-server/admin-api-paths';
import { ABOUT, SETTINGS, ALERTS, MOCKS, ROUTES, ROUTES_VARIANTS, MOCK_CUSTOM_ROUTES_VARIANTS, DEFAULT_BASE_PATH } from '@mocks-server/admin-api-paths';

@@ -183,13 +183,4 @@ function ownKeys(object, enumerableOnly) {

};
var mockCustomRoutesVariants = new Fetcher(MOCK_CUSTOM_ROUTES_VARIANTS); // legacy methods
var mockCustomRoutesVariants = new Fetcher(MOCK_CUSTOM_ROUTES_VARIANTS);
var behaviors = new Fetcher("".concat(LEGACY, "/").concat(BEHAVIORS));
var behavior = function behavior(name) {
return new Fetcher("".concat(LEGACY, "/").concat(BEHAVIORS), name);
};
var fixtures = new Fetcher("".concat(LEGACY, "/").concat(FIXTURES));
var fixture = function fixture(id) {
return new Fetcher("".concat(LEGACY, "/").concat(FIXTURES), id);
};
function readAbout() {

@@ -238,17 +229,4 @@ return about.read();

return mockCustomRoutesVariants["delete"]();
} // legacy
function readBehaviors() {
return behaviors.read();
}
function readBehavior(name) {
return behavior(name).read();
}
function readFixtures() {
return fixtures.read();
}
function readFixture(id) {
return fixture(id).read();
}
export { config, readAbout, readAlert, readAlerts, readBehavior, readBehaviors, readCustomRoutesVariants, readFixture, readFixtures, readMock, readMocks, readRoute, readRouteVariant, readRoutes, readRoutesVariants, readSettings, restoreRoutesVariants, updateSettings, useRouteVariant };
export { config, readAbout, readAlert, readAlerts, readCustomRoutesVariants, readMock, readMocks, readRoute, readRouteVariant, readRoutes, readRoutesVariants, readSettings, restoreRoutesVariants, updateSettings, useRouteVariant };

2

dist/index.umd.js

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

!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";function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function o(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function a(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var u={exports:{}};!function(e,t){var r="undefined"!=typeof self?self:s,n=function(){function e(){this.fetch=!1,this.DOMException=r.DOMException}return e.prototype=r,new e}();!function(e){!function(t){var r="URLSearchParams"in e,n="Symbol"in e&&"iterator"in Symbol,o="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),i="FormData"in e,s="ArrayBuffer"in e;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(e){return e&&a.indexOf(Object.prototype.toString.call(e))>-1};function c(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 f(e){return"string"!=typeof e&&(e=String(e)),e}function d(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function h(e){this.map={},e instanceof h?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 p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function l(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function y(e){var t=new FileReader,r=l(t);return t.readAsArrayBuffer(e),r}function b(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function w(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:o&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:i&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():s&&o&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=b(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(e)||u(e))?this._bodyArrayBuffer=b(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"))},o&&(this.blob=function(){var e=p(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?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var e,t,r,n=p(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=l(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[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(E)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(e,t){e=c(e),t=f(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},h.prototype.delete=function(e){delete this.map[c(e)]},h.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},h.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},h.prototype.set=function(e,t){this.map[c(e)]=f(t)},h.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},h.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),d(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),d(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),d(e)},n&&(h.prototype[Symbol.iterator]=h.prototype.entries);var m=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var r,n,o=(t=t||{}).body;if(e instanceof v){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new h(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,o||null==e._bodyInit||(o=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 h(t.headers)),this.method=(r=t.method||this.method||"GET",n=r.toUpperCase(),m.indexOf(n)>-1?n:r),this.mode=t.mode||this.mode||null,this.signal=t.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 E(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(o))}})),t}function O(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 h(t.headers),this.url=t.url||"",this._initBody(e)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},w.call(v.prototype),w.call(O.prototype),O.prototype.clone=function(){return new O(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},O.error=function(){var e=new O(null,{status:0,statusText:""});return e.type="error",e};var A=[301,302,303,307,308];O.redirect=function(e,t){if(-1===A.indexOf(t))throw new RangeError("Invalid status code");return new O(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 _(e,r){return new Promise((function(n,i){var s=new v(e,r);if(s.signal&&s.signal.aborted)return i(new t.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var e,t,r={status:a.status,statusText:a.statusText,headers:(e=a.getAllResponseHeaders()||"",t=new h,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var r=e.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();t.append(n,o)}})),t)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;n(new O(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 t.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(e,t){a.setRequestHeader(t,e)})),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)}))}_.polyfill=!0,e.fetch||(e.fetch=_,e.Headers=h,e.Request=v,e.Response=O),t.Headers=h,t.Request=v,t.Response=O,t.fetch=_,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}(u,u.exports);var c=a(u.exports),f=n({},{adminApiPath:t.DEFAULT_BASE_PATH,baseUrl:"http://127.0.0.1:3100"});function d(e){return e.status>199&&e.status<300?e.json().catch((function(){return Promise.resolve()})):e.json().then((function(e){return Promise.reject(new Error(e.message))}))}var h=function(){function e(t,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._url=t,this._id=r?"/".concat(encodeURIComponent(r)):""}var t,r,n;return t=e,(r=[{key:"url",get:function(){return"".concat(f.baseUrl).concat(f.adminApiPath).concat(this._url).concat(this._id)}},{key:"_read",value:function(){return c(this.url).then(d)}},{key:"_patch",value:function(e){return c(this.url,{method:"PATCH",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}}).then(d)}},{key:"_delete",value:function(){return c(this.url,{method:"DELETE"}).then(d)}},{key:"_create",value:function(e){return c(this.url,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}}).then(d)}},{key:"read",value:function(){return this._read()}},{key:"update",value:function(e){return this._patch(e)}},{key:"delete",value:function(){return this._delete()}},{key:"create",value:function(e){return this._create(e)}}])&&o(t.prototype,r),n&&o(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}(),p=new h(t.ABOUT),l=new h(t.SETTINGS),y=new h(t.ALERTS),b=new h(t.MOCKS),w=new h(t.ROUTES),m=new h(t.ROUTES_VARIANTS),v=new h(t.MOCK_CUSTOM_ROUTES_VARIANTS),E=new h("".concat(t.LEGACY,"/").concat(t.BEHAVIORS)),O=new h("".concat(t.LEGACY,"/").concat(t.FIXTURES));e.config=function(e){f=n(n({},f),e)},e.readAbout=function(){return p.read()},e.readAlert=function(e){return function(e){return new h(t.ALERTS,e)}(e).read()},e.readAlerts=function(){return y.read()},e.readBehavior=function(e){return function(e){return new h("".concat(t.LEGACY,"/").concat(t.BEHAVIORS),e)}(e).read()},e.readBehaviors=function(){return E.read()},e.readCustomRoutesVariants=function(){return v.read()},e.readFixture=function(e){return function(e){return new h("".concat(t.LEGACY,"/").concat(t.FIXTURES),e)}(e).read()},e.readFixtures=function(){return O.read()},e.readMock=function(e){return function(e){return new h(t.MOCKS,e)}(e).read()},e.readMocks=function(){return b.read()},e.readRoute=function(e){return function(e){return new h(t.ROUTES,e)}(e).read()},e.readRouteVariant=function(e){return function(e){return new h(t.ROUTES_VARIANTS,e)}(e).read()},e.readRoutes=function(){return w.read()},e.readRoutesVariants=function(){return m.read()},e.readSettings=function(){return l.read()},e.restoreRoutesVariants=function(){return v.delete()},e.updateSettings=function(e){return l.update(e)},e.useRouteVariant=function(e){return v.create({id:e})},Object.defineProperty(e,"__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";function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function o(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function a(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var u={exports:{}};!function(e,t){var r="undefined"!=typeof self?self:s,n=function(){function e(){this.fetch=!1,this.DOMException=r.DOMException}return e.prototype=r,new e}();!function(e){!function(t){var r="URLSearchParams"in e,n="Symbol"in e&&"iterator"in Symbol,o="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),i="FormData"in e,s="ArrayBuffer"in e;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(e){return e&&a.indexOf(Object.prototype.toString.call(e))>-1};function c(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 f(e){return"string"!=typeof e&&(e=String(e)),e}function d(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function h(e){this.map={},e instanceof h?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 p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function l(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function y(e){var t=new FileReader,r=l(t);return t.readAsArrayBuffer(e),r}function b(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:o&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:i&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():s&&o&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=b(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(e)||u(e))?this._bodyArrayBuffer=b(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"))},o&&(this.blob=function(){var e=p(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?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var e,t,r,n=p(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=l(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[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(e,t){e=c(e),t=f(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},h.prototype.delete=function(e){delete this.map[c(e)]},h.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},h.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},h.prototype.set=function(e,t){this.map[c(e)]=f(t)},h.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},h.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),d(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),d(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),d(e)},n&&(h.prototype[Symbol.iterator]=h.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var r,n,o=(t=t||{}).body;if(e instanceof v){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new h(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,o||null==e._bodyInit||(o=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 h(t.headers)),this.method=(r=t.method||this.method||"GET",n=r.toUpperCase(),w.indexOf(n)>-1?n:r),this.mode=t.mode||this.mode||null,this.signal=t.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(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(o))}})),t}function E(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 h(t.headers),this.url=t.url||"",this._initBody(e)}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 e=new E(null,{status:0,statusText:""});return e.type="error",e};var _=[301,302,303,307,308];E.redirect=function(e,t){if(-1===_.indexOf(t))throw new RangeError("Invalid status code");return new E(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 A(e,r){return new Promise((function(n,i){var s=new v(e,r);if(s.signal&&s.signal.aborted)return i(new t.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var e,t,r={status:a.status,statusText:a.statusText,headers:(e=a.getAllResponseHeaders()||"",t=new h,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var r=e.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();t.append(n,o)}})),t)};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 t.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(e,t){a.setRequestHeader(t,e)})),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,e.fetch||(e.fetch=A,e.Headers=h,e.Request=v,e.Response=E),t.Headers=h,t.Request=v,t.Response=E,t.fetch=A,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}(u,u.exports);var c=a(u.exports),f=n({},{adminApiPath:t.DEFAULT_BASE_PATH,baseUrl:"http://127.0.0.1:3100"});function d(e){return e.status>199&&e.status<300?e.json().catch((function(){return Promise.resolve()})):e.json().then((function(e){return Promise.reject(new Error(e.message))}))}var h=function(){function e(t,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._url=t,this._id=r?"/".concat(encodeURIComponent(r)):""}var t,r,n;return t=e,(r=[{key:"url",get:function(){return"".concat(f.baseUrl).concat(f.adminApiPath).concat(this._url).concat(this._id)}},{key:"_read",value:function(){return c(this.url).then(d)}},{key:"_patch",value:function(e){return c(this.url,{method:"PATCH",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}}).then(d)}},{key:"_delete",value:function(){return c(this.url,{method:"DELETE"}).then(d)}},{key:"_create",value:function(e){return c(this.url,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}}).then(d)}},{key:"read",value:function(){return this._read()}},{key:"update",value:function(e){return this._patch(e)}},{key:"delete",value:function(){return this._delete()}},{key:"create",value:function(e){return this._create(e)}}])&&o(t.prototype,r),n&&o(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}(),p=new h(t.ABOUT),l=new h(t.SETTINGS),y=new h(t.ALERTS),b=new h(t.MOCKS),m=new h(t.ROUTES),w=new h(t.ROUTES_VARIANTS),v=new h(t.MOCK_CUSTOM_ROUTES_VARIANTS);e.config=function(e){f=n(n({},f),e)},e.readAbout=function(){return p.read()},e.readAlert=function(e){return function(e){return new h(t.ALERTS,e)}(e).read()},e.readAlerts=function(){return y.read()},e.readCustomRoutesVariants=function(){return v.read()},e.readMock=function(e){return function(e){return new h(t.MOCKS,e)}(e).read()},e.readMocks=function(){return b.read()},e.readRoute=function(e){return function(e){return new h(t.ROUTES,e)}(e).read()},e.readRouteVariant=function(e){return function(e){return new h(t.ROUTES_VARIANTS,e)}(e).read()},e.readRoutes=function(){return m.read()},e.readRoutesVariants=function(){return w.read()},e.readSettings=function(){return l.read()},e.restoreRoutesVariants=function(){return v.delete()},e.updateSettings=function(e){return l.update(e)},e.useRouteVariant=function(e){return v.create({id:e})},Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "@mocks-server/admin-api-client",
"version": "4.0.1",
"version": "5.0.0",
"description": "Client of @mocks-server/plugin-admin-api",

@@ -16,3 +16,7 @@ "keywords": [

"license": "MIT",
"repository": "https://github.com/mocks-server/main",
"repository": {
"type": "git",
"url": "https://github.com/mocks-server/main.git",
"directory": "packages/admin-api-client"
},
"homepage": "https://www.mocks-server.org",

@@ -25,10 +29,10 @@ "publishConfig": {

],
"main": "dist/index.umd.js",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"dependencies": {
"@mocks-server/admin-api-paths": "2.2.1",
"@mocks-server/admin-api-paths": "3.0.0",
"cross-fetch": "3.1.5"
},
"engines": {
"node": ">=12.0.0"
"node": ">=14.0.0"
},

@@ -41,3 +45,3 @@ "scripts": {

},
"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 contains methods for administrating Mocks Server _(using the [Admin API plugin](https://github.com/mocks-server/plugin-admin-api) under the hood)_.\n\nRequests to the Mocks Server API are made using [`cross-fetch`](https://www.npmjs.com/package/cross-fetch), which makes this package compatible with browsers and nodejs 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:\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) (except the `config` method) return Promises when executed:\n\n```js\nimport { readAbout, readSettings, updateSettings } from \"@mocks-server/admin-api-client\";\n\nconst example = async () => {\n const { version } = await readAbout();\n console.log(`Current Admin API plugin version is ${version}`);\n\n const currentSettings = await readSettings();\n console.log(\"Current Mocks Server settings are\", currentSettings);\n\n await updateSettings({\n mock: \"user-super-admin\",\n delay: 1000\n });\n console.log(\"Mock 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* `readSettings()` - Returns current Mocks Server settings.\n* `updateSettings(settingsObject)` - Updates Mocks Server settings. A settings 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* `readMocks()` - Returns available mocks.\n* `readMock(id)` - Returns data of a specific mock.\n* `readRoutes()` - Returns available routes.\n* `readRoute(id)` - Returns data of a specific route.\n* `readRoutesVariants()` - Returns available routes variants.\n* `readRouteVariant(id)` - Returns data of a specific route variant.\n* `readCustomRoutesVariants()` - Returns current routes variants manually added to current mock.\n* `useRouteVariant(id)` - Sets a specific route variant to be used by current mock.\n* `restoreRoutesVariants()` - Restore routes variants to those defined in current mock.\n\n##### Legacy methods\n\n* `readBehaviors()` - Returns collection of available behaviors.\n* `readBehavior(behaviorName)` - Returns an specific behavior.\n* `readFixtures()` - Returns collection of available fixtures.\n* `readFixture(fixtureId)` - Returns an specific fixture.\n\n## Configuration\n\nBy default, the client is configured to request to `http://127.0.0.1:3100/admin`, based in the [default options of Mocks Server](https://www.mocks-server.org/docs/configuration-options)\n\nYou can change both the base url of Mocks Server, and the path of the [Admin API plugin][plugin-admin-api-url] using the `config` method:\n\n```js\nimport { config } from \"@mocks-server/admin-api-client\";\n\nconfig({\n adminApiPath: \"/foo-admin\",\n baseUrl: \"http://my-mocks-server:3000\"\n});\n```\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/plugin-admin-api\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 _(it performs requests to the [Admin API plugin][plugin-admin-api-url] under the hood)_.\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) (except the `config` method) return Promises when executed:\n\n```js\nimport { readAbout, readSettings, updateSettings } from \"@mocks-server/admin-api-client\";\n\nconst example = async () => {\n const { version } = await readAbout();\n console.log(`Current Admin API plugin version is ${version}`);\n\n const currentSettings = await readSettings();\n console.log(\"Current Mocks Server settings are\", currentSettings);\n\n await updateSettings({\n mock: \"user-super-admin\",\n delay: 1000\n });\n console.log(\"Mock 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* `readSettings()` - Returns current Mocks Server settings.\n* `updateSettings(settingsObject)` - Updates Mocks Server settings. A settings 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* `readMocks()` - Returns available mocks.\n* `readMock(id)` - Returns data of a specific mock.\n* `readRoutes()` - Returns available routes.\n* `readRoute(id)` - Returns data of a specific route.\n* `readRoutesVariants()` - Returns available routes variants.\n* `readRouteVariant(id)` - Returns data of a specific route variant.\n* `readCustomRoutesVariants()` - Returns current routes variants manually added to current mock.\n* `useRouteVariant(id)` - Sets a specific route variant to be used by current mock.\n* `restoreRoutesVariants()` - Restore routes variants to those defined in current mock.\n\n## Configuration\n\nBy default, the client is configured to request to `http://127.0.0.1:3100/admin`, based in the [default options of Mocks Server](https://www.mocks-server.org/docs/configuration-options)\n\nYou can change both the base url of Mocks Server, and the path of the [Admin API plugin][plugin-admin-api-url] using the `config` method:\n\n```js\nimport { config } from \"@mocks-server/admin-api-client\";\n\nconfig({\n adminApiPath: \"/foo-admin\",\n baseUrl: \"http://my-mocks-server:3000\"\n});\n```\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/plugin-admin-api\n"
}

@@ -16,5 +16,5 @@ <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>

This package contains methods for administrating Mocks Server _(using the [Admin API plugin](https://github.com/mocks-server/plugin-admin-api) under the hood)_.
This package provides an API client for administrating Mocks Server _(it performs requests to the [Admin API plugin][plugin-admin-api-url] under the hood)_.
Requests to the Mocks Server API are made using [`cross-fetch`](https://www.npmjs.com/package/cross-fetch), which makes this package compatible with browsers and nodejs 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.
Requests 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.

@@ -27,3 +27,3 @@ ## Install

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

@@ -78,9 +78,2 @@ ```html

##### Legacy methods
* `readBehaviors()` - Returns collection of available behaviors.
* `readBehavior(behaviorName)` - Returns an specific behavior.
* `readFixtures()` - Returns collection of available fixtures.
* `readFixture(fixtureId)` - Returns an specific fixture.
## Configuration

@@ -87,0 +80,0 @@

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