Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

meepojs

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

meepojs - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

2

index.js

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

"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r}function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)}Object.defineProperty(exports,"__esModule",{value:!0});var ApiError=function(e){function t(e,r){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"ApiGeneratorErrorCode: "+e+". Message: "+r))}return _inherits(t,Error),t}(),errMsg={TYPE_ERROR:function(e,r){return new ApiError(100,"Param type error, expect type `"+r+"` but got value "+e)},PARAM_NOT_FOUND:function(e){return new ApiError(101,"Param `"+e+"` is required but not found.")},TIME_OUT:function(e){return new ApiError(102,"API `"+e+"` time out")},HTTP_ERROR:function(e,r){return new ApiError(103,"API `"+r.name+"` - HTTP error, status: "+e+".")},API_ERROR:function(e,r,t){return new ApiError(104,"API `"+t.name+"` - API error, status: "+r)}},validators={null:function(e){return null===e},string:function(e){return"string"==typeof e},number:function(e){return"number"==typeof e},boolean:function(e){return"boolean"==typeof e},object:function(e){return e.constructor===Object},array:function(e){return Array.isArray(e)}},checkParam=function(e,r){if(validators[r](e))return e;throw errMsg.TYPE_ERROR(e,r)},checkParams=function(e,r){if(!r)return null;for(var t={},n=Object.keys(r),o=0;o<n.length;++o){var i=n[o],a=i;if("?"!==i[i.length-1]){if(void 0===e[i])throw new Error(errMsg.PARAM_NOT_FOUND(i))}else if(void 0===e[a=i.substr(0,i.length-1)])continue;t[a]=checkParam(e[a],r[i])}return t},isHttpErrorStatus=function(e){return(""+e).startsWith("4")||(""+e).startsWith("5")},makeUrl=function(e,r,t){var n=e;if(t)for(var o in t)n=n.replace(":"+o,t[o]);return r&&(n+="?"+new URLSearchParams(r).toString()),n},makeApi=function(e){var C=e.apiConfig,r=e.handlers,w=r.apiSuccChecker,_=r.httpErrorHandler,T=r.apiErrorHandler,j=r.timeoutHandler,k=r.requestParamsPreprocessor,x=r.beforeRequestHandler,S=r.beforeResolveBodyHandler,t=r.apiRejectedHandler;return function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},O=e.body,E=e.query,P=e.params,v=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},H=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return new Promise(function(t,n){var e=C.url,r=C.needs,o=Object.assign({},C.meta,v),i=Object.assign({},C.options,H),a=i.cache,s=i.credentials,u=i.headers,c=i.method,p=i.mode,f=i.redirect,l=i.referrer,d=i.timeout,h=i.dataType,m=i.prefix,g=setTimeout(function(){return n(j({apiConfig:C}))},d);k&&k({body:O,params:P,query:E},o),checkParams(Object.assign({},O,P,E),r);var b=void 0,y={},R={cache:a,credentials:s,method:c,mode:p,redirect:f,referrer:l},A=O;if(A){switch(h){case"URLSearchParams":A=new URLSearchParams(A),y["content-type"]="application/x-www-form-urlencoded";break;case"FormData":A=new window.FormData(A),y["content-type"]="multipart/form-data";break;case"JSON":A=JSON.stringify(A),y["content-type"]="application/json"}R.body=A}a&&(y["Cache-Control"]=a),R.headers=Object.assign(y,u),x&&x({body:O,query:E,params:P},o),window.fetch(makeUrl(m+e,E,P),R).then(function(e){switch(g&&clearTimeout(g),b=e.status){case 200:return e.json();case 204:default:return null}}).then(function(e){if(isHttpErrorStatus(b))n(_({body:e,status:b,apiConfig:overridedApiConfig}));else{var r=Object.assign({},C,{meta:o},{options:i});w({body:e,status:b,apiConfig:r})?t(S?S(e,o):e):n(T({body:e,status:b,apiConfig:r}))}})}).catch(t)}},defaultFetchOptions={credentials:"omit",headers:{},method:"GET",mode:"cors",redirect:"follow",referrer:"client",timeout:5e3,prefix:"",dataType:"JSON"},defaultApiSuccChecker=function(e){var r=e.body,t=e.status;e.apiConfig;return 204===t||200===t&&null!==r&&0===r.error_code},defaultHttpErrorHandler=function(e){var r=e.status,t=e.apiConfig;return errMsg.HTTP_ERROR(r,t)},defaultApiErrorHandler=function(e){var r=e.body,t=e.status,n=e.apiConfig;return errMsg.API_ERROR(r,t,n)},defaultTimeoutHandler=function(e){var r=e.apiConfig;return errMsg.TIME_OUT(r.name)},defaultHandlers={apiSuccChecker:defaultApiSuccChecker,httpErrorHandler:defaultHttpErrorHandler,apiErrorHandler:defaultApiErrorHandler,timeoutHandler:defaultTimeoutHandler},handlers=defaultHandlers,fetchOptions=defaultFetchOptions,apis={},registerApi=function(e){var r=e.name,t=e.url,n=e.options,o=e.needs,i=e.meta,a={name:r,url:t,options:Object.assign({},fetchOptions,n),needs:o,meta:i};return apis[r]=makeApi({apiConfig:a,handlers:handlers}),apis[r].runWith=function(e){return makeApi({apiConfig:a,handlers:Object.assign({},handlers,e)})},apis[r]},registerApis=function(e){var r={};for(var t in e)r[t]=registerApi(e[t]);return r},configDefaultFetchOptions=function(e){fetchOptions=Object.assign({},fetchOptions,e)},registerApiSuccChecker=function(e){handlers.apiSuccChecker=e},onTimeout=function(e){handlers.timeoutHandler=e},onHttpError=function(e){handlers.httpErrorHandler=e},onApiError=function(e){handlers.apiErrorHandler=e},registerRequestParamsPreprocessor=function(e){handlers.requestParamsPreprocessor=e},beforeRequest=function(e){handlers.beforeRequestHandler=e},beforeResolveBody=function(e){handlers.beforeResolveBodyHandler=e},onApiRejected=function(e){handlers.apiRejectedHandler=e};exports.apis=apis,exports.registerApi=registerApi,exports.registerApis=registerApis,exports.configDefaultFetchOptions=configDefaultFetchOptions,exports.registerApiSuccChecker=registerApiSuccChecker,exports.onTimeout=onTimeout,exports.onHttpError=onHttpError,exports.onApiError=onApiError,exports.registerRequestParamsPreprocessor=registerRequestParamsPreprocessor,exports.beforeRequest=beforeRequest,exports.beforeResolveBody=beforeResolveBody,exports.onApiRejected=onApiRejected;
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var fetch=_interopDefault(require("isomorphic-unfetch"));function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r}function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)}var ApiError=function(e){function t(e,r){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"ApiGeneratorErrorCode: "+e+". Message: "+r))}return _inherits(t,Error),t}(),errMsg={TYPE_ERROR:function(e,r){return new ApiError(100,"Param type error, expect type `"+r+"` but got value "+e)},PARAM_NOT_FOUND:function(e){return new ApiError(101,"Param `"+e+"` is required but not found.")},TIME_OUT:function(e){return new ApiError(102,"API `"+e+"` time out")},HTTP_ERROR:function(e,r){return new ApiError(103,"API `"+r.name+"` - HTTP error, status: "+e+".")},API_ERROR:function(e,r,t){return new ApiError(104,"API `"+t.name+"` - API error, status: "+r)}},validators={null:function(e){return null===e},string:function(e){return"string"==typeof e},number:function(e){return"number"==typeof e},boolean:function(e){return"boolean"==typeof e},object:function(e){return e.constructor===Object},array:function(e){return Array.isArray(e)}},checkParam=function(e,r){if(validators[r](e))return e;throw errMsg.TYPE_ERROR(e,r)},checkParams=function(e,r){if(!r)return null;for(var t={},n=Object.keys(r),o=0;o<n.length;++o){var i=n[o],a=i;if("?"!==i[i.length-1]){if(void 0===e[i])throw new Error(errMsg.PARAM_NOT_FOUND(i))}else if(void 0===e[a=i.substr(0,i.length-1)])continue;t[a]=checkParam(e[a],r[i])}return t},isHttpErrorStatus=function(e){return(""+e).startsWith("4")||(""+e).startsWith("5")},makeUrl=function(e,r,t){var n=e;if(t)for(var o in t)n=n.replace(":"+o,t[o]);return r&&(n+="?"+new URLSearchParams(r).toString()),n},makeApi=function(e){var _=e.apiConfig,r=e.handlers,C=r.apiSuccChecker,w=r.httpErrorHandler,T=r.apiErrorHandler,j=r.timeoutHandler,k=r.requestParamsPreprocessor,x=r.beforeRequestHandler,S=r.beforeResolveBodyHandler,t=r.apiRejectedHandler;return function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},O=e.body,E=e.query,P=e.params,v=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},H=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return new Promise(function(t,n){var e=_.url,r=_.needs,o=Object.assign({},_.meta,v),i=Object.assign({},_.options,H),a=i.cache,s=i.credentials,u=i.headers,c=i.method,p=i.mode,f=i.redirect,l=i.referrer,d=i.timeout,h=i.dataType,m=i.prefix,g=setTimeout(function(){return n(j({apiConfig:_}))},d);k&&k({body:O,params:P,query:E},o),checkParams(Object.assign({},O,P,E),r);var b=void 0,y={},R={cache:a,credentials:s,method:c,mode:p,redirect:f,referrer:l},A=O;if(A){switch(h){case"URLSearchParams":A=new URLSearchParams(A),y["content-type"]="application/x-www-form-urlencoded";break;case"FormData":A=new window.FormData(A),y["content-type"]="multipart/form-data";break;case"JSON":A=JSON.stringify(A),y["content-type"]="application/json"}R.body=A}a&&(y["Cache-Control"]=a),R.headers=Object.assign(y,u),x&&x({body:O,query:E,params:P},o),fetch(makeUrl(m+e,E,P),R).then(function(e){switch(g&&clearTimeout(g),b=e.status){case 200:return e.json();case 204:default:return null}}).then(function(e){var r=Object.assign({},_,{meta:o},{options:i});isHttpErrorStatus(b)?n(w({body:e,status:b,apiConfig:r})):C({body:e,status:b,apiConfig:r})?t(S?S(e,o):e):n(T({body:e,status:b,apiConfig:r}))})}).catch(t)}},defaultFetchOptions={credentials:"omit",headers:{},method:"GET",mode:"cors",redirect:"follow",referrer:"client",timeout:5e3,prefix:"",dataType:"JSON"},defaultApiSuccChecker=function(e){var r=e.body,t=e.status;e.apiConfig;return 204===t||200===t&&null!==r&&0===r.error_code},defaultHttpErrorHandler=function(e){var r=e.status,t=e.apiConfig;return errMsg.HTTP_ERROR(r,t)},defaultApiErrorHandler=function(e){var r=e.body,t=e.status,n=e.apiConfig;return errMsg.API_ERROR(r,t,n)},defaultTimeoutHandler=function(e){var r=e.apiConfig;return errMsg.TIME_OUT(r.name)},defaultHandlers={apiSuccChecker:defaultApiSuccChecker,httpErrorHandler:defaultHttpErrorHandler,apiErrorHandler:defaultApiErrorHandler,timeoutHandler:defaultTimeoutHandler},handlers=defaultHandlers,fetchOptions=defaultFetchOptions,apis={},registerApi=function(e){var r=e.name,t=e.url,n=e.options,o=e.needs,i=e.meta,a={name:r,url:t,options:Object.assign({},fetchOptions,n),needs:o,meta:i};return apis[r]=makeApi({apiConfig:a,handlers:handlers}),apis[r].runWith=function(e){return makeApi({apiConfig:a,handlers:Object.assign({},handlers,e)})},apis[r]},registerApis=function(e){var r={};for(var t in e)r[t]=registerApi(e[t]);return r},configDefaultFetchOptions=function(e){fetchOptions=Object.assign({},fetchOptions,e)},registerApiSuccChecker=function(e){handlers.apiSuccChecker=e},onTimeout=function(e){handlers.timeoutHandler=e},onHttpError=function(e){handlers.httpErrorHandler=e},onApiError=function(e){handlers.apiErrorHandler=e},registerRequestParamsPreprocessor=function(e){handlers.requestParamsPreprocessor=e},beforeRequest=function(e){handlers.beforeRequestHandler=e},beforeResolveBody=function(e){handlers.beforeResolveBodyHandler=e},onApiRejected=function(e){handlers.apiRejectedHandler=e};exports.apis=apis,exports.registerApi=registerApi,exports.registerApis=registerApis,exports.configDefaultFetchOptions=configDefaultFetchOptions,exports.registerApiSuccChecker=registerApiSuccChecker,exports.onTimeout=onTimeout,exports.onHttpError=onHttpError,exports.onApiError=onApiError,exports.registerRequestParamsPreprocessor=registerRequestParamsPreprocessor,exports.beforeRequest=beforeRequest,exports.beforeResolveBody=beforeResolveBody,exports.onApiRejected=onApiRejected;
{
"name": "meepojs",
"version": "0.2.5",
"version": "0.2.6",
"description": "JavaScript API generator",

@@ -5,0 +5,0 @@ "main": "./lib/meepojs",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc