@merkur/plugin-http-client 0.36.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +10 -3
- package/lib/index.es9.cjs +13 -5
- package/lib/index.es9.mjs +13 -5
- package/lib/index.js +10 -3
- package/lib/index.mjs +10 -3
- package/lib/index.umd.js +1 -1
- package/package.json +3 -3
package/lib/index.cjs
CHANGED
|
@@ -75,7 +75,14 @@ function httpClientAPI() {
|
|
|
75
75
|
);
|
|
76
76
|
|
|
77
77
|
if (!response.ok) {
|
|
78
|
-
|
|
78
|
+
const error = new Error(`${response.statusText}: ${request.url}`, {
|
|
79
|
+
cause: { request, response },
|
|
80
|
+
});
|
|
81
|
+
// keep compatablity
|
|
82
|
+
error.request = request;
|
|
83
|
+
error.response = response;
|
|
84
|
+
|
|
85
|
+
return Promise.reject(error);
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
return { request, response };
|
|
@@ -96,10 +103,10 @@ async function runTransformers(widget, transformers, method, ...rest) {
|
|
|
96
103
|
|
|
97
104
|
function getFetchAPI() {
|
|
98
105
|
if (typeof window === 'undefined') {
|
|
99
|
-
return global
|
|
106
|
+
return global?.fetch;
|
|
100
107
|
}
|
|
101
108
|
|
|
102
|
-
return window
|
|
109
|
+
return window?.fetch?.bind?.(window);
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
function transformQuery() {
|
package/lib/index.es9.cjs
CHANGED
|
@@ -47,10 +47,16 @@ function httpClientAPI() {
|
|
|
47
47
|
response = !response ? await widget.$dependencies.fetch(request.url, request) : response;
|
|
48
48
|
[request, response] = await runTransformers(widget, transformers, 'transformResponse', request, response);
|
|
49
49
|
if (!response.ok) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
const error = new Error(`${response.statusText}: ${request.url}`, {
|
|
51
|
+
cause: {
|
|
52
|
+
request,
|
|
53
|
+
response
|
|
54
|
+
}
|
|
53
55
|
});
|
|
56
|
+
// keep compatablity
|
|
57
|
+
error.request = request;
|
|
58
|
+
error.response = response;
|
|
59
|
+
return Promise.reject(error);
|
|
54
60
|
}
|
|
55
61
|
return {
|
|
56
62
|
request,
|
|
@@ -69,10 +75,12 @@ async function runTransformers(widget, transformers, method, ...rest) {
|
|
|
69
75
|
return rest;
|
|
70
76
|
}
|
|
71
77
|
function getFetchAPI() {
|
|
78
|
+
var _window, _window$bind;
|
|
72
79
|
if (typeof window === 'undefined') {
|
|
73
|
-
|
|
80
|
+
var _global;
|
|
81
|
+
return (_global = global) === null || _global === void 0 ? void 0 : _global.fetch;
|
|
74
82
|
}
|
|
75
|
-
return window.fetch.bind(window);
|
|
83
|
+
return (_window = window) === null || _window === void 0 || (_window = _window.fetch) === null || _window === void 0 || (_window$bind = _window.bind) === null || _window$bind === void 0 ? void 0 : _window$bind.call(_window, window);
|
|
76
84
|
}
|
|
77
85
|
function transformQuery() {
|
|
78
86
|
return {
|
package/lib/index.es9.mjs
CHANGED
|
@@ -45,10 +45,16 @@ function httpClientAPI() {
|
|
|
45
45
|
response = !response ? await widget.$dependencies.fetch(request.url, request) : response;
|
|
46
46
|
[request, response] = await runTransformers(widget, transformers, 'transformResponse', request, response);
|
|
47
47
|
if (!response.ok) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
const error = new Error(`${response.statusText}: ${request.url}`, {
|
|
49
|
+
cause: {
|
|
50
|
+
request,
|
|
51
|
+
response
|
|
52
|
+
}
|
|
51
53
|
});
|
|
54
|
+
// keep compatablity
|
|
55
|
+
error.request = request;
|
|
56
|
+
error.response = response;
|
|
57
|
+
return Promise.reject(error);
|
|
52
58
|
}
|
|
53
59
|
return {
|
|
54
60
|
request,
|
|
@@ -67,10 +73,12 @@ async function runTransformers(widget, transformers, method, ...rest) {
|
|
|
67
73
|
return rest;
|
|
68
74
|
}
|
|
69
75
|
function getFetchAPI() {
|
|
76
|
+
var _window, _window$bind;
|
|
70
77
|
if (typeof window === 'undefined') {
|
|
71
|
-
|
|
78
|
+
var _global;
|
|
79
|
+
return (_global = global) === null || _global === void 0 ? void 0 : _global.fetch;
|
|
72
80
|
}
|
|
73
|
-
return window.fetch.bind(window);
|
|
81
|
+
return (_window = window) === null || _window === void 0 || (_window = _window.fetch) === null || _window === void 0 || (_window$bind = _window.bind) === null || _window$bind === void 0 ? void 0 : _window$bind.call(_window, window);
|
|
74
82
|
}
|
|
75
83
|
function transformQuery() {
|
|
76
84
|
return {
|
package/lib/index.js
CHANGED
|
@@ -75,7 +75,14 @@ function httpClientAPI() {
|
|
|
75
75
|
);
|
|
76
76
|
|
|
77
77
|
if (!response.ok) {
|
|
78
|
-
|
|
78
|
+
const error = new Error(`${response.statusText}: ${request.url}`, {
|
|
79
|
+
cause: { request, response },
|
|
80
|
+
});
|
|
81
|
+
// keep compatablity
|
|
82
|
+
error.request = request;
|
|
83
|
+
error.response = response;
|
|
84
|
+
|
|
85
|
+
return Promise.reject(error);
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
return { request, response };
|
|
@@ -96,10 +103,10 @@ async function runTransformers(widget, transformers, method, ...rest) {
|
|
|
96
103
|
|
|
97
104
|
function getFetchAPI() {
|
|
98
105
|
if (typeof window === 'undefined') {
|
|
99
|
-
return global
|
|
106
|
+
return global?.fetch;
|
|
100
107
|
}
|
|
101
108
|
|
|
102
|
-
return window
|
|
109
|
+
return window?.fetch?.bind?.(window);
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
function transformQuery() {
|
package/lib/index.mjs
CHANGED
|
@@ -73,7 +73,14 @@ function httpClientAPI() {
|
|
|
73
73
|
);
|
|
74
74
|
|
|
75
75
|
if (!response.ok) {
|
|
76
|
-
|
|
76
|
+
const error = new Error(`${response.statusText}: ${request.url}`, {
|
|
77
|
+
cause: { request, response },
|
|
78
|
+
});
|
|
79
|
+
// keep compatablity
|
|
80
|
+
error.request = request;
|
|
81
|
+
error.response = response;
|
|
82
|
+
|
|
83
|
+
return Promise.reject(error);
|
|
77
84
|
}
|
|
78
85
|
|
|
79
86
|
return { request, response };
|
|
@@ -94,10 +101,10 @@ async function runTransformers(widget, transformers, method, ...rest) {
|
|
|
94
101
|
|
|
95
102
|
function getFetchAPI() {
|
|
96
103
|
if (typeof window === 'undefined') {
|
|
97
|
-
return global
|
|
104
|
+
return global?.fetch;
|
|
98
105
|
}
|
|
99
106
|
|
|
100
|
-
return window
|
|
107
|
+
return window?.fetch?.bind?.(window);
|
|
101
108
|
}
|
|
102
109
|
|
|
103
110
|
function transformQuery() {
|
package/lib/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){if("function"==typeof define&&define.amd)define("@merkur/plugin-http-client",["exports","@merkur/core"],e);else if("undefined"!=typeof exports)e(exports,require("@merkur/core"));else{var r={exports:{}};e(r.exports,t.Merkur.Core),t.Merkur=t.Merkur||{},t.Merkur.Plugin=t.Merkur.Plugin||{},t.Merkur.Plugin.Httpclient=r.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(t,e){function r(t){return function(t){if(Array.isArray(t))return u(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||i(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,u,a=[],f=!0,
|
|
1
|
+
!function(t,e){if("function"==typeof define&&define.amd)define("@merkur/plugin-http-client",["exports","@merkur/core"],e);else if("undefined"!=typeof exports)e(exports,require("@merkur/core"));else{var r={exports:{}};e(r.exports,t.Merkur.Core),t.Merkur=t.Merkur||{},t.Merkur.Plugin=t.Merkur.Plugin||{},t.Merkur.Plugin.Httpclient=r.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(t,e){function r(t){return function(t){if(Array.isArray(t))return u(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||i(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,u,a=[],f=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;f=!1}else for(;!(f=(n=i.call(r)).done)&&(a.push(n.value),a.length!==e);f=!0);}catch(t){l=!0,o=t}finally{try{if(!f&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(l)throw o}}return a}}(t,e)||i(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,e){if(t){if("string"==typeof t)return u(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(t,e):void 0}}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function a(t,e,r,n,o,i,u){try{var a=t[i](u),f=a.value}catch(t){return void r(t)}a.done?e(f):Promise.resolve(f).then(n,o)}function f(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function u(t){a(i,n,o,u,f,"next",t)}function f(t){a(i,n,o,u,f,"throw",t)}u(void 0)}))}}function l(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 c(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?l(Object(r),!0).forEach((function(e){s(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function s(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==n(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function y(t){return[b(),m(),v()]}function d(t,e,r){return p.apply(this,arguments)}function p(){return p=f((function*(t,e,n){for(var o=arguments.length,u=new Array(o>3?o-3:0),a=3;a<o;a++)u[a-3]=arguments[a];var f,l=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=i(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,a=!0,f=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){f=!0,u=t},f:function(){try{a||null==r.return||r.return()}finally{if(f)throw u}}}}(e);try{for(l.s();!(f=l.n()).done;){var c=f.value;"function"==typeof c[n]&&(u=yield c[n].apply(c,[t].concat(r(u))))}}catch(t){l.e(t)}finally{l.f()}return u})),p.apply(this,arguments)}function m(){return{transformRequest:function(t,e,r){return f((function*(){var t=c({},e),n=e.baseUrl,o=void 0===n?"":n,i=e.path,u=void 0===i?"/":i;e.url?t.url=e.url:t.url="".concat(o.endsWith("/")?o.substring(0,o.length-1):o,"/").concat(u.startsWith("/")?u.substring(1):u);var a=Object.keys(e.query).map((function(t){return[t,e.query[t]].map(encodeURIComponent).join("=")})).join("&"),f=-1!==t.url.indexOf("?");return t.url+=f?a?"&".concat(a):"":a?"?".concat(a):"",[t,r]}))()}}}function b(){return{transformResponse:function(t,e,r){return f((function*(){if(204!==r.status&&"function"==typeof r.json){var t=r.headers.get("content-type"),n=null;n=t&&t.includes("application/json")?yield r.json():yield r.text();var o=h(r);return o.body=n,[e,o]}return[e,r]}))()},transformRequest:function(t,e,r){return f((function*(){var t=e.body,n=e.headers,o=e.method;return t&&"application/json"===(n["Content-Type"]||n["content-type"])&&!["GET","HEAD"].includes(o)?[c(c({},e),{},{body:JSON.stringify(t)}),r]:[e,r]}))()}}}function v(){return{transformRequest:function(t,e,r){return f((function*(){var n=c({},e);if("timeout"in e){var o=new t.$dependencies.AbortController;n.signal=o.signal,n.timeoutTimer=setTimeout((function(){o.abort()}),e.timeout)}return[n,r]}))()},transformResponse:function(t,e,r){return f((function*(){return"timeoutTimer"in e&&clearTimeout(e.timeoutTimer),[e,r]}))()}}}function h(t){var e=t.body,r=t.headers,n=t.ok,o=t.redirected,i=t.status,u=t.statusText,a=t.trailers,f=t.type,l=t.url,c=t.useFinalURL;return{body:j({},e),headers:r,ok:n,redirected:o,status:i,statusText:u,trailers:a,type:f,url:l,useFinalURL:c}}Object.defineProperty(t,"__esModule",{value:!0}),t.copyResponse=h,t.getDefaultTransformers=y,t.httpClientPlugin=function(){return{setup:function(t){return f((function*(){var r,n,i;return(0,e.assignMissingKeys)(t,{http:{request:function(t,e){return f((function*(){var r=null,n=c(c({},t.$in.httpClient.defaultConfig),e),i=n.transformers,u=o(yield d(t,i,"transformRequest",n,r),2);n=u[0],r=(r=u[1])||(yield t.$dependencies.fetch(n.url,n));var a=o(yield d(t,i,"transformResponse",n,r),2);if(n=a[0],!(r=a[1]).ok){var f=new Error("".concat(r.statusText,": ").concat(n.url),{cause:{request:n,response:r}});return f.request=n,f.response=r,Promise.reject(f)}return{request:n,response:r}}))()}}}),t.$in.httpClient={defaultConfig:{method:"GET",transformers:y(),headers:{},query:{},timeout:15e3}},t.$dependencies.fetch="undefined"==typeof window?null===(i=global)||void 0===i?void 0:i.fetch:null===(r=window)||void 0===r||null===(r=r.fetch)||void 0===r||null===(n=r.bind)||void 0===n?void 0:n.call(r,window),t.$dependencies.AbortController=AbortController,t}))()},create:function(t){return f((function*(){return(0,e.bindWidgetToFunctions)(t,t.http),t}))()}}},t.setDefaultConfig=function(t,e){t.$in.httpClient.defaultConfig=c(c({},t.$in.httpClient.defaultConfig),e)},t.transformBody=b,t.transformQuery=m,t.transformTimeout=v;var g=["__proto__","prototype","constructor"];function j(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=0,o=Object.keys(e);n<o.length;n++){var i=o[n];if(g.includes(i))return;var u=e[i],a=r?r+"."+i:i;u instanceof Array?t[i]=u.slice():!(u instanceof Object)||u instanceof Function||u instanceof RegExp?t[i]=u:(t[i]instanceof Object||(t[i]={}),j(t[i],u,a))}return t}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkur/plugin-http-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Merkur event emitter plugin.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"module": "lib/index",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://merkur.js.org/",
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@merkur/core": "^0.
|
|
51
|
+
"@merkur/core": "^0.37.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@merkur/core": "*"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "af826493e5ed4b37602dd43ce89a59baeeb1bada"
|
|
57
57
|
}
|