@binamik/js-providers 0.1.6 → 0.1.7

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.
@@ -21,9 +21,13 @@ interface SetToOptions {
21
21
  export declare class SafeDate {
22
22
  private value;
23
23
  private isDateValid;
24
- static isValid(value?: Date | string | Dayjs): boolean;
24
+ private locale;
25
25
  private returnHandler;
26
+ private i18nFormat;
27
+ private getI18nCode;
28
+ static isValid(value?: Date | string | Dayjs): boolean;
26
29
  get isValid(): boolean;
30
+ get lang(): string;
27
31
  get jsDate(): Date;
28
32
  get timestamp(): number;
29
33
  get isoDate(): string;
@@ -58,6 +62,7 @@ export declare class SafeDate {
58
62
  getDiff(date: Date | string, unit: DateTimeUnits): number;
59
63
  clone(): SafeDate;
60
64
  format(format: string): string;
65
+ setLocale(locale: string): this;
61
66
  constructor(pValue?: Date | string | Dayjs);
62
67
  }
63
68
  export {};
@@ -0,0 +1,5 @@
1
+ export interface LangFormatProps {
2
+ shortDayAndMonth: string;
3
+ longDayAndMonth: string;
4
+ }
5
+ export declare const localizedFormatString: Record<string, LangFormatProps>;
@@ -0,0 +1 @@
1
+ export declare const getSafeLangCode: (langCode: string) => string;
@@ -23,25 +23,116 @@ import "dayjs/locale/pt-br";
23
23
  import { parseCookies, setCookie, destroyCookie } from "nookies";
24
24
  import axios from "axios";
25
25
  import { object } from "yup";
26
+ var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
27
+ var es = { exports: {} };
28
+ (function(module, exports) {
29
+ !function(e, o) {
30
+ module.exports = o(dayjs);
31
+ }(commonjsGlobal, function(e) {
32
+ function o(e2) {
33
+ return e2 && typeof e2 == "object" && "default" in e2 ? e2 : { default: e2 };
34
+ }
35
+ var s = o(e), d = { name: "es", monthsShort: "ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic".split("_"), weekdays: "domingo_lunes_martes_mi\xE9rcoles_jueves_viernes_s\xE1bado".split("_"), weekdaysShort: "dom._lun._mar._mi\xE9._jue._vie._s\xE1b.".split("_"), weekdaysMin: "do_lu_ma_mi_ju_vi_s\xE1".split("_"), months: "enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre".split("_"), weekStart: 1, formats: { LT: "H:mm", LTS: "H:mm:ss", L: "DD/MM/YYYY", LL: "D [de] MMMM [de] YYYY", LLL: "D [de] MMMM [de] YYYY H:mm", LLLL: "dddd, D [de] MMMM [de] YYYY H:mm" }, relativeTime: { future: "en %s", past: "hace %s", s: "unos segundos", m: "un minuto", mm: "%d minutos", h: "una hora", hh: "%d horas", d: "un d\xEDa", dd: "%d d\xEDas", M: "un mes", MM: "%d meses", y: "un a\xF1o", yy: "%d a\xF1os" }, ordinal: function(e2) {
36
+ return e2 + "\xBA";
37
+ } };
38
+ return s.default.locale(d, null, true), d;
39
+ });
40
+ })(es);
41
+ var en = { exports: {} };
42
+ (function(module, exports) {
43
+ !function(e, n) {
44
+ module.exports = n();
45
+ }(commonjsGlobal, function() {
46
+ return { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_") };
47
+ });
48
+ })(en);
49
+ var localizedFormat$1 = { exports: {} };
50
+ (function(module, exports) {
51
+ !function(e, t) {
52
+ module.exports = t();
53
+ }(commonjsGlobal, function() {
54
+ var e = { LTS: "h:mm:ss A", LT: "h:mm A", L: "MM/DD/YYYY", LL: "MMMM D, YYYY", LLL: "MMMM D, YYYY h:mm A", LLLL: "dddd, MMMM D, YYYY h:mm A" };
55
+ return function(t, o, n) {
56
+ var r = o.prototype, i = r.format;
57
+ n.en.formats = e, r.format = function(t2) {
58
+ t2 === void 0 && (t2 = "YYYY-MM-DDTHH:mm:ssZ");
59
+ var o2 = this.$locale().formats, n2 = function(t3, o3) {
60
+ return t3.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, function(t4, n3, r2) {
61
+ var i2 = r2 && r2.toUpperCase();
62
+ return n3 || o3[r2] || e[r2] || o3[i2].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, function(e2, t5, o4) {
63
+ return t5 || o4.slice(1);
64
+ });
65
+ });
66
+ }(t2, o2 === void 0 ? {} : o2);
67
+ return i.call(this, n2);
68
+ };
69
+ };
70
+ });
71
+ })(localizedFormat$1);
72
+ var localizedFormat = localizedFormat$1.exports;
73
+ const localizedFormatString = {
74
+ en: {
75
+ shortDayAndMonth: "MMM DD",
76
+ longDayAndMonth: "MMMM DD"
77
+ },
78
+ es: {
79
+ shortDayAndMonth: "DD MMM",
80
+ longDayAndMonth: "DD [de] MMMM"
81
+ },
82
+ "pt-br": {
83
+ shortDayAndMonth: "DD MMM",
84
+ longDayAndMonth: "DD [de] MMMM"
85
+ }
86
+ };
87
+ const safeLangCodes = {
88
+ pt: "pt-br",
89
+ pt_br: "pt-br",
90
+ "pt-br": "pt-br",
91
+ en: "en",
92
+ en_us: "en",
93
+ "en-us": "en",
94
+ en_gb: "en",
95
+ "en-gb": "en",
96
+ es: "es",
97
+ es_es: "es",
98
+ "es-es": "es"
99
+ };
100
+ const getSafeLangCode = (langCode) => {
101
+ const code = safeLangCodes[langCode.toLowerCase()];
102
+ return code || safeLangCodes.pt;
103
+ };
104
+ dayjs.extend(localizedFormat);
26
105
  class SafeDate {
27
106
  constructor(pValue) {
28
107
  __publicField(this, "value", dayjs());
29
108
  __publicField(this, "isDateValid", true);
109
+ __publicField(this, "locale", "pt-br");
110
+ this.locale = "pt-br";
30
111
  this.value = dayjs(pValue).locale("pt-br");
31
112
  this.isDateValid = this.value.isValid();
32
113
  if (!this.isDateValid) {
33
114
  console.error("Invalid date:", pValue);
34
115
  }
35
116
  }
36
- static isValid(value) {
37
- return dayjs(value || "").isValid();
38
- }
39
117
  returnHandler(value, onInvalid) {
40
118
  return this.isDateValid ? value : onInvalid;
41
119
  }
120
+ i18nFormat(key, fallback) {
121
+ var _a;
122
+ return ((_a = localizedFormatString[this.locale]) == null ? void 0 : _a[key]) || fallback;
123
+ }
124
+ getI18nCode(locale) {
125
+ return getSafeLangCode(locale);
126
+ }
127
+ static isValid(value) {
128
+ return dayjs(value || "").isValid();
129
+ }
42
130
  get isValid() {
43
131
  return this.isDateValid;
44
132
  }
133
+ get lang() {
134
+ return this.locale;
135
+ }
45
136
  get jsDate() {
46
137
  return this.value.toDate();
47
138
  }
@@ -55,19 +146,19 @@ class SafeDate {
55
146
  return this.returnHandler(this.value.format("YYYY-MM-DDTHH:mm:ss"), "");
56
147
  }
57
148
  get dateString() {
58
- return this.returnHandler(this.value.format("DD/MM/YYYY"), "");
149
+ return this.returnHandler(this.value.format("L"), "");
59
150
  }
60
151
  get longDayMonth() {
61
- return this.returnHandler(this.value.format("DD [de] MMMM"), "");
152
+ return this.returnHandler(this.value.format(this.i18nFormat("longDayAndMonth", "DD [de] MMMM")), "");
62
153
  }
63
154
  get shortDayMonth() {
64
- return this.returnHandler(this.value.format("DD MMM"), "");
155
+ return this.returnHandler(this.value.format(this.i18nFormat("shortDayAndMonth", "DD MMM")), "");
65
156
  }
66
157
  get longDateString() {
67
- return this.returnHandler(this.value.format("DD [de] MMMM [de] YYYY"), "");
158
+ return this.returnHandler(this.value.format("LL"), "");
68
159
  }
69
160
  get timeString() {
70
- return this.returnHandler(this.value.format("HH:mm"), "");
161
+ return this.returnHandler(this.value.format("LT"), "");
71
162
  }
72
163
  get daysInMonth() {
73
164
  return this.returnHandler(this.value.daysInMonth(), 0);
@@ -179,6 +270,12 @@ class SafeDate {
179
270
  format(format) {
180
271
  return this.returnHandler(this.value.format(format), "");
181
272
  }
273
+ setLocale(locale) {
274
+ const safeLocale = this.getI18nCode(locale);
275
+ this.value = this.value.locale(safeLocale);
276
+ this.locale = safeLocale;
277
+ return this;
278
+ }
182
279
  }
183
280
  const get = (_domain, prefix) => (key) => {
184
281
  const cookies = parseCookies();
@@ -1 +1 @@
1
- (function(n,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("dayjs"),require("dayjs/locale/pt-br"),require("nookies"),require("axios"),require("yup")):typeof define=="function"&&define.amd?define(["exports","dayjs","dayjs/locale/pt-br","nookies","axios","yup"],i):(n=typeof globalThis!="undefined"?globalThis:n||self,i(n.BinamikJSProviders={},n.dayjs,null,n.nookies,n.axios,n.yup))})(this,function(n,i,o,g,S,_){"use strict";var $=Object.defineProperty;var I=Object.getOwnPropertySymbols;var R=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var H=(n,i,o)=>i in n?$(n,i,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[i]=o,E=(n,i)=>{for(var o in i||(i={}))R.call(i,o)&&H(n,o,i[o]);if(I)for(var o of I(i))L.call(i,o)&&H(n,o,i[o]);return n};var V=(n,i,o)=>(H(n,typeof i!="symbol"?i+"":i,o),o);function A(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var D=A(i),Y=A(S);class M{constructor(t){V(this,"value",D.default());V(this,"isDateValid",!0);this.value=D.default(t).locale("pt-br"),this.isDateValid=this.value.isValid(),this.isDateValid||console.error("Invalid date:",t)}static isValid(t){return D.default(t||"").isValid()}returnHandler(t,a){return this.isDateValid?t:a}get isValid(){return this.isDateValid}get jsDate(){return this.value.toDate()}get timestamp(){return this.returnHandler(this.jsDate.getTime(),NaN)}get isoDate(){return this.returnHandler(this.value.format("YYYY-MM-DD"),"")}get isoString(){return this.returnHandler(this.value.format("YYYY-MM-DDTHH:mm:ss"),"")}get dateString(){return this.returnHandler(this.value.format("DD/MM/YYYY"),"")}get longDayMonth(){return this.returnHandler(this.value.format("DD [de] MMMM"),"")}get shortDayMonth(){return this.returnHandler(this.value.format("DD MMM"),"")}get longDateString(){return this.returnHandler(this.value.format("DD [de] MMMM [de] YYYY"),"")}get timeString(){return this.returnHandler(this.value.format("HH:mm"),"")}get daysInMonth(){return this.returnHandler(this.value.daysInMonth(),0)}get dateObj(){return this.returnHandler({year:this.value.year(),month:this.value.month(),date:this.value.date(),weekday:this.value.day(),hours:this.value.hour(),minutes:this.value.minute(),seconds:this.value.second(),milliseconds:this.value.millisecond()},{year:0,month:0,date:0,weekday:0,hours:0,minutes:0,seconds:0,milliseconds:0})}setToStartOf(t){return this.value=this.value.startOf(t),this}addDays(t){return this.value=this.isDateValid?this.value.add(t,"day"):this.value,this}addMonths(t){return this.value=this.isDateValid?this.value.add(t,"month"):this.value,this}addYears(t){return this.value=this.isDateValid?this.value.add(t,"year"):this.value,this}addHours(t){return this.value=this.isDateValid?this.value.add(t,"hour"):this.value,this}addToDate({years:t=0,months:a=0,weeks:s=0,days:u=0,hours:h=0,minutes:d=0,seconds:r=0}){return this.value=this.isDateValid?this.value.add(t,"year").add(a,"month").add(s,"week").add(u,"day").add(h,"hour").add(d,"minute").add(r,"second"):this.value,this}setTo(t){const a=this.isDateValid?{year:this.value.year(),month:this.value.month(),day:this.value.date(),hour:this.value.hour(),minute:this.value.minute(),second:this.value.second(),milisecond:this.value.millisecond()}:{year:0,month:0,day:0,hour:0,minute:0,second:0,milisecond:0},{year:s=a.year,month:u=a.month,day:h=a.day,hour:d=a.hour,minute:r=a.minute,second:p=a.second,milisecond:l=a.milisecond}=t;return this.value=this.isDateValid?this.value.year(s).month(u).date(h).hour(d).minute(r).second(p).millisecond(l):this.value,this}isBefore(t,a){return this.returnHandler(this.value.isBefore(t,a),!1)}isAfter(t,a){return this.returnHandler(this.value.isAfter(t,a),!1)}isSame(t,a){return this.returnHandler(this.value.isSame(t,a),!1)}isBetween(t,a,s){const u=this.returnHandler(this.value.isAfter(t,s),!1),h=this.returnHandler(this.value.isBefore(a,s),!1),d=u&&h||!u&&!h;return this.returnHandler(d,!1)}getDiff(t,a){return this.returnHandler(this.value.diff(t,a),0)}clone(){return new M(this.value)}format(t){return this.returnHandler(this.value.format(t),"")}}const w=(e,t)=>a=>g.parseCookies()[`${t}-${a}`],T=(e,t)=>(a,s,u)=>{g.setCookie(null,`${t}-${a}`,s,{maxAge:(u==null?void 0:u.maxAge)||60*60*24*90,path:"/",domain:e,secure:!0,httpOnly:!0})},m=(e,t)=>(a,s)=>{g.destroyCookie(null,`${t}-${a}`,s)},j=(e,t)=>a=>{m(e,t)("auth-key",a),m(e,t)("user",a),m(e,t)("company",a),m(e,t)("orb-selected",a)},N=({cookieDomain:e,cookiePrefix:t})=>({get:w(e,t),set:T(e,t),remove:m(e,t),cleanAuth:j(e,t)}),P=typeof window=="undefined",O=e=>/(^(\d{1,3}\.){3}(\d{1,3})(:\d{1,5})?$)/.test(e),b=e=>({}.NEXT_PUBLIC_APP_ENV||{}.REACT_APP_ENVIRONMENT||{}.REACT_APP_ENV||"production")==="local"&&(e.includes("localhost")||O(e)),k=e=>{var a;const t={};return(a=e==null?void 0:e.inner)!=null&&a.length?e.inner.forEach(s=>{t[(s==null?void 0:s.path)||"unknown"]=s.message}):(e==null?void 0:e.path)&&(e==null?void 0:e.message)?t[e.path]=e.message:!(e!=null&&e.path)&&(e==null?void 0:e.type)==="typeError"&&(t.body=e.errors[0]),t},q=async({name:e="",url:t="",req:a={},res:s={},schema:u=_.object()})=>{var h;P||!b((h=window==null?void 0:window.location)==null?void 0:h.hostname)||u.validate(s,{abortEarly:!1}).catch(d=>{const r=k(d);console.warn(`PLEASE check the backend IO for >> ${e} <<, some discrepancies were found in the expected response`,{functionName:e,endPoint:t,request:a,response:s,validationErrors:r})})},B=e=>t=>{if(e&&(t==null?void 0:t.status)){const a=t.status,s=e[a];s&&s(t)}},f=e=>t=>{var a,s;return e&&e.name&&e.schema&&q({name:e.name,schema:e.schema,req:{body:((a=t==null?void 0:t.config)==null?void 0:a.data)||null,query:(s=t==null?void 0:t.config)==null?void 0:s.params},res:t==null?void 0:t.data,url:t==null?void 0:t.request.url}),[t.data,null,{status:t.status}]},y=e=>t=>{var u,h,d;const a=(u=t==null?void 0:t.response)==null?void 0:u.data,s=e?e(a||null):void 0;return[null,{status:((h=t==null?void 0:t.response)==null?void 0:h.status)||599,message:(a==null?void 0:a.message)||(a==null?void 0:a.msg)||"Unknown IO Error",errorData:a||null,errors:s},{status:((d=t==null?void 0:t.response)==null?void 0:d.status)||599}]},C=(e,t)=>{const{withAuth:a=!1,authKey:s="",ioIntegrityCheck:u,onStatusCode:h,errorParser:d}=t||{},r=Y.default.create({baseURL:e,headers:a?{"Content-Type":"application/json",Authorization:s||"no_auth_key"}:{"Content-Type":"application/json"}}),p=B(h);return r.interceptors.response.use(l=>(p(l),l),l=>{throw l!=null&&l.response&&p(l.response),l}),{get:(l,c,v={})=>r.get(l,E({params:c},v)).then(f(u)).catch(y(d)),post:(l,c,v)=>r.post(l,c,v).then(f(u)).catch(y(d)),patch:(l,c,v)=>r.patch(l,c,v).then(f(u)).catch(y(d)),delete:(l,c,v={})=>r.delete(l,E({params:c},v)).then(f(u)).catch(y(d))}};n.AppStorageProvider=N,n.SafeDate=M,n.createIoInstance=C,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(o,d){typeof exports=="object"&&typeof module!="undefined"?d(exports,require("dayjs"),require("dayjs/locale/pt-br"),require("nookies"),require("axios"),require("yup")):typeof define=="function"&&define.amd?define(["exports","dayjs","dayjs/locale/pt-br","nookies","axios","yup"],d):(o=typeof globalThis!="undefined"?globalThis:o||self,d(o.BinamikJSProviders={},o.dayjs,null,o.nookies,o.axios,o.yup))})(this,function(o,d,r,g,E,V){"use strict";var tt=Object.defineProperty;var j=Object.getOwnPropertySymbols;var et=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable;var L=(o,d,r)=>d in o?tt(o,d,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[d]=r,A=(o,d)=>{for(var r in d||(d={}))et.call(d,r)&&L(o,r,d[r]);if(j)for(var r of j(d))at.call(d,r)&&L(o,r,d[r]);return o};var D=(o,d,r)=>(L(o,typeof d!="symbol"?d+"":d,r),r);function S(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var v=S(d),I=S(E),Y=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},N={exports:{}};(function(e,t){(function(a,n){e.exports=n(v.default)})(Y,function(a){function n(s){return s&&typeof s=="object"&&"default"in s?s:{default:s}}var i=n(a),l={name:"es",monthsShort:"ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic".split("_"),weekdays:"domingo_lunes_martes_mi\xE9rcoles_jueves_viernes_s\xE1bado".split("_"),weekdaysShort:"dom._lun._mar._mi\xE9._jue._vie._s\xE1b.".split("_"),weekdaysMin:"do_lu_ma_mi_ju_vi_s\xE1".split("_"),months:"enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre".split("_"),weekStart:1,formats:{LT:"H:mm",LTS:"H:mm:ss",L:"DD/MM/YYYY",LL:"D [de] MMMM [de] YYYY",LLL:"D [de] MMMM [de] YYYY H:mm",LLLL:"dddd, D [de] MMMM [de] YYYY H:mm"},relativeTime:{future:"en %s",past:"hace %s",s:"unos segundos",m:"un minuto",mm:"%d minutos",h:"una hora",hh:"%d horas",d:"un d\xEDa",dd:"%d d\xEDas",M:"un mes",MM:"%d meses",y:"un a\xF1o",yy:"%d a\xF1os"},ordinal:function(s){return s+"\xBA"}};return i.default.locale(l,null,!0),l})})(N);var k={exports:{}};(function(e,t){(function(a,n){e.exports=n()})(Y,function(){return{name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_")}})})(k);var H={exports:{}};(function(e,t){(function(a,n){e.exports=n()})(Y,function(){var a={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(n,i,l){var s=i.prototype,h=s.format;l.en.formats=a,s.format=function(f){f===void 0&&(f="YYYY-MM-DDTHH:mm:ssZ");var u=this.$locale().formats,c=function(m,w){return m.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(nt,W,_){var X=_&&_.toUpperCase();return W||w[_]||a[_]||w[X].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(st,Z,Q){return Z||Q.slice(1)})})}(f,u===void 0?{}:u);return h.call(this,c)}}})})(H);var C=H.exports;const P={en:{shortDayAndMonth:"MMM DD",longDayAndMonth:"MMMM DD"},es:{shortDayAndMonth:"DD MMM",longDayAndMonth:"DD [de] MMMM"},"pt-br":{shortDayAndMonth:"DD MMM",longDayAndMonth:"DD [de] MMMM"}},T={pt:"pt-br",pt_br:"pt-br","pt-br":"pt-br",en:"en",en_us:"en","en-us":"en",en_gb:"en","en-gb":"en",es:"es",es_es:"es","es-es":"es"},O=e=>T[e.toLowerCase()]||T.pt;v.default.extend(C);class b{constructor(t){D(this,"value",v.default());D(this,"isDateValid",!0);D(this,"locale","pt-br");this.locale="pt-br",this.value=v.default(t).locale("pt-br"),this.isDateValid=this.value.isValid(),this.isDateValid||console.error("Invalid date:",t)}returnHandler(t,a){return this.isDateValid?t:a}i18nFormat(t,a){var n;return((n=P[this.locale])==null?void 0:n[t])||a}getI18nCode(t){return O(t)}static isValid(t){return v.default(t||"").isValid()}get isValid(){return this.isDateValid}get lang(){return this.locale}get jsDate(){return this.value.toDate()}get timestamp(){return this.returnHandler(this.jsDate.getTime(),NaN)}get isoDate(){return this.returnHandler(this.value.format("YYYY-MM-DD"),"")}get isoString(){return this.returnHandler(this.value.format("YYYY-MM-DDTHH:mm:ss"),"")}get dateString(){return this.returnHandler(this.value.format("L"),"")}get longDayMonth(){return this.returnHandler(this.value.format(this.i18nFormat("longDayAndMonth","DD [de] MMMM")),"")}get shortDayMonth(){return this.returnHandler(this.value.format(this.i18nFormat("shortDayAndMonth","DD MMM")),"")}get longDateString(){return this.returnHandler(this.value.format("LL"),"")}get timeString(){return this.returnHandler(this.value.format("LT"),"")}get daysInMonth(){return this.returnHandler(this.value.daysInMonth(),0)}get dateObj(){return this.returnHandler({year:this.value.year(),month:this.value.month(),date:this.value.date(),weekday:this.value.day(),hours:this.value.hour(),minutes:this.value.minute(),seconds:this.value.second(),milliseconds:this.value.millisecond()},{year:0,month:0,date:0,weekday:0,hours:0,minutes:0,seconds:0,milliseconds:0})}setToStartOf(t){return this.value=this.value.startOf(t),this}addDays(t){return this.value=this.isDateValid?this.value.add(t,"day"):this.value,this}addMonths(t){return this.value=this.isDateValid?this.value.add(t,"month"):this.value,this}addYears(t){return this.value=this.isDateValid?this.value.add(t,"year"):this.value,this}addHours(t){return this.value=this.isDateValid?this.value.add(t,"hour"):this.value,this}addToDate({years:t=0,months:a=0,weeks:n=0,days:i=0,hours:l=0,minutes:s=0,seconds:h=0}){return this.value=this.isDateValid?this.value.add(t,"year").add(a,"month").add(n,"week").add(i,"day").add(l,"hour").add(s,"minute").add(h,"second"):this.value,this}setTo(t){const a=this.isDateValid?{year:this.value.year(),month:this.value.month(),day:this.value.date(),hour:this.value.hour(),minute:this.value.minute(),second:this.value.second(),milisecond:this.value.millisecond()}:{year:0,month:0,day:0,hour:0,minute:0,second:0,milisecond:0},{year:n=a.year,month:i=a.month,day:l=a.day,hour:s=a.hour,minute:h=a.minute,second:f=a.second,milisecond:u=a.milisecond}=t;return this.value=this.isDateValid?this.value.year(n).month(i).date(l).hour(s).minute(h).second(f).millisecond(u):this.value,this}isBefore(t,a){return this.returnHandler(this.value.isBefore(t,a),!1)}isAfter(t,a){return this.returnHandler(this.value.isAfter(t,a),!1)}isSame(t,a){return this.returnHandler(this.value.isSame(t,a),!1)}isBetween(t,a,n){const i=this.returnHandler(this.value.isAfter(t,n),!1),l=this.returnHandler(this.value.isBefore(a,n),!1),s=i&&l||!i&&!l;return this.returnHandler(s,!1)}getDiff(t,a){return this.returnHandler(this.value.diff(t,a),0)}clone(){return new b(this.value)}format(t){return this.returnHandler(this.value.format(t),"")}setLocale(t){const a=this.getI18nCode(t);return this.value=this.value.locale(a),this.locale=a,this}}const x=(e,t)=>a=>g.parseCookies()[`${t}-${a}`],$=(e,t)=>(a,n,i)=>{g.setCookie(null,`${t}-${a}`,n,{maxAge:(i==null?void 0:i.maxAge)||60*60*24*90,path:"/",domain:e,secure:!0,httpOnly:!0})},M=(e,t)=>(a,n)=>{g.destroyCookie(null,`${t}-${a}`,n)},q=(e,t)=>a=>{M(e,t)("auth-key",a),M(e,t)("user",a),M(e,t)("company",a),M(e,t)("orb-selected",a)},B=({cookieDomain:e,cookiePrefix:t})=>({get:x(e,t),set:$(e,t),remove:M(e,t),cleanAuth:q(e,t)}),F=typeof window=="undefined",R=e=>/(^(\d{1,3}\.){3}(\d{1,3})(:\d{1,5})?$)/.test(e),z=e=>({}.NEXT_PUBLIC_APP_ENV||{}.REACT_APP_ENVIRONMENT||{}.REACT_APP_ENV||"production")==="local"&&(e.includes("localhost")||R(e)),J=e=>{var a;const t={};return(a=e==null?void 0:e.inner)!=null&&a.length?e.inner.forEach(n=>{t[(n==null?void 0:n.path)||"unknown"]=n.message}):(e==null?void 0:e.path)&&(e==null?void 0:e.message)?t[e.path]=e.message:!(e!=null&&e.path)&&(e==null?void 0:e.type)==="typeError"&&(t.body=e.errors[0]),t},U=async({name:e="",url:t="",req:a={},res:n={},schema:i=V.object()})=>{var l;F||!z((l=window==null?void 0:window.location)==null?void 0:l.hostname)||i.validate(n,{abortEarly:!1}).catch(s=>{const h=J(s);console.warn(`PLEASE check the backend IO for >> ${e} <<, some discrepancies were found in the expected response`,{functionName:e,endPoint:t,request:a,response:n,validationErrors:h})})},G=e=>t=>{if(e&&(t==null?void 0:t.status)){const a=t.status,n=e[a];n&&n(t)}},p=e=>t=>{var a,n;return e&&e.name&&e.schema&&U({name:e.name,schema:e.schema,req:{body:((a=t==null?void 0:t.config)==null?void 0:a.data)||null,query:(n=t==null?void 0:t.config)==null?void 0:n.params},res:t==null?void 0:t.data,url:t==null?void 0:t.request.url}),[t.data,null,{status:t.status}]},y=e=>t=>{var i,l,s;const a=(i=t==null?void 0:t.response)==null?void 0:i.data,n=e?e(a||null):void 0;return[null,{status:((l=t==null?void 0:t.response)==null?void 0:l.status)||599,message:(a==null?void 0:a.message)||(a==null?void 0:a.msg)||"Unknown IO Error",errorData:a||null,errors:n},{status:((s=t==null?void 0:t.response)==null?void 0:s.status)||599}]},K=(e,t)=>{const{withAuth:a=!1,authKey:n="",ioIntegrityCheck:i,onStatusCode:l,errorParser:s}=t||{},h=I.default.create({baseURL:e,headers:a?{"Content-Type":"application/json",Authorization:n||"no_auth_key"}:{"Content-Type":"application/json"}}),f=G(l);return h.interceptors.response.use(u=>(f(u),u),u=>{throw u!=null&&u.response&&f(u.response),u}),{get:(u,c,m={})=>h.get(u,A({params:c},m)).then(p(i)).catch(y(s)),post:(u,c,m)=>h.post(u,c,m).then(p(i)).catch(y(s)),patch:(u,c,m)=>h.patch(u,c,m).then(p(i)).catch(y(s)),delete:(u,c,m={})=>h.delete(u,A({params:c},m)).then(p(i)).catch(y(s))}};o.AppStorageProvider=B,o.SafeDate=b,o.createIoInstance=K,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@binamik/js-providers",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "scripts": {
5
5
  "dev": "vite",
6
6
  "build": "tsc && vite build",