@binamik/js-providers 0.1.2 → 0.1.6
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,8 +21,8 @@ export interface IoErrorProps {
|
|
|
21
21
|
export interface IoResponseMetaProps {
|
|
22
22
|
status: number;
|
|
23
23
|
}
|
|
24
|
-
declare type IOResponseType<T> = [T, null, IoResponseMetaProps];
|
|
25
|
-
declare type IOResponseErrorType = [null, IoErrorProps, IoResponseMetaProps];
|
|
24
|
+
declare type IOResponseType<T> = [T, null, IoResponseMetaProps?];
|
|
25
|
+
declare type IOResponseErrorType = [null, IoErrorProps, IoResponseMetaProps?];
|
|
26
26
|
export declare type ApiResponseDTO<T> = IOResponseType<T> | IOResponseErrorType;
|
|
27
27
|
declare type IoFn = <T>(url: string, payload?: Record<string, unknown>, config?: AxiosRequestConfig) => Promise<ApiResponseDTO<T>>;
|
|
28
28
|
interface IoInstanceProps {
|
|
@@ -30,6 +30,7 @@ export declare class SafeDate {
|
|
|
30
30
|
get isoString(): string;
|
|
31
31
|
get dateString(): string;
|
|
32
32
|
get longDayMonth(): string;
|
|
33
|
+
get shortDayMonth(): string;
|
|
33
34
|
get longDateString(): string;
|
|
34
35
|
get timeString(): string;
|
|
35
36
|
get daysInMonth(): number;
|
|
@@ -56,6 +57,7 @@ export declare class SafeDate {
|
|
|
56
57
|
isBetween(startingDate: Date | string, endingDate: Date | string, unit?: DateTimeUnits): boolean;
|
|
57
58
|
getDiff(date: Date | string, unit: DateTimeUnits): number;
|
|
58
59
|
clone(): SafeDate;
|
|
60
|
+
format(format: string): string;
|
|
59
61
|
constructor(pValue?: Date | string | Dayjs);
|
|
60
62
|
}
|
|
61
63
|
export {};
|
|
@@ -60,6 +60,9 @@ class SafeDate {
|
|
|
60
60
|
get longDayMonth() {
|
|
61
61
|
return this.returnHandler(this.value.format("DD [de] MMMM"), "");
|
|
62
62
|
}
|
|
63
|
+
get shortDayMonth() {
|
|
64
|
+
return this.returnHandler(this.value.format("DD MMM"), "");
|
|
65
|
+
}
|
|
63
66
|
get longDateString() {
|
|
64
67
|
return this.returnHandler(this.value.format("DD [de] MMMM [de] YYYY"), "");
|
|
65
68
|
}
|
|
@@ -173,6 +176,9 @@ class SafeDate {
|
|
|
173
176
|
clone() {
|
|
174
177
|
return new SafeDate(this.value);
|
|
175
178
|
}
|
|
179
|
+
format(format) {
|
|
180
|
+
return this.returnHandler(this.value.format(format), "");
|
|
181
|
+
}
|
|
176
182
|
}
|
|
177
183
|
const get = (_domain, prefix) => (key) => {
|
|
178
184
|
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
|
|
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"}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@binamik/js-providers",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite",
|
|
6
6
|
"build": "tsc && vite build",
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"files": [
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
|
-
"main": "./dist/binamik-providers.umd.js",
|
|
42
|
-
"module": "./dist/binamik-providers.es.js",
|
|
41
|
+
"main": "./dist/binamik-js-providers.umd.js",
|
|
42
|
+
"module": "./dist/binamik-js-providers.es.js",
|
|
43
43
|
"types": "./dist/index.d.ts",
|
|
44
44
|
"exports": {
|
|
45
45
|
".": {
|
|
46
|
-
"import": "./dist/binamik-providers.es.js",
|
|
47
|
-
"require": "./dist/binamik-providers.umd.js"
|
|
46
|
+
"import": "./dist/binamik-js-providers.es.js",
|
|
47
|
+
"require": "./dist/binamik-js-providers.umd.js"
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
}
|