@yeepay/client-utils 1.2.0 → 1.2.1
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/dist/client-utils.esm.js +1 -1
- package/dist/client-utils.min.js +1 -1
- package/lib/request.js +1 -1
- package/package.json +1 -1
package/dist/client-utils.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"axios";import e from"js-cookie";import n from"apollo-boost";import r from"unfetch";function o(t){var e=(t=null==t?window.location.href:t).substring(t.lastIndexOf("?")+1),n={};return e.replace(/([^?&=]+)=([^?&=]*)/g,(function(t,e,r){var o=decodeURIComponent(e),i=decodeURIComponent(r);return i=String(i),n[o]=i,t})),n}var i="";function u(){return i||e.get("TOKEN")}function a(t){if(i=o(window.location.href)[t]){var n=i.indexOf("#");-1!==n&&(i=i.slice(0,n)),i="Bearer "+i,e.set("TOKEN",i);var r=new RegExp("("+t+"=[^&]+&?)");window.history.replaceState(null,null,window.location.href.replace(r,(function(t){return""})))}}function c(){return e.remove("TOKEN")}function s(t,e){return e?t===e:0===t||"0"===t||"000000"===t||200===t||!t}function l(e){
|
|
1
|
+
import t from"axios";import e from"js-cookie";import n from"apollo-boost";import r from"unfetch";function o(t){var e=(t=null==t?window.location.href:t).substring(t.lastIndexOf("?")+1),n={};return e.replace(/([^?&=]+)=([^?&=]*)/g,(function(t,e,r){var o=decodeURIComponent(e),i=decodeURIComponent(r);return i=String(i),n[o]=i,t})),n}var i="";function u(){return i||e.get("TOKEN")}function a(t){if(i=o(window.location.href)[t]){var n=i.indexOf("#");-1!==n&&(i=i.slice(0,n)),i="Bearer "+i,e.set("TOKEN",i);var r=new RegExp("("+t+"=[^&]+&?)");window.history.replaceState(null,null,window.location.href.replace(r,(function(t){return""})))}}function c(){return e.remove("TOKEN")}function s(t,e){return e?t===e||!t:0===t||"0"===t||"000000"===t||200===t||!t}function l(t,e){return"function"!=typeof t&&t?t:{successCallback:t||function(){return{}},failCallback:e[0]||function(){return{}},unauthorizedCallback:e[1]||function(){return{}},forbiddenCallback:e[2]||function(){return{}},notfoundCallback:e[3]||function(){return{}},requestInterceptor:e[4]||function(t){return t},responseInterceptor:e[5]||function(t){return t}}}function f(e,n){for(var r=e.baseUrl,o=void 0===r?"/":r,i=e.timeout,a=void 0===i?12e5:i,c=e.headers,f=e.code,d=arguments.length,p=new Array(d>2?d-2:0),v=2;v<d;v++)p[v-2]=arguments[v];var h=l(n,p),m=h.successCallback,b=void 0===m?function(){return{}}:m,y=h.failCallback,g=void 0===y?function(){return{}}:y,q=h.unauthorizedCallback,w=void 0===q?function(){return{}}:q,C=h.forbiddenCallback,k=void 0===C?function(){return{}}:C,j=h.notfoundCallback,O=void 0===j?function(){return{}}:j,S=h.requestInterceptor,E=void 0===S?function(t){return t}:S,I=h.responseInterceptor,x=void 0===I?function(t){return t}:I,A=t.create({baseURL:o,timeout:a,headers:c,validateStatus:function(t){return t>=200&&t<300||401===t||403===t||400===t||500===t}});return A.interceptors.request.use((function(t){t.headers.Authorization=u(),t.headers["Content-Type"]="application/json";var e=t.method,n=t.url;return"get"===e&&(-1!==n.indexOf("?")?t.url="".concat(n,"&_t=").concat((new Date).getTime()):t.url="".concat(n,"?_t=").concat((new Date).getTime())),t}),(function(t){console.log(t),Promise.reject(t)})),A.interceptors.request.use(E,(function(t){console.log(t),Promise.reject(t)})),A.interceptors.response.use((function(t){return t.status&&401===t.status?w(t):t.status&&403===t.status?k(t):(!t.status||400!==t.status&&500!==t.status)&&s(t.data.code,f)?(b(t),t):(g(t),Promise.reject(t))}),(function(t){var e=0;try{e=t.response.status||t.response.data.status}catch(e){if(-1!==t.toString().indexOf("Error: timeout"))return Promise.reject(t)}return e?403===e?k(t):404===e?O(t):g(t.response):g(t.response),Promise.reject(t)})),A.interceptors.response.use(x,(function(t){})),A}function d(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function p(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=t[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return v(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(t,e)}(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 v(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var h=function(){function t(e){var o=this,i=e.gqlServer,u=e.requestForRest;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.gql={},this.inject=function(t,e){o.register(t);for(var n=function(){var e=p(i[r],2),n=e[0],u=e[1];if(!["definitions","kind","loc"].includes(n))if("query"===u.definitions[0].operation)"production"===process.env.NODE_ENV?o.gql[t][n]=function(e){return o.restfulReq("/".concat(t,"/").concat(n),e)}:o.gql[t][n]=function(t){return o.query(u,t)};else{if("mutation"!==u.definitions[0].operation)return"continue";"production"===process.env.NODE_ENV?o.gql[t][n]=function(e){return o.restfulReq("/".concat(t,"/").concat(n),e)}:o.gql[t][n]=function(t){return o.mutation(u,t)}}},r=0,i=Object.entries(e);r<i.length;r++)n()},this.gqlServer=i,this.request=u,this.apolloClient=new n({uri:i,fetch:r})}var e,o,i;return e=t,(o=[{key:"register",value:function(t){this.gql[t]||(this.gql[t]={})}},{key:"query",value:function(t,e){return this.apolloClient.query({query:t,variables:e||{}})}},{key:"mutation",value:function(t,e){return this.apolloClient.mutate({mutation:t,variables:e||{}})}},{key:"restfulReq",value:function(t,e){return this.request({url:t,method:"post",data:{variables:e}})}}])&&d(e.prototype,o),i&&d(e,i),t}();export{h as GraphQLClient,o as getQueryObject,u as getToken,c as removeToken,f as serviceFactory,a as setTokenFromUrl};
|
package/dist/client-utils.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("axios"),require("js-cookie"),require("apollo-boost"),require("unfetch")):"function"==typeof define&&define.amd?define(["exports","axios","js-cookie","apollo-boost","unfetch"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).YeepayClientUtils={},e.axios,e.Cookie,e.ApolloClient,e.fetch)}(this,(function(e,t,n,r,o){"use strict";function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=i(t),a=i(n),
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("axios"),require("js-cookie"),require("apollo-boost"),require("unfetch")):"function"==typeof define&&define.amd?define(["exports","axios","js-cookie","apollo-boost","unfetch"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).YeepayClientUtils={},e.axios,e.Cookie,e.ApolloClient,e.fetch)}(this,(function(e,t,n,r,o){"use strict";function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=i(t),a=i(n),c=i(r),s=i(o);function l(e){var t=(e=null==e?window.location.href:e).substring(e.lastIndexOf("?")+1),n={};return t.replace(/([^?&=]+)=([^?&=]*)/g,(function(e,t,r){var o=decodeURIComponent(t),i=decodeURIComponent(r);return i=String(i),n[o]=i,e})),n}var f="TOKEN",d="";function p(){return d||a.default.get(f)}function v(e,t){return t?e===t||!e:0===e||"0"===e||"000000"===e||200===e||!e}function h(e,t){return"function"!=typeof e&&e?e:{successCallback:e||function(){return{}},failCallback:t[0]||function(){return{}},unauthorizedCallback:t[1]||function(){return{}},forbiddenCallback:t[2]||function(){return{}},notfoundCallback:t[3]||function(){return{}},requestInterceptor:t[4]||function(e){return e},responseInterceptor:t[5]||function(e){return e}}}function y(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return m(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return m(e,t)}(e,t)||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 m(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var g=function(){function e(t){var n=this,r=t.gqlServer,o=t.requestForRest;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.gql={},this.inject=function(e,t){n.register(e);for(var r=function(){var t=b(i[o],2),r=t[0],u=t[1];if(!["definitions","kind","loc"].includes(r))if("query"===u.definitions[0].operation)"production"===process.env.NODE_ENV?n.gql[e][r]=function(t){return n.restfulReq("/".concat(e,"/").concat(r),t)}:n.gql[e][r]=function(e){return n.query(u,e)};else{if("mutation"!==u.definitions[0].operation)return"continue";"production"===process.env.NODE_ENV?n.gql[e][r]=function(t){return n.restfulReq("/".concat(e,"/").concat(r),t)}:n.gql[e][r]=function(e){return n.mutation(u,e)}}},o=0,i=Object.entries(t);o<i.length;o++)r()},this.gqlServer=r,this.request=o,this.apolloClient=new c.default({uri:r,fetch:s.default})}var t,n,r;return t=e,(n=[{key:"register",value:function(e){this.gql[e]||(this.gql[e]={})}},{key:"query",value:function(e,t){return this.apolloClient.query({query:e,variables:t||{}})}},{key:"mutation",value:function(e,t){return this.apolloClient.mutate({mutation:e,variables:t||{}})}},{key:"restfulReq",value:function(e,t){return this.request({url:e,method:"post",data:{variables:t}})}}])&&y(t.prototype,n),r&&y(t,r),e}();e.GraphQLClient=g,e.getQueryObject=l,e.getToken=p,e.removeToken=function(){return a.default.remove(f)},e.serviceFactory=function(e,t){for(var n=e.baseUrl,r=void 0===n?"/":n,o=e.timeout,i=void 0===o?12e5:o,a=e.headers,c=e.code,s=arguments.length,l=new Array(s>2?s-2:0),f=2;f<s;f++)l[f-2]=arguments[f];var d=h(t,l),y=d.successCallback,b=void 0===y?function(){return{}}:y,m=d.failCallback,g=void 0===m?function(){return{}}:m,q=d.unauthorizedCallback,k=void 0===q?function(){return{}}:q,C=d.forbiddenCallback,w=void 0===C?function(){return{}}:C,j=d.notfoundCallback,O=void 0===j?function(){return{}}:j,x=d.requestInterceptor,S=void 0===x?function(e){return e}:x,T=d.responseInterceptor,I=void 0===T?function(e){return e}:T,A=u.default.create({baseURL:r,timeout:i,headers:a,validateStatus:function(e){return e>=200&&e<300||401===e||403===e||400===e||500===e}});return A.interceptors.request.use((function(e){e.headers.Authorization=p(),e.headers["Content-Type"]="application/json";var t=e.method,n=e.url;return"get"===t&&(-1!==n.indexOf("?")?e.url="".concat(n,"&_t=").concat((new Date).getTime()):e.url="".concat(n,"?_t=").concat((new Date).getTime())),e}),(function(e){console.log(e),Promise.reject(e)})),A.interceptors.request.use(S,(function(e){console.log(e),Promise.reject(e)})),A.interceptors.response.use((function(e){return e.status&&401===e.status?k(e):e.status&&403===e.status?w(e):(!e.status||400!==e.status&&500!==e.status)&&v(e.data.code,c)?(b(e),e):(g(e),Promise.reject(e))}),(function(e){var t=0;try{t=e.response.status||e.response.data.status}catch(t){if(-1!==e.toString().indexOf("Error: timeout"))return Promise.reject(e)}return t?403===t?w(e):404===t?O(e):g(e.response):g(e.response),Promise.reject(e)})),A.interceptors.response.use(I,(function(e){})),A},e.setTokenFromUrl=function(e){if(d=l(window.location.href)[e]){var t=d.indexOf("#");-1!==t&&(d=d.slice(0,t)),d="Bearer "+d,a.default.set(f,d);var n=new RegExp("("+e+"=[^&]+&?)");window.history.replaceState(null,null,window.location.href.replace(n,(function(e){return""})))}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/lib/request.js
CHANGED