@binamik/js-providers 0.1.6 → 1.0.0
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/AppStorageProvider/binamik-js-providers.es.js +12 -0
- package/dist/IoProvider/binamik-js-providers.es.js +37 -0
- package/dist/IoProvider/binamik-js-providers.es2.js +12 -0
- package/dist/SafeDate/SafeDate.d.ts +25 -32
- package/dist/SafeDate/binamik-js-providers.es.js +109 -0
- package/dist/SafeDate/i18n/binamik-js-providers.es.js +2 -0
- package/dist/SafeDate/i18n/binamik-js-providers.es2.js +2 -0
- package/dist/SafeDate/i18n/localizedFormatString.d.ts +20 -0
- package/dist/SafeDate/i18n/safeLangCode.d.ts +1 -0
- package/dist/binamik-js-providers.es.js +3 -326
- package/dist/utils/binamik-js-providers.es.js +2 -0
- package/dist/utils/binamik-js-providers.es2.js +2 -0
- package/dist/utils/yup/binamik-js-providers.es.js +8 -0
- package/package.json +8 -7
- package/dist/binamik-js-providers.umd.js +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parseCookies as e, setCookie as o, destroyCookie as t } from "nookies";
|
|
2
|
+
const r = (e2, t2) => (r2, n2, a2) => {
|
|
3
|
+
o(null, `${t2}-${r2}`, n2, { maxAge: (a2 == null ? void 0 : a2.maxAge) || 7776e3, path: "/", domain: e2, secure: true, httpOnly: true });
|
|
4
|
+
}, n = (e2, o2) => (e3, r2) => {
|
|
5
|
+
t(null, `${o2}-${e3}`, r2);
|
|
6
|
+
}, a = (e2, o2) => (e3) => {
|
|
7
|
+
n(0, o2)("auth-key", e3), n(0, o2)("user", e3), n(0, o2)("company", e3), n(0, o2)("orb-selected", e3);
|
|
8
|
+
}, m = ({ cookieDomain: o2, cookiePrefix: t2 }) => {
|
|
9
|
+
return { get: (m2 = t2, (o3) => e()[`${m2}-${o3}`]), set: r(o2, t2), remove: n(0, t2), cleanAuth: a(0, t2) };
|
|
10
|
+
var m2;
|
|
11
|
+
};
|
|
12
|
+
export { m as AppStorageProvider };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a2, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a2, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a2, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a2;
|
|
16
|
+
};
|
|
17
|
+
import t from "axios";
|
|
18
|
+
import { checkIoIntegrity as e } from "./binamik-js-providers.es2.js";
|
|
19
|
+
const s = (t2) => (s2) => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
return t2 && t2.name && t2.schema && e({ name: t2.name, schema: t2.schema, req: { body: ((_a = s2 == null ? void 0 : s2.config) == null ? void 0 : _a.data) || null, query: (_b = s2 == null ? void 0 : s2.config) == null ? void 0 : _b.params }, res: s2 == null ? void 0 : s2.data, url: s2 == null ? void 0 : s2.request.url }), [s2.data, null, { status: s2.status }];
|
|
22
|
+
}, a = (t2) => (e2) => {
|
|
23
|
+
var _a, _b, _c;
|
|
24
|
+
const s2 = (_a = e2 == null ? void 0 : e2.response) == null ? void 0 : _a.data, a2 = t2 ? t2(s2 || null) : void 0;
|
|
25
|
+
return [null, { status: ((_b = e2 == null ? void 0 : e2.response) == null ? void 0 : _b.status) || 599, message: (s2 == null ? void 0 : s2.message) || (s2 == null ? void 0 : s2.msg) || "Unknown IO Error", errorData: s2 || null, errors: a2 }, { status: ((_c = e2 == null ? void 0 : e2.response) == null ? void 0 : _c.status) || 599 }];
|
|
26
|
+
}, r = (e2, r2) => {
|
|
27
|
+
const { withAuth: n = false, authKey: o = "", ioIntegrityCheck: u, onStatusCode: c, errorParser: p } = r2 || {}, h = t.create({ baseURL: e2, headers: n ? { "Content-Type": "application/json", Authorization: o || "no_auth_key" } : { "Content-Type": "application/json" } }), i = ((t2) => (e3) => {
|
|
28
|
+
if (t2 && (e3 == null ? void 0 : e3.status)) {
|
|
29
|
+
const s2 = e3.status, a2 = t2[s2];
|
|
30
|
+
a2 && a2(e3);
|
|
31
|
+
}
|
|
32
|
+
})(c);
|
|
33
|
+
return h.interceptors.response.use((t2) => (i(t2), t2), (t2) => {
|
|
34
|
+
throw (t2 == null ? void 0 : t2.response) && i(t2.response), t2;
|
|
35
|
+
}), { get: (t2, e3, r3 = {}) => h.get(t2, __spreadValues({ params: e3 }, r3)).then(s(u)).catch(a(p)), post: (t2, e3, r3) => h.post(t2, e3, r3).then(s(u)).catch(a(p)), patch: (t2, e3, r3) => h.patch(t2, e3, r3).then(s(u)).catch(a(p)), delete: (t2, e3, r3 = {}) => h.delete(t2, __spreadValues({ params: e3 }, r3)).then(s(u)).catch(a(p)) };
|
|
36
|
+
};
|
|
37
|
+
export { r as createIoInstance };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { object as e } from "yup";
|
|
2
|
+
import { isServer as s } from "../utils/binamik-js-providers.es.js";
|
|
3
|
+
import { isLocalhost as o } from "../utils/binamik-js-providers.es2.js";
|
|
4
|
+
import { getYupValidationErrors as r } from "../utils/yup/binamik-js-providers.es.js";
|
|
5
|
+
const i = async ({ name: i2 = "", url: n = "", req: t = {}, res: a = {}, schema: m = e() }) => {
|
|
6
|
+
var _a;
|
|
7
|
+
s || o((_a = window == null ? void 0 : window.location) == null ? void 0 : _a.hostname) && m.validate(a, { abortEarly: false }).catch((e2) => {
|
|
8
|
+
const s2 = r(e2);
|
|
9
|
+
console.warn(`PLEASE check the backend IO for >> ${i2} <<, some discrepancies were found in the expected response`, { functionName: i2, endPoint: n, request: t, response: a, validationErrors: s2 });
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export { i as checkIoIntegrity };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Dayjs } from 'dayjs';
|
|
2
|
+
import { LangFormatProps } from './i18n/localizedFormatString';
|
|
2
3
|
declare type DateTimeUnits = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
|
|
3
4
|
interface DateTimeOptions {
|
|
4
5
|
years?: number;
|
|
@@ -9,48 +10,38 @@ interface DateTimeOptions {
|
|
|
9
10
|
minutes?: number;
|
|
10
11
|
seconds?: number;
|
|
11
12
|
}
|
|
12
|
-
interface
|
|
13
|
-
year
|
|
14
|
-
month
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
interface DateObjProps {
|
|
14
|
+
year: number;
|
|
15
|
+
month: number;
|
|
16
|
+
date: number;
|
|
17
|
+
weekday: number;
|
|
18
|
+
hour: number;
|
|
19
|
+
minute: number;
|
|
20
|
+
second: number;
|
|
21
|
+
millisecond: number;
|
|
20
22
|
}
|
|
23
|
+
declare type ToOptions = Partial<Omit<DateObjProps, 'weekday'>>;
|
|
21
24
|
export declare class SafeDate {
|
|
22
25
|
private value;
|
|
23
26
|
private isDateValid;
|
|
27
|
+
private locale;
|
|
24
28
|
static isValid(value?: Date | string | Dayjs): boolean;
|
|
25
|
-
private
|
|
29
|
+
private validationHandler;
|
|
30
|
+
private imutableHandler;
|
|
31
|
+
private i18nFormat;
|
|
32
|
+
private getI18nCode;
|
|
26
33
|
get isValid(): boolean;
|
|
34
|
+
get lang(): string;
|
|
27
35
|
get jsDate(): Date;
|
|
28
36
|
get timestamp(): number;
|
|
29
37
|
get isoDate(): string;
|
|
30
38
|
get isoString(): string;
|
|
31
|
-
get dateString(): string;
|
|
32
|
-
get longDayMonth(): string;
|
|
33
|
-
get shortDayMonth(): string;
|
|
34
|
-
get longDateString(): string;
|
|
35
|
-
get timeString(): string;
|
|
36
39
|
get daysInMonth(): number;
|
|
37
|
-
get dateObj():
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
hours: number;
|
|
43
|
-
minutes: number;
|
|
44
|
-
seconds: number;
|
|
45
|
-
milliseconds: number;
|
|
46
|
-
};
|
|
47
|
-
setToStartOf(unit: DateTimeUnits): this;
|
|
48
|
-
addDays(days: number): this;
|
|
49
|
-
addMonths(months: number): this;
|
|
50
|
-
addYears(years: number): this;
|
|
51
|
-
addHours(hours: number): this;
|
|
52
|
-
addToDate({ years, months, weeks, days, hours, minutes, seconds }: DateTimeOptions): this;
|
|
53
|
-
setTo(newValues: SetToOptions): this;
|
|
40
|
+
get dateObj(): DateObjProps;
|
|
41
|
+
toStartOf(unit: DateTimeUnits): SafeDate;
|
|
42
|
+
add({ years, months, weeks, days, hours, minutes, seconds }: DateTimeOptions): SafeDate;
|
|
43
|
+
subtract({ years, months, weeks, days, hours, minutes, seconds }: DateTimeOptions): SafeDate;
|
|
44
|
+
to(newValues: ToOptions): SafeDate;
|
|
54
45
|
isBefore(date: Date | string, unit?: DateTimeUnits): boolean;
|
|
55
46
|
isAfter(date: Date | string, unit?: DateTimeUnits): boolean;
|
|
56
47
|
isSame(date: Date | string, unit?: DateTimeUnits): boolean;
|
|
@@ -58,6 +49,8 @@ export declare class SafeDate {
|
|
|
58
49
|
getDiff(date: Date | string, unit: DateTimeUnits): number;
|
|
59
50
|
clone(): SafeDate;
|
|
60
51
|
format(format: string): string;
|
|
61
|
-
|
|
52
|
+
formatIntl(formatTo: keyof LangFormatProps): string;
|
|
53
|
+
setLocale(locale: string): SafeDate;
|
|
54
|
+
constructor(pValue?: Date | string | Dayjs, locale?: string);
|
|
62
55
|
}
|
|
63
56
|
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import t from "dayjs";
|
|
8
|
+
import "dayjs/locale/pt-br";
|
|
9
|
+
import "dayjs/locale/es";
|
|
10
|
+
import "dayjs/locale/en";
|
|
11
|
+
import e from "dayjs/plugin/localizedFormat";
|
|
12
|
+
import { localizedFormatString as a } from "./i18n/binamik-js-providers.es.js";
|
|
13
|
+
import { getSafeLangCode as i } from "./i18n/binamik-js-providers.es2.js";
|
|
14
|
+
t.extend(e);
|
|
15
|
+
class s {
|
|
16
|
+
constructor(e2, a2 = "pt-br") {
|
|
17
|
+
__publicField(this, "value", t());
|
|
18
|
+
__publicField(this, "isDateValid", true);
|
|
19
|
+
__publicField(this, "locale", "pt-br");
|
|
20
|
+
this.locale = this.getI18nCode(a2), this.value = t(e2).locale(this.locale), this.isDateValid = this.value.isValid(), this.isDateValid || console.error("Invalid date:", e2);
|
|
21
|
+
}
|
|
22
|
+
static isValid(e2) {
|
|
23
|
+
return t(e2 || "").isValid();
|
|
24
|
+
}
|
|
25
|
+
validationHandler(t2, e2) {
|
|
26
|
+
return this.isDateValid ? t2 : e2;
|
|
27
|
+
}
|
|
28
|
+
imutableHandler(t2, e2) {
|
|
29
|
+
return new s(t2, e2 || this.locale);
|
|
30
|
+
}
|
|
31
|
+
i18nFormat(t2) {
|
|
32
|
+
var _a;
|
|
33
|
+
return ((_a = a[this.locale]) == null ? void 0 : _a[t2]) || a.default[t2] || "";
|
|
34
|
+
}
|
|
35
|
+
getI18nCode(t2) {
|
|
36
|
+
return i(t2);
|
|
37
|
+
}
|
|
38
|
+
get isValid() {
|
|
39
|
+
return this.isDateValid;
|
|
40
|
+
}
|
|
41
|
+
get lang() {
|
|
42
|
+
return this.locale;
|
|
43
|
+
}
|
|
44
|
+
get jsDate() {
|
|
45
|
+
return this.value.toDate();
|
|
46
|
+
}
|
|
47
|
+
get timestamp() {
|
|
48
|
+
return this.validationHandler(this.jsDate.getTime(), NaN);
|
|
49
|
+
}
|
|
50
|
+
get isoDate() {
|
|
51
|
+
return this.validationHandler(this.value.format("YYYY-MM-DD"), "");
|
|
52
|
+
}
|
|
53
|
+
get isoString() {
|
|
54
|
+
return this.validationHandler(this.value.format("YYYY-MM-DDTHH:mm:ss"), "");
|
|
55
|
+
}
|
|
56
|
+
get daysInMonth() {
|
|
57
|
+
return this.validationHandler(this.value.daysInMonth(), 0);
|
|
58
|
+
}
|
|
59
|
+
get dateObj() {
|
|
60
|
+
return this.validationHandler({ year: this.value.year(), month: this.value.month(), date: this.value.date(), weekday: this.value.day(), hour: this.value.hour(), minute: this.value.minute(), second: this.value.second(), millisecond: this.value.millisecond() }, { year: 0, month: 0, date: 0, weekday: 0, hour: 0, minute: 0, second: 0, millisecond: 0 });
|
|
61
|
+
}
|
|
62
|
+
toStartOf(t2) {
|
|
63
|
+
const e2 = this.validationHandler(this.value.startOf(t2), this.value);
|
|
64
|
+
return this.imutableHandler(e2);
|
|
65
|
+
}
|
|
66
|
+
add({ years: t2 = 0, months: e2 = 0, weeks: a2 = 0, days: i2 = 0, hours: s2 = 0, minutes: r = 0, seconds: n = 0 }) {
|
|
67
|
+
const l = this.validationHandler(this.value.add(t2, "year").add(e2, "month").add(a2, "week").add(i2, "day").add(s2, "hour").add(r, "minute").add(n, "second"), this.value);
|
|
68
|
+
return this.imutableHandler(l);
|
|
69
|
+
}
|
|
70
|
+
subtract({ years: t2 = 0, months: e2 = 0, weeks: a2 = 0, days: i2 = 0, hours: s2 = 0, minutes: r = 0, seconds: n = 0 }) {
|
|
71
|
+
const l = this.validationHandler(this.value.subtract(t2, "year").subtract(e2, "month").subtract(a2, "week").subtract(i2, "day").subtract(s2, "hour").subtract(r, "minute").subtract(n, "second"), this.value);
|
|
72
|
+
return this.imutableHandler(l);
|
|
73
|
+
}
|
|
74
|
+
to(t2) {
|
|
75
|
+
const e2 = this.dateObj, { year: a2 = e2.year, month: i2 = e2.month, date: s2 = e2.date, hour: r = e2.hour, minute: n = e2.minute, second: l = e2.second, millisecond: d = e2.millisecond } = t2, o = this.validationHandler(this.value.year(a2).month(i2).date(s2).hour(r).minute(n).second(l).millisecond(d), this.value);
|
|
76
|
+
return this.imutableHandler(o);
|
|
77
|
+
}
|
|
78
|
+
isBefore(t2, e2) {
|
|
79
|
+
return this.validationHandler(this.value.isBefore(t2, e2), false);
|
|
80
|
+
}
|
|
81
|
+
isAfter(t2, e2) {
|
|
82
|
+
return this.validationHandler(this.value.isAfter(t2, e2), false);
|
|
83
|
+
}
|
|
84
|
+
isSame(t2, e2) {
|
|
85
|
+
return this.validationHandler(this.value.isSame(t2, e2), false);
|
|
86
|
+
}
|
|
87
|
+
isBetween(t2, e2, a2) {
|
|
88
|
+
const i2 = this.validationHandler(this.value.isAfter(t2, a2), false), s2 = this.validationHandler(this.value.isBefore(e2, a2), false), r = i2 && s2 || !i2 && !s2;
|
|
89
|
+
return this.validationHandler(r, false);
|
|
90
|
+
}
|
|
91
|
+
getDiff(t2, e2) {
|
|
92
|
+
return this.validationHandler(this.value.diff(t2, e2), 0);
|
|
93
|
+
}
|
|
94
|
+
clone() {
|
|
95
|
+
return this.imutableHandler(this.value);
|
|
96
|
+
}
|
|
97
|
+
format(t2) {
|
|
98
|
+
return this.validationHandler(this.value.format(t2), "");
|
|
99
|
+
}
|
|
100
|
+
formatIntl(t2) {
|
|
101
|
+
const e2 = this.i18nFormat(t2);
|
|
102
|
+
return this.format(e2);
|
|
103
|
+
}
|
|
104
|
+
setLocale(t2) {
|
|
105
|
+
const e2 = this.getI18nCode(t2);
|
|
106
|
+
return this.imutableHandler(this.value, e2);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export { s as SafeDate };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const M = { default: { "DD MMM": "DD MMM", "DD [de] MMMM": "DD [de] MMMM", "DD MMM, YYYY": "DD MMM, YYYY", "DD/MM/YY": "DD/MM/YY", "DD/MM/YYYY": "L", "DD/MM/YYYY HH:mm": "L LT", "HH:mm": "LT", "HH:mm:ss": "LTS", "D [de] MMMM [de] YYYY": "LL", "D [de] MMMM [de] YYYY [\xE0s] HH:mm": "LLL" }, en: { "DD/MM/YY": "MM/DD/YY", "DD MMM": "MMM DD", "DD MMM, YYYY": "ll", "DD [de] MMMM": "MMMM DD" }, es: { "DD/MM/YY": "DD/MM/YY", "DD MMM": "DD MMM", "DD MMM, YYYY": "DD MMM, YYYY", "DD [de] MMMM": "DD [de] MMMM" }, "pt-br": { "DD/MM/YY": "DD/MM/YY", "DD MMM": "DD MMM", "DD MMM, YYYY": "DD MMM, YYYY", "DD [de] MMMM": "DD [de] MMMM" } };
|
|
2
|
+
export { M as localizedFormatString };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface LangFormatProps {
|
|
2
|
+
'DD MMM': string;
|
|
3
|
+
'DD [de] MMMM': string;
|
|
4
|
+
'DD MMM, YYYY': string;
|
|
5
|
+
'DD/MM/YY': string;
|
|
6
|
+
'DD/MM/YYYY'?: string;
|
|
7
|
+
'DD/MM/YYYY HH:mm'?: string;
|
|
8
|
+
'HH:mm'?: string;
|
|
9
|
+
'HH:mm:ss'?: string;
|
|
10
|
+
'D [de] MMMM [de] YYYY'?: string;
|
|
11
|
+
'D [de] MMMM [de] YYYY [às] HH:mm'?: string;
|
|
12
|
+
}
|
|
13
|
+
interface LocalizedFormatStringProps extends Record<string, LangFormatProps> {
|
|
14
|
+
default: Required<LangFormatProps>;
|
|
15
|
+
en: LangFormatProps;
|
|
16
|
+
'pt-br': LangFormatProps;
|
|
17
|
+
es: LangFormatProps;
|
|
18
|
+
}
|
|
19
|
+
export declare const localizedFormatString: LocalizedFormatStringProps;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getSafeLangCode: (langCode: string) => string;
|
|
@@ -1,326 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
var __publicField = (obj, key, value) => {
|
|
18
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
19
|
-
return value;
|
|
20
|
-
};
|
|
21
|
-
import dayjs from "dayjs";
|
|
22
|
-
import "dayjs/locale/pt-br";
|
|
23
|
-
import { parseCookies, setCookie, destroyCookie } from "nookies";
|
|
24
|
-
import axios from "axios";
|
|
25
|
-
import { object } from "yup";
|
|
26
|
-
class SafeDate {
|
|
27
|
-
constructor(pValue) {
|
|
28
|
-
__publicField(this, "value", dayjs());
|
|
29
|
-
__publicField(this, "isDateValid", true);
|
|
30
|
-
this.value = dayjs(pValue).locale("pt-br");
|
|
31
|
-
this.isDateValid = this.value.isValid();
|
|
32
|
-
if (!this.isDateValid) {
|
|
33
|
-
console.error("Invalid date:", pValue);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
static isValid(value) {
|
|
37
|
-
return dayjs(value || "").isValid();
|
|
38
|
-
}
|
|
39
|
-
returnHandler(value, onInvalid) {
|
|
40
|
-
return this.isDateValid ? value : onInvalid;
|
|
41
|
-
}
|
|
42
|
-
get isValid() {
|
|
43
|
-
return this.isDateValid;
|
|
44
|
-
}
|
|
45
|
-
get jsDate() {
|
|
46
|
-
return this.value.toDate();
|
|
47
|
-
}
|
|
48
|
-
get timestamp() {
|
|
49
|
-
return this.returnHandler(this.jsDate.getTime(), NaN);
|
|
50
|
-
}
|
|
51
|
-
get isoDate() {
|
|
52
|
-
return this.returnHandler(this.value.format("YYYY-MM-DD"), "");
|
|
53
|
-
}
|
|
54
|
-
get isoString() {
|
|
55
|
-
return this.returnHandler(this.value.format("YYYY-MM-DDTHH:mm:ss"), "");
|
|
56
|
-
}
|
|
57
|
-
get dateString() {
|
|
58
|
-
return this.returnHandler(this.value.format("DD/MM/YYYY"), "");
|
|
59
|
-
}
|
|
60
|
-
get longDayMonth() {
|
|
61
|
-
return this.returnHandler(this.value.format("DD [de] MMMM"), "");
|
|
62
|
-
}
|
|
63
|
-
get shortDayMonth() {
|
|
64
|
-
return this.returnHandler(this.value.format("DD MMM"), "");
|
|
65
|
-
}
|
|
66
|
-
get longDateString() {
|
|
67
|
-
return this.returnHandler(this.value.format("DD [de] MMMM [de] YYYY"), "");
|
|
68
|
-
}
|
|
69
|
-
get timeString() {
|
|
70
|
-
return this.returnHandler(this.value.format("HH:mm"), "");
|
|
71
|
-
}
|
|
72
|
-
get daysInMonth() {
|
|
73
|
-
return this.returnHandler(this.value.daysInMonth(), 0);
|
|
74
|
-
}
|
|
75
|
-
get dateObj() {
|
|
76
|
-
return this.returnHandler({
|
|
77
|
-
year: this.value.year(),
|
|
78
|
-
month: this.value.month(),
|
|
79
|
-
date: this.value.date(),
|
|
80
|
-
weekday: this.value.day(),
|
|
81
|
-
hours: this.value.hour(),
|
|
82
|
-
minutes: this.value.minute(),
|
|
83
|
-
seconds: this.value.second(),
|
|
84
|
-
milliseconds: this.value.millisecond()
|
|
85
|
-
}, {
|
|
86
|
-
year: 0,
|
|
87
|
-
month: 0,
|
|
88
|
-
date: 0,
|
|
89
|
-
weekday: 0,
|
|
90
|
-
hours: 0,
|
|
91
|
-
minutes: 0,
|
|
92
|
-
seconds: 0,
|
|
93
|
-
milliseconds: 0
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
setToStartOf(unit) {
|
|
97
|
-
this.value = this.value.startOf(unit);
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
addDays(days) {
|
|
101
|
-
this.value = this.isDateValid ? this.value.add(days, "day") : this.value;
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
addMonths(months) {
|
|
105
|
-
this.value = this.isDateValid ? this.value.add(months, "month") : this.value;
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
addYears(years) {
|
|
109
|
-
this.value = this.isDateValid ? this.value.add(years, "year") : this.value;
|
|
110
|
-
return this;
|
|
111
|
-
}
|
|
112
|
-
addHours(hours) {
|
|
113
|
-
this.value = this.isDateValid ? this.value.add(hours, "hour") : this.value;
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
addToDate({
|
|
117
|
-
years = 0,
|
|
118
|
-
months = 0,
|
|
119
|
-
weeks = 0,
|
|
120
|
-
days = 0,
|
|
121
|
-
hours = 0,
|
|
122
|
-
minutes = 0,
|
|
123
|
-
seconds = 0
|
|
124
|
-
}) {
|
|
125
|
-
this.value = this.isDateValid ? this.value.add(years, "year").add(months, "month").add(weeks, "week").add(days, "day").add(hours, "hour").add(minutes, "minute").add(seconds, "second") : this.value;
|
|
126
|
-
return this;
|
|
127
|
-
}
|
|
128
|
-
setTo(newValues) {
|
|
129
|
-
const currentValues = this.isDateValid ? {
|
|
130
|
-
year: this.value.year(),
|
|
131
|
-
month: this.value.month(),
|
|
132
|
-
day: this.value.date(),
|
|
133
|
-
hour: this.value.hour(),
|
|
134
|
-
minute: this.value.minute(),
|
|
135
|
-
second: this.value.second(),
|
|
136
|
-
milisecond: this.value.millisecond()
|
|
137
|
-
} : {
|
|
138
|
-
year: 0,
|
|
139
|
-
month: 0,
|
|
140
|
-
day: 0,
|
|
141
|
-
hour: 0,
|
|
142
|
-
minute: 0,
|
|
143
|
-
second: 0,
|
|
144
|
-
milisecond: 0
|
|
145
|
-
};
|
|
146
|
-
const {
|
|
147
|
-
year = currentValues.year,
|
|
148
|
-
month = currentValues.month,
|
|
149
|
-
day = currentValues.day,
|
|
150
|
-
hour = currentValues.hour,
|
|
151
|
-
minute = currentValues.minute,
|
|
152
|
-
second = currentValues.second,
|
|
153
|
-
milisecond = currentValues.milisecond
|
|
154
|
-
} = newValues;
|
|
155
|
-
this.value = this.isDateValid ? this.value.year(year).month(month).date(day).hour(hour).minute(minute).second(second).millisecond(milisecond) : this.value;
|
|
156
|
-
return this;
|
|
157
|
-
}
|
|
158
|
-
isBefore(date, unit) {
|
|
159
|
-
return this.returnHandler(this.value.isBefore(date, unit), false);
|
|
160
|
-
}
|
|
161
|
-
isAfter(date, unit) {
|
|
162
|
-
return this.returnHandler(this.value.isAfter(date, unit), false);
|
|
163
|
-
}
|
|
164
|
-
isSame(date, unit) {
|
|
165
|
-
return this.returnHandler(this.value.isSame(date, unit), false);
|
|
166
|
-
}
|
|
167
|
-
isBetween(startingDate, endingDate, unit) {
|
|
168
|
-
const isAfterStartingDate = this.returnHandler(this.value.isAfter(startingDate, unit), false);
|
|
169
|
-
const isBeforeEndingDate = this.returnHandler(this.value.isBefore(endingDate, unit), false);
|
|
170
|
-
const isBetweenDates = isAfterStartingDate && isBeforeEndingDate || !isAfterStartingDate && !isBeforeEndingDate;
|
|
171
|
-
return this.returnHandler(isBetweenDates, false);
|
|
172
|
-
}
|
|
173
|
-
getDiff(date, unit) {
|
|
174
|
-
return this.returnHandler(this.value.diff(date, unit), 0);
|
|
175
|
-
}
|
|
176
|
-
clone() {
|
|
177
|
-
return new SafeDate(this.value);
|
|
178
|
-
}
|
|
179
|
-
format(format) {
|
|
180
|
-
return this.returnHandler(this.value.format(format), "");
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
const get = (_domain, prefix) => (key) => {
|
|
184
|
-
const cookies = parseCookies();
|
|
185
|
-
return cookies[`${prefix}-${key}`];
|
|
186
|
-
};
|
|
187
|
-
const set = (domain, prefix) => (key, value, options) => {
|
|
188
|
-
setCookie(null, `${prefix}-${key}`, value, {
|
|
189
|
-
maxAge: (options == null ? void 0 : options.maxAge) || 60 * 60 * 24 * 90,
|
|
190
|
-
path: "/",
|
|
191
|
-
domain,
|
|
192
|
-
secure: true,
|
|
193
|
-
httpOnly: true
|
|
194
|
-
});
|
|
195
|
-
};
|
|
196
|
-
const remove = (_domain, prefix) => (key, options) => {
|
|
197
|
-
destroyCookie(null, `${prefix}-${key}`, options);
|
|
198
|
-
};
|
|
199
|
-
const cleanAuth = (domain, prefix) => (options) => {
|
|
200
|
-
remove(domain, prefix)("auth-key", options);
|
|
201
|
-
remove(domain, prefix)("user", options);
|
|
202
|
-
remove(domain, prefix)("company", options);
|
|
203
|
-
remove(domain, prefix)("orb-selected", options);
|
|
204
|
-
};
|
|
205
|
-
const AppStorageProvider = ({
|
|
206
|
-
cookieDomain,
|
|
207
|
-
cookiePrefix
|
|
208
|
-
}) => ({
|
|
209
|
-
get: get(cookieDomain, cookiePrefix),
|
|
210
|
-
set: set(cookieDomain, cookiePrefix),
|
|
211
|
-
remove: remove(cookieDomain, cookiePrefix),
|
|
212
|
-
cleanAuth: cleanAuth(cookieDomain, cookiePrefix)
|
|
213
|
-
});
|
|
214
|
-
const isServer = typeof window === "undefined";
|
|
215
|
-
const isIpv4 = (str) => /(^(\d{1,3}\.){3}(\d{1,3})(:\d{1,5})?$)/.test(str);
|
|
216
|
-
const isLocalhost = (host) => {
|
|
217
|
-
const APP_ENVIRONMENT = {}.NEXT_PUBLIC_APP_ENV || {}.REACT_APP_ENVIRONMENT || {}.REACT_APP_ENV || "production";
|
|
218
|
-
return APP_ENVIRONMENT === "local" && (host.includes("localhost") || isIpv4(host));
|
|
219
|
-
};
|
|
220
|
-
const getYupValidationErrors = (err) => {
|
|
221
|
-
var _a;
|
|
222
|
-
const validationErrors = {};
|
|
223
|
-
if ((_a = err == null ? void 0 : err.inner) == null ? void 0 : _a.length) {
|
|
224
|
-
err.inner.forEach((error) => {
|
|
225
|
-
validationErrors[(error == null ? void 0 : error.path) || "unknown"] = error.message;
|
|
226
|
-
});
|
|
227
|
-
} else if ((err == null ? void 0 : err.path) && (err == null ? void 0 : err.message)) {
|
|
228
|
-
validationErrors[err.path] = err.message;
|
|
229
|
-
} else if (!(err == null ? void 0 : err.path) && (err == null ? void 0 : err.type) === "typeError") {
|
|
230
|
-
validationErrors.body = err.errors[0];
|
|
231
|
-
}
|
|
232
|
-
return validationErrors;
|
|
233
|
-
};
|
|
234
|
-
const checkIoIntegrity = async ({
|
|
235
|
-
name = "",
|
|
236
|
-
url = "",
|
|
237
|
-
req = {},
|
|
238
|
-
res = {},
|
|
239
|
-
schema = object()
|
|
240
|
-
}) => {
|
|
241
|
-
var _a;
|
|
242
|
-
if (isServer)
|
|
243
|
-
return;
|
|
244
|
-
if (!isLocalhost((_a = window == null ? void 0 : window.location) == null ? void 0 : _a.hostname))
|
|
245
|
-
return;
|
|
246
|
-
schema.validate(res, { abortEarly: false }).catch((err) => {
|
|
247
|
-
const validationErrors = getYupValidationErrors(err);
|
|
248
|
-
console.warn(`PLEASE check the backend IO for >> ${name} <<, some discrepancies were found in the expected response`, {
|
|
249
|
-
functionName: name,
|
|
250
|
-
endPoint: url,
|
|
251
|
-
request: req,
|
|
252
|
-
response: res,
|
|
253
|
-
validationErrors
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
};
|
|
257
|
-
const createCheckStatusCodeFn = (onStatusCode) => (res) => {
|
|
258
|
-
if (onStatusCode && (res == null ? void 0 : res.status)) {
|
|
259
|
-
const statusCode = res.status;
|
|
260
|
-
const handler = onStatusCode[statusCode];
|
|
261
|
-
if (handler)
|
|
262
|
-
handler(res);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
const handleIOSuccess = (integrityCheck) => (res) => {
|
|
266
|
-
var _a, _b;
|
|
267
|
-
if (integrityCheck && integrityCheck.name && integrityCheck.schema) {
|
|
268
|
-
checkIoIntegrity({
|
|
269
|
-
name: integrityCheck.name,
|
|
270
|
-
schema: integrityCheck.schema,
|
|
271
|
-
req: { body: ((_a = res == null ? void 0 : res.config) == null ? void 0 : _a.data) || null, query: (_b = res == null ? void 0 : res.config) == null ? void 0 : _b.params },
|
|
272
|
-
res: res == null ? void 0 : res.data,
|
|
273
|
-
url: res == null ? void 0 : res.request.url
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
return [res.data, null, { status: res.status }];
|
|
277
|
-
};
|
|
278
|
-
const handleIOError = (errorParser) => (err) => {
|
|
279
|
-
var _a, _b, _c;
|
|
280
|
-
const resData = (_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data;
|
|
281
|
-
const errors = errorParser ? errorParser(resData || null) : void 0;
|
|
282
|
-
return [
|
|
283
|
-
null,
|
|
284
|
-
{
|
|
285
|
-
status: ((_b = err == null ? void 0 : err.response) == null ? void 0 : _b.status) || 599,
|
|
286
|
-
message: (resData == null ? void 0 : resData.message) || (resData == null ? void 0 : resData.msg) || "Unknown IO Error",
|
|
287
|
-
errorData: resData || null,
|
|
288
|
-
errors
|
|
289
|
-
},
|
|
290
|
-
{
|
|
291
|
-
status: ((_c = err == null ? void 0 : err.response) == null ? void 0 : _c.status) || 599
|
|
292
|
-
}
|
|
293
|
-
];
|
|
294
|
-
};
|
|
295
|
-
const createIoInstance = (baseUrl, options) => {
|
|
296
|
-
const {
|
|
297
|
-
withAuth = false,
|
|
298
|
-
authKey = "",
|
|
299
|
-
ioIntegrityCheck,
|
|
300
|
-
onStatusCode,
|
|
301
|
-
errorParser
|
|
302
|
-
} = options || {};
|
|
303
|
-
const instance = axios.create({
|
|
304
|
-
baseURL: baseUrl,
|
|
305
|
-
headers: withAuth ? {
|
|
306
|
-
"Content-Type": "application/json",
|
|
307
|
-
Authorization: authKey || "no_auth_key"
|
|
308
|
-
} : { "Content-Type": "application/json" }
|
|
309
|
-
});
|
|
310
|
-
const checkStatusCode = createCheckStatusCodeFn(onStatusCode);
|
|
311
|
-
instance.interceptors.response.use((res) => {
|
|
312
|
-
checkStatusCode(res);
|
|
313
|
-
return res;
|
|
314
|
-
}, (error) => {
|
|
315
|
-
if (error == null ? void 0 : error.response)
|
|
316
|
-
checkStatusCode(error.response);
|
|
317
|
-
throw error;
|
|
318
|
-
});
|
|
319
|
-
return {
|
|
320
|
-
get: (url, params, config = {}) => instance.get(url, __spreadValues({ params }, config)).then(handleIOSuccess(ioIntegrityCheck)).catch(handleIOError(errorParser)),
|
|
321
|
-
post: (url, data, config) => instance.post(url, data, config).then(handleIOSuccess(ioIntegrityCheck)).catch(handleIOError(errorParser)),
|
|
322
|
-
patch: (url, data, config) => instance.patch(url, data, config).then(handleIOSuccess(ioIntegrityCheck)).catch(handleIOError(errorParser)),
|
|
323
|
-
delete: (url, params, config = {}) => instance.delete(url, __spreadValues({ params }, config)).then(handleIOSuccess(ioIntegrityCheck)).catch(handleIOError(errorParser))
|
|
324
|
-
};
|
|
325
|
-
};
|
|
326
|
-
export { AppStorageProvider, SafeDate, createIoInstance };
|
|
1
|
+
export { SafeDate } from "./SafeDate/binamik-js-providers.es.js";
|
|
2
|
+
export { AppStorageProvider } from "./AppStorageProvider/binamik-js-providers.es.js";
|
|
3
|
+
export { createIoInstance } from "./IoProvider/binamik-js-providers.es.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const e = (e2) => {
|
|
2
|
+
var _a;
|
|
3
|
+
const r = {};
|
|
4
|
+
return ((_a = e2 == null ? void 0 : e2.inner) == null ? void 0 : _a.length) ? e2.inner.forEach((e3) => {
|
|
5
|
+
r[(e3 == null ? void 0 : e3.path) || "unknown"] = e3.message;
|
|
6
|
+
}) : (e2 == null ? void 0 : e2.path) && (e2 == null ? void 0 : e2.message) ? r[e2.path] = e2.message : (e2 == null ? void 0 : e2.path) || (e2 == null ? void 0 : e2.type) !== "typeError" || (r.body = e2.errors[0]), r;
|
|
7
|
+
};
|
|
8
|
+
export { e as getYupValidationErrors };
|
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@binamik/js-providers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite",
|
|
6
6
|
"build": "tsc && vite build",
|
|
7
7
|
"test": "vitest",
|
|
8
8
|
"lint": "eslint"
|
|
9
9
|
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"axios": "^0.21.1",
|
|
12
|
+
"dayjs": "^1.11.0",
|
|
13
|
+
"nookies": "^2.5.2",
|
|
14
|
+
"yup": "^0.32.8"
|
|
15
|
+
},
|
|
10
16
|
"devDependencies": {
|
|
11
17
|
"@types/node": "^17.0.41",
|
|
12
18
|
"@typescript-eslint/eslint-plugin": "^5.30.0",
|
|
@@ -23,18 +29,13 @@
|
|
|
23
29
|
"eslint-plugin-promise": "^6.0.0",
|
|
24
30
|
"nookies": "^2.5.2",
|
|
25
31
|
"prettier": "^2.7.1",
|
|
32
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
26
33
|
"typescript": "^4.5.4",
|
|
27
34
|
"vite": "^2.9.9",
|
|
28
35
|
"vite-plugin-dts": "^1.2.0",
|
|
29
36
|
"vitest": "^0.16.0",
|
|
30
37
|
"yup": "^0.32.11"
|
|
31
38
|
},
|
|
32
|
-
"peerDependencies": {
|
|
33
|
-
"axios": ">=0.20.0",
|
|
34
|
-
"dayjs": ">=1.11.0",
|
|
35
|
-
"nookies": ">=2.0.0",
|
|
36
|
-
"yup": ">=0.30.0"
|
|
37
|
-
},
|
|
38
39
|
"files": [
|
|
39
40
|
"dist"
|
|
40
41
|
],
|
|
@@ -1 +0,0 @@
|
|
|
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"}})});
|