@mp-front/common 0.0.2-next.3 → 0.0.2-next.4

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.
@@ -17,7 +17,7 @@ export declare class RedisCache<T> {
17
17
  ttl(key: string, time: number): void;
18
18
  simpleGet(key: string): Promise<string>;
19
19
  simpleHGet(key: string, field: string): Promise<string>;
20
- simpleHGetBuffer(key: string, field: string): Promise<Buffer<ArrayBufferLike>>;
20
+ simpleHGetBuffer(key: string, field: string): Promise<Buffer>;
21
21
  simpleHSet<T extends string | number | Buffer = string>(key: string, field: string, value: T): Promise<number>;
22
22
  simpleHGetAll(key: string): Promise<Record<string, string>>;
23
23
  }
@@ -3,13 +3,13 @@ var $ = (o, e, t) => e in o ? L(o, e, { enumerable: !0, configurable: !0, writab
3
3
  var i = (o, e, t) => $(o, typeof e != "symbol" ? e + "" : e, t);
4
4
  import { switchMap as d, of as h, catchError as q, filter as J, EMPTY as A } from "rxjs";
5
5
  import { L as R } from "./logger-DtlFWyFO.js";
6
- import "./lodash-QjAkD17S.js";
6
+ import "./lodash-BzOkiDvV.js";
7
7
  import "node-jose";
8
8
  import "crypto";
9
9
  import { R as B, a as y, E as I } from "./default-errors-DsKmUZbG.js";
10
10
  import { f as N } from "./fetch-CUIb9XhZ.js";
11
11
  import { A as k } from "./authorization-service-DE-hoYji.js";
12
- import { E as j } from "./encoder-CXAlLf5T.js";
12
+ import { E as j } from "./encoder-DQ28XRzN.js";
13
13
  import { L as S } from "./loading-handler-ivYFmS_V.js";
14
14
  import { v as T } from "./v5-Cu1sjPlx.js";
15
15
  class H {
@@ -106,8 +106,8 @@ class te {
106
106
  (a) => N(e, {
107
107
  ...r,
108
108
  headers: {
109
- ...r.headers,
110
- ...a
109
+ ...a,
110
+ ...r.headers
111
111
  }
112
112
  }).pipe(
113
113
  q((n) => {
@@ -1 +1 @@
1
- "use strict";var L=Object.defineProperty;var P=(c,e,t)=>e in c?L(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var o=(c,e,t)=>P(c,typeof e!="symbol"?e+"":e,t);const i=require("rxjs"),q=require("./logger-BMbeDoGU.cjs");require("./lodash-DNCgFYS7.cjs");require("node-jose");require("crypto");const l=require("./default-errors-DiEIEEE2.cjs"),y=require("./fetch-BZP9DZLg.cjs"),x=require("./authorization-service-DkLS18Us.cjs"),$=require("./encoder-BEp9qfLf.cjs"),p=require("./loading-handler-BrN0O37N.cjs"),B=require("./v5-BTqP79vV.cjs");class R{constructor(e={}){o(this,"logger",new q.Logger);o(this,"headers");this.headers={Accept:"application/json","Content-Type":"application/vnd.api+json",...e}}addTokenBackend(e){return this.logger.logDebug("addTokenBackend HttpHeaders",JSON.stringify(e)),new x.AuthorizationService().get().pipe(i.switchMap(t=>i.of({...e,Authorization:`Bearer ${t}`})))}get(e){this.logger.logDebug("get HttpHeaders");const t=i.of({...this.headers});return e?t.pipe(i.switchMap(s=>this.addTokenBackend(s))):t}}const J=process.env.ID_FRONT??"NOT_AVAILABLE";class I{constructor(){o(this,"httpHeaders",new R);o(this,"logger",new q.Logger)}errorCatcher(e,t){var s,r,n;if(e!=null&&e.errors)throw new l.RuntimeError(((n=(r=(s=e.errors).at)==null?void 0:r.call(s,0))==null?void 0:n.code)??l.RuntimeErrorCode.DEFAULT,t??"");return!(e!=null&&e.errors)}get(e,t={}){const s=this.buildRequest("GET",e,null,t);return this.request(s)}post(e,t,s={}){const r=this.buildRequest("POST",e,t,s);return this.request(r)}put(e,t,s={}){const r=this.buildRequest("PUT",e,t,s);return this.request(r)}delete(e,t={}){const s=this.buildRequest("DELETE",e,null,t);return this.request(s)}formatParams(e,t){return JSON.stringify(t==="JSON:API"?{data:{type:J,attributes:e}}:e)}buildRequest(e,t,s,r){const n=r.format??"JSON:API",a={requestID:r==null?void 0:r.requestID,withCredentials:(r==null?void 0:r.withCredentials)??!0,url:t,headers:r.headers,method:e,selector:u=>u.json()};if(e==="GET"){const u=new URL(t);if(r.params)for(const g of Object.keys(r.params))u.searchParams.append(g,`${r.params[g]}`);return{...a,url:u.toString()}}return{...a,body:this.formatParams(s,n)}}request({url:e,requestID:t,withCredentials:s=!1,...r}){return this.httpHeaders.get(s).pipe(i.switchMap(n=>y.fromFetch(e,{...r,headers:{...r.headers,...n}}).pipe(i.catchError(a=>{throw this.logger.logError(JSON.stringify(a)),this.logger.logError(`HttpBackend \x1B[37m <URL>: \x1B[33m ${e} \x1B[37m <RequestID>: \x1B[33m ${t} \x1B[37m <HEADERS>: \x1B[33m ${JSON.stringify(n)} \x1B[37m <BODY>: \x1B[33m ${JSON.stringify(this.formatParams(r.body,r.format))} \x1B[37m <RESPONSE>: \x1B[33m ${JSON.stringify(a)} \x1B[33m`),new l.RuntimeError(l.RuntimeErrorCode.DEFAULT,t)}),i.switchMap(a=>(this.logger.logDebug(`HttpBackend \x1B[37m <URL>: \x1B[33m ${e} \x1B[37m <RequestID>: \x1B[33m ${t} \x1B[37m <HEADERS>: \x1B[33m ${JSON.stringify(n)} \x1B[37m <BODY>: \x1B[33m ${JSON.stringify(this.formatParams(r.body,r.format))} \x1B[37m <RESPONSE>: \x1B[33m ${JSON.stringify(a)} \x1B[33m`),i.of(a))))),i.filter(n=>this.errorCatcher(n,t)))}}const H="requestID",O="Content-Type";class A{constructor(){o(this,"httpHeaders",new R);o(this,"logger",new q.Logger);o(this,"encoder",new $.Encoder);o(this,"isLoadingEnabled",!0)}setIsLoadingEnabled(e){this.isLoadingEnabled=e}get(e,t={}){const s=this.buildRequest("GET",e,null,t);return this.request(s)}post(e,t,s={}){const r=this.buildRequest("POST",e,t,s);return this.request(r)}put(e,t,s={}){const r=this.buildRequest("PUT",e,t,s);return this.request(r)}patch(e,t,s={}){const r=this.buildRequest("PATCH",e,t,s);return this.request(r)}delete(e,t={}){const s=this.buildRequest("DELETE",e,null,t);return this.request(s)}buildRequest(e,t,s,r){const a=new URLSearchParams(window.location.search).get("flow")??"N/A",u={url:t,headers:{...r.headers,flow:a},method:e,selector:d=>d.json()},g=new Date().toISOString(),E=B.v5(g,B.v5.URL);if(e==="GET"){const d=new URL(t,location.origin),f=r.params??{},w=Object.entries(f).reduce((h,N)=>{const[m,D]=N;if(h[m]=`${D}`,Object.hasOwn(f,m)){const S=f[m];S!=null&&(h[m]=S)}return h},{}),T=this.encoder.encode(w,E),b=JSON.parse(T);for(const h of Object.keys(b))d.searchParams.append(h,`${b[h]}`);return{...u,url:d.toString()}}if(new Headers(r.headers).get("Content-Type")==="multipart/form-data"){const d=s;return d.append(H,E),{...u,body:d}}return{...u,body:this.encoder.encode(s??{},E)}}request({url:e,...t}){return p.LoadingHandler.getInstance().setSubject(this.isLoadingEnabled),this.httpHeaders.get(!1).pipe(i.switchMap(s=>{const r={...s,...t.headers};return O in r&&r[O]==="multipart/form-data"&&delete r[O],y.fromFetch(e,{...t,headers:r}).pipe(i.switchMap(n=>i.of(this.encoder.decode(n))),i.switchMap(n=>{if("code"in n)throw n;return p.LoadingHandler.getInstance().setSubject(!1),this.logger.logDebug(`HttpClient <URL>: ${e} <HEADERS>: ${JSON.stringify(r)} <BODY> ${JSON.stringify(t.body)} <RESPONSE>: ${JSON.stringify(n)}`),i.of(n)}),i.catchError(n=>(this.logger.logError(`HttpClient <URL>: ${e} <HEADERS>: ${JSON.stringify(r)} <BODY> ${JSON.stringify(t.body)} <ERROR>: ${JSON.stringify(n)}`),p.LoadingHandler.getInstance().setSubject(!1),l.ErrorHandler.getInstance().setSubject(n),i.EMPTY)))}))}}exports.HttpBackend=I;exports.HttpClient=A;exports.HttpHeaders=R;exports.REQUEST_ID_KEY=H;
1
+ "use strict";var L=Object.defineProperty;var P=(c,e,t)=>e in c?L(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var o=(c,e,t)=>P(c,typeof e!="symbol"?e+"":e,t);const i=require("rxjs"),q=require("./logger-BMbeDoGU.cjs");require("./lodash-DahFf0th.cjs");require("node-jose");require("crypto");const l=require("./default-errors-DiEIEEE2.cjs"),y=require("./fetch-BZP9DZLg.cjs"),x=require("./authorization-service-DkLS18Us.cjs"),$=require("./encoder-DrKsNmKq.cjs"),p=require("./loading-handler-BrN0O37N.cjs"),B=require("./v5-BTqP79vV.cjs");class R{constructor(e={}){o(this,"logger",new q.Logger);o(this,"headers");this.headers={Accept:"application/json","Content-Type":"application/vnd.api+json",...e}}addTokenBackend(e){return this.logger.logDebug("addTokenBackend HttpHeaders",JSON.stringify(e)),new x.AuthorizationService().get().pipe(i.switchMap(t=>i.of({...e,Authorization:`Bearer ${t}`})))}get(e){this.logger.logDebug("get HttpHeaders");const t=i.of({...this.headers});return e?t.pipe(i.switchMap(s=>this.addTokenBackend(s))):t}}const J=process.env.ID_FRONT??"NOT_AVAILABLE";class I{constructor(){o(this,"httpHeaders",new R);o(this,"logger",new q.Logger)}errorCatcher(e,t){var s,r,n;if(e!=null&&e.errors)throw new l.RuntimeError(((n=(r=(s=e.errors).at)==null?void 0:r.call(s,0))==null?void 0:n.code)??l.RuntimeErrorCode.DEFAULT,t??"");return!(e!=null&&e.errors)}get(e,t={}){const s=this.buildRequest("GET",e,null,t);return this.request(s)}post(e,t,s={}){const r=this.buildRequest("POST",e,t,s);return this.request(r)}put(e,t,s={}){const r=this.buildRequest("PUT",e,t,s);return this.request(r)}delete(e,t={}){const s=this.buildRequest("DELETE",e,null,t);return this.request(s)}formatParams(e,t){return JSON.stringify(t==="JSON:API"?{data:{type:J,attributes:e}}:e)}buildRequest(e,t,s,r){const n=r.format??"JSON:API",a={requestID:r==null?void 0:r.requestID,withCredentials:(r==null?void 0:r.withCredentials)??!0,url:t,headers:r.headers,method:e,selector:u=>u.json()};if(e==="GET"){const u=new URL(t);if(r.params)for(const g of Object.keys(r.params))u.searchParams.append(g,`${r.params[g]}`);return{...a,url:u.toString()}}return{...a,body:this.formatParams(s,n)}}request({url:e,requestID:t,withCredentials:s=!1,...r}){return this.httpHeaders.get(s).pipe(i.switchMap(n=>y.fromFetch(e,{...r,headers:{...n,...r.headers}}).pipe(i.catchError(a=>{throw this.logger.logError(JSON.stringify(a)),this.logger.logError(`HttpBackend \x1B[37m <URL>: \x1B[33m ${e} \x1B[37m <RequestID>: \x1B[33m ${t} \x1B[37m <HEADERS>: \x1B[33m ${JSON.stringify(n)} \x1B[37m <BODY>: \x1B[33m ${JSON.stringify(this.formatParams(r.body,r.format))} \x1B[37m <RESPONSE>: \x1B[33m ${JSON.stringify(a)} \x1B[33m`),new l.RuntimeError(l.RuntimeErrorCode.DEFAULT,t)}),i.switchMap(a=>(this.logger.logDebug(`HttpBackend \x1B[37m <URL>: \x1B[33m ${e} \x1B[37m <RequestID>: \x1B[33m ${t} \x1B[37m <HEADERS>: \x1B[33m ${JSON.stringify(n)} \x1B[37m <BODY>: \x1B[33m ${JSON.stringify(this.formatParams(r.body,r.format))} \x1B[37m <RESPONSE>: \x1B[33m ${JSON.stringify(a)} \x1B[33m`),i.of(a))))),i.filter(n=>this.errorCatcher(n,t)))}}const H="requestID",O="Content-Type";class A{constructor(){o(this,"httpHeaders",new R);o(this,"logger",new q.Logger);o(this,"encoder",new $.Encoder);o(this,"isLoadingEnabled",!0)}setIsLoadingEnabled(e){this.isLoadingEnabled=e}get(e,t={}){const s=this.buildRequest("GET",e,null,t);return this.request(s)}post(e,t,s={}){const r=this.buildRequest("POST",e,t,s);return this.request(r)}put(e,t,s={}){const r=this.buildRequest("PUT",e,t,s);return this.request(r)}patch(e,t,s={}){const r=this.buildRequest("PATCH",e,t,s);return this.request(r)}delete(e,t={}){const s=this.buildRequest("DELETE",e,null,t);return this.request(s)}buildRequest(e,t,s,r){const a=new URLSearchParams(window.location.search).get("flow")??"N/A",u={url:t,headers:{...r.headers,flow:a},method:e,selector:d=>d.json()},g=new Date().toISOString(),E=B.v5(g,B.v5.URL);if(e==="GET"){const d=new URL(t,location.origin),f=r.params??{},w=Object.entries(f).reduce((h,N)=>{const[m,D]=N;if(h[m]=`${D}`,Object.hasOwn(f,m)){const S=f[m];S!=null&&(h[m]=S)}return h},{}),T=this.encoder.encode(w,E),b=JSON.parse(T);for(const h of Object.keys(b))d.searchParams.append(h,`${b[h]}`);return{...u,url:d.toString()}}if(new Headers(r.headers).get("Content-Type")==="multipart/form-data"){const d=s;return d.append(H,E),{...u,body:d}}return{...u,body:this.encoder.encode(s??{},E)}}request({url:e,...t}){return p.LoadingHandler.getInstance().setSubject(this.isLoadingEnabled),this.httpHeaders.get(!1).pipe(i.switchMap(s=>{const r={...s,...t.headers};return O in r&&r[O]==="multipart/form-data"&&delete r[O],y.fromFetch(e,{...t,headers:r}).pipe(i.switchMap(n=>i.of(this.encoder.decode(n))),i.switchMap(n=>{if("code"in n)throw n;return p.LoadingHandler.getInstance().setSubject(!1),this.logger.logDebug(`HttpClient <URL>: ${e} <HEADERS>: ${JSON.stringify(r)} <BODY> ${JSON.stringify(t.body)} <RESPONSE>: ${JSON.stringify(n)}`),i.of(n)}),i.catchError(n=>(this.logger.logError(`HttpClient <URL>: ${e} <HEADERS>: ${JSON.stringify(r)} <BODY> ${JSON.stringify(t.body)} <ERROR>: ${JSON.stringify(n)}`),p.LoadingHandler.getInstance().setSubject(!1),l.ErrorHandler.getInstance().setSubject(n),i.EMPTY)))}))}}exports.HttpBackend=I;exports.HttpClient=A;exports.HttpHeaders=R;exports.REQUEST_ID_KEY=H;
@@ -1,7 +1,7 @@
1
1
  var i = Object.defineProperty;
2
2
  var c = (e, r, o) => r in e ? i(e, r, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[r] = o;
3
3
  var s = (e, r, o) => c(e, typeof r != "symbol" ? r + "" : r, o);
4
- import { l as g } from "./lodash-QjAkD17S.js";
4
+ import { l as g } from "./lodash-BzOkiDvV.js";
5
5
  import { L as f } from "./logger-DtlFWyFO.js";
6
6
  import "node-jose";
7
7
  import "crypto";
@@ -1 +1 @@
1
- "use strict";var i=Object.defineProperty;var c=(o,r,e)=>r in o?i(o,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[r]=e;var n=(o,r,e)=>c(o,typeof r!="symbol"?r+"":r,e);const g=require("./lodash-DNCgFYS7.cjs"),f=require("./logger-BMbeDoGU.cjs");require("node-jose");require("crypto");class l{constructor(){n(this,"logger",new f.Logger)}encode(r,e){try{this.logger.logDebug("encode Encoder",JSON.stringify(r));const s=JSON.stringify(r),t=Buffer.from(s).toString("base64");return JSON.stringify({info:t,requestID:e})}catch{return this.logger.logDebug("error convert to base64"),JSON.stringify({info:r,requestID:e})}}decode(r){try{g.lodashExports.isString(r)&&(r=JSON.parse(r));const{info:e}=r;this.logger.logDebug("decode Encoder",JSON.stringify(e));const s=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;if(g.lodashExports.isString(e)&&s.test(e)){const t=Buffer.from(e,"base64").toString();return JSON.parse(t)}}catch{this.logger.logError("error convert to base64")}return r}}exports.Encoder=l;
1
+ "use strict";var i=Object.defineProperty;var c=(o,r,e)=>r in o?i(o,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[r]=e;var n=(o,r,e)=>c(o,typeof r!="symbol"?r+"":r,e);const g=require("./lodash-DahFf0th.cjs"),f=require("./logger-BMbeDoGU.cjs");require("node-jose");require("crypto");class l{constructor(){n(this,"logger",new f.Logger)}encode(r,e){try{this.logger.logDebug("encode Encoder",JSON.stringify(r));const s=JSON.stringify(r),t=Buffer.from(s).toString("base64");return JSON.stringify({info:t,requestID:e})}catch{return this.logger.logDebug("error convert to base64"),JSON.stringify({info:r,requestID:e})}}decode(r){try{g.lodashExports.isString(r)&&(r=JSON.parse(r));const{info:e}=r;this.logger.logDebug("decode Encoder",JSON.stringify(e));const s=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;if(g.lodashExports.isString(e)&&s.test(e)){const t=Buffer.from(e,"base64").toString();return JSON.parse(t)}}catch{this.logger.logError("error convert to base64")}return r}}exports.Encoder=l;
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty;var o=(t,e,r)=>e in t?c(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var i=(t,e,r)=>o(t,typeof e!="symbol"?e+"":e,r);const n=require("node-jose"),g=require("crypto"),E=require("./logger-BMbeDoGU.cjs");require("./lodash-DNCgFYS7.cjs");const a=t=>t.replace(/[\u00A0-\uffff]/gu,e=>"\\u"+("000"+e.charCodeAt(0).toString(16)).slice(-4));class y{constructor(){i(this,"logger",new E.Logger);i(this,"signatureKey")}async generateKey(){const e=process.env.SECRET_SIGNATURE;if(!e)throw new Error("Define a SECRET_SIGNATURE from `.env`");this.signatureKey=await n.JWK.asKey({kty:"oct",k:n.util.base64url.encode(e)})}async encrypt(e){if(await this.generateKey(),!this.signatureKey)throw new Error("PLEASE CREATE A KEY TO ENCRYPT 🙂");const r=JSON.stringify(e),s=a(r);return await n.JWE.createEncrypt({format:"compact"},this.signatureKey).update(s).final()}async decrypt(e){if(await this.generateKey(),!this.signatureKey)throw new Error("PLEASE CREATE A KEY TO DECRYPT 🙂");const{payload:r}=await n.JWE.createDecrypt(this.signatureKey).decrypt(e);return JSON.parse(r.toString())}async isEncrypted(e){this.logger.logInfo("EncryptionHandler",e);try{return await this.decrypt(e??""),this.logger.logDebug("EncryptionHandler","IS ENCRYPTED 🥵"),!0}catch(r){return this.logger.logWarn("EncryptionHandler",JSON.stringify(r)),this.logger.logDebug("EncryptionHandler","IS NOT ENCRYPTED 🙂"),!1}}generateSHA(e){const r=JSON.stringify(e);return g.createHash("sha256").update(r).digest("hex")}}exports.Encrypter=y;exports.escapeUnicode=a;
1
+ "use strict";var c=Object.defineProperty;var o=(t,e,r)=>e in t?c(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var i=(t,e,r)=>o(t,typeof e!="symbol"?e+"":e,r);const n=require("node-jose"),g=require("crypto"),E=require("./logger-BMbeDoGU.cjs");require("./lodash-DahFf0th.cjs");const a=t=>t.replace(/[\u00A0-\uffff]/gu,e=>"\\u"+("000"+e.charCodeAt(0).toString(16)).slice(-4));class y{constructor(){i(this,"logger",new E.Logger);i(this,"signatureKey")}async generateKey(){const e=process.env.SECRET_SIGNATURE;if(!e)throw new Error("Define a SECRET_SIGNATURE from `.env`");this.signatureKey=await n.JWK.asKey({kty:"oct",k:n.util.base64url.encode(e)})}async encrypt(e){if(await this.generateKey(),!this.signatureKey)throw new Error("PLEASE CREATE A KEY TO ENCRYPT 🙂");const r=JSON.stringify(e),s=a(r);return await n.JWE.createEncrypt({format:"compact"},this.signatureKey).update(s).final()}async decrypt(e){if(await this.generateKey(),!this.signatureKey)throw new Error("PLEASE CREATE A KEY TO DECRYPT 🙂");const{payload:r}=await n.JWE.createDecrypt(this.signatureKey).decrypt(e);return JSON.parse(r.toString())}async isEncrypted(e){this.logger.logInfo("EncryptionHandler",e);try{return await this.decrypt(e??""),this.logger.logDebug("EncryptionHandler","IS ENCRYPTED 🥵"),!0}catch(r){return this.logger.logWarn("EncryptionHandler",JSON.stringify(r)),this.logger.logDebug("EncryptionHandler","IS NOT ENCRYPTED 🙂"),!1}}generateSHA(e){const r=JSON.stringify(e);return g.createHash("sha256").update(r).digest("hex")}}exports.Encrypter=y;exports.escapeUnicode=a;
@@ -4,7 +4,7 @@ var a = (t, e, r) => s(t, typeof e != "symbol" ? e + "" : e, r);
4
4
  import n from "node-jose";
5
5
  import { createHash as c } from "crypto";
6
6
  import { L as E } from "./logger-DtlFWyFO.js";
7
- import "./lodash-QjAkD17S.js";
7
+ import "./lodash-BzOkiDvV.js";
8
8
  const g = (t) => t.replace(/[\u00A0-\uffff]/gu, (e) => "\\u" + ("000" + e.charCodeAt(0).toString(16)).slice(-4));
9
9
  class d {
10
10
  constructor() {