dinocollab-core 2.1.30 → 2.1.32
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/src/http-service/base/service-base.js +1 -1
- package/dist/src/http-service/base/service-base.js.map +1 -1
- package/dist/src/http-service/graphql/app-profile.js +1 -1
- package/dist/src/http-service/graphql/app-profile.js.map +1 -1
- package/dist/src/utils/singletone.js +2 -0
- package/dist/src/utils/singletone.js.map +1 -0
- package/dist/types/http-service/base/service-base.d.ts +9 -1
- package/dist/types/http-service/base/service-base.old.d.ts +148 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/singletone.d.ts +13 -0
- package/dist/utils/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{defineProperty as t,createClass as n,asyncToGenerator as r,regenerator as e,classCallCheck as a,inherits as u,wrapNativeSuper as s,callSuper as i,superPropGet as o}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{authService as c}from"partner-oidc-auth";import h from"axios";import{HttpService as f}from"./gateway.js";import{createObjectSingleton as p}from"../../utils/singletone.js";import{ApiAlertContext as l,handleResponseError as v}from"./helpers.js";var d=function(){return n(function t(){a(this,t)},[{key:"getToken",value:(s=r(e().m(function t(){var n;return e().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,c.getAccessToken();case 1:if(n=t.v){t.n=2;break}n=void 0;case 2:return t.a(2,n)}},t)})),function(){return s.apply(this,arguments)})},{key:"reSignIn",value:(u=r(e().m(function t(){return e().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,c.signIn({});case 1:return t.a(2)}},t)})),function(){return u.apply(this,arguments)})},{key:"getRoles",value:(t=r(e().m(function t(){var n;return e().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,c.getRoles();case 1:return n=t.v,t.a(2,n||void 0)}},t)})),function(){return t.apply(this,arguments)})}]);var t,u,s}(),y=function(){function u(n){var s=this;a(this,u),t(this,"mapResponse",function(){s._http.interceptors.response.use(function(t){return t},function(t){return s.tryFetchToken(t,v)}),s._http.interceptors.request.use(function(t){return s.interuptHeader(t)})}),t(this,"tryFetchToken",function(){var t=r(e().m(function t(n,r){var a,i;return e().w(function(t){for(;;)switch(t.n){case 0:if(i=n.config,401!==(null==n||null===(a=n.response)||void 0===a?void 0:a.status)||!i){t.n=3;break}return t.n=1,u.tokenProvider.reSignIn();case 1:return t.n=2,s.interuptHeader(i);case 2:return t.a(2,h(i));case 3:return t.a(2,r(n))}},t)}));return function(n,r){return t.apply(this,arguments)}}()),t(this,"getToken",r(e().m(function t(){var n;return e().w(function(t){for(;;)switch(t.n){case 0:if(void 0!==s._token){t.n=2;break}return t.n=1,u.tokenProvider.getToken();case 1:n=t.v,t.n=3;break;case 2:n=s._token;case 3:return t.a(2,n)}},t)}))),t(this,"addtoken",function(){var t=r(e().m(function t(n){var r;return e().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,s.getToken();case 1:return(r=t.v)&&null!=n&&n.headers&&(n.headers.Authorization="Bearer "+r),t.a(2,n)}},t)}));return function(n){return t.apply(this,arguments)}}()),this._http=n||f,this.mapResponse()}return n(u,[{key:"setToken",value:function(t){this._token=t}},{key:"addCustomHeader",value:(A=r(e().m(function t(n){return e().w(function(t){for(;;)if(0===t.n)return n||(n={headers:{}}),n.headers||(n.headers={}),t.a(2,n)},t)})),function(t){return A.apply(this,arguments)})},{key:"interuptHeader",value:(P=r(e().m(function t(n){return e().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.addtoken(n);case 1:return t.a(2,n)}},t,this)})),function(t){return P.apply(this,arguments)})},{key:"get",value:(H=r(e().m(function t(n,r){var a,u,s;return e().w(function(t){for(;;)switch(t.n){case 0:return u=this._http,s=n,t.n=1,this.addCustomHeader(r);case 1:return t.n=2,u.get.call(u,s,t.v);case 2:return a=t.v,t.a(2,a.data)}},t,this)})),function(t,n){return H.apply(this,arguments)})},{key:"tryGet",value:(C=r(e().m(function t(n,r){return e().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.a(2,this.get(n,r));case 1:return t.p=1,t.v,t.a(2,null)}},t,this,[[0,1]])})),function(t,n){return C.apply(this,arguments)})},{key:"post",value:(_=r(e().m(function t(n,r,a){var u,s,i,o;return e().w(function(t){for(;;)switch(t.n){case 0:return s=this._http,i=n,o=r,t.n=1,this.addCustomHeader(a);case 1:return t.n=2,s.post.call(s,i,o,t.v);case 2:return u=t.v,t.a(2,u.data)}},t,this)})),function(t,n,r){return _.apply(this,arguments)})},{key:"put",value:(g=r(e().m(function t(n,r,a){var u,s,i,o;return e().w(function(t){for(;;)switch(t.n){case 0:return s=this._http,i=n,o=r,t.n=1,this.addCustomHeader(a);case 1:return t.n=2,s.put.call(s,i,o,t.v);case 2:return u=t.v,t.a(2,u.data)}},t,this)})),function(t,n,r){return g.apply(this,arguments)})},{key:"tryPut",value:(m=r(e().m(function t(n,r,a){return e().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.addCustomHeader(a);case 1:return t.n=2,this.put(n,r,a);case 2:return t.a(2,t.v);case 3:return t.p=3,t.v,t.a(2,null)}},t,this,[[0,3]])})),function(t,n,r){return m.apply(this,arguments)})},{key:"patch",value:(w=r(e().m(function t(n,r,a){var u,s,i,o;return e().w(function(t){for(;;)switch(t.n){case 0:return s=this._http,i=n,o=r,t.n=1,this.addCustomHeader(a);case 1:return t.n=2,s.patch.call(s,i,o,t.v);case 2:return u=t.v,t.a(2,u.data)}},t,this)})),function(t,n,r){return w.apply(this,arguments)})},{key:"tryPatch",value:(k=r(e().m(function t(n,r,a){return e().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.addCustomHeader(a);case 1:return t.n=2,this.patch(n,r,a);case 2:return t.a(2,t.v);case 3:return t.p=3,t.v,t.a(2,null)}},t,this,[[0,3]])})),function(t,n,r){return k.apply(this,arguments)})},{key:"tryPost",value:(y=r(e().m(function t(n,r,a){return e().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.post(n,r,a);case 1:return t.a(2,t.v);case 2:return t.p=2,t.v,t.a(2,null)}},t,this,[[0,2]])})),function(t,n,r){return y.apply(this,arguments)})},{key:"delete",value:(c=r(e().m(function t(n,r){var a,u,s;return e().w(function(t){for(;;)switch(t.n){case 0:return u=this._http,s=n,t.n=1,this.addCustomHeader(r);case 1:return t.n=2,u.delete.call(u,s,t.v);case 2:return a=t.v,t.a(2,a.data)}},t,this)})),function(t,n){return c.apply(this,arguments)})},{key:"tryDelete",value:(o=r(e().m(function t(n,r){var a,u;return e().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,a=this,u=n,t.n=1,this.addCustomHeader(r);case 1:return t.n=2,a.delete.call(a,u,t.v);case 2:return t.a(2,t.v);case 3:return t.p=3,t.v,t.a(2,null)}},t,this,[[0,3]])})),function(t,n){return o.apply(this,arguments)})},{key:"tryPushNotify",value:(i=r(e().m(function t(n){var r,a,u,s=arguments;return e().w(function(t){for(;;)switch(t.p=t.n){case 0:for(t.p=0,r=s.length,a=new Array(r>1?r-1:0),u=1;u<r;u++)a[u-1]=s[u];return t.n=1,this.pushNotify.apply(this,[n].concat(a));case 1:return t.a(2,t.v);case 2:t.p=2,t.v;case 3:return t.a(2)}},t,this,[[0,2]])})),function(t){return i.apply(this,arguments)})},{key:"pushNotify",value:(s=r(e().m(function t(n){var r,a,u,s,i,o,c,h=arguments;return e().w(function(t){for(;;)switch(t.p=t.n){case 0:for(t.p=0,r=h.length,a=new Array(r>1?r-1:0),u=1;u<r;u++)a[u-1]=h[u];return t.n=1,n.bind(this).apply(void 0,a);case 1:return t.a(2,t.v);case 2:throw t.p=2,c=t.v,(o=null===(s=(i=c).response)||void 0===s?void 0:s.data)&&Object.keys(o).forEach(function(t){var n=o[t];Array.isArray(n)&&n.forEach(function(t){var n;null==l||null===(n=l.ApiAlert)||void 0===n||n.PushError(t)})}),i;case 3:return t.a(2)}},t,this,[[0,2]])})),function(t){return s.apply(this,arguments)})}],[{key:"tokenProvider",get:function(){var t;return null!==(t=p(u.key_token_provider).get())&&void 0!==t?t:new d}},{key:"setTokenProvider",value:function(t){p(u.key_token_provider).set(null!=t?t:new d)}}]);var s,i,o,c,y,k,w,m,g,_,C,H,P,A}();t(y,"key_token_provider","__t1_22zzz_t_pro_key__");var k=function(r){function e(){var n;a(this,e);for(var r=arguments.length,u=new Array(r),s=0;s<r;s++)u[s]=arguments[s];return n=i(this,e,[].concat(u)),t(n,"cancel",function(){n.trigger&&n.trigger(),o(e,"abort",n)([])}),n}return u(e,r),n(e)}(s(AbortController));export{k as CancelAction,y as default};
|
|
2
2
|
//# sourceMappingURL=service-base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-base.js","sources":["../../../../src/http-service/base/service-base.ts"],"sourcesContent":["import { authService } from 'partner-oidc-auth'\r\nimport type { AxiosError, AxiosInstance, AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios'\r\nimport axios from 'axios'\r\nimport { HttpService } from './gateway'\r\nimport { handleResponseError, ApiAlertContext } from './helpers'\r\n\r\n/**\r\n * Base service class for HTTP operations with authentication and error handling\r\n * Provides common CRUD operations with automatic token management and retry logic\r\n */\r\nexport default class ServiceBase {\r\n private _http: AxiosInstance\r\n constructor(http?: AxiosInstance) {\r\n if (http) {\r\n this._http = http\r\n } else {\r\n this._http = HttpService\r\n }\r\n this.mapResponse()\r\n }\r\n /**\r\n * Maps response and request interceptors for handling authentication and errors\r\n * Automatically adds authorization headers and retries requests on 401 errors\r\n */\r\n mapResponse = () => {\r\n this._http.interceptors.response.use(\r\n (res) => res,\r\n (err) => this.tryFetchToken(err, handleResponseError)\r\n )\r\n this._http.interceptors.request.use((req) => {\r\n return this.interuptHeader(req)\r\n })\r\n }\r\n /**\r\n * Tries to fetch a new token if the current one is expired\r\n * @param error - The axios error containing response data\r\n * @param next - The next middleware function to call\r\n * @returns A promise resolving to the response data or an error\r\n */\r\n tryFetchToken = async (error: AxiosError, next: (error: AxiosError) => Promise<any>): Promise<any> => {\r\n const originalRequest = error.config\r\n if (error?.response?.status === 401 && originalRequest) {\r\n await authService.signIn({})\r\n await this.interuptHeader(originalRequest)\r\n return axios(originalRequest)\r\n }\r\n return next(error)\r\n }\r\n private _token?: string\r\n /**\r\n * Sets the token to be used for authentication\r\n * @param token - The token string to set\r\n */\r\n setToken(token?: string) {\r\n this._token = token\r\n }\r\n /**\r\n * Gets the current token, fetching a new one if not set\r\n * @returns A promise resolving to the token string\r\n */\r\n getToken = async () => {\r\n return this._token === undefined ? await authService.getAccessToken() : this._token\r\n }\r\n /**\r\n * Adds custom headers to the request configuration\r\n * @param config - The Axios request configuration object\r\n * @returns A promise resolving to the updated configuration object\r\n */\r\n async addCustomHeader(config?: AxiosRequestConfig) {\r\n if (!config) {\r\n config = { headers: {} }\r\n }\r\n if (!config.headers) {\r\n config.headers = {}\r\n }\r\n return config\r\n }\r\n /**\r\n * Intercepts the request to add the authorization token\r\n * @param config - The Axios request configuration object\r\n * @returns The updated configuration object with the token added\r\n */\r\n private async interuptHeader(config: InternalAxiosRequestConfig) {\r\n await this.addtoken(config)\r\n return config\r\n }\r\n /**\r\n * Adds the authorization token to the request headers\r\n * @param config - The Axios request configuration object\r\n * @returns The updated configuration object with the token added\r\n */\r\n private addtoken = async (config?: AxiosRequestConfig) => {\r\n const _token = await this.getToken()\r\n if (_token && config?.headers) {\r\n config.headers.Authorization = 'Bearer ' + _token\r\n }\r\n return config\r\n }\r\n /**\r\n * HTTP GET request with automatic authentication\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async get<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.get<TModel>(url, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP GET request with error handling\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryGet<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n return this.get<TModel>(url, config)\r\n } catch {\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP POST request with automatic authentication\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async post<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.post<TModel>(url, data, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP PUT request with automatic authentication\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async put<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.put<TModel>(url, data, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP PUT request with error handling\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryPut<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n await this.addCustomHeader(config)\r\n return await this.put<TModel>(url, data, config)\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP PATCH request with automatic authentication\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async patch<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.patch<TModel>(url, data, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP PATCH request with error handling\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryPatch<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n await this.addCustomHeader(config)\r\n return await this.patch<TModel>(url, data, config)\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP POST request with error handling\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryPost<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n return await this.post<TModel>(url, data, config)\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP DELETE request with automatic authentication\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async delete<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.delete<TModel>(url, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP DELETE request with error handling\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryDelete<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n return await this.delete<TModel>(url, await this.addCustomHeader(config))\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * Push notification with error handling\r\n * @param action - The function to execute\r\n * @param p - Parameters to pass to the function\r\n * @returns Promise with the result of the function execution\r\n */\r\n async tryPushNotify<TFunc extends (...param: any[]) => any>(action: TFunc, ...p: Parameters<TFunc>) {\r\n try {\r\n return await this.pushNotify(action, ...p)\r\n } catch (err) {}\r\n }\r\n /**\r\n * Push notification with error handling\r\n * @param action - The function to execute\r\n * @param p - Parameters to pass to the function\r\n * @returns Promise with the result of the function execution\r\n */\r\n async pushNotify<TFunc extends (...param: any[]) => any>(action: TFunc, ...p: Parameters<TFunc>): Promise<ReturnType<TFunc>> {\r\n try {\r\n return await action.bind(this)(...p)\r\n } catch (err) {\r\n const error = err as AxiosError\r\n const data = error.response?.data as any\r\n if (data) {\r\n const keys = Object.keys(data)\r\n keys.forEach((key) => {\r\n const errors = data[key] as string[]\r\n if (Array.isArray(errors)) {\r\n errors.forEach((message) => {\r\n ApiAlertContext?.ApiAlert?.PushError(message)\r\n })\r\n }\r\n })\r\n }\r\n throw error\r\n }\r\n }\r\n}\r\n/**\r\n * CancelAction class extends AbortController to provide a cancel method\r\n * This class can be used to cancel ongoing HTTP requests\r\n */\r\nexport class CancelAction extends AbortController {\r\n cancel = () => {\r\n this.trigger && this.trigger()\r\n super.abort()\r\n }\r\n trigger?: () => void\r\n}\r\n"],"names":["ServiceBase","_createClass","http","_this","this","_classCallCheck","_defineProperty","_http","interceptors","response","use","res","err","tryFetchToken","handleResponseError","request","req","interuptHeader","_ref","_asyncToGenerator","_regenerator","m","_callee","error","next","_error$response","originalRequest","w","_context","n","config","status","authService","signIn","a","axios","_x","_x2","apply","arguments","_callee2","_t","_context2","undefined","_token","getAccessToken","v","_ref3","_callee3","_context3","getToken","headers","Authorization","_x3","HttpService","mapResponse","key","value","token","_addCustomHeader","_callee4","_context4","_x4","_interuptHeader","_callee5","_context5","addtoken","_x5","_get","_callee6","url","_t2","_t3","_context6","addCustomHeader","get","call","data","_x6","_x7","_tryGet","_callee7","_context7","p","_x8","_x9","_post","_callee8","_t5","_t6","_t7","_context8","post","_x0","_x1","_x10","_put","_callee9","_t8","_t9","_t0","_context9","put","_x11","_x12","_x13","_tryPut","_callee0","_context0","_x14","_x15","_x16","_patch","_callee1","_t10","_t11","_t12","_context1","patch","_x17","_x18","_x19","_tryPatch","_callee10","_context10","_x20","_x21","_x22","_tryPost","_callee11","_context11","_x23","_x24","_x25","_delete2","_callee12","_t15","_t16","_context12","_x26","_x27","_tryDelete","_callee13","_t17","_t18","_context13","_x28","_x29","_tryPushNotify","_callee14","action","_len","_key","_args14","_context14","length","Array","pushNotify","concat","_x30","_pushNotify","_callee15","_len2","_key2","_error$response2","_t21","_args15","_context15","bind","Object","keys","forEach","errors","isArray","message","_ApiAlertContext$ApiA","ApiAlertContext","ApiAlert","PushError","_x31","CancelAction","_AbortController","_this2","_len3","args","_key3","_callSuper","trigger","_superPropGet","_inherits","_wrapNativeSuper","AbortController"],"mappings":"wZAMA,IAIqBA,EAAW,WAS7B,OAAAC,EAPD,SAAAD,EAAYE,GAAoB,IAAAC,EAAAC,KAAAC,OAAAL,GAQhCM,qBAIc,WACZH,EAAKI,MAAMC,aAAaC,SAASC,IAC/B,SAACC,GAAG,OAAKA,CAAG,EACZ,SAACC,GAAG,OAAKT,EAAKU,cAAcD,EAAKE,KAEnCX,EAAKI,MAAMC,aAAaO,QAAQL,IAAI,SAACM,GACnC,OAAOb,EAAKc,eAAeD,EAC7B,KAEFV,EAAAF,KAAA,gBAAA,WAAA,IAAAc,EAAAC,EAAAC,IAAAC,EAMgB,SAAAC,EAAOC,EAAmBC,GAAyC,IAAAC,EAAAC,EAAA,OAAAN,IAAAO,EAAA,SAAAC,GAAA,cAAAA,EAAAC,GAAA,KAAA,EAC7C,GAA9BH,EAAkBH,EAAMO,OACE,OAA5BP,SAAeE,QAAVA,EAALF,EAAOd,oBAAQgB,SAAfA,EAAiBM,UAAkBL,EAAe,CAAAE,EAAAC,EAAA,EAAA,KAAA,CAAA,OAAAD,EAAAC,EAAA,EAC9CG,EAAYC,OAAO,IAAG,KAAA,EAAA,OAAAL,EAAAC,EAAA,EACtB1B,EAAKc,eAAeS,GAAgB,KAAA,EAAA,OAAAE,EAAAM,IACnCC,EAAMT,IAAgB,KAAA,EAAA,OAAAE,EAAAM,IAExBV,EAAKD,IAAM,EAAAD,MACnB,OAAAc,SAAAA,EAAAC,GAAA,OAAAnB,EAAAoB,MAAAlC,KAAAmC,UAAA,CAAA,CAdD,IAuBAjC,EAAAF,KAAA,WAAAe,EAAAC,IAAAC,EAIW,SAAAmB,IAAA,IAAAC,EAAA,OAAArB,IAAAO,EAAA,SAAAe,GAAA,cAAAA,EAAAb,GAAA,KAAA,EAAA,QACcc,IAAhBxC,EAAKyC,OAAoB,CAAAF,EAAAb,EAAA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B,QAAjBuF,GADJ7I,EAAK8I,GACQ5J,gBAAQ,IAAA2J,OAAA,EAAdA,EAAgBvF,OAEd4F,OAAOC,KAAK7F,GACpB8F,QAAQ,SAACnH,GACZ,IAAMoH,EAAS/F,EAAKrB,GAChBoG,MAAMiB,QAAQD,IAChBA,EAAOD,QAAQ,SAACG,GAAW,IAAAC,EACzBC,SAAyBD,QAAVA,EAAfC,EAAiBC,oBAAQF,GAAzBA,EAA2BG,UAAUJ,EACvC,EAEJ,GAEIvJ,EAAK,KAAA,EAAA,OAAAgJ,EAAArI,EAAA,GAAA,EAAA+H,EAAA7J,KAAA,CAAA,CAAA,EAAA,QAEd,SAnBe+K,GAAA,OAAAnB,EAAA1H,MAAAlC,KAAAmC,UAAA,MANhB,IAAAyH,EAXAZ,EAdAP,EAVAP,EAfAN,EAhBAN,EAXAV,EAhBAN,EAXAV,EAXAV,EAbAN,EAVAZ,EArBAL,EAdAJ,CAmLgB,CAxOc,GAiQnByH,WAAaC,GAAA,SAAAD,IAAA,IAAAE,EAAAjL,OAAA+K,GAAA,IAAA,IAAAG,EAAAhJ,UAAAoH,OAAA6B,EAAA5B,IAAAA,MAAA2B,GAAAE,EAAA,EAAAA,EAAAF,EAAAE,IAAAD,EAAAC,GAAAlJ,UAAAkJ,GAIvB,OAJuBH,EAAAI,EAAAtL,KAAAgL,EAAAtB,GAAAA,OAAA0B,IAAAlL,EAAAgL,EAAA,SACf,WACPA,EAAKK,SAAWL,EAAKK,UACrBC,EAAAR,UAAAE,EAAAM,CAAA,MACDN,CAAA,CAAA,OAAAO,EAAAT,EAAAC,GAAApL,EAAAmL,EAAA,EAAAU,EAJ+BC"}
|
|
1
|
+
{"version":3,"file":"service-base.js","sources":["../../../../src/http-service/base/service-base.ts"],"sourcesContent":["import { authService } from 'partner-oidc-auth'\r\nimport type { AxiosError, AxiosInstance, AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios'\r\nimport axios from 'axios'\r\nimport { HttpService } from './gateway'\r\nimport { createObjectSingleton } from '../../utils/singletone'\r\nimport { handleResponseError, ApiAlertContext } from './helpers'\r\n\r\nexport interface ITokenProvider {\r\n getToken: () => Promise<string | undefined>\r\n reSignIn: () => Promise<void>\r\n getRoles: () => Promise<string[] | undefined>\r\n}\r\n\r\nclass TokenProviderDefault implements ITokenProvider {\r\n async getToken(): Promise<string | undefined> {\r\n return (await authService.getAccessToken()) || undefined\r\n }\r\n async reSignIn() {\r\n await authService.signIn({})\r\n }\r\n async getRoles(): Promise<string[] | undefined> {\r\n const roles = await authService.getRoles()\r\n return roles || undefined\r\n }\r\n}\r\n\r\n/**\r\n * Base service class for HTTP operations with authentication and error handling\r\n * Provides common CRUD operations with automatic token management and retry logic\r\n */\r\nexport default class ServiceBase {\r\n static key_token_provider = '__t1_22zzz_t_pro_key__'\r\n static get tokenProvider(): ITokenProvider {\r\n const ObjectProvider = createObjectSingleton<ITokenProvider>(ServiceBase.key_token_provider)\r\n return ObjectProvider.get() ?? new TokenProviderDefault()\r\n }\r\n static setTokenProvider(provider: ITokenProvider) {\r\n const ObjectProvider = createObjectSingleton<ITokenProvider>(ServiceBase.key_token_provider)\r\n ObjectProvider.set(provider ?? new TokenProviderDefault())\r\n }\r\n\r\n private _http: AxiosInstance\r\n constructor(http?: AxiosInstance) {\r\n if (http) {\r\n this._http = http\r\n } else {\r\n this._http = HttpService\r\n }\r\n this.mapResponse()\r\n }\r\n /**\r\n * Maps response and request interceptors for handling authentication and errors\r\n * Automatically adds authorization headers and retries requests on 401 errors\r\n */\r\n mapResponse = () => {\r\n this._http.interceptors.response.use(\r\n (res) => res,\r\n (err) => this.tryFetchToken(err, handleResponseError)\r\n )\r\n this._http.interceptors.request.use((req) => {\r\n return this.interuptHeader(req)\r\n })\r\n }\r\n /**\r\n * Tries to fetch a new token if the current one is expired\r\n * @param error - The axios error containing response data\r\n * @param next - The next middleware function to call\r\n * @returns A promise resolving to the response data or an error\r\n */\r\n tryFetchToken = async (error: AxiosError, next: (error: AxiosError) => Promise<any>): Promise<any> => {\r\n const originalRequest = error.config\r\n if (error?.response?.status === 401 && originalRequest) {\r\n await ServiceBase.tokenProvider.reSignIn()\r\n await this.interuptHeader(originalRequest)\r\n return axios(originalRequest)\r\n }\r\n return next(error)\r\n }\r\n private _token?: string\r\n /**\r\n * Sets the token to be used for authentication\r\n * @param token - The token string to set\r\n */\r\n setToken(token?: string) {\r\n this._token = token\r\n }\r\n /**\r\n * Gets the current token, fetching a new one if not set\r\n * @returns A promise resolving to the token string\r\n */\r\n getToken = async () => {\r\n return this._token === undefined ? await ServiceBase.tokenProvider.getToken() : this._token\r\n }\r\n /**\r\n * Adds custom headers to the request configuration\r\n * @param config - The Axios request configuration object\r\n * @returns A promise resolving to the updated configuration object\r\n */\r\n async addCustomHeader(config?: AxiosRequestConfig) {\r\n if (!config) {\r\n config = { headers: {} }\r\n }\r\n if (!config.headers) {\r\n config.headers = {}\r\n }\r\n return config\r\n }\r\n /**\r\n * Intercepts the request to add the authorization token\r\n * @param config - The Axios request configuration object\r\n * @returns The updated configuration object with the token added\r\n */\r\n private async interuptHeader(config: InternalAxiosRequestConfig) {\r\n await this.addtoken(config)\r\n return config\r\n }\r\n /**\r\n * Adds the authorization token to the request headers\r\n * @param config - The Axios request configuration object\r\n * @returns The updated configuration object with the token added\r\n */\r\n private addtoken = async (config?: AxiosRequestConfig) => {\r\n const _token = await this.getToken()\r\n if (_token && config?.headers) {\r\n config.headers.Authorization = 'Bearer ' + _token\r\n }\r\n return config\r\n }\r\n /**\r\n * HTTP GET request with automatic authentication\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async get<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.get<TModel>(url, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP GET request with error handling\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryGet<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n return this.get<TModel>(url, config)\r\n } catch {\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP POST request with automatic authentication\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async post<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.post<TModel>(url, data, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP PUT request with automatic authentication\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async put<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.put<TModel>(url, data, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP PUT request with error handling\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryPut<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n await this.addCustomHeader(config)\r\n return await this.put<TModel>(url, data, config)\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP PATCH request with automatic authentication\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async patch<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.patch<TModel>(url, data, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP PATCH request with error handling\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryPatch<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n await this.addCustomHeader(config)\r\n return await this.patch<TModel>(url, data, config)\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP POST request with error handling\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryPost<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n return await this.post<TModel>(url, data, config)\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP DELETE request with automatic authentication\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async delete<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.delete<TModel>(url, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP DELETE request with error handling\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryDelete<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n return await this.delete<TModel>(url, await this.addCustomHeader(config))\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * Push notification with error handling\r\n * @param action - The function to execute\r\n * @param p - Parameters to pass to the function\r\n * @returns Promise with the result of the function execution\r\n */\r\n async tryPushNotify<TFunc extends (...param: any[]) => any>(action: TFunc, ...p: Parameters<TFunc>) {\r\n try {\r\n return await this.pushNotify(action, ...p)\r\n } catch (err) {}\r\n }\r\n /**\r\n * Push notification with error handling\r\n * @param action - The function to execute\r\n * @param p - Parameters to pass to the function\r\n * @returns Promise with the result of the function execution\r\n */\r\n async pushNotify<TFunc extends (...param: any[]) => any>(action: TFunc, ...p: Parameters<TFunc>): Promise<ReturnType<TFunc>> {\r\n try {\r\n return await action.bind(this)(...p)\r\n } catch (err) {\r\n const error = err as AxiosError\r\n const data = error.response?.data as any\r\n if (data) {\r\n const keys = Object.keys(data)\r\n keys.forEach((key) => {\r\n const errors = data[key] as string[]\r\n if (Array.isArray(errors)) {\r\n errors.forEach((message) => {\r\n ApiAlertContext?.ApiAlert?.PushError(message)\r\n })\r\n }\r\n })\r\n }\r\n throw error\r\n }\r\n }\r\n}\r\n/**\r\n * CancelAction class extends AbortController to provide a cancel method\r\n * This class can be used to cancel ongoing HTTP requests\r\n */\r\nexport class CancelAction extends AbortController {\r\n cancel = () => {\r\n this.trigger && this.trigger()\r\n super.abort()\r\n }\r\n trigger?: () => void\r\n}\r\n"],"names":["TokenProviderDefault","_createClass","_classCallCheck","key","value","_getToken","_asyncToGenerator","_regenerator","m","_callee","_t","w","_context","n","authService","getAccessToken","v","undefined","a","apply","this","arguments","_reSignIn","_callee2","_context2","signIn","_getRoles","_callee3","roles","_context3","getRoles","ServiceBase","http","_this","_defineProperty","_http","interceptors","response","use","res","err","tryFetchToken","handleResponseError","request","req","interuptHeader","_ref","_callee4","error","next","_error$response","originalRequest","_context4","config","status","tokenProvider","reSignIn","axios","_x","_x2","_callee5","_t2","_context5","_token","getToken","_ref3","_callee6","_context6","headers","Authorization","_x3","HttpService","mapResponse","token","_addCustomHeader","_callee7","_context7","_x4","_interuptHeader","_callee8","_context8","addtoken","_x5","_get","_callee9","url","_t3","_t4","_context9","addCustomHeader","get","call","data","_x6","_x7","_tryGet","_callee0","_context0","p","_x8","_x9","_post","_callee1","_t6","_t7","_t8","_context1","post","_x0","_x1","_x10","_put","_callee10","_t9","_t0","_t1","_context10","put","_x11","_x12","_x13","_tryPut","_callee11","_context11","_x14","_x15","_x16","_patch","_callee12","_t11","_t12","_t13","_context12","patch","_x17","_x18","_x19","_tryPatch","_callee13","_context13","_x20","_x21","_x22","_tryPost","_callee14","_context14","_x23","_x24","_x25","_delete2","_callee15","_t16","_t17","_context15","_x26","_x27","_tryDelete","_callee16","_t18","_t19","_context16","_x28","_x29","_tryPushNotify","_callee17","action","_len","_key","_args17","_context17","length","Array","pushNotify","concat","_x30","_pushNotify","_callee18","_len2","_key2","_error$response2","_t22","_args18","_context18","bind","Object","keys","forEach","errors","isArray","message","_ApiAlertContext$ApiA","ApiAlertContext","ApiAlert","PushError","_x31","_ObjectProvider$get","createObjectSingleton","key_token_provider","provider","set","CancelAction","_AbortController","_this2","_len3","args","_key3","_callSuper","trigger","_superPropGet","_inherits","_wrapNativeSuper","AbortController"],"mappings":"0dAKgE,IAQ1DA,EAAoB,WAAA,OAAAC,EAAA,SAAAD,IAAAE,OAAAF,EAAA,EAAA,CAAA,CAAAG,IAAA,WAAAC,OAAAC,EAAAC,EAAAC,IAAAC,EACxB,SAAAC,IAAA,IAAAC,EAAA,OAAAH,IAAAI,EAAA,SAAAC,GAAA,cAAAA,EAAAC,GAAA,KAAA,EAAA,OAAAD,EAAAC,EAAA,EACgBC,EAAYC,iBAAgB,KAAA,EAAA,GAAAL,EAAAE,EAAAI,EAAA,CAAAJ,EAAAC,EAAA,EAAA,KAAA,CAAAH,OAAKO,EAAS,KAAA,EAAA,OAAAL,EAAAM,EAAA,EAAAR,GAAA,EAAAD,MACzD,WAFa,OAAAJ,EAAAc,MAAAC,KAAAC,UAAA,IAAA,CAAAlB,IAAA,WAAAC,OAAAkB,EAAAhB,EAAAC,IAAAC,EAGd,SAAAe,IAAA,OAAAhB,IAAAI,EAAA,SAAAa,GAAA,cAAAA,EAAAX,GAAA,KAAA,EAAA,OAAAW,EAAAX,EAAA,EACQC,EAAYW,OAAO,IAAG,KAAA,EAAA,OAAAD,EAAAN,EAAA,GAAA,EAAAK,MAC7B,WAFa,OAAAD,EAAAH,MAAAC,KAAAC,UAAA,IAAA,CAAAlB,IAAA,WAAAC,OAAAsB,EAAApB,EAAAC,IAAAC,EAGd,SAAAmB,IAAA,IAAAC,EAAA,OAAArB,IAAAI,EAAA,SAAAkB,GAAA,cAAAA,EAAAhB,GAAA,KAAA,EAAA,OAAAgB,EAAAhB,EAAA,EACsBC,EAAYgB,WAAU,KAAA,EAA/B,OAALF,EAAKC,EAAAb,EAAAa,EAA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EAAAwK,EAAA,SACf,WACPA,EAAKK,SAAWL,EAAKK,UACrBC,EAAAR,UAAAE,EAAAM,CAAA,MACDN,CAAA,CAAA,OAAAO,EAAAT,EAAAC,GAAAxM,EAAAuM,EAAA,EAAAU,EAJ+BC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createClass as e,classCallCheck as n,defineProperty as r,asyncToGenerator as
|
|
1
|
+
import{createClass as e,classCallCheck as n,defineProperty as r,asyncToGenerator as i,regenerator as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{EAppName as a}from"./types.js";import s from"../base/service-base.js";import"../base/gateway.js";import"../base/helpers.js";var o;!function(e){e.Admin="Admin",e.User="User",e.Manage="Manage"}(o||(o={}));var l=new(e(function e(){var l=this;n(this,e),r(this,"getAppName",function(){var e,n;return null!==(e=null===(n=l.window)||void 0===n||null===(n=n.env)||void 0===n?void 0:n.REACT_APP_NAME)&&void 0!==e?e:a.ClientApp}),r(this,"isAdmin",function(e){return(null!=e?e:[]).some(function(e){return e===o.Admin})&&l.getAppName()===a.ClientAdmin}),r(this,"getGraphqlSite",i(t().m(function e(){var n,r,i;return t().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,s.tokenProvider.getRoles();case 1:n=e.v,r=l.getAppName(),i=r,e.n=i===a.ClientAdmin?2:(a.ClientApp,3);break;case 2:return e.a(2,l.isAdmin(n)?o.Admin:o.Manage);case 3:return e.a(2,o.User);case 4:return e.a(2)}},e)}))),this.window=global.window}));export{l as AppProfile};
|
|
2
2
|
//# sourceMappingURL=app-profile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-profile.js","sources":["../../../../src/http-service/graphql/app-profile.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"app-profile.js","sources":["../../../../src/http-service/graphql/app-profile.ts"],"sourcesContent":["import { EAppName } from './types'\r\nimport { ServiceBase } from '../base'\r\n\r\nenum RoleKeyInternalSite {\r\n Admin = 'Admin',\r\n User = 'User',\r\n Manage = 'Manage'\r\n}\r\n\r\nclass AppProfileBase {\r\n window: Window & { [key: string]: any }\r\n constructor() {\r\n this.window = global.window\r\n }\r\n\r\n getAppName = () => (this.window?.env?.REACT_APP_NAME as EAppName) ?? EAppName.ClientApp\r\n\r\n isAdmin = (roles?: string[]) => {\r\n return (roles ?? []).some((e) => e === RoleKeyInternalSite.Admin) && this.getAppName() === EAppName.ClientAdmin\r\n }\r\n\r\n getGraphqlSite = async () => {\r\n const roles = await ServiceBase.tokenProvider.getRoles()\r\n const appName = this.getAppName()\r\n switch (appName) {\r\n case EAppName.ClientAdmin:\r\n return this.isAdmin(roles) ? RoleKeyInternalSite.Admin : RoleKeyInternalSite.Manage\r\n case EAppName.ClientApp:\r\n default:\r\n return RoleKeyInternalSite.User\r\n }\r\n }\r\n}\r\n\r\nexport const AppProfile = new AppProfileBase()\r\n"],"names":["RoleKeyInternalSite","AppProfile","_createClass","AppProfileBase","_this","this","_classCallCheck","_defineProperty","_this$window$env$REAC","_this$window","window","env","REACT_APP_NAME","EAppName","ClientApp","roles","some","e","Admin","getAppName","ClientAdmin","_asyncToGenerator","_regenerator","m","_callee","appName","_t","w","_context","n","ServiceBase","tokenProvider","getRoles","v","a","isAdmin","Manage","User","global"],"mappings":"+RAGA,IAAKA,GAAL,SAAKA,GACHA,EAAA,MAAA,QACAA,EAAA,KAAA,OACAA,EAAA,OAAA,QACD,CAJD,CAAKA,IAAAA,EAIJ,CAAA,IAAA,IA2BYC,EAAa,IAzBNC,EAElB,SAAAC,IAAA,IAAAC,EAAAC,KAAAC,OAAAH,GAAAI,EAIaF,KAAA,aAAA,WAAA,IAAAG,EAAAC,EAAA,OAAoD,QAApDD,EAAkB,QAAlBC,EAAOL,EAAKM,cAAM,IAAAD,GAAK,QAALA,EAAXA,EAAaE,WAAG,IAAAF,OAAA,EAAhBA,EAAkBG,sBAA2B,IAAAJ,EAAAA,EAAIK,EAASC,SAAS,GAAAP,EAAAF,KAAA,UAE7E,SAACU,GACT,OAAQA,QAAAA,EAAS,IAAIC,KAAK,SAACC,GAAC,OAAKA,IAAMjB,EAAoBkB,KAAM,IAAId,EAAKe,eAAiBN,EAASO,cACrGb,EAAAF,KAAA,iBAAAgB,EAAAC,IAAAC,EAEgB,SAAAC,IAAA,IAAAT,EAAAU,EAAAC,EAAA,OAAAJ,IAAAK,EAAA,SAAAC,GAAA,cAAAA,EAAAC,GAAA,KAAA,EAAA,OAAAD,EAAAC,EAAA,EACKC,EAAYC,cAAcC,WAAU,KAAA,EAAlDjB,EAAKa,EAAAK,EACLR,EAAUrB,EAAKe,aAAYO,EACzBD,EAAOG,EAAAC,EAAAH,IACRb,EAASO,YAAWM,GAEpBb,EAASC,UAAS,GAAA,MAAA,KAAA,EAAA,OAAAc,EAAAM,EADd9B,EAAAA,EAAK+B,QAAQpB,GAASf,EAAoBkB,MAAQlB,EAAoBoC,QAAM,KAAA,EAAA,OAAAR,EAAAM,EAG5ElC,EAAAA,EAAoBqC,MAAI,KAAA,EAAA,OAAAT,EAAAM,EAAA,GAAA,EAAAV,EAEpC,KAnBCnB,KAAKK,OAAS4B,OAAO5B,MACvB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createClass as e,classCallCheck as n}from"../../_virtual/_rollupPluginBabelHelpers.js";function t(t){var u=globalThis,r={},l=function(){return e(function e(){return n(this,e),new Proxy(this,{get:function(e,n){return"set"===n?e.set.bind(e):"get"===n?e.get.bind(e):"delete"===n?e.delete.bind(e):"has"===n?e.has.bind(e):"clear"===n?e.clear.bind(e):"keys"===n?e.keys.bind(e):"values"===n?e.values.bind(e):"entries"===n?e.entries.bind(e):"size"===n?Object.keys(r).length:e[n]}})},[{key:"set",value:function(e,n){r[e]=n}},{key:"get",value:function(e){return r[e]}},{key:"delete",value:function(e){return e in r&&(delete r[e],!0)}},{key:"has",value:function(e){return e in r}},{key:"clear",value:function(){Object.keys(r).forEach(function(e){return delete r[e]})}},{key:"keys",value:function(){return Object.keys(r)}},{key:"values",value:function(){return Object.values(r)}},{key:"entries",value:function(){return Object.entries(r)}}])}(),i=function(e,n,t){return null!=n||(n=u),n[e]||(n[e]=null!=t?t:{}),n[e]}("z_y1s_651_ps",u,new l);return{get:function(){return i.get(t)},set:function(e){return i.set(t,e)},delete:function(){return i.delete(t)},has:function(){return i.has(t)}}}export{t as createObjectSingleton,t as default};
|
|
2
|
+
//# sourceMappingURL=singletone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"singletone.js","sources":["../../../src/utils/singletone.ts"],"sourcesContent":["/**\r\n * CreateObjectSingleton\r\n *\r\n * Lightweight global singleton registry (per-string key).\r\n * Exposes per-key helpers: `get()`, `set(value)`, `delete()`, `has()`.\r\n */\r\nexport function createObjectSingleton<T = any>(key: string) {\r\n // Use `globalThis` as the shared container so the registry survives\r\n // across module boundaries, multiple bundles, and hot-reloads.\r\n const GWindow: any = globalThis\r\n\r\n // Ensure the internal registry object exists on the provided `store`\r\n // (defaults to `globalThis`). Returns the registry object at `store[key]`.\r\n const getWindowHandler = (key: string, store?: any, value?: any) => {\r\n store ??= GWindow\r\n if (!store[key]) {\r\n store[key] = value ?? {}\r\n }\r\n return store[key]\r\n }\r\n\r\n // Internal storage for entries. This object holds actual values and is\r\n // captured by the Proxy so methods can interact with this underlying map.\r\n const handlerActions: Record<string, T> = {}\r\n\r\n class ProxyMapSingleton {\r\n constructor() {\r\n // The Proxy intercepts property access so we can expose the class\r\n // methods and derived properties (like `size`) while forwarding any\r\n // unknown properties to the underlying instance.\r\n return new Proxy(this, {\r\n get: (target: any, prop: string | symbol) => {\r\n if (prop === 'set') return target.set.bind(target)\r\n if (prop === 'get') return target.get.bind(target)\r\n if (prop === 'delete') return target.delete.bind(target)\r\n if (prop === 'has') return target.has.bind(target)\r\n if (prop === 'clear') return target.clear.bind(target)\r\n if (prop === 'keys') return target.keys.bind(target)\r\n if (prop === 'values') return target.values.bind(target)\r\n if (prop === 'entries') return target.entries.bind(target)\r\n // Expose a read-only `size` derived from the internal storage.\r\n if (prop === 'size') return Object.keys(handlerActions).length\r\n return (target as any)[prop] // other properties (if any)\r\n }\r\n })\r\n }\r\n\r\n // Set a value for `key` in the shared registry.\r\n set(key: string, value: T) {\r\n handlerActions[key] = value\r\n }\r\n\r\n // Get the value for `key` from the shared registry.\r\n get(key: string): T | undefined {\r\n return handlerActions[key]\r\n }\r\n\r\n // Delete an entry by `key`. Returns `true` if removed.\r\n delete(key: string) {\r\n if (key in handlerActions) {\r\n delete handlerActions[key]\r\n return true\r\n }\r\n return false\r\n }\r\n\r\n // Check whether `key` exists in the registry.\r\n has(key: string) {\r\n return key in handlerActions\r\n }\r\n\r\n // Remove all entries from the registry.\r\n clear() {\r\n Object.keys(handlerActions).forEach((key) => delete handlerActions[key])\r\n }\r\n\r\n // Return an array of stored keys.\r\n keys() {\r\n return Object.keys(handlerActions)\r\n }\r\n\r\n // Return an array of stored values.\r\n values() {\r\n return Object.values(handlerActions)\r\n }\r\n\r\n // Return an array of [key, value] pairs.\r\n entries() {\r\n return Object.entries(handlerActions)\r\n }\r\n }\r\n\r\n // Create or reuse the shared proxy-backed registry stored on `globalThis`.\r\n const HandlerAction: any = getWindowHandler('z_y1s_651_ps', GWindow, new ProxyMapSingleton())\r\n\r\n // Return a compact per-key API that operates against the shared registry.\r\n // Note: This returns only the per-key helpers; other registry-level helpers\r\n // (like `size`, `keys`, etc.) are available on the shared proxy itself.\r\n return {\r\n get: () => HandlerAction.get(key),\r\n set: (value: T) => HandlerAction.set(key, value),\r\n delete: () => HandlerAction.delete(key),\r\n has: () => HandlerAction.has(key)\r\n }\r\n}\r\nexport default createObjectSingleton\r\n"],"names":["createObjectSingleton","key","GWindow","globalThis","handlerActions","ProxyMapSingleton","_createClass","_classCallCheck","Proxy","this","get","target","prop","set","bind","has","clear","keys","values","entries","Object","length","value","forEach","HandlerAction","store","getWindowHandler","delete"],"mappings":"8FAMM,SAAUA,EAA+BC,GAG7C,IAAMC,EAAeC,WAcfC,E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B,EAAMxB,KACTwB,EAAMxB,GAAOqB,QAAAA,EAAS,CAAE,GAEnBG,EAAMxB,EACd,CA0E0ByB,CAAiB,eAAgBxB,EAAS,IAAIG,GAKzE,MAAO,CACLK,IAAK,WAAF,OAAQc,EAAcd,IAAIT,EAAI,EACjCY,IAAK,SAACS,GAAQ,OAAKE,EAAcX,IAAIZ,EAAKqB,EAAM,EAChDK,OAAQ,WAAF,OAAQH,EAAa,OAAQvB,EAAI,EACvCc,IAAK,WAAF,OAAQS,EAAcT,IAAId,EAAI,EAErC"}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
export interface ITokenProvider {
|
|
3
|
+
getToken: () => Promise<string | undefined>;
|
|
4
|
+
reSignIn: () => Promise<void>;
|
|
5
|
+
getRoles: () => Promise<string[] | undefined>;
|
|
6
|
+
}
|
|
2
7
|
/**
|
|
3
8
|
* Base service class for HTTP operations with authentication and error handling
|
|
4
9
|
* Provides common CRUD operations with automatic token management and retry logic
|
|
5
10
|
*/
|
|
6
11
|
export default class ServiceBase {
|
|
12
|
+
static key_token_provider: string;
|
|
13
|
+
static get tokenProvider(): ITokenProvider;
|
|
14
|
+
static setTokenProvider(provider: ITokenProvider): void;
|
|
7
15
|
private _http;
|
|
8
16
|
constructor(http?: AxiosInstance);
|
|
9
17
|
/**
|
|
@@ -28,7 +36,7 @@ export default class ServiceBase {
|
|
|
28
36
|
* Gets the current token, fetching a new one if not set
|
|
29
37
|
* @returns A promise resolving to the token string
|
|
30
38
|
*/
|
|
31
|
-
getToken: () => Promise<string |
|
|
39
|
+
getToken: () => Promise<string | undefined>;
|
|
32
40
|
/**
|
|
33
41
|
* Adds custom headers to the request configuration
|
|
34
42
|
* @param config - The Axios request configuration object
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* Base service class for HTTP operations with authentication and error handling
|
|
4
|
+
* Provides common CRUD operations with automatic token management and retry logic
|
|
5
|
+
*/
|
|
6
|
+
export default class ServiceBase {
|
|
7
|
+
private _http;
|
|
8
|
+
constructor(http?: AxiosInstance);
|
|
9
|
+
/**
|
|
10
|
+
* Maps response and request interceptors for handling authentication and errors
|
|
11
|
+
* Automatically adds authorization headers and retries requests on 401 errors
|
|
12
|
+
*/
|
|
13
|
+
mapResponse: () => void;
|
|
14
|
+
/**
|
|
15
|
+
* Tries to fetch a new token if the current one is expired
|
|
16
|
+
* @param error - The axios error containing response data
|
|
17
|
+
* @param next - The next middleware function to call
|
|
18
|
+
* @returns A promise resolving to the response data or an error
|
|
19
|
+
*/
|
|
20
|
+
tryFetchToken: (error: AxiosError, next: (error: AxiosError) => Promise<any>) => Promise<any>;
|
|
21
|
+
private _token?;
|
|
22
|
+
/**
|
|
23
|
+
* Sets the token to be used for authentication
|
|
24
|
+
* @param token - The token string to set
|
|
25
|
+
*/
|
|
26
|
+
setToken(token?: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the current token, fetching a new one if not set
|
|
29
|
+
* @returns A promise resolving to the token string
|
|
30
|
+
*/
|
|
31
|
+
getToken: () => Promise<string | null | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Adds custom headers to the request configuration
|
|
34
|
+
* @param config - The Axios request configuration object
|
|
35
|
+
* @returns A promise resolving to the updated configuration object
|
|
36
|
+
*/
|
|
37
|
+
addCustomHeader(config?: AxiosRequestConfig): Promise<AxiosRequestConfig<any>>;
|
|
38
|
+
/**
|
|
39
|
+
* Intercepts the request to add the authorization token
|
|
40
|
+
* @param config - The Axios request configuration object
|
|
41
|
+
* @returns The updated configuration object with the token added
|
|
42
|
+
*/
|
|
43
|
+
private interuptHeader;
|
|
44
|
+
/**
|
|
45
|
+
* Adds the authorization token to the request headers
|
|
46
|
+
* @param config - The Axios request configuration object
|
|
47
|
+
* @returns The updated configuration object with the token added
|
|
48
|
+
*/
|
|
49
|
+
private addtoken;
|
|
50
|
+
/**
|
|
51
|
+
* HTTP GET request with automatic authentication
|
|
52
|
+
* @param url - The request URL
|
|
53
|
+
* @param config - Optional axios configuration
|
|
54
|
+
* @returns Promise with the response data
|
|
55
|
+
*/
|
|
56
|
+
get<TModel>(url: string, config?: AxiosRequestConfig | undefined): Promise<TModel>;
|
|
57
|
+
/**
|
|
58
|
+
* HTTP GET request with error handling
|
|
59
|
+
* @param url - The request URL
|
|
60
|
+
* @param config - Optional axios configuration
|
|
61
|
+
* @returns Promise with the response data or null if an error occurs
|
|
62
|
+
*/
|
|
63
|
+
tryGet<TModel>(url: string, config?: AxiosRequestConfig | undefined): Promise<TModel | null>;
|
|
64
|
+
/**
|
|
65
|
+
* HTTP POST request with automatic authentication
|
|
66
|
+
* @param url - The request URL
|
|
67
|
+
* @param data - Optional data to send in the request body
|
|
68
|
+
* @param config - Optional axios configuration
|
|
69
|
+
* @returns Promise with the response data
|
|
70
|
+
*/
|
|
71
|
+
post<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined): Promise<TModel>;
|
|
72
|
+
/**
|
|
73
|
+
* HTTP PUT request with automatic authentication
|
|
74
|
+
* @param url - The request URL
|
|
75
|
+
* @param data - Optional data to send in the request body
|
|
76
|
+
* @param config - Optional axios configuration
|
|
77
|
+
* @returns Promise with the response data
|
|
78
|
+
*/
|
|
79
|
+
put<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined): Promise<TModel>;
|
|
80
|
+
/**
|
|
81
|
+
* HTTP PUT request with error handling
|
|
82
|
+
* @param url - The request URL
|
|
83
|
+
* @param data - Optional data to send in the request body
|
|
84
|
+
* @param config - Optional axios configuration
|
|
85
|
+
* @returns Promise with the response data or null if an error occurs
|
|
86
|
+
*/
|
|
87
|
+
tryPut<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined): Promise<TModel | null>;
|
|
88
|
+
/**
|
|
89
|
+
* HTTP PATCH request with automatic authentication
|
|
90
|
+
* @param url - The request URL
|
|
91
|
+
* @param data - Optional data to send in the request body
|
|
92
|
+
* @param config - Optional axios configuration
|
|
93
|
+
* @returns Promise with the response data
|
|
94
|
+
*/
|
|
95
|
+
patch<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined): Promise<TModel>;
|
|
96
|
+
/**
|
|
97
|
+
* HTTP PATCH request with error handling
|
|
98
|
+
* @param url - The request URL
|
|
99
|
+
* @param data - Optional data to send in the request body
|
|
100
|
+
* @param config - Optional axios configuration
|
|
101
|
+
* @returns Promise with the response data or null if an error occurs
|
|
102
|
+
*/
|
|
103
|
+
tryPatch<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined): Promise<TModel | null>;
|
|
104
|
+
/**
|
|
105
|
+
* HTTP POST request with error handling
|
|
106
|
+
* @param url - The request URL
|
|
107
|
+
* @param data - Optional data to send in the request body
|
|
108
|
+
* @param config - Optional axios configuration
|
|
109
|
+
* @returns Promise with the response data or null if an error occurs
|
|
110
|
+
*/
|
|
111
|
+
tryPost<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined): Promise<TModel | null>;
|
|
112
|
+
/**
|
|
113
|
+
* HTTP DELETE request with automatic authentication
|
|
114
|
+
* @param url - The request URL
|
|
115
|
+
* @param config - Optional axios configuration
|
|
116
|
+
* @returns Promise with the response data
|
|
117
|
+
*/
|
|
118
|
+
delete<TModel>(url: string, config?: AxiosRequestConfig | undefined): Promise<TModel>;
|
|
119
|
+
/**
|
|
120
|
+
* HTTP DELETE request with error handling
|
|
121
|
+
* @param url - The request URL
|
|
122
|
+
* @param config - Optional axios configuration
|
|
123
|
+
* @returns Promise with the response data or null if an error occurs
|
|
124
|
+
*/
|
|
125
|
+
tryDelete<TModel>(url: string, config?: AxiosRequestConfig | undefined): Promise<TModel | null>;
|
|
126
|
+
/**
|
|
127
|
+
* Push notification with error handling
|
|
128
|
+
* @param action - The function to execute
|
|
129
|
+
* @param p - Parameters to pass to the function
|
|
130
|
+
* @returns Promise with the result of the function execution
|
|
131
|
+
*/
|
|
132
|
+
tryPushNotify<TFunc extends (...param: any[]) => any>(action: TFunc, ...p: Parameters<TFunc>): Promise<ReturnType<TFunc> | undefined>;
|
|
133
|
+
/**
|
|
134
|
+
* Push notification with error handling
|
|
135
|
+
* @param action - The function to execute
|
|
136
|
+
* @param p - Parameters to pass to the function
|
|
137
|
+
* @returns Promise with the result of the function execution
|
|
138
|
+
*/
|
|
139
|
+
pushNotify<TFunc extends (...param: any[]) => any>(action: TFunc, ...p: Parameters<TFunc>): Promise<ReturnType<TFunc>>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* CancelAction class extends AbortController to provide a cancel method
|
|
143
|
+
* This class can be used to cancel ongoing HTTP requests
|
|
144
|
+
*/
|
|
145
|
+
export declare class CancelAction extends AbortController {
|
|
146
|
+
cancel: () => void;
|
|
147
|
+
trigger?: () => void;
|
|
148
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CreateObjectSingleton
|
|
3
|
+
*
|
|
4
|
+
* Lightweight global singleton registry (per-string key).
|
|
5
|
+
* Exposes per-key helpers: `get()`, `set(value)`, `delete()`, `has()`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createObjectSingleton<T = any>(key: string): {
|
|
8
|
+
get: () => any;
|
|
9
|
+
set: (value: T) => any;
|
|
10
|
+
delete: () => any;
|
|
11
|
+
has: () => any;
|
|
12
|
+
};
|
|
13
|
+
export default createObjectSingleton;
|
package/dist/utils/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{cleanObject,decodeBase64,deepRemoveEmptyFields,encodeBase64,fetchDelay,formatCapitalizeFirstText,formatCurrency,formatDatetime,formatFileSize,formatNumberWithCommas,isGuid,isValidEmail,isValidPhoneNumber,isValidURL,mergeClasses,mergeObjects,sleep,tryParseArray,tryParseCsvFileToArray,tryParseIntRequired,tryParseObject,windowScrollToTop}from"../src/utils/helpers.js";import"../src/utils/dayjs-config.js";export{default as JObject}from"../src/utils/json-object.js";export{QueryParam}from"../src/utils/query-param.js";export{default as dayjsCustom}from"dayjs";
|
|
1
|
+
export{cleanObject,decodeBase64,deepRemoveEmptyFields,encodeBase64,fetchDelay,formatCapitalizeFirstText,formatCurrency,formatDatetime,formatFileSize,formatNumberWithCommas,isGuid,isValidEmail,isValidPhoneNumber,isValidURL,mergeClasses,mergeObjects,sleep,tryParseArray,tryParseCsvFileToArray,tryParseIntRequired,tryParseObject,windowScrollToTop}from"../src/utils/helpers.js";import"../src/utils/dayjs-config.js";export{default as JObject}from"../src/utils/json-object.js";export{QueryParam}from"../src/utils/query-param.js";export{createObjectSingleton}from"../src/utils/singletone.js";export{default as dayjsCustom}from"dayjs";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|