@binamik/js-providers 0.1.7 → 1.0.1
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 +13 -0
- package/dist/AppStorageProvider/binamik-js-providers.es.js.map +1 -0
- package/dist/IoProvider/binamik-js-providers.es.js +38 -0
- package/dist/IoProvider/binamik-js-providers.es.js.map +1 -0
- package/dist/IoProvider/binamik-js-providers.es2.js +13 -0
- package/dist/IoProvider/binamik-js-providers.es2.js.map +1 -0
- package/dist/SafeDate/SafeDate.d.ts +22 -34
- package/dist/SafeDate/binamik-js-providers.es.js +110 -0
- package/dist/SafeDate/binamik-js-providers.es.js.map +1 -0
- package/dist/SafeDate/i18n/binamik-js-providers.es.js +3 -0
- package/dist/SafeDate/i18n/binamik-js-providers.es.js.map +1 -0
- package/dist/SafeDate/i18n/binamik-js-providers.es2.js +3 -0
- package/dist/SafeDate/i18n/binamik-js-providers.es2.js.map +1 -0
- package/dist/SafeDate/i18n/localizedFormatString.d.ts +18 -3
- package/dist/binamik-js-providers.es.js +4 -423
- package/dist/binamik-js-providers.es.js.map +1 -0
- package/dist/utils/binamik-js-providers.es.js +3 -0
- package/dist/utils/binamik-js-providers.es.js.map +1 -0
- package/dist/utils/binamik-js-providers.es2.js +3 -0
- package/dist/utils/binamik-js-providers.es2.js.map +1 -0
- package/dist/utils/yup/binamik-js-providers.es.js +9 -0
- package/dist/utils/yup/binamik-js-providers.es.js.map +1 -0
- package/package.json +8 -7
- package/dist/binamik-js-providers.umd.js +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
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 };
|
|
13
|
+
//# sourceMappingURL=binamik-js-providers.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binamik-js-providers.es.js","sources":["../../src/AppStorageProvider/AppStorageProvider.ts"],"sourcesContent":["import { parseCookies, setCookie, destroyCookie } from 'nookies'\n\ninterface CookieOptionsType {\n expires?: number\n path?: string\n domain?: string\n secure?: boolean\n httpOnly?: boolean\n maxAge?: number\n sameSite?: 'Strict' | 'Lax' | 'None'\n}\n\nconst get =\n (_domain: string, prefix: string) =>\n (key: string): string => {\n const cookies = parseCookies()\n return cookies[`${prefix}-${key}`]\n }\n\nconst set =\n (domain: string, prefix: string) =>\n (key: string, value: string, options?: CookieOptionsType) => {\n setCookie(null, `${prefix}-${key}`, value, {\n maxAge: options?.maxAge || 60 * 60 * 24 * 90, // 90 days\n path: '/',\n domain,\n secure: true,\n httpOnly: true\n })\n }\n\nconst remove =\n (_domain: string, prefix: string) =>\n (key: string, options?: CookieOptionsType) => {\n destroyCookie(null, `${prefix}-${key}`, options)\n }\n\nconst cleanAuth =\n (domain: string, prefix: string) => (options?: CookieOptionsType) => {\n remove(domain, prefix)('auth-key', options)\n remove(domain, prefix)('user', options)\n remove(domain, prefix)('company', options)\n remove(domain, prefix)('orb-selected', options)\n }\n\ninterface AppStorageProviderProps {\n cookieDomain: string\n cookiePrefix: string\n}\n\nexport const AppStorageProvider = ({\n cookieDomain,\n cookiePrefix\n}: AppStorageProviderProps) => ({\n get: get(cookieDomain, cookiePrefix),\n set: set(cookieDomain, cookiePrefix),\n remove: remove(cookieDomain, cookiePrefix),\n cleanAuth: cleanAuth(cookieDomain, cookiePrefix)\n})\n"],"names":["set","domain","prefix","key","value","options","setCookie","maxAge","path","secure","httpOnly","remove","_domain","destroyCookie","cleanAuth","AppStorageProvider","cookieDomain","cookiePrefix","get","parseCookies"],"mappings":";AAYA,MAOMA,IACJ,CAACC,IAAgBC,OACjB,CAACC,IAAaC,IAAeC;AAC3BC,IAAU,MAAM,GAAGJ,MAAUC,MAAOC,IAAO,EACzCG,QAAQF,0BAASE,WAAU,QAC3BC,MAAM,KACNP,QACAQ,IAAAA,QAAAA,MACAC,UAAU,KAAA,CAAA;AACX,GAGCC,IACJ,CAACC,IAAiBV,OAClB,CAACC,IAAaE;AACZQ,IAAc,MAAM,GAAGX,MAAUC,MAAOE,EAAAA;AAAO,GAG7CS,IACJ,CAACb,IAAgBC,OAAoBG,QACnCM;AAAAA,IAAOV,GAAQC,EAAfS,EAAuB,YAAYN,EACnCM,GAAAA,EAAOV,GAAQC,EAAfS,EAAuB,QAAQN,EAAAA,GAC/BM,EAAOV,GAAQC,IAAQ,WAAWG,KAClCM,EAAOV,GAAQC,IAAQ,gBAAgBG,EAAO;AAAA,GAQrCU,IAAqB,CAAA,EAChCC,kBACAC,cAC8B,SAAA;AAAA,SAAA,EAC9BC,KAzCkBhB,MAyCKe,IAxCtBd,QACiBgB,EACD,EAAA,GAAGjB,MAAUC,QAuC9BH,KAAKA,EAAIgB,IAAcC,EACvBN,GAAAA,QAAQA,EAAOK,GAAcC,EAC7BH,GAAAA,WAAWA,EAAUE,GAAcC,EAAAA,EAAAA;AA5CnC,MAAkBf;AA6CpB;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 };
|
|
38
|
+
//# sourceMappingURL=binamik-js-providers.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binamik-js-providers.es.js","sources":["../../src/IoProvider/IoProvider.ts"],"sourcesContent":["import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'\nimport { AnyObjectSchema } from 'yup'\n\nimport { checkIoIntegrity } from './checkIoIntegrity'\n\nexport interface IOIntegrityCheckProps {\n name: string\n schema: AnyObjectSchema\n}\n\nexport type ApiErrorParserType = (\n err?: Record<string, unknown> | null\n) => string[]\n\ninterface IoInstanceOptions {\n withAuth: boolean\n authKey?: string\n ioIntegrityCheck?: IOIntegrityCheckProps\n onStatusCode?: Record<number, (res: AxiosResponse) => void>\n errorParser?: ApiErrorParserType\n}\n\nexport interface IoErrorProps {\n status: number\n message: string\n errorData: Record<string, unknown> | null\n errors?: string[]\n}\n\nexport interface IoResponseMetaProps {\n status: number\n}\n\ntype IOResponseType<T> = [T, null, IoResponseMetaProps?]\ntype IOResponseErrorType = [null, IoErrorProps, IoResponseMetaProps?]\n\nexport type ApiResponseDTO<T> = IOResponseType<T> | IOResponseErrorType\n\ntype IoFn = <T>(\n url: string,\n payload?: Record<string, unknown>,\n config?: AxiosRequestConfig\n) => Promise<ApiResponseDTO<T>>\n\ninterface IoInstanceProps {\n get: IoFn\n post: IoFn\n patch: IoFn\n delete: IoFn\n}\n\nconst createCheckStatusCodeFn =\n (onStatusCode?: { [code: number]: (res: AxiosResponse) => void }) =>\n (res: AxiosResponse) => {\n if (onStatusCode && res?.status) {\n const statusCode = res.status\n const handler = onStatusCode[statusCode]\n if (handler) handler(res)\n }\n }\n\nconst handleIOSuccess =\n <T>(integrityCheck?: IOIntegrityCheckProps) =>\n (res: AxiosResponse<T>): IOResponseType<T> => {\n if (integrityCheck && integrityCheck.name && integrityCheck.schema) {\n checkIoIntegrity({\n name: integrityCheck.name,\n schema: integrityCheck.schema,\n req: { body: res?.config?.data || null, query: res?.config?.params },\n res: res?.data,\n url: res?.request.url\n })\n }\n\n return [res.data, null, { status: res.status }]\n }\n\nconst handleIOError =\n (errorParser?: ApiErrorParserType) =>\n (err: AxiosError): IOResponseErrorType => {\n const resData = err?.response?.data as Record<string, unknown>\n\n const errors = errorParser ? errorParser(resData || null) : undefined\n\n return [\n null,\n {\n status: err?.response?.status || 599,\n message:\n (resData?.message as string) ||\n (resData?.msg as string) ||\n 'Unknown IO Error',\n errorData: resData || null,\n errors\n },\n {\n status: err?.response?.status || 599\n }\n ]\n }\n\nexport const createIoInstance = (\n baseUrl: string,\n options?: IoInstanceOptions\n): IoInstanceProps => {\n const {\n withAuth = false,\n authKey = '',\n ioIntegrityCheck,\n onStatusCode,\n errorParser\n } = options || {}\n\n const instance = axios.create({\n baseURL: baseUrl,\n headers: withAuth\n ? {\n 'Content-Type': 'application/json',\n Authorization: authKey || 'no_auth_key'\n }\n : { 'Content-Type': 'application/json' }\n })\n\n const checkStatusCode = createCheckStatusCodeFn(onStatusCode)\n\n instance.interceptors.response.use(\n res => {\n checkStatusCode(res)\n return res\n },\n error => {\n if (error?.response) checkStatusCode(error.response)\n throw error\n }\n )\n\n return {\n get: <T>(url: string, params?: Record<string, unknown>, config = {}) =>\n instance\n .get<T>(url, { params, ...config })\n .then(handleIOSuccess<T>(ioIntegrityCheck))\n .catch(handleIOError(errorParser)),\n\n post: <T>(\n url: string,\n data?: Record<string, unknown>,\n config?: AxiosRequestConfig\n ) =>\n instance\n .post<T>(url, data, config)\n .then(handleIOSuccess<T>(ioIntegrityCheck))\n .catch(handleIOError(errorParser)),\n\n patch: <T>(\n url: string,\n data?: Record<string, unknown>,\n config?: AxiosRequestConfig\n ) =>\n instance\n .patch<T>(url, data, config)\n .then(handleIOSuccess<T>(ioIntegrityCheck))\n .catch(handleIOError(errorParser)),\n\n delete: <T>(url: string, params?: Record<string, unknown>, config = {}) =>\n instance\n .delete<T>(url, { params, ...config })\n .then(handleIOSuccess<T>(ioIntegrityCheck))\n .catch(handleIOError(errorParser))\n }\n}\n"],"names":["handleIOSuccess","integrityCheck","res","name","schema","checkIoIntegrity","req","body","config","data","query","params","url","request","status","handleIOError","errorParser","err","resData","response","errors","message","msg","errorData","createIoInstance","baseUrl","options","withAuth","authKey","ioIntegrityCheck","onStatusCode","instance","axios","create","baseURL","headers","Authorization","checkStatusCode","statusCode","handler","createCheckStatusCodeFn","interceptors","use","error","get","then","catch","post","patch","delete"],"mappings":";;;;;;;;;;;;;;;;;;AAmDA,MAUMA,IACAC,QACHC,QACKD;;AAAAA,eAAkBA,GAAeE,QAAQF,GAAeG,UACzCC,EAAA,EACfF,MAAMF,GAAeE,MACrBC,QAAQH,GAAeG,QACvBE,KAAK,EAAEC,MAAML,gCAAKM,WAALN,mBAAaO,SAAQ,MAAMC,OAAOR,+BAAKM,WAALN,mBAAaS,OAC5DT,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H,KACzBqC,KAAK7C,EAAmB6B,CACxBiB,CAAAA,EAAAA,MAAM/B,EAAcC,CAAAA,CAAAA,GAEzB+B,MAAM,CACJnC,IACAH,IACAD,OAEAuB,EACGgB,KAAQnC,IAAKH,IAAMD,EACnBqC,EAAAA,KAAK7C,EAAmB6B,CAAAA,CAAAA,EACxBiB,MAAM/B,EAAcC,CAEzBgC,CAAAA,GAAAA,OAAO,CACLpC,IACAH,IACAD,OAEAuB,EACGiB,MAASpC,IAAKH,IAAMD,EAAAA,EACpBqC,KAAK7C,EAAmB6B,CACxBiB,CAAAA,EAAAA,MAAM/B,EAAcC,CAAAA,CAAAA,GAEzBiC,QAAQ,CAAIrC,IAAaD,IAAkCH,KAAS,CAAA,MAClEuB,EACGkB,OAAUrC,IAAK,iBAAED,QAAWH,MAAAA,GAAAA,EAC5BqC,KAAK7C,EAAmB6B,CACxBiB,CAAAA,EAAAA,MAAM/B,EAAcC,CAAAA,CAAAA,EAAAA;AAC3B;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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 };
|
|
13
|
+
//# sourceMappingURL=binamik-js-providers.es2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binamik-js-providers.es2.js","sources":["../../src/IoProvider/checkIoIntegrity.ts"],"sourcesContent":["import { AnyObjectSchema, object as yupObject } from 'yup'\n\nimport { isServer, isLocalhost, getYupValidationErrors } from '@/utils'\n\ninterface CheckIoIntegrityProps {\n name: string\n url: string\n req: unknown\n res: unknown\n schema: AnyObjectSchema\n}\n\nexport const checkIoIntegrity = async ({\n name = '',\n url = '',\n req = {},\n res = {},\n schema = yupObject()\n}: CheckIoIntegrityProps): Promise<void> => {\n if (isServer) return\n if (!isLocalhost(window?.location?.hostname)) return\n\n schema.validate(res, { abortEarly: false }).catch(err => {\n const validationErrors = getYupValidationErrors(err)\n\n console.warn(\n `PLEASE check the backend IO for >> ${name} <<, some discrepancies were found in the expected response`,\n {\n functionName: name,\n endPoint: url,\n request: req,\n response: res,\n validationErrors\n }\n )\n })\n}\n"],"names":["checkIoIntegrity","async","name","url","req","res","schema","yupObject","isServer","isLocalhost","window","location","hostname","validate","abortEarly","catch","err","validationErrors","getYupValidationErrors","console","warn","functionName","endPoint","request","response"],"mappings":";;;;AAYO,MAAMA,IAAmBC,OAAAA,EAC9BC,MAAO,KAAA,IACPC,SAAM,IACNC,KAAAA,IAAM,CAAC,GACPC,KAAM,IAAA,CAAC,GACPC,QAAAA,IAASC,EAELC,QAAAA;;AAAAA,OACCC,EAAYC,uCAAQC,aAARD,mBAAkBE,QAAAA,KAE5BN,EAAAO,SAASR,GAAK,EAAES,YAAAA,MAAqBC,CAAAA,EAAAA,MAAaC;AACjD,UAAAC,KAAmBC,EAAuBF,EAAAA;AAExCG,YAAAC,KACN,sCAAsClB,iEACtC,EACEmB,cAAcnB,IACdoB,UAAUnB,GACVoB,SAASnB,GACToB,UAAUnB,GACVY,kBAEJ,GAAA,CAAA;AAAA,EAAA,CAAA;AACD;;"}
|
|
@@ -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,52 +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;
|
|
24
27
|
private locale;
|
|
25
|
-
|
|
28
|
+
static isValid(value?: Date | string | Dayjs): boolean;
|
|
29
|
+
private validationHandler;
|
|
30
|
+
private imutableHandler;
|
|
26
31
|
private i18nFormat;
|
|
27
32
|
private getI18nCode;
|
|
28
|
-
static isValid(value?: Date | string | Dayjs): boolean;
|
|
29
33
|
get isValid(): boolean;
|
|
30
34
|
get lang(): string;
|
|
31
35
|
get jsDate(): Date;
|
|
32
36
|
get timestamp(): number;
|
|
33
37
|
get isoDate(): string;
|
|
34
38
|
get isoString(): string;
|
|
35
|
-
get dateString(): string;
|
|
36
|
-
get longDayMonth(): string;
|
|
37
|
-
get shortDayMonth(): string;
|
|
38
|
-
get longDateString(): string;
|
|
39
|
-
get timeString(): string;
|
|
40
39
|
get daysInMonth(): number;
|
|
41
|
-
get dateObj():
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
hours: number;
|
|
47
|
-
minutes: number;
|
|
48
|
-
seconds: number;
|
|
49
|
-
milliseconds: number;
|
|
50
|
-
};
|
|
51
|
-
setToStartOf(unit: DateTimeUnits): this;
|
|
52
|
-
addDays(days: number): this;
|
|
53
|
-
addMonths(months: number): this;
|
|
54
|
-
addYears(years: number): this;
|
|
55
|
-
addHours(hours: number): this;
|
|
56
|
-
addToDate({ years, months, weeks, days, hours, minutes, seconds }: DateTimeOptions): this;
|
|
57
|
-
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;
|
|
58
45
|
isBefore(date: Date | string, unit?: DateTimeUnits): boolean;
|
|
59
46
|
isAfter(date: Date | string, unit?: DateTimeUnits): boolean;
|
|
60
47
|
isSame(date: Date | string, unit?: DateTimeUnits): boolean;
|
|
@@ -62,7 +49,8 @@ export declare class SafeDate {
|
|
|
62
49
|
getDiff(date: Date | string, unit: DateTimeUnits): number;
|
|
63
50
|
clone(): SafeDate;
|
|
64
51
|
format(format: string): string;
|
|
65
|
-
|
|
66
|
-
|
|
52
|
+
formatIntl(formatTo: keyof LangFormatProps): string;
|
|
53
|
+
setLocale(locale: string): SafeDate;
|
|
54
|
+
constructor(pValue?: Date | string | Dayjs, locale?: string);
|
|
67
55
|
}
|
|
68
56
|
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
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 };
|
|
110
|
+
//# sourceMappingURL=binamik-js-providers.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binamik-js-providers.es.js","sources":["../../src/SafeDate/SafeDate.ts"],"sourcesContent":["import dayjs, { Dayjs } from 'dayjs'\n\nimport 'dayjs/locale/pt-br'\nimport 'dayjs/locale/es'\nimport 'dayjs/locale/en'\n\nimport localizedFormat from 'dayjs/plugin/localizedFormat'\nimport {\n localizedFormatString,\n LangFormatProps\n} from './i18n/localizedFormatString'\nimport { getSafeLangCode } from './i18n/safeLangCode'\n\ndayjs.extend(localizedFormat)\n\ntype DateTimeUnits =\n | 'year'\n | 'month'\n | 'week'\n | 'day'\n | 'hour'\n | 'minute'\n | 'second'\n\ninterface DateTimeOptions {\n years?: number\n months?: number\n weeks?: number\n days?: number\n hours?: number\n minutes?: number\n seconds?: number\n}\n\ninterface DateObjProps {\n year: number\n month: number\n date: number\n weekday: number\n hour: number\n minute: number\n second: number\n millisecond: number\n}\n\ntype ToOptions = Partial<Omit<DateObjProps, 'weekday'>>\n\nexport class SafeDate {\n private value: Dayjs = dayjs()\n private isDateValid = true\n private locale = 'pt-br'\n\n public static isValid(value?: Date | string | Dayjs) {\n return dayjs(value || '').isValid()\n }\n\n private validationHandler<T>(value: T, onInvalid: T): T {\n return this.isDateValid ? value : onInvalid\n }\n\n private imutableHandler(value: Dayjs, locale?: string) {\n return new SafeDate(value, locale || this.locale)\n }\n\n private i18nFormat(key: keyof LangFormatProps) {\n return (\n localizedFormatString[this.locale]?.[key] ||\n localizedFormatString.default[key] ||\n ''\n )\n }\n\n private getI18nCode(locale: string) {\n return getSafeLangCode(locale)\n }\n\n public get isValid(): boolean {\n return this.isDateValid\n }\n\n public get lang() {\n return this.locale\n }\n\n public get jsDate() {\n return this.value.toDate()\n }\n\n public get timestamp() {\n return this.validationHandler(this.jsDate.getTime(), NaN)\n }\n\n public get isoDate() {\n return this.validationHandler(this.value.format('YYYY-MM-DD'), '')\n }\n\n public get isoString() {\n return this.validationHandler(this.value.format('YYYY-MM-DDTHH:mm:ss'), '')\n }\n\n public get daysInMonth() {\n return this.validationHandler(this.value.daysInMonth(), 0)\n }\n\n public get dateObj(): DateObjProps {\n return this.validationHandler(\n {\n year: this.value.year(),\n month: this.value.month(),\n date: this.value.date(),\n weekday: this.value.day(),\n hour: this.value.hour(),\n minute: this.value.minute(),\n second: this.value.second(),\n millisecond: this.value.millisecond()\n },\n {\n year: 0,\n month: 0,\n date: 0,\n weekday: 0,\n hour: 0,\n minute: 0,\n second: 0,\n millisecond: 0\n }\n )\n }\n\n public toStartOf(unit: DateTimeUnits) {\n const newValue = this.validationHandler(\n this.value.startOf(unit),\n this.value\n )\n return this.imutableHandler(newValue)\n }\n\n public add({\n years = 0,\n months = 0,\n weeks = 0,\n days = 0,\n hours = 0,\n minutes = 0,\n seconds = 0\n }: DateTimeOptions) {\n const newValue = this.validationHandler(\n this.value\n .add(years, 'year')\n .add(months, 'month')\n .add(weeks, 'week')\n .add(days, 'day')\n .add(hours, 'hour')\n .add(minutes, 'minute')\n .add(seconds, 'second'),\n this.value\n )\n return this.imutableHandler(newValue)\n }\n\n public subtract({\n years = 0,\n months = 0,\n weeks = 0,\n days = 0,\n hours = 0,\n minutes = 0,\n seconds = 0\n }: DateTimeOptions) {\n const newValue = this.validationHandler(\n this.value\n .subtract(years, 'year')\n .subtract(months, 'month')\n .subtract(weeks, 'week')\n .subtract(days, 'day')\n .subtract(hours, 'hour')\n .subtract(minutes, 'minute')\n .subtract(seconds, 'second'),\n this.value\n )\n return this.imutableHandler(newValue)\n }\n\n public to(newValues: ToOptions) {\n const currentValues: Required<ToOptions> = this.dateObj\n\n const {\n year = currentValues.year,\n month = currentValues.month,\n date = currentValues.date,\n hour = currentValues.hour,\n minute = currentValues.minute,\n second = currentValues.second,\n millisecond = currentValues.millisecond\n } = newValues\n\n const newValue = this.validationHandler(\n this.value\n .year(year)\n .month(month)\n .date(date)\n .hour(hour)\n .minute(minute)\n .second(second)\n .millisecond(millisecond),\n this.value\n )\n\n return this.imutableHandler(newValue)\n }\n\n public isBefore(date: Date | string, unit?: DateTimeUnits) {\n return this.validationHandler(this.value.isBefore(date, unit), false)\n }\n\n public isAfter(date: Date | string, unit?: DateTimeUnits) {\n return this.validationHandler(this.value.isAfter(date, unit), false)\n }\n\n public isSame(date: Date | string, unit?: DateTimeUnits) {\n return this.validationHandler(this.value.isSame(date, unit), false)\n }\n\n public isBetween(\n startingDate: Date | string,\n endingDate: Date | string,\n unit?: DateTimeUnits\n ) {\n const isAfterStartingDate = this.validationHandler(\n this.value.isAfter(startingDate, unit),\n false\n )\n const isBeforeEndingDate = this.validationHandler(\n this.value.isBefore(endingDate, unit),\n false\n )\n\n const isBetweenDates =\n (isAfterStartingDate && isBeforeEndingDate) ||\n (!isAfterStartingDate && !isBeforeEndingDate)\n\n return this.validationHandler(isBetweenDates, false)\n }\n\n public getDiff(date: Date | string, unit: DateTimeUnits) {\n return this.validationHandler(this.value.diff(date, unit), 0)\n }\n\n public clone() {\n return this.imutableHandler(this.value)\n }\n\n public format(format: string) {\n return this.validationHandler(this.value.format(format), '')\n }\n\n public formatIntl(formatTo: keyof LangFormatProps) {\n const formatStr = this.i18nFormat(formatTo)\n return this.format(formatStr)\n }\n\n public setLocale(locale: string) {\n const safeLocale = this.getI18nCode(locale)\n return this.imutableHandler(this.value, safeLocale)\n }\n\n constructor(pValue?: Date | string | Dayjs, locale = 'pt-br') {\n this.locale = this.getI18nCode(locale)\n this.value = dayjs(pValue).locale(this.locale)\n this.isDateValid = this.value.isValid()\n\n if (!this.isDateValid) {\n console.error('Invalid date:', pValue)\n }\n }\n}\n"],"names":["dayjs","extend","localizedFormat","SafeDate","value","constructor","pValue","locale","isDateValid","this","getI18nCode","isValid","console","error","static","validationHandler","onInvalid","imutableHandler","i18nFormat","key","localizedFormatString","default","getSafeLangCode","lang","jsDate","toDate","timestamp","getTime","NaN","isoDate","format","isoString","daysInMonth","dateObj","year","month","date","weekday","day","hour","minute","second","millisecond","toStartOf","unit","newValue","startOf","add","years","months","weeks","days","hours","minutes","seconds","subtract","to","newValues","currentValues","isBefore","isAfter","isSame","isBetween","startingDate","endingDate","isAfterStartingDate","isBeforeEndingDate","isBetweenDates","getDiff","diff","clone","formatIntl","formatTo","formatStr","setLocale","safeLocale"],"mappings":";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0 +1,3 @@
|
|
|
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 };
|
|
3
|
+
//# sourceMappingURL=binamik-js-providers.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binamik-js-providers.es.js","sources":["../../../src/SafeDate/i18n/localizedFormatString.ts"],"sourcesContent":["export interface LangFormatProps {\n 'DD MMM': string\n 'DD [de] MMMM': string\n 'DD MMM, YYYY': string\n 'DD/MM/YY': string\n 'DD/MM/YYYY'?: string\n 'DD/MM/YYYY HH:mm'?: string\n 'HH:mm'?: string\n 'HH:mm:ss'?: string\n 'D [de] MMMM [de] YYYY'?: string\n 'D [de] MMMM [de] YYYY [às] HH:mm'?: string\n}\n\nconst defaultValues: Required<LangFormatProps> = {\n 'DD MMM': 'DD MMM',\n 'DD [de] MMMM': 'DD [de] MMMM',\n 'DD MMM, YYYY': 'DD MMM, YYYY',\n 'DD/MM/YY': 'DD/MM/YY',\n 'DD/MM/YYYY': 'L',\n 'DD/MM/YYYY HH:mm': 'L LT',\n 'HH:mm': 'LT',\n 'HH:mm:ss': 'LTS',\n 'D [de] MMMM [de] YYYY': 'LL',\n 'D [de] MMMM [de] YYYY [às] HH:mm': 'LLL'\n}\n\nconst enValues: LangFormatProps = {\n 'DD/MM/YY': 'MM/DD/YY',\n 'DD MMM': 'MMM DD',\n 'DD MMM, YYYY': 'll',\n 'DD [de] MMMM': 'MMMM DD'\n}\n\nconst ptValues: LangFormatProps = {\n 'DD/MM/YY': 'DD/MM/YY',\n 'DD MMM': 'DD MMM',\n 'DD MMM, YYYY': 'DD MMM, YYYY',\n 'DD [de] MMMM': 'DD [de] MMMM'\n}\n\nconst esValues: LangFormatProps = {\n 'DD/MM/YY': 'DD/MM/YY',\n 'DD MMM': 'DD MMM',\n 'DD MMM, YYYY': 'DD MMM, YYYY',\n 'DD [de] MMMM': 'DD [de] MMMM'\n}\n\ninterface LocalizedFormatStringProps extends Record<string, LangFormatProps> {\n default: Required<LangFormatProps>\n en: LangFormatProps\n 'pt-br': LangFormatProps\n es: LangFormatProps\n}\n\nexport const localizedFormatString: LocalizedFormatStringProps = {\n default: defaultValues,\n en: enValues,\n es: esValues,\n 'pt-br': ptValues\n}\n"],"names":["localizedFormatString","default","en","es"],"mappings":"AAaA,MAyCaA,IAAoD,EAC/DC,SA1C+C,EAC/C,UAAU,UACV,gBAAgB,gBAChB,gBAAgB,gBAChB,YAAY,YACZ,cAAc,KACd,oBAAoB,QACpB,SAAS,MACT,YAAY,OACZ,yBAAyB,MACzB,uCAAoC,MAAA,GAiCpCC,IA9BgC,EAChC,YAAY,YACZ,UAAU,UACV,gBAAgB,MAChB,gBAAgB,aA2BhBC,IAjBgC,EAChC,YAAY,YACZ,UAAU,UACV,gBAAgB,gBAChB,gBAAgB,eAchB,GAAA,SAzBgC,EAChC,YAAY,YACZ,UAAU,UACV,gBAAgB,gBAChB,gBAAgB;;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const e = { 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" }, s = (s2) => e[s2.toLowerCase()] || e.pt;
|
|
2
|
+
export { s as getSafeLangCode };
|
|
3
|
+
//# sourceMappingURL=binamik-js-providers.es2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binamik-js-providers.es2.js","sources":["../../../src/SafeDate/i18n/safeLangCode.ts"],"sourcesContent":["const safeLangCodes: Record<string, string> = {\n pt: 'pt-br',\n pt_br: 'pt-br',\n 'pt-br': 'pt-br',\n\n en: 'en',\n en_us: 'en',\n 'en-us': 'en',\n en_gb: 'en',\n 'en-gb': 'en',\n\n es: 'es',\n es_es: 'es',\n 'es-es': 'es'\n}\n\nexport const getSafeLangCode = (langCode: string) => {\n const code = safeLangCodes[langCode.toLowerCase()]\n return code || safeLangCodes.pt\n}\n"],"names":["safeLangCodes","pt","pt_br","en","en_us","en_gb","es","es_es","getSafeLangCode","langCode","toLowerCase"],"mappings":"AAAA,MAAMA,IAAwC,EAC5CC,IAAI,SACJC,OAAO,SACP,SAAS,SAETC,IAAI,MACJC,OAAO,MACP,SAAS,MACTC,OAAO,MACP,SAAS,MAETC,IAAI,MACJC,OAAO,MACP,SAAS,KAGEC,GAAAA,IAAmBC,QACjBT,EAAcS,GAASC,YAAAA,MACrBV,EAAcC;;"}
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
export interface LangFormatProps {
|
|
2
|
-
|
|
3
|
-
|
|
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;
|
|
4
12
|
}
|
|
5
|
-
|
|
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 {};
|
|
@@ -1,423 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
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);
|
|
105
|
-
class SafeDate {
|
|
106
|
-
constructor(pValue) {
|
|
107
|
-
__publicField(this, "value", dayjs());
|
|
108
|
-
__publicField(this, "isDateValid", true);
|
|
109
|
-
__publicField(this, "locale", "pt-br");
|
|
110
|
-
this.locale = "pt-br";
|
|
111
|
-
this.value = dayjs(pValue).locale("pt-br");
|
|
112
|
-
this.isDateValid = this.value.isValid();
|
|
113
|
-
if (!this.isDateValid) {
|
|
114
|
-
console.error("Invalid date:", pValue);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
returnHandler(value, onInvalid) {
|
|
118
|
-
return this.isDateValid ? value : onInvalid;
|
|
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
|
-
}
|
|
130
|
-
get isValid() {
|
|
131
|
-
return this.isDateValid;
|
|
132
|
-
}
|
|
133
|
-
get lang() {
|
|
134
|
-
return this.locale;
|
|
135
|
-
}
|
|
136
|
-
get jsDate() {
|
|
137
|
-
return this.value.toDate();
|
|
138
|
-
}
|
|
139
|
-
get timestamp() {
|
|
140
|
-
return this.returnHandler(this.jsDate.getTime(), NaN);
|
|
141
|
-
}
|
|
142
|
-
get isoDate() {
|
|
143
|
-
return this.returnHandler(this.value.format("YYYY-MM-DD"), "");
|
|
144
|
-
}
|
|
145
|
-
get isoString() {
|
|
146
|
-
return this.returnHandler(this.value.format("YYYY-MM-DDTHH:mm:ss"), "");
|
|
147
|
-
}
|
|
148
|
-
get dateString() {
|
|
149
|
-
return this.returnHandler(this.value.format("L"), "");
|
|
150
|
-
}
|
|
151
|
-
get longDayMonth() {
|
|
152
|
-
return this.returnHandler(this.value.format(this.i18nFormat("longDayAndMonth", "DD [de] MMMM")), "");
|
|
153
|
-
}
|
|
154
|
-
get shortDayMonth() {
|
|
155
|
-
return this.returnHandler(this.value.format(this.i18nFormat("shortDayAndMonth", "DD MMM")), "");
|
|
156
|
-
}
|
|
157
|
-
get longDateString() {
|
|
158
|
-
return this.returnHandler(this.value.format("LL"), "");
|
|
159
|
-
}
|
|
160
|
-
get timeString() {
|
|
161
|
-
return this.returnHandler(this.value.format("LT"), "");
|
|
162
|
-
}
|
|
163
|
-
get daysInMonth() {
|
|
164
|
-
return this.returnHandler(this.value.daysInMonth(), 0);
|
|
165
|
-
}
|
|
166
|
-
get dateObj() {
|
|
167
|
-
return this.returnHandler({
|
|
168
|
-
year: this.value.year(),
|
|
169
|
-
month: this.value.month(),
|
|
170
|
-
date: this.value.date(),
|
|
171
|
-
weekday: this.value.day(),
|
|
172
|
-
hours: this.value.hour(),
|
|
173
|
-
minutes: this.value.minute(),
|
|
174
|
-
seconds: this.value.second(),
|
|
175
|
-
milliseconds: this.value.millisecond()
|
|
176
|
-
}, {
|
|
177
|
-
year: 0,
|
|
178
|
-
month: 0,
|
|
179
|
-
date: 0,
|
|
180
|
-
weekday: 0,
|
|
181
|
-
hours: 0,
|
|
182
|
-
minutes: 0,
|
|
183
|
-
seconds: 0,
|
|
184
|
-
milliseconds: 0
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
setToStartOf(unit) {
|
|
188
|
-
this.value = this.value.startOf(unit);
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
addDays(days) {
|
|
192
|
-
this.value = this.isDateValid ? this.value.add(days, "day") : this.value;
|
|
193
|
-
return this;
|
|
194
|
-
}
|
|
195
|
-
addMonths(months) {
|
|
196
|
-
this.value = this.isDateValid ? this.value.add(months, "month") : this.value;
|
|
197
|
-
return this;
|
|
198
|
-
}
|
|
199
|
-
addYears(years) {
|
|
200
|
-
this.value = this.isDateValid ? this.value.add(years, "year") : this.value;
|
|
201
|
-
return this;
|
|
202
|
-
}
|
|
203
|
-
addHours(hours) {
|
|
204
|
-
this.value = this.isDateValid ? this.value.add(hours, "hour") : this.value;
|
|
205
|
-
return this;
|
|
206
|
-
}
|
|
207
|
-
addToDate({
|
|
208
|
-
years = 0,
|
|
209
|
-
months = 0,
|
|
210
|
-
weeks = 0,
|
|
211
|
-
days = 0,
|
|
212
|
-
hours = 0,
|
|
213
|
-
minutes = 0,
|
|
214
|
-
seconds = 0
|
|
215
|
-
}) {
|
|
216
|
-
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;
|
|
217
|
-
return this;
|
|
218
|
-
}
|
|
219
|
-
setTo(newValues) {
|
|
220
|
-
const currentValues = this.isDateValid ? {
|
|
221
|
-
year: this.value.year(),
|
|
222
|
-
month: this.value.month(),
|
|
223
|
-
day: this.value.date(),
|
|
224
|
-
hour: this.value.hour(),
|
|
225
|
-
minute: this.value.minute(),
|
|
226
|
-
second: this.value.second(),
|
|
227
|
-
milisecond: this.value.millisecond()
|
|
228
|
-
} : {
|
|
229
|
-
year: 0,
|
|
230
|
-
month: 0,
|
|
231
|
-
day: 0,
|
|
232
|
-
hour: 0,
|
|
233
|
-
minute: 0,
|
|
234
|
-
second: 0,
|
|
235
|
-
milisecond: 0
|
|
236
|
-
};
|
|
237
|
-
const {
|
|
238
|
-
year = currentValues.year,
|
|
239
|
-
month = currentValues.month,
|
|
240
|
-
day = currentValues.day,
|
|
241
|
-
hour = currentValues.hour,
|
|
242
|
-
minute = currentValues.minute,
|
|
243
|
-
second = currentValues.second,
|
|
244
|
-
milisecond = currentValues.milisecond
|
|
245
|
-
} = newValues;
|
|
246
|
-
this.value = this.isDateValid ? this.value.year(year).month(month).date(day).hour(hour).minute(minute).second(second).millisecond(milisecond) : this.value;
|
|
247
|
-
return this;
|
|
248
|
-
}
|
|
249
|
-
isBefore(date, unit) {
|
|
250
|
-
return this.returnHandler(this.value.isBefore(date, unit), false);
|
|
251
|
-
}
|
|
252
|
-
isAfter(date, unit) {
|
|
253
|
-
return this.returnHandler(this.value.isAfter(date, unit), false);
|
|
254
|
-
}
|
|
255
|
-
isSame(date, unit) {
|
|
256
|
-
return this.returnHandler(this.value.isSame(date, unit), false);
|
|
257
|
-
}
|
|
258
|
-
isBetween(startingDate, endingDate, unit) {
|
|
259
|
-
const isAfterStartingDate = this.returnHandler(this.value.isAfter(startingDate, unit), false);
|
|
260
|
-
const isBeforeEndingDate = this.returnHandler(this.value.isBefore(endingDate, unit), false);
|
|
261
|
-
const isBetweenDates = isAfterStartingDate && isBeforeEndingDate || !isAfterStartingDate && !isBeforeEndingDate;
|
|
262
|
-
return this.returnHandler(isBetweenDates, false);
|
|
263
|
-
}
|
|
264
|
-
getDiff(date, unit) {
|
|
265
|
-
return this.returnHandler(this.value.diff(date, unit), 0);
|
|
266
|
-
}
|
|
267
|
-
clone() {
|
|
268
|
-
return new SafeDate(this.value);
|
|
269
|
-
}
|
|
270
|
-
format(format) {
|
|
271
|
-
return this.returnHandler(this.value.format(format), "");
|
|
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
|
-
}
|
|
279
|
-
}
|
|
280
|
-
const get = (_domain, prefix) => (key) => {
|
|
281
|
-
const cookies = parseCookies();
|
|
282
|
-
return cookies[`${prefix}-${key}`];
|
|
283
|
-
};
|
|
284
|
-
const set = (domain, prefix) => (key, value, options) => {
|
|
285
|
-
setCookie(null, `${prefix}-${key}`, value, {
|
|
286
|
-
maxAge: (options == null ? void 0 : options.maxAge) || 60 * 60 * 24 * 90,
|
|
287
|
-
path: "/",
|
|
288
|
-
domain,
|
|
289
|
-
secure: true,
|
|
290
|
-
httpOnly: true
|
|
291
|
-
});
|
|
292
|
-
};
|
|
293
|
-
const remove = (_domain, prefix) => (key, options) => {
|
|
294
|
-
destroyCookie(null, `${prefix}-${key}`, options);
|
|
295
|
-
};
|
|
296
|
-
const cleanAuth = (domain, prefix) => (options) => {
|
|
297
|
-
remove(domain, prefix)("auth-key", options);
|
|
298
|
-
remove(domain, prefix)("user", options);
|
|
299
|
-
remove(domain, prefix)("company", options);
|
|
300
|
-
remove(domain, prefix)("orb-selected", options);
|
|
301
|
-
};
|
|
302
|
-
const AppStorageProvider = ({
|
|
303
|
-
cookieDomain,
|
|
304
|
-
cookiePrefix
|
|
305
|
-
}) => ({
|
|
306
|
-
get: get(cookieDomain, cookiePrefix),
|
|
307
|
-
set: set(cookieDomain, cookiePrefix),
|
|
308
|
-
remove: remove(cookieDomain, cookiePrefix),
|
|
309
|
-
cleanAuth: cleanAuth(cookieDomain, cookiePrefix)
|
|
310
|
-
});
|
|
311
|
-
const isServer = typeof window === "undefined";
|
|
312
|
-
const isIpv4 = (str) => /(^(\d{1,3}\.){3}(\d{1,3})(:\d{1,5})?$)/.test(str);
|
|
313
|
-
const isLocalhost = (host) => {
|
|
314
|
-
const APP_ENVIRONMENT = {}.NEXT_PUBLIC_APP_ENV || {}.REACT_APP_ENVIRONMENT || {}.REACT_APP_ENV || "production";
|
|
315
|
-
return APP_ENVIRONMENT === "local" && (host.includes("localhost") || isIpv4(host));
|
|
316
|
-
};
|
|
317
|
-
const getYupValidationErrors = (err) => {
|
|
318
|
-
var _a;
|
|
319
|
-
const validationErrors = {};
|
|
320
|
-
if ((_a = err == null ? void 0 : err.inner) == null ? void 0 : _a.length) {
|
|
321
|
-
err.inner.forEach((error) => {
|
|
322
|
-
validationErrors[(error == null ? void 0 : error.path) || "unknown"] = error.message;
|
|
323
|
-
});
|
|
324
|
-
} else if ((err == null ? void 0 : err.path) && (err == null ? void 0 : err.message)) {
|
|
325
|
-
validationErrors[err.path] = err.message;
|
|
326
|
-
} else if (!(err == null ? void 0 : err.path) && (err == null ? void 0 : err.type) === "typeError") {
|
|
327
|
-
validationErrors.body = err.errors[0];
|
|
328
|
-
}
|
|
329
|
-
return validationErrors;
|
|
330
|
-
};
|
|
331
|
-
const checkIoIntegrity = async ({
|
|
332
|
-
name = "",
|
|
333
|
-
url = "",
|
|
334
|
-
req = {},
|
|
335
|
-
res = {},
|
|
336
|
-
schema = object()
|
|
337
|
-
}) => {
|
|
338
|
-
var _a;
|
|
339
|
-
if (isServer)
|
|
340
|
-
return;
|
|
341
|
-
if (!isLocalhost((_a = window == null ? void 0 : window.location) == null ? void 0 : _a.hostname))
|
|
342
|
-
return;
|
|
343
|
-
schema.validate(res, { abortEarly: false }).catch((err) => {
|
|
344
|
-
const validationErrors = getYupValidationErrors(err);
|
|
345
|
-
console.warn(`PLEASE check the backend IO for >> ${name} <<, some discrepancies were found in the expected response`, {
|
|
346
|
-
functionName: name,
|
|
347
|
-
endPoint: url,
|
|
348
|
-
request: req,
|
|
349
|
-
response: res,
|
|
350
|
-
validationErrors
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
};
|
|
354
|
-
const createCheckStatusCodeFn = (onStatusCode) => (res) => {
|
|
355
|
-
if (onStatusCode && (res == null ? void 0 : res.status)) {
|
|
356
|
-
const statusCode = res.status;
|
|
357
|
-
const handler = onStatusCode[statusCode];
|
|
358
|
-
if (handler)
|
|
359
|
-
handler(res);
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
const handleIOSuccess = (integrityCheck) => (res) => {
|
|
363
|
-
var _a, _b;
|
|
364
|
-
if (integrityCheck && integrityCheck.name && integrityCheck.schema) {
|
|
365
|
-
checkIoIntegrity({
|
|
366
|
-
name: integrityCheck.name,
|
|
367
|
-
schema: integrityCheck.schema,
|
|
368
|
-
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 },
|
|
369
|
-
res: res == null ? void 0 : res.data,
|
|
370
|
-
url: res == null ? void 0 : res.request.url
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
return [res.data, null, { status: res.status }];
|
|
374
|
-
};
|
|
375
|
-
const handleIOError = (errorParser) => (err) => {
|
|
376
|
-
var _a, _b, _c;
|
|
377
|
-
const resData = (_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data;
|
|
378
|
-
const errors = errorParser ? errorParser(resData || null) : void 0;
|
|
379
|
-
return [
|
|
380
|
-
null,
|
|
381
|
-
{
|
|
382
|
-
status: ((_b = err == null ? void 0 : err.response) == null ? void 0 : _b.status) || 599,
|
|
383
|
-
message: (resData == null ? void 0 : resData.message) || (resData == null ? void 0 : resData.msg) || "Unknown IO Error",
|
|
384
|
-
errorData: resData || null,
|
|
385
|
-
errors
|
|
386
|
-
},
|
|
387
|
-
{
|
|
388
|
-
status: ((_c = err == null ? void 0 : err.response) == null ? void 0 : _c.status) || 599
|
|
389
|
-
}
|
|
390
|
-
];
|
|
391
|
-
};
|
|
392
|
-
const createIoInstance = (baseUrl, options) => {
|
|
393
|
-
const {
|
|
394
|
-
withAuth = false,
|
|
395
|
-
authKey = "",
|
|
396
|
-
ioIntegrityCheck,
|
|
397
|
-
onStatusCode,
|
|
398
|
-
errorParser
|
|
399
|
-
} = options || {};
|
|
400
|
-
const instance = axios.create({
|
|
401
|
-
baseURL: baseUrl,
|
|
402
|
-
headers: withAuth ? {
|
|
403
|
-
"Content-Type": "application/json",
|
|
404
|
-
Authorization: authKey || "no_auth_key"
|
|
405
|
-
} : { "Content-Type": "application/json" }
|
|
406
|
-
});
|
|
407
|
-
const checkStatusCode = createCheckStatusCodeFn(onStatusCode);
|
|
408
|
-
instance.interceptors.response.use((res) => {
|
|
409
|
-
checkStatusCode(res);
|
|
410
|
-
return res;
|
|
411
|
-
}, (error) => {
|
|
412
|
-
if (error == null ? void 0 : error.response)
|
|
413
|
-
checkStatusCode(error.response);
|
|
414
|
-
throw error;
|
|
415
|
-
});
|
|
416
|
-
return {
|
|
417
|
-
get: (url, params, config = {}) => instance.get(url, __spreadValues({ params }, config)).then(handleIOSuccess(ioIntegrityCheck)).catch(handleIOError(errorParser)),
|
|
418
|
-
post: (url, data, config) => instance.post(url, data, config).then(handleIOSuccess(ioIntegrityCheck)).catch(handleIOError(errorParser)),
|
|
419
|
-
patch: (url, data, config) => instance.patch(url, data, config).then(handleIOSuccess(ioIntegrityCheck)).catch(handleIOError(errorParser)),
|
|
420
|
-
delete: (url, params, config = {}) => instance.delete(url, __spreadValues({ params }, config)).then(handleIOSuccess(ioIntegrityCheck)).catch(handleIOError(errorParser))
|
|
421
|
-
};
|
|
422
|
-
};
|
|
423
|
-
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";
|
|
4
|
+
//# sourceMappingURL=binamik-js-providers.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binamik-js-providers.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binamik-js-providers.es.js","sources":["../../src/utils/isServer.ts"],"sourcesContent":["export const isServer = typeof window === 'undefined'\n"],"names":["isServer","window"],"mappings":"AAAa,MAAAA,IAA6B,OAAXC,UAAW;;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const o = (o2) => ({}.NEXT_PUBLIC_APP_ENV || {}.REACT_APP_ENVIRONMENT || {}.REACT_APP_ENV || "production") === "local" && (o2.includes("localhost") || /(^(\d{1,3}\.){3}(\d{1,3})(:\d{1,5})?$)/.test(o2));
|
|
2
|
+
export { o as isLocalhost };
|
|
3
|
+
//# sourceMappingURL=binamik-js-providers.es2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binamik-js-providers.es2.js","sources":["../../src/utils/isLocalhost.ts"],"sourcesContent":["const isIpv4 = (str: string): boolean =>\n /(^(\\d{1,3}\\.){3}(\\d{1,3})(:\\d{1,5})?$)/.test(str)\n\nexport const isLocalhost = (host: string): boolean => {\n const APP_ENVIRONMENT =\n process.env.NEXT_PUBLIC_APP_ENV ||\n process.env.REACT_APP_ENVIRONMENT ||\n process.env.REACT_APP_ENV ||\n process.env.NODE_ENV\n return (\n APP_ENVIRONMENT === 'local' && (host.includes('localhost') || isIpv4(host))\n )\n}\n"],"names":["isLocalhost","host","NEXT_PUBLIC_APP_ENV","REACT_APP_ENVIRONMENT","REACT_APP_ENV","includes","test"],"mappings":"AAAA,MAGaA,IAAeC,QAOJ,AALpB,IAAYC,uBACZ,CAAA,EAAYC,yBACZ,CAAY,EAAAC,iBACZ,kBAEoB,WAAYH,IAAKI,SAAS,WAThD,KAAA,yCAAyCC,KAS8BL;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 };
|
|
9
|
+
//# sourceMappingURL=binamik-js-providers.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binamik-js-providers.es.js","sources":["../../../src/utils/yup/getYupValidationErrors.ts"],"sourcesContent":["import { ValidationError } from 'yup'\n\nexport const getYupValidationErrors = (\n err: ValidationError\n): Record<string, string> => {\n const validationErrors = {} as Record<string, string>\n\n if (err?.inner?.length) {\n err.inner.forEach(error => {\n validationErrors[error?.path || 'unknown'] = error.message\n })\n } else if (err?.path && err?.message) {\n validationErrors[err.path] = err.message\n } else if (!err?.path && err?.type === 'typeError') {\n validationErrors.body = err.errors[0]\n }\n\n return validationErrors\n}\n"],"names":["getYupValidationErrors","err","validationErrors","inner","length","forEach","error","path","message","type","body","errors"],"mappings":"AAEa,MAAAA,IACXC,QAEA;AAHW;AAGX,QAAMC,IAAmB,CAAA;AAYlB,SAVHD,gCAAKE,UAALF,mBAAYG,UACVH,GAAAE,MAAME,QAAiBC,QAAAA;AACRJ,MAAAI,0BAAOC,SAAQ,aAAaD,GAAME;AAAAA,EAAA,CAE5CP,IAAAA,0BAAKM,SAAQN,0BAAKO,WACVN,EAAAD,GAAIM,QAAQN,GAAIO,UACvBP,0BAAKM,SAAsB,AAAdN,0BAAKQ,UAAS,eACpBP,GAAAQ,OAAOT,GAAIU,OAAO,KAG9BT;AAAA;;"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@binamik/js-providers",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "1.0.1",
|
|
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(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"}})});
|