@agendar/shared 0.1.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/README.md +68 -0
- package/dist/chunk-436SJQLU.js +26 -0
- package/dist/chunk-436SJQLU.js.map +1 -0
- package/dist/chunk-DRXSG6VD.js +11 -0
- package/dist/chunk-DRXSG6VD.js.map +1 -0
- package/dist/chunk-FGDW32SI.js +20 -0
- package/dist/chunk-FGDW32SI.js.map +1 -0
- package/dist/chunk-I5B37D6W.js +6 -0
- package/dist/chunk-I5B37D6W.js.map +1 -0
- package/dist/chunk-IQAEBJUI.js +6 -0
- package/dist/chunk-IQAEBJUI.js.map +1 -0
- package/dist/chunk-IXJZJJT6.js +1948 -0
- package/dist/chunk-IXJZJJT6.js.map +1 -0
- package/dist/chunk-LMKYYUVF.js +1948 -0
- package/dist/chunk-LMKYYUVF.js.map +1 -0
- package/dist/chunk-PR273U3O.js +101 -0
- package/dist/chunk-PR273U3O.js.map +1 -0
- package/dist/chunk-SMKDDJXC.js +9 -0
- package/dist/chunk-SMKDDJXC.js.map +1 -0
- package/dist/chunk-SYJKOSLA.js +11 -0
- package/dist/chunk-SYJKOSLA.js.map +1 -0
- package/dist/chunk-YXJIMNQE.js +75 -0
- package/dist/chunk-YXJIMNQE.js.map +1 -0
- package/dist/chunk-ZZQ2WJR4.js +1930 -0
- package/dist/chunk-ZZQ2WJR4.js.map +1 -0
- package/dist/constants/masks.cjs +41 -0
- package/dist/constants/masks.cjs.map +1 -0
- package/dist/constants/masks.d.cts +5 -0
- package/dist/constants/masks.d.ts +5 -0
- package/dist/constants/masks.js +37 -0
- package/dist/constants/masks.js.map +1 -0
- package/dist/constants/milliseconds.cjs +14 -0
- package/dist/constants/milliseconds.cjs.map +1 -0
- package/dist/constants/milliseconds.d.cts +6 -0
- package/dist/constants/milliseconds.d.ts +6 -0
- package/dist/constants/milliseconds.js +3 -0
- package/dist/constants/milliseconds.js.map +1 -0
- package/dist/constants/regex.cjs +18 -0
- package/dist/constants/regex.cjs.map +1 -0
- package/dist/constants/regex.d.cts +12 -0
- package/dist/constants/regex.d.ts +12 -0
- package/dist/constants/regex.js +3 -0
- package/dist/constants/regex.js.map +1 -0
- package/dist/constants/status-colors.cjs +13 -0
- package/dist/constants/status-colors.cjs.map +1 -0
- package/dist/constants/status-colors.d.cts +9 -0
- package/dist/constants/status-colors.d.ts +9 -0
- package/dist/constants/status-colors.js +3 -0
- package/dist/constants/status-colors.js.map +1 -0
- package/dist/hooks/use-debounce.cjs +30 -0
- package/dist/hooks/use-debounce.cjs.map +1 -0
- package/dist/hooks/use-debounce.d.cts +3 -0
- package/dist/hooks/use-debounce.d.ts +3 -0
- package/dist/hooks/use-debounce.js +24 -0
- package/dist/hooks/use-debounce.js.map +1 -0
- package/dist/i18n/en.cjs +1950 -0
- package/dist/i18n/en.cjs.map +1 -0
- package/dist/i18n/en.d.cts +1889 -0
- package/dist/i18n/en.d.ts +1889 -0
- package/dist/i18n/en.js +3 -0
- package/dist/i18n/en.js.map +1 -0
- package/dist/i18n/es.cjs +1932 -0
- package/dist/i18n/es.cjs.map +1 -0
- package/dist/i18n/es.d.cts +1871 -0
- package/dist/i18n/es.d.ts +1871 -0
- package/dist/i18n/es.js +3 -0
- package/dist/i18n/es.js.map +1 -0
- package/dist/i18n/index.cjs +5824 -0
- package/dist/i18n/index.cjs.map +1 -0
- package/dist/i18n/index.d.cts +3 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/index.js +5 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/pt.cjs +1950 -0
- package/dist/i18n/pt.cjs.map +1 -0
- package/dist/i18n/pt.d.cts +1889 -0
- package/dist/i18n/pt.d.ts +1889 -0
- package/dist/i18n/pt.js +3 -0
- package/dist/i18n/pt.js.map +1 -0
- package/dist/index.cjs +120 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/native/index.cjs +33 -0
- package/dist/native/index.cjs.map +1 -0
- package/dist/native/index.d.cts +6 -0
- package/dist/native/index.d.ts +6 -0
- package/dist/native/index.js +14 -0
- package/dist/native/index.js.map +1 -0
- package/dist/react-query/config.cjs +51 -0
- package/dist/react-query/config.cjs.map +1 -0
- package/dist/react-query/config.d.cts +19 -0
- package/dist/react-query/config.d.ts +19 -0
- package/dist/react-query/config.js +41 -0
- package/dist/react-query/config.js.map +1 -0
- package/dist/react-query/pagination.cjs +21 -0
- package/dist/react-query/pagination.cjs.map +1 -0
- package/dist/react-query/pagination.d.cts +4 -0
- package/dist/react-query/pagination.d.ts +4 -0
- package/dist/react-query/pagination.js +18 -0
- package/dist/react-query/pagination.js.map +1 -0
- package/dist/schemas/absence-form.cjs +36 -0
- package/dist/schemas/absence-form.cjs.map +1 -0
- package/dist/schemas/absence-form.d.cts +38 -0
- package/dist/schemas/absence-form.d.ts +38 -0
- package/dist/schemas/absence-form.js +32 -0
- package/dist/schemas/absence-form.js.map +1 -0
- package/dist/schemas/cash-drawer-movement-form.cjs +22 -0
- package/dist/schemas/cash-drawer-movement-form.cjs.map +1 -0
- package/dist/schemas/cash-drawer-movement-form.d.cts +17 -0
- package/dist/schemas/cash-drawer-movement-form.d.ts +17 -0
- package/dist/schemas/cash-drawer-movement-form.js +19 -0
- package/dist/schemas/cash-drawer-movement-form.js.map +1 -0
- package/dist/schemas/cash-drawer-opening-form.cjs +20 -0
- package/dist/schemas/cash-drawer-opening-form.cjs.map +1 -0
- package/dist/schemas/cash-drawer-opening-form.d.cts +14 -0
- package/dist/schemas/cash-drawer-opening-form.d.ts +14 -0
- package/dist/schemas/cash-drawer-opening-form.js +17 -0
- package/dist/schemas/cash-drawer-opening-form.js.map +1 -0
- package/dist/schemas/category-form.cjs +23 -0
- package/dist/schemas/category-form.cjs.map +1 -0
- package/dist/schemas/category-form.d.cts +20 -0
- package/dist/schemas/category-form.d.ts +20 -0
- package/dist/schemas/category-form.js +20 -0
- package/dist/schemas/category-form.js.map +1 -0
- package/dist/schemas/change-contact-form.cjs +21 -0
- package/dist/schemas/change-contact-form.cjs.map +1 -0
- package/dist/schemas/change-contact-form.d.cts +20 -0
- package/dist/schemas/change-contact-form.d.ts +20 -0
- package/dist/schemas/change-contact-form.js +19 -0
- package/dist/schemas/change-contact-form.js.map +1 -0
- package/dist/schemas/change-password-form.cjs +33 -0
- package/dist/schemas/change-password-form.cjs.map +1 -0
- package/dist/schemas/change-password-form.d.cts +21 -0
- package/dist/schemas/change-password-form.d.ts +21 -0
- package/dist/schemas/change-password-form.js +25 -0
- package/dist/schemas/change-password-form.js.map +1 -0
- package/dist/schemas/client-balance-adjustment-form.cjs +25 -0
- package/dist/schemas/client-balance-adjustment-form.cjs.map +1 -0
- package/dist/schemas/client-balance-adjustment-form.d.cts +24 -0
- package/dist/schemas/client-balance-adjustment-form.d.ts +24 -0
- package/dist/schemas/client-balance-adjustment-form.js +22 -0
- package/dist/schemas/client-balance-adjustment-form.js.map +1 -0
- package/dist/schemas/commission-form.cjs +23 -0
- package/dist/schemas/commission-form.cjs.map +1 -0
- package/dist/schemas/commission-form.d.cts +19 -0
- package/dist/schemas/commission-form.d.ts +19 -0
- package/dist/schemas/commission-form.js +3 -0
- package/dist/schemas/commission-form.js.map +1 -0
- package/dist/schemas/create-appointment.cjs +40 -0
- package/dist/schemas/create-appointment.cjs.map +1 -0
- package/dist/schemas/create-appointment.d.cts +29 -0
- package/dist/schemas/create-appointment.d.ts +29 -0
- package/dist/schemas/create-appointment.js +29 -0
- package/dist/schemas/create-appointment.js.map +1 -0
- package/dist/schemas/create-business-form.cjs +20 -0
- package/dist/schemas/create-business-form.cjs.map +1 -0
- package/dist/schemas/create-business-form.d.cts +14 -0
- package/dist/schemas/create-business-form.d.ts +14 -0
- package/dist/schemas/create-business-form.js +17 -0
- package/dist/schemas/create-business-form.js.map +1 -0
- package/dist/schemas/create-client.cjs +71 -0
- package/dist/schemas/create-client.cjs.map +1 -0
- package/dist/schemas/create-client.d.cts +31 -0
- package/dist/schemas/create-client.d.ts +31 -0
- package/dist/schemas/create-client.js +33 -0
- package/dist/schemas/create-client.js.map +1 -0
- package/dist/schemas/create-establishment-form.cjs +36 -0
- package/dist/schemas/create-establishment-form.cjs.map +1 -0
- package/dist/schemas/create-establishment-form.d.cts +31 -0
- package/dist/schemas/create-establishment-form.d.ts +31 -0
- package/dist/schemas/create-establishment-form.js +10 -0
- package/dist/schemas/create-establishment-form.js.map +1 -0
- package/dist/schemas/create-professional.cjs +31 -0
- package/dist/schemas/create-professional.cjs.map +1 -0
- package/dist/schemas/create-professional.d.cts +28 -0
- package/dist/schemas/create-professional.d.ts +28 -0
- package/dist/schemas/create-professional.js +28 -0
- package/dist/schemas/create-professional.js.map +1 -0
- package/dist/schemas/edit-business.cjs +32 -0
- package/dist/schemas/edit-business.cjs.map +1 -0
- package/dist/schemas/edit-business.d.cts +22 -0
- package/dist/schemas/edit-business.d.ts +22 -0
- package/dist/schemas/edit-business.js +24 -0
- package/dist/schemas/edit-business.js.map +1 -0
- package/dist/schemas/edit-establishment.cjs +32 -0
- package/dist/schemas/edit-establishment.cjs.map +1 -0
- package/dist/schemas/edit-establishment.d.cts +32 -0
- package/dist/schemas/edit-establishment.d.ts +32 -0
- package/dist/schemas/edit-establishment.js +4 -0
- package/dist/schemas/edit-establishment.js.map +1 -0
- package/dist/schemas/edit-profile.cjs +28 -0
- package/dist/schemas/edit-profile.cjs.map +1 -0
- package/dist/schemas/edit-profile.d.cts +19 -0
- package/dist/schemas/edit-profile.d.ts +19 -0
- package/dist/schemas/edit-profile.js +20 -0
- package/dist/schemas/edit-profile.js.map +1 -0
- package/dist/schemas/expense-category-form.cjs +21 -0
- package/dist/schemas/expense-category-form.cjs.map +1 -0
- package/dist/schemas/expense-category-form.d.cts +16 -0
- package/dist/schemas/expense-category-form.d.ts +16 -0
- package/dist/schemas/expense-category-form.js +18 -0
- package/dist/schemas/expense-category-form.js.map +1 -0
- package/dist/schemas/expense-form.cjs +34 -0
- package/dist/schemas/expense-form.cjs.map +1 -0
- package/dist/schemas/expense-form.d.cts +50 -0
- package/dist/schemas/expense-form.d.ts +50 -0
- package/dist/schemas/expense-form.js +29 -0
- package/dist/schemas/expense-form.js.map +1 -0
- package/dist/schemas/forgot-password-form.cjs +21 -0
- package/dist/schemas/forgot-password-form.cjs.map +1 -0
- package/dist/schemas/forgot-password-form.d.cts +14 -0
- package/dist/schemas/forgot-password-form.d.ts +14 -0
- package/dist/schemas/forgot-password-form.js +18 -0
- package/dist/schemas/forgot-password-form.js.map +1 -0
- package/dist/schemas/package-form.cjs +26 -0
- package/dist/schemas/package-form.cjs.map +1 -0
- package/dist/schemas/package-form.d.cts +24 -0
- package/dist/schemas/package-form.d.ts +24 -0
- package/dist/schemas/package-form.js +23 -0
- package/dist/schemas/package-form.js.map +1 -0
- package/dist/schemas/package-sale-form.cjs +23 -0
- package/dist/schemas/package-sale-form.cjs.map +1 -0
- package/dist/schemas/package-sale-form.d.cts +19 -0
- package/dist/schemas/package-sale-form.d.ts +19 -0
- package/dist/schemas/package-sale-form.js +20 -0
- package/dist/schemas/package-sale-form.js.map +1 -0
- package/dist/schemas/package-service-form.cjs +27 -0
- package/dist/schemas/package-service-form.cjs.map +1 -0
- package/dist/schemas/package-service-form.d.cts +24 -0
- package/dist/schemas/package-service-form.d.ts +24 -0
- package/dist/schemas/package-service-form.js +24 -0
- package/dist/schemas/package-service-form.js.map +1 -0
- package/dist/schemas/product-form.cjs +34 -0
- package/dist/schemas/product-form.cjs.map +1 -0
- package/dist/schemas/product-form.d.cts +38 -0
- package/dist/schemas/product-form.d.ts +38 -0
- package/dist/schemas/product-form.js +31 -0
- package/dist/schemas/product-form.js.map +1 -0
- package/dist/schemas/profession-role-form.cjs +22 -0
- package/dist/schemas/profession-role-form.cjs.map +1 -0
- package/dist/schemas/profession-role-form.d.cts +18 -0
- package/dist/schemas/profession-role-form.d.ts +18 -0
- package/dist/schemas/profession-role-form.js +19 -0
- package/dist/schemas/profession-role-form.js.map +1 -0
- package/dist/schemas/professional-form.cjs +30 -0
- package/dist/schemas/professional-form.cjs.map +1 -0
- package/dist/schemas/professional-form.d.cts +31 -0
- package/dist/schemas/professional-form.d.ts +31 -0
- package/dist/schemas/professional-form.js +27 -0
- package/dist/schemas/professional-form.js.map +1 -0
- package/dist/schemas/register-business-owner-form.cjs +94 -0
- package/dist/schemas/register-business-owner-form.cjs.map +1 -0
- package/dist/schemas/register-business-owner-form.d.cts +44 -0
- package/dist/schemas/register-business-owner-form.d.ts +44 -0
- package/dist/schemas/register-business-owner-form.js +59 -0
- package/dist/schemas/register-business-owner-form.js.map +1 -0
- package/dist/schemas/reset-password-form.cjs +31 -0
- package/dist/schemas/reset-password-form.cjs.map +1 -0
- package/dist/schemas/reset-password-form.d.cts +18 -0
- package/dist/schemas/reset-password-form.d.ts +18 -0
- package/dist/schemas/reset-password-form.js +23 -0
- package/dist/schemas/reset-password-form.js.map +1 -0
- package/dist/schemas/service-form.cjs +80 -0
- package/dist/schemas/service-form.cjs.map +1 -0
- package/dist/schemas/service-form.d.cts +58 -0
- package/dist/schemas/service-form.d.ts +58 -0
- package/dist/schemas/service-form.js +62 -0
- package/dist/schemas/service-form.js.map +1 -0
- package/dist/schemas/signin.cjs +23 -0
- package/dist/schemas/signin.cjs.map +1 -0
- package/dist/schemas/signin.d.cts +17 -0
- package/dist/schemas/signin.d.ts +17 -0
- package/dist/schemas/signin.js +20 -0
- package/dist/schemas/signin.js.map +1 -0
- package/dist/schemas/specialization-form.cjs +21 -0
- package/dist/schemas/specialization-form.cjs.map +1 -0
- package/dist/schemas/specialization-form.d.cts +16 -0
- package/dist/schemas/specialization-form.d.ts +16 -0
- package/dist/schemas/specialization-form.js +18 -0
- package/dist/schemas/specialization-form.js.map +1 -0
- package/dist/schemas/tab-cancel-form.cjs +20 -0
- package/dist/schemas/tab-cancel-form.cjs.map +1 -0
- package/dist/schemas/tab-cancel-form.d.cts +14 -0
- package/dist/schemas/tab-cancel-form.d.ts +14 -0
- package/dist/schemas/tab-cancel-form.js +17 -0
- package/dist/schemas/tab-cancel-form.js.map +1 -0
- package/dist/schemas/tab-close-form.cjs +20 -0
- package/dist/schemas/tab-close-form.cjs.map +1 -0
- package/dist/schemas/tab-close-form.d.cts +14 -0
- package/dist/schemas/tab-close-form.d.ts +14 -0
- package/dist/schemas/tab-close-form.js +17 -0
- package/dist/schemas/tab-close-form.js.map +1 -0
- package/dist/schemas/tab-item-form.cjs +32 -0
- package/dist/schemas/tab-item-form.cjs.map +1 -0
- package/dist/schemas/tab-item-form.d.cts +32 -0
- package/dist/schemas/tab-item-form.d.ts +32 -0
- package/dist/schemas/tab-item-form.js +29 -0
- package/dist/schemas/tab-item-form.js.map +1 -0
- package/dist/tracking/events.cjs +4 -0
- package/dist/tracking/events.cjs.map +1 -0
- package/dist/tracking/events.d.cts +50 -0
- package/dist/tracking/events.d.ts +50 -0
- package/dist/tracking/events.js +3 -0
- package/dist/tracking/events.js.map +1 -0
- package/dist/types/api-error.cjs +4 -0
- package/dist/types/api-error.cjs.map +1 -0
- package/dist/types/api-error.d.cts +9 -0
- package/dist/types/api-error.d.ts +9 -0
- package/dist/types/api-error.js +3 -0
- package/dist/types/api-error.js.map +1 -0
- package/dist/types/common.cjs +4 -0
- package/dist/types/common.cjs.map +1 -0
- package/dist/types/common.d.cts +8 -0
- package/dist/types/common.d.ts +8 -0
- package/dist/types/common.js +3 -0
- package/dist/types/common.js.map +1 -0
- package/dist/utils/appointment-status.cjs +59 -0
- package/dist/utils/appointment-status.cjs.map +1 -0
- package/dist/utils/appointment-status.d.cts +13 -0
- package/dist/utils/appointment-status.d.ts +13 -0
- package/dist/utils/appointment-status.js +47 -0
- package/dist/utils/appointment-status.js.map +1 -0
- package/dist/utils/appointments.cjs +87 -0
- package/dist/utils/appointments.cjs.map +1 -0
- package/dist/utils/appointments.d.cts +50 -0
- package/dist/utils/appointments.d.ts +50 -0
- package/dist/utils/appointments.js +65 -0
- package/dist/utils/appointments.js.map +1 -0
- package/dist/utils/avatar.cjs +44 -0
- package/dist/utils/avatar.cjs.map +1 -0
- package/dist/utils/avatar.d.cts +8 -0
- package/dist/utils/avatar.d.ts +8 -0
- package/dist/utils/avatar.js +37 -0
- package/dist/utils/avatar.js.map +1 -0
- package/dist/utils/date.cjs +95 -0
- package/dist/utils/date.cjs.map +1 -0
- package/dist/utils/date.d.cts +31 -0
- package/dist/utils/date.d.ts +31 -0
- package/dist/utils/date.js +3 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/decode-jwt.cjs +44 -0
- package/dist/utils/decode-jwt.cjs.map +1 -0
- package/dist/utils/decode-jwt.d.cts +10 -0
- package/dist/utils/decode-jwt.d.ts +10 -0
- package/dist/utils/decode-jwt.js +41 -0
- package/dist/utils/decode-jwt.js.map +1 -0
- package/dist/utils/error-response.cjs +134 -0
- package/dist/utils/error-response.cjs.map +1 -0
- package/dist/utils/error-response.d.cts +11 -0
- package/dist/utils/error-response.d.ts +11 -0
- package/dist/utils/error-response.js +131 -0
- package/dist/utils/error-response.js.map +1 -0
- package/dist/utils/firebase-phone-auth-errors.cjs +19 -0
- package/dist/utils/firebase-phone-auth-errors.cjs.map +1 -0
- package/dist/utils/firebase-phone-auth-errors.d.cts +3 -0
- package/dist/utils/firebase-phone-auth-errors.d.ts +3 -0
- package/dist/utils/firebase-phone-auth-errors.js +17 -0
- package/dist/utils/firebase-phone-auth-errors.js.map +1 -0
- package/dist/utils/fullname.cjs +8 -0
- package/dist/utils/fullname.cjs.map +1 -0
- package/dist/utils/fullname.d.cts +3 -0
- package/dist/utils/fullname.d.ts +3 -0
- package/dist/utils/fullname.js +3 -0
- package/dist/utils/fullname.js.map +1 -0
- package/dist/utils/professional-schedules.cjs +24 -0
- package/dist/utils/professional-schedules.cjs.map +1 -0
- package/dist/utils/professional-schedules.d.cts +28 -0
- package/dist/utils/professional-schedules.d.ts +28 -0
- package/dist/utils/professional-schedules.js +20 -0
- package/dist/utils/professional-schedules.js.map +1 -0
- package/dist/utils/schedule-availability.cjs +41 -0
- package/dist/utils/schedule-availability.cjs.map +1 -0
- package/dist/utils/schedule-availability.d.cts +23 -0
- package/dist/utils/schedule-availability.d.ts +23 -0
- package/dist/utils/schedule-availability.js +38 -0
- package/dist/utils/schedule-availability.js.map +1 -0
- package/dist/utils/string.cjs +56 -0
- package/dist/utils/string.cjs.map +1 -0
- package/dist/utils/string.d.cts +7 -0
- package/dist/utils/string.d.ts +7 -0
- package/dist/utils/string.js +50 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/utils/timeline-layout.cjs +58 -0
- package/dist/utils/timeline-layout.cjs.map +1 -0
- package/dist/utils/timeline-layout.d.cts +19 -0
- package/dist/utils/timeline-layout.d.ts +19 -0
- package/dist/utils/timeline-layout.js +56 -0
- package/dist/utils/timeline-layout.js.map +1 -0
- package/package.json +389 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dayjs = require('dayjs');
|
|
4
|
+
var localeData = require('dayjs/plugin/localeData');
|
|
5
|
+
var localizedFormat = require('dayjs/plugin/localizedFormat');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
|
|
10
|
+
var localeData__default = /*#__PURE__*/_interopDefault(localeData);
|
|
11
|
+
var localizedFormat__default = /*#__PURE__*/_interopDefault(localizedFormat);
|
|
12
|
+
|
|
13
|
+
// src/core/utils/date.ts
|
|
14
|
+
dayjs__default.default.extend(localizedFormat__default.default);
|
|
15
|
+
dayjs__default.default.extend(localeData__default.default);
|
|
16
|
+
function addDays(date, days) {
|
|
17
|
+
return dayjs__default.default(date).add(days, "day").toDate();
|
|
18
|
+
}
|
|
19
|
+
function calculateAge(birthday) {
|
|
20
|
+
return dayjs__default.default().diff(dayjs__default.default(birthday), "year");
|
|
21
|
+
}
|
|
22
|
+
function isValidCalendarDate(value) {
|
|
23
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
24
|
+
if (!match) return false;
|
|
25
|
+
const [, yearStr, monthStr, dayStr] = match;
|
|
26
|
+
const year = Number(yearStr);
|
|
27
|
+
const month = Number(monthStr);
|
|
28
|
+
const day = Number(dayStr);
|
|
29
|
+
const date = new Date(year, month - 1, day);
|
|
30
|
+
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
|
|
31
|
+
}
|
|
32
|
+
function isoToDisplayDate(iso) {
|
|
33
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso);
|
|
34
|
+
if (!match) return "";
|
|
35
|
+
const [, year, month, day] = match;
|
|
36
|
+
return `${day}/${month}/${year}`;
|
|
37
|
+
}
|
|
38
|
+
function maskedDigitsToIsoDate(digits) {
|
|
39
|
+
if (digits.length !== 8) return "";
|
|
40
|
+
const day = digits.slice(0, 2);
|
|
41
|
+
const month = digits.slice(2, 4);
|
|
42
|
+
const year = digits.slice(4, 8);
|
|
43
|
+
return `${year}-${month}-${day}`;
|
|
44
|
+
}
|
|
45
|
+
function toDateString(date) {
|
|
46
|
+
return dayjs__default.default(date).format("YYYY-MM-DD");
|
|
47
|
+
}
|
|
48
|
+
function parseDateParts(dateString) {
|
|
49
|
+
const date = dayjs__default.default(dateString);
|
|
50
|
+
return {
|
|
51
|
+
month: date.format("MMM").toUpperCase(),
|
|
52
|
+
day: date.format("D")
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function formatMonthDay(dateString) {
|
|
56
|
+
return dayjs__default.default(dateString).format("MMM D");
|
|
57
|
+
}
|
|
58
|
+
function formatTime12h(time) {
|
|
59
|
+
return dayjs__default.default(`1970-01-01 ${time}`).format("h:mm a");
|
|
60
|
+
}
|
|
61
|
+
function addMinutesToTime(time, minutes) {
|
|
62
|
+
return dayjs__default.default(`1970-01-01 ${time}`).add(minutes, "minute").format("HH:mm");
|
|
63
|
+
}
|
|
64
|
+
function formatLocalizedDate(date) {
|
|
65
|
+
if (!date) return "\u2014";
|
|
66
|
+
return dayjs__default.default(date).format("L");
|
|
67
|
+
}
|
|
68
|
+
function formatLocalizedDateTime(date) {
|
|
69
|
+
if (!date) return "\u2014";
|
|
70
|
+
return dayjs__default.default(date).format("L LT");
|
|
71
|
+
}
|
|
72
|
+
function localizedShortDatePattern() {
|
|
73
|
+
const longFormat = dayjs__default.default.localeData().longDateFormat("L");
|
|
74
|
+
return longFormat.replace(/^[,./\-\s]*Y+[,./\-\s]*/, "").replace(/[,./\-\s]*Y+[,./\-\s]*$/, "");
|
|
75
|
+
}
|
|
76
|
+
function formatLocalizedShortDate(date) {
|
|
77
|
+
if (!date) return "\u2014";
|
|
78
|
+
return dayjs__default.default(date).format(localizedShortDatePattern());
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
exports.addDays = addDays;
|
|
82
|
+
exports.addMinutesToTime = addMinutesToTime;
|
|
83
|
+
exports.calculateAge = calculateAge;
|
|
84
|
+
exports.formatLocalizedDate = formatLocalizedDate;
|
|
85
|
+
exports.formatLocalizedDateTime = formatLocalizedDateTime;
|
|
86
|
+
exports.formatLocalizedShortDate = formatLocalizedShortDate;
|
|
87
|
+
exports.formatMonthDay = formatMonthDay;
|
|
88
|
+
exports.formatTime12h = formatTime12h;
|
|
89
|
+
exports.isValidCalendarDate = isValidCalendarDate;
|
|
90
|
+
exports.isoToDisplayDate = isoToDisplayDate;
|
|
91
|
+
exports.maskedDigitsToIsoDate = maskedDigitsToIsoDate;
|
|
92
|
+
exports.parseDateParts = parseDateParts;
|
|
93
|
+
exports.toDateString = toDateString;
|
|
94
|
+
//# sourceMappingURL=date.cjs.map
|
|
95
|
+
//# sourceMappingURL=date.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/utils/date.ts"],"names":["dayjs","localizedFormat","localeData"],"mappings":";;;;;;;;;;;;;AAIAA,sBAAA,CAAM,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CAAA;AAC1E;AAGO,SAAS,oBACd,IAAA,EACQ;AACR,EAAA,IAAI,CAAC,MAAM,OAAO,QAAA;AAClB,EAAA,OAAOA,sBAAA,CAAM,IAAI,CAAA,CAAE,MAAA,CAAO,GAAG,CAAA;AAC/B;AAGO,SAAS,wBACd,IAAA,EACQ;AACR,EAAA,IAAI,CAAC,MAAM,OAAO,QAAA;AAClB,EAAA,OAAOA,sBAAA,CAAM,IAAI,CAAA,CAAE,MAAA,CAAO,MAAM,CAAA;AAClC;AAGA,SAAS,yBAAA,GAAoC;AAC3C,EAAA,MAAM,UAAA,GAAaA,sBAAA,CAAM,UAAA,EAAW,CAAE,eAAe,GAAG,CAAA;AACxD,EAAA,OAAO,WACJ,OAAA,CAAQ,yBAAA,EAA2B,EAAE,CAAA,CACrC,OAAA,CAAQ,2BAA2B,EAAE,CAAA;AAC1C;AAGO,SAAS,yBACd,IAAA,EACQ;AACR,EAAA,IAAI,CAAC,MAAM,OAAO,QAAA;AAClB,EAAA,OAAOA,sBAAA,CAAM,IAAI,CAAA,CAAE,MAAA,CAAO,2BAA2B,CAAA;AACvD","file":"date.cjs","sourcesContent":["import dayjs from \"dayjs\";\nimport localeData from \"dayjs/plugin/localeData\";\nimport localizedFormat from \"dayjs/plugin/localizedFormat\";\n\ndayjs.extend(localizedFormat);\ndayjs.extend(localeData);\n\nexport function addDays(date: Date, days: number): Date {\n return dayjs(date).add(days, \"day\").toDate();\n}\n\n/** Full years elapsed since a \"YYYY-MM-DD\" birthday, as of today. */\nexport function calculateAge(birthday: string): number {\n return dayjs().diff(dayjs(birthday), \"year\");\n}\n\n/**\n * Whether a \"YYYY-MM-DD\" string is a real calendar date (rejects e.g. \"2024-02-30\"\n * or \"2024-13-01\", which a shape-only regex like `birthdayRegex` would let through).\n */\nexport function isValidCalendarDate(value: string): boolean {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(value);\n if (!match) return false;\n\n const [, yearStr, monthStr, dayStr] = match;\n const year = Number(yearStr);\n const month = Number(monthStr);\n const day = Number(dayStr);\n\n const date = new Date(year, month - 1, day);\n return (\n date.getFullYear() === year &&\n date.getMonth() === month - 1 &&\n date.getDate() === day\n );\n}\n\n/** Converts a \"YYYY-MM-DD\" value to \"DD/MM/YYYY\" for masked-input display. Empty in, empty out. */\nexport function isoToDisplayDate(iso: string): string {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(iso);\n if (!match) return \"\";\n\n const [, year, month, day] = match;\n return `${day}/${month}/${year}`;\n}\n\n/**\n * Converts the raw digits typed into a DD/MM/YYYY mask (e.g. \"15081990\") into\n * \"YYYY-MM-DD\". Returns \"\" until all 8 digits have been entered.\n */\nexport function maskedDigitsToIsoDate(digits: string): string {\n if (digits.length !== 8) return \"\";\n\n const day = digits.slice(0, 2);\n const month = digits.slice(2, 4);\n const year = digits.slice(4, 8);\n return `${year}-${month}-${day}`;\n}\n\nexport function toDateString(date: Date): string {\n return dayjs(date).format(\"YYYY-MM-DD\");\n}\n\nexport function parseDateParts(dateString: string): {\n month: string;\n day: string;\n} {\n const date = dayjs(dateString);\n return {\n month: date.format(\"MMM\").toUpperCase(),\n day: date.format(\"D\"),\n };\n}\n\nexport function formatMonthDay(dateString: string): string {\n return dayjs(dateString).format(\"MMM D\");\n}\n\nexport function formatTime12h(time: string): string {\n return dayjs(`1970-01-01 ${time}`).format(\"h:mm a\");\n}\n\nexport function addMinutesToTime(time: string, minutes: number): string {\n return dayjs(`1970-01-01 ${time}`).add(minutes, \"minute\").format(\"HH:mm\");\n}\n\n/** Formats a date using the active dayjs locale (e.g. DD/MM/YYYY for pt-br, MM/DD/YYYY for en). */\nexport function formatLocalizedDate(\n date: Date | string | null | undefined,\n): string {\n if (!date) return \"—\";\n return dayjs(date).format(\"L\");\n}\n\n/** Formats a date and time using the active dayjs locale. */\nexport function formatLocalizedDateTime(\n date: Date | string | null | undefined,\n): string {\n if (!date) return \"—\";\n return dayjs(date).format(\"L LT\");\n}\n\n/** Day/month order for the active dayjs locale, derived from its full date pattern (e.g. \"DD/MM\" for pt-br, \"MM/DD\" for en). */\nfunction localizedShortDatePattern(): string {\n const longFormat = dayjs.localeData().longDateFormat(\"L\");\n return longFormat\n .replace(/^[,./\\-\\s]*Y+[,./\\-\\s]*/, \"\")\n .replace(/[,./\\-\\s]*Y+[,./\\-\\s]*$/, \"\");\n}\n\n/** Formats a date as day/month (no year), in the order the active dayjs locale uses. */\nexport function formatLocalizedShortDate(\n date: Date | string | null | undefined,\n): string {\n if (!date) return \"—\";\n return dayjs(date).format(localizedShortDatePattern());\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare function addDays(date: Date, days: number): Date;
|
|
2
|
+
/** Full years elapsed since a "YYYY-MM-DD" birthday, as of today. */
|
|
3
|
+
declare function calculateAge(birthday: string): number;
|
|
4
|
+
/**
|
|
5
|
+
* Whether a "YYYY-MM-DD" string is a real calendar date (rejects e.g. "2024-02-30"
|
|
6
|
+
* or "2024-13-01", which a shape-only regex like `birthdayRegex` would let through).
|
|
7
|
+
*/
|
|
8
|
+
declare function isValidCalendarDate(value: string): boolean;
|
|
9
|
+
/** Converts a "YYYY-MM-DD" value to "DD/MM/YYYY" for masked-input display. Empty in, empty out. */
|
|
10
|
+
declare function isoToDisplayDate(iso: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Converts the raw digits typed into a DD/MM/YYYY mask (e.g. "15081990") into
|
|
13
|
+
* "YYYY-MM-DD". Returns "" until all 8 digits have been entered.
|
|
14
|
+
*/
|
|
15
|
+
declare function maskedDigitsToIsoDate(digits: string): string;
|
|
16
|
+
declare function toDateString(date: Date): string;
|
|
17
|
+
declare function parseDateParts(dateString: string): {
|
|
18
|
+
month: string;
|
|
19
|
+
day: string;
|
|
20
|
+
};
|
|
21
|
+
declare function formatMonthDay(dateString: string): string;
|
|
22
|
+
declare function formatTime12h(time: string): string;
|
|
23
|
+
declare function addMinutesToTime(time: string, minutes: number): string;
|
|
24
|
+
/** Formats a date using the active dayjs locale (e.g. DD/MM/YYYY for pt-br, MM/DD/YYYY for en). */
|
|
25
|
+
declare function formatLocalizedDate(date: Date | string | null | undefined): string;
|
|
26
|
+
/** Formats a date and time using the active dayjs locale. */
|
|
27
|
+
declare function formatLocalizedDateTime(date: Date | string | null | undefined): string;
|
|
28
|
+
/** Formats a date as day/month (no year), in the order the active dayjs locale uses. */
|
|
29
|
+
declare function formatLocalizedShortDate(date: Date | string | null | undefined): string;
|
|
30
|
+
|
|
31
|
+
export { addDays, addMinutesToTime, calculateAge, formatLocalizedDate, formatLocalizedDateTime, formatLocalizedShortDate, formatMonthDay, formatTime12h, isValidCalendarDate, isoToDisplayDate, maskedDigitsToIsoDate, parseDateParts, toDateString };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare function addDays(date: Date, days: number): Date;
|
|
2
|
+
/** Full years elapsed since a "YYYY-MM-DD" birthday, as of today. */
|
|
3
|
+
declare function calculateAge(birthday: string): number;
|
|
4
|
+
/**
|
|
5
|
+
* Whether a "YYYY-MM-DD" string is a real calendar date (rejects e.g. "2024-02-30"
|
|
6
|
+
* or "2024-13-01", which a shape-only regex like `birthdayRegex` would let through).
|
|
7
|
+
*/
|
|
8
|
+
declare function isValidCalendarDate(value: string): boolean;
|
|
9
|
+
/** Converts a "YYYY-MM-DD" value to "DD/MM/YYYY" for masked-input display. Empty in, empty out. */
|
|
10
|
+
declare function isoToDisplayDate(iso: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Converts the raw digits typed into a DD/MM/YYYY mask (e.g. "15081990") into
|
|
13
|
+
* "YYYY-MM-DD". Returns "" until all 8 digits have been entered.
|
|
14
|
+
*/
|
|
15
|
+
declare function maskedDigitsToIsoDate(digits: string): string;
|
|
16
|
+
declare function toDateString(date: Date): string;
|
|
17
|
+
declare function parseDateParts(dateString: string): {
|
|
18
|
+
month: string;
|
|
19
|
+
day: string;
|
|
20
|
+
};
|
|
21
|
+
declare function formatMonthDay(dateString: string): string;
|
|
22
|
+
declare function formatTime12h(time: string): string;
|
|
23
|
+
declare function addMinutesToTime(time: string, minutes: number): string;
|
|
24
|
+
/** Formats a date using the active dayjs locale (e.g. DD/MM/YYYY for pt-br, MM/DD/YYYY for en). */
|
|
25
|
+
declare function formatLocalizedDate(date: Date | string | null | undefined): string;
|
|
26
|
+
/** Formats a date and time using the active dayjs locale. */
|
|
27
|
+
declare function formatLocalizedDateTime(date: Date | string | null | undefined): string;
|
|
28
|
+
/** Formats a date as day/month (no year), in the order the active dayjs locale uses. */
|
|
29
|
+
declare function formatLocalizedShortDate(date: Date | string | null | undefined): string;
|
|
30
|
+
|
|
31
|
+
export { addDays, addMinutesToTime, calculateAge, formatLocalizedDate, formatLocalizedDateTime, formatLocalizedShortDate, formatMonthDay, formatTime12h, isValidCalendarDate, isoToDisplayDate, maskedDigitsToIsoDate, parseDateParts, toDateString };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { addDays, addMinutesToTime, calculateAge, formatLocalizedDate, formatLocalizedDateTime, formatLocalizedShortDate, formatMonthDay, formatTime12h, isValidCalendarDate, isoToDisplayDate, maskedDigitsToIsoDate, parseDateParts, toDateString } from '../chunk-YXJIMNQE.js';
|
|
2
|
+
//# sourceMappingURL=date.js.map
|
|
3
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"date.js"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/core/utils/decode-jwt.ts
|
|
4
|
+
var decodeBase64 = (base64) => {
|
|
5
|
+
try {
|
|
6
|
+
const atobFn = typeof atob === "function" ? atob : void 0;
|
|
7
|
+
if (typeof atobFn === "function") {
|
|
8
|
+
return atobFn(base64);
|
|
9
|
+
}
|
|
10
|
+
} catch {
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const bufferCtor = typeof Buffer !== "undefined" ? Buffer : void 0;
|
|
14
|
+
if (bufferCtor && typeof bufferCtor.from === "function") {
|
|
15
|
+
return bufferCtor.from(base64, "base64").toString("utf-8");
|
|
16
|
+
}
|
|
17
|
+
} catch {
|
|
18
|
+
}
|
|
19
|
+
throw new Error("Base64 decoding not supported in this environment");
|
|
20
|
+
};
|
|
21
|
+
function decodeJwtPayload(token) {
|
|
22
|
+
try {
|
|
23
|
+
const parts = token.split(".");
|
|
24
|
+
if (parts.length !== 3) return null;
|
|
25
|
+
const base64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
26
|
+
const padded = base64.padEnd(
|
|
27
|
+
base64.length + (4 - base64.length % 4) % 4,
|
|
28
|
+
"="
|
|
29
|
+
);
|
|
30
|
+
const decoded = JSON.parse(decodeBase64(padded));
|
|
31
|
+
return decoded;
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function getBusinessIdFromToken(token) {
|
|
37
|
+
const payload = decodeJwtPayload(token);
|
|
38
|
+
return payload?.business_id;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.decodeJwtPayload = decodeJwtPayload;
|
|
42
|
+
exports.getBusinessIdFromToken = getBusinessIdFromToken;
|
|
43
|
+
//# sourceMappingURL=decode-jwt.cjs.map
|
|
44
|
+
//# sourceMappingURL=decode-jwt.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/utils/decode-jwt.ts"],"names":[],"mappings":";;;AAOA,IAAM,YAAA,GAAe,CAAC,MAAA,KAA2B;AAC/C,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GACJ,OAAO,IAAA,KAAS,UAAA,GAAa,IAAA,GAAO,KAAA,CAAA;AACtC,IAAA,IAAI,OAAO,WAAW,UAAA,EAAY;AAChC,MAAA,OAAO,OAAO,MAAM,CAAA;AAAA,IACtB;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,IAAI;AACF,IAAA,MAAM,UAAA,GACJ,OAAO,MAAA,KAAW,WAAA,GAAc,MAAA,GAAS,KAAA,CAAA;AAC3C,IAAA,IAAI,UAAA,IAAc,OAAO,UAAA,CAAW,IAAA,KAAS,UAAA,EAAY;AACvD,MAAA,OAAO,WAAW,IAAA,CAAK,MAAA,EAAQ,QAAQ,CAAA,CAAE,SAAS,OAAO,CAAA;AAAA,IAC3D;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,MAAM,IAAI,MAAM,mDAAmD,CAAA;AACrE,CAAA;AAEO,SAAS,iBAAiB,KAAA,EAAkC;AACjE,EAAA,IAAI;AACF,IAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,KAAA,CAAM,GAAG,CAAA;AAC7B,IAAA,IAAI,KAAA,CAAM,MAAA,KAAW,CAAA,EAAG,OAAO,IAAA;AAE/B,IAAA,MAAM,MAAA,GAAS,KAAA,CAAM,CAAC,CAAA,CAAE,OAAA,CAAQ,MAAM,GAAG,CAAA,CAAE,OAAA,CAAQ,IAAA,EAAM,GAAG,CAAA;AAC5D,IAAA,MAAM,SAAS,MAAA,CAAO,MAAA;AAAA,MACpB,MAAA,CAAO,MAAA,GAAA,CAAW,CAAA,GAAK,MAAA,CAAO,SAAS,CAAA,IAAM,CAAA;AAAA,MAC7C;AAAA,KACF;AACA,IAAA,MAAM,OAAA,GAAU,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,MAAM,CAAC,CAAA;AAE/C,IAAA,OAAO,OAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAEO,SAAS,uBAAuB,KAAA,EAAmC;AACxE,EAAA,MAAM,OAAA,GAAU,iBAAiB,KAAK,CAAA;AACtC,EAAA,OAAO,OAAA,EAAS,WAAA;AAClB","file":"decode-jwt.cjs","sourcesContent":["export interface JwtPayload {\n sub?: string;\n business_id?: number;\n role?: string;\n [key: string]: unknown;\n}\n\nconst decodeBase64 = (base64: string): string => {\n try {\n const atobFn: ((value: string) => string) | undefined =\n typeof atob === \"function\" ? atob : undefined;\n if (typeof atobFn === \"function\") {\n return atobFn(base64);\n }\n } catch {\n // no-op fallback to Buffer branch\n }\n\n try {\n const bufferCtor: typeof Buffer | undefined =\n typeof Buffer !== \"undefined\" ? Buffer : undefined;\n if (bufferCtor && typeof bufferCtor.from === \"function\") {\n return bufferCtor.from(base64, \"base64\").toString(\"utf-8\");\n }\n } catch {\n // no-op\n }\n\n throw new Error(\"Base64 decoding not supported in this environment\");\n};\n\nexport function decodeJwtPayload(token: string): JwtPayload | null {\n try {\n const parts = token.split(\".\");\n if (parts.length !== 3) return null;\n\n const base64 = parts[1].replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padded = base64.padEnd(\n base64.length + ((4 - (base64.length % 4)) % 4),\n \"=\",\n );\n const decoded = JSON.parse(decodeBase64(padded)) as JwtPayload;\n\n return decoded;\n } catch {\n return null;\n }\n}\n\nexport function getBusinessIdFromToken(token: string): number | undefined {\n const payload = decodeJwtPayload(token);\n return payload?.business_id;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface JwtPayload {
|
|
2
|
+
sub?: string;
|
|
3
|
+
business_id?: number;
|
|
4
|
+
role?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
declare function decodeJwtPayload(token: string): JwtPayload | null;
|
|
8
|
+
declare function getBusinessIdFromToken(token: string): number | undefined;
|
|
9
|
+
|
|
10
|
+
export { type JwtPayload, decodeJwtPayload, getBusinessIdFromToken };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface JwtPayload {
|
|
2
|
+
sub?: string;
|
|
3
|
+
business_id?: number;
|
|
4
|
+
role?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
declare function decodeJwtPayload(token: string): JwtPayload | null;
|
|
8
|
+
declare function getBusinessIdFromToken(token: string): number | undefined;
|
|
9
|
+
|
|
10
|
+
export { type JwtPayload, decodeJwtPayload, getBusinessIdFromToken };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/core/utils/decode-jwt.ts
|
|
2
|
+
var decodeBase64 = (base64) => {
|
|
3
|
+
try {
|
|
4
|
+
const atobFn = typeof atob === "function" ? atob : void 0;
|
|
5
|
+
if (typeof atobFn === "function") {
|
|
6
|
+
return atobFn(base64);
|
|
7
|
+
}
|
|
8
|
+
} catch {
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const bufferCtor = typeof Buffer !== "undefined" ? Buffer : void 0;
|
|
12
|
+
if (bufferCtor && typeof bufferCtor.from === "function") {
|
|
13
|
+
return bufferCtor.from(base64, "base64").toString("utf-8");
|
|
14
|
+
}
|
|
15
|
+
} catch {
|
|
16
|
+
}
|
|
17
|
+
throw new Error("Base64 decoding not supported in this environment");
|
|
18
|
+
};
|
|
19
|
+
function decodeJwtPayload(token) {
|
|
20
|
+
try {
|
|
21
|
+
const parts = token.split(".");
|
|
22
|
+
if (parts.length !== 3) return null;
|
|
23
|
+
const base64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
24
|
+
const padded = base64.padEnd(
|
|
25
|
+
base64.length + (4 - base64.length % 4) % 4,
|
|
26
|
+
"="
|
|
27
|
+
);
|
|
28
|
+
const decoded = JSON.parse(decodeBase64(padded));
|
|
29
|
+
return decoded;
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function getBusinessIdFromToken(token) {
|
|
35
|
+
const payload = decodeJwtPayload(token);
|
|
36
|
+
return payload?.business_id;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { decodeJwtPayload, getBusinessIdFromToken };
|
|
40
|
+
//# sourceMappingURL=decode-jwt.js.map
|
|
41
|
+
//# sourceMappingURL=decode-jwt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/utils/decode-jwt.ts"],"names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A,OAAO,OAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAEO,SAAS,uBAAuB,KAAA,EAAmC;AACxE,EAAA,MAAM,OAAA,GAAU,iBAAiB,KAAK,CAAA;AACtC,EAAA,OAAO,OAAA,EAAS,WAAA;AAClB","file":"decode-jwt.js","sourcesContent":["export interface JwtPayload {\n sub?: string;\n business_id?: number;\n role?: string;\n [key: string]: unknown;\n}\n\nconst decodeBase64 = (base64: string): string => {\n try {\n const atobFn: ((value: string) => string) | undefined =\n typeof atob === \"function\" ? atob : undefined;\n if (typeof atobFn === \"function\") {\n return atobFn(base64);\n }\n } catch {\n // no-op fallback to Buffer branch\n }\n\n try {\n const bufferCtor: typeof Buffer | undefined =\n typeof Buffer !== \"undefined\" ? Buffer : undefined;\n if (bufferCtor && typeof bufferCtor.from === \"function\") {\n return bufferCtor.from(base64, \"base64\").toString(\"utf-8\");\n }\n } catch {\n // no-op\n }\n\n throw new Error(\"Base64 decoding not supported in this environment\");\n};\n\nexport function decodeJwtPayload(token: string): JwtPayload | null {\n try {\n const parts = token.split(\".\");\n if (parts.length !== 3) return null;\n\n const base64 = parts[1].replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padded = base64.padEnd(\n base64.length + ((4 - (base64.length % 4)) % 4),\n \"=\",\n );\n const decoded = JSON.parse(decodeBase64(padded)) as JwtPayload;\n\n return decoded;\n } catch {\n return null;\n }\n}\n\nexport function getBusinessIdFromToken(token: string): number | undefined {\n const payload = decodeJwtPayload(token);\n return payload?.business_id;\n}\n"]}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/core/utils/error-response.ts
|
|
4
|
+
var hasProperty = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
5
|
+
var asObject = (value) => {
|
|
6
|
+
if (!value || typeof value !== "object") {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
var readFirstArrayMessage = (value) => {
|
|
12
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
const first = asObject(value[0]);
|
|
16
|
+
if (!first || typeof first.message !== "string") {
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
19
|
+
return first.message;
|
|
20
|
+
};
|
|
21
|
+
var parseApiError = (error) => {
|
|
22
|
+
const parsed = {
|
|
23
|
+
code: "",
|
|
24
|
+
statusCode: "",
|
|
25
|
+
message: "",
|
|
26
|
+
type: ""
|
|
27
|
+
};
|
|
28
|
+
const errorObject = asObject(error);
|
|
29
|
+
if (!errorObject) {
|
|
30
|
+
return parsed;
|
|
31
|
+
}
|
|
32
|
+
if (hasProperty(errorObject, "response")) {
|
|
33
|
+
const response = asObject(errorObject.response);
|
|
34
|
+
if (response) {
|
|
35
|
+
if (hasProperty(response, "status") && response.status != null) {
|
|
36
|
+
parsed.statusCode = String(response.status);
|
|
37
|
+
}
|
|
38
|
+
if (hasProperty(response, "data")) {
|
|
39
|
+
const data = asObject(response.data);
|
|
40
|
+
const dataCode = data && typeof data.code === "string" ? data.code : "";
|
|
41
|
+
const dataMessage = data && typeof data.message === "string" ? data.message : "";
|
|
42
|
+
const dataError = data ? asObject(data.error) : null;
|
|
43
|
+
if (dataCode) {
|
|
44
|
+
parsed.code = dataCode;
|
|
45
|
+
}
|
|
46
|
+
if (dataMessage) {
|
|
47
|
+
parsed.message = dataMessage;
|
|
48
|
+
}
|
|
49
|
+
if (!parsed.code && data && typeof data.error === "string") {
|
|
50
|
+
parsed.code = data.error;
|
|
51
|
+
}
|
|
52
|
+
if (!parsed.message && dataError && typeof dataError.message === "string") {
|
|
53
|
+
parsed.message = dataError.message;
|
|
54
|
+
}
|
|
55
|
+
if (!parsed.code && dataError && typeof dataError.code === "string") {
|
|
56
|
+
parsed.code = dataError.code;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const responseErrorsMessage = hasProperty(response, "errors") ? readFirstArrayMessage(response.errors) : "";
|
|
60
|
+
if (responseErrorsMessage) {
|
|
61
|
+
parsed.message = responseErrorsMessage;
|
|
62
|
+
}
|
|
63
|
+
parsed.type = "response";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (typeof errorObject.message === "string" && !parsed.message) {
|
|
67
|
+
if (errorObject.message.includes("response")) {
|
|
68
|
+
const result = errorObject.message.match(/([^:]+)/);
|
|
69
|
+
parsed.message = result ? result[0].trim() : "";
|
|
70
|
+
} else {
|
|
71
|
+
parsed.message = errorObject.message;
|
|
72
|
+
}
|
|
73
|
+
if (!parsed.type) {
|
|
74
|
+
parsed.type = "message";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (hasProperty(errorObject, "graphQLErrors")) {
|
|
78
|
+
const graphQLErrors = errorObject.graphQLErrors;
|
|
79
|
+
if (Array.isArray(graphQLErrors) && graphQLErrors.length > 0) {
|
|
80
|
+
const graphQLError = asObject(graphQLErrors[0]);
|
|
81
|
+
if (graphQLError) {
|
|
82
|
+
if (typeof graphQLError.message === "string") {
|
|
83
|
+
parsed.message = graphQLError.message;
|
|
84
|
+
}
|
|
85
|
+
const extensions = asObject(graphQLError.extensions);
|
|
86
|
+
const response = extensions ? asObject(extensions.response) : null;
|
|
87
|
+
if (response) {
|
|
88
|
+
if (response.statusCode != null) {
|
|
89
|
+
parsed.statusCode = String(response.statusCode);
|
|
90
|
+
}
|
|
91
|
+
if (typeof response.message === "string") {
|
|
92
|
+
parsed.message = response.message;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
parsed.type = "graphQLErrors";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (hasProperty(errorObject, "networkError")) {
|
|
100
|
+
const networkError = asObject(errorObject.networkError);
|
|
101
|
+
if (networkError) {
|
|
102
|
+
if (networkError.statusCode != null) {
|
|
103
|
+
parsed.statusCode = String(networkError.statusCode);
|
|
104
|
+
}
|
|
105
|
+
const result = asObject(networkError.result);
|
|
106
|
+
const networkErrorsMessage = result ? readFirstArrayMessage(result.errors) : "";
|
|
107
|
+
if (networkErrorsMessage) {
|
|
108
|
+
parsed.message = networkErrorsMessage;
|
|
109
|
+
} else if (networkError.statusCode != null) {
|
|
110
|
+
parsed.message = "common.serverError";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
parsed.type = "networkError";
|
|
114
|
+
}
|
|
115
|
+
return parsed;
|
|
116
|
+
};
|
|
117
|
+
var translateKey = (translate, key) => {
|
|
118
|
+
const trimmedKey = key.trim();
|
|
119
|
+
if (!trimmedKey) {
|
|
120
|
+
return "";
|
|
121
|
+
}
|
|
122
|
+
return translate(trimmedKey, "");
|
|
123
|
+
};
|
|
124
|
+
var resolveApiErrorMessage = (error, translate) => {
|
|
125
|
+
const parsed = parseApiError(error);
|
|
126
|
+
const translatedCode = translateKey(translate, parsed.code);
|
|
127
|
+
const translatedMessageKey = translateKey(translate, parsed.message);
|
|
128
|
+
return translatedCode || translatedMessageKey || parsed.message || (error instanceof Error ? error.message : String(error));
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
exports.parseApiError = parseApiError;
|
|
132
|
+
exports.resolveApiErrorMessage = resolveApiErrorMessage;
|
|
133
|
+
//# sourceMappingURL=error-response.cjs.map
|
|
134
|
+
//# sourceMappingURL=error-response.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/utils/error-response.ts"],"names":[],"mappings":";;;AASA,IAAM,WAAA,GAAc,CAClB,KAAA,EACA,GAAA,KAEA,OAAO,SAAA,CAAU,cAAA,CAAe,IAAA,CAAK,KAAA,EAAO,GAAG,CAAA;AAEjD,IAAM,QAAA,GAAW,CAAC,KAAA,KAAmD;AACnE,EAAA,IAAI,CAAC,KAAA,IAAS,OAAO,KAAA,KAAU,QAAA,EAAU;AACvC,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,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S,cAAc,KAAK,CAAA;AAClC,EAAA,MAAM,cAAA,GAAiB,YAAA,CAAa,SAAA,EAAW,MAAA,CAAO,IAAI,CAAA;AAC1D,EAAA,MAAM,oBAAA,GAAuB,YAAA,CAAa,SAAA,EAAW,MAAA,CAAO,OAAO,CAAA;AAEnE,EAAA,OACE,cAAA,IACA,wBACA,MAAA,CAAO,OAAA,KACN,iBAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,MAAA,CAAO,KAAK,CAAA,CAAA;AAE1D","file":"error-response.cjs","sourcesContent":["export interface ParsedApiError {\n code: string;\n statusCode: string;\n message: string;\n type: string;\n}\n\ntype TranslateFn = (key: string, defaultValue?: string) => string;\n\nconst hasProperty = <K extends string>(\n value: object,\n key: K,\n): value is Record<K, unknown> =>\n Object.prototype.hasOwnProperty.call(value, key);\n\nconst asObject = (value: unknown): Record<string, unknown> | null => {\n if (!value || typeof value !== \"object\") {\n return null;\n }\n\n return value as Record<string, unknown>;\n};\n\nconst readFirstArrayMessage = (value: unknown): string => {\n if (!Array.isArray(value) || value.length === 0) {\n return \"\";\n }\n\n const first = asObject(value[0]);\n if (!first || typeof first.message !== \"string\") {\n return \"\";\n }\n\n return first.message;\n};\n\nexport const parseApiError = (error: unknown): ParsedApiError => {\n const parsed: ParsedApiError = {\n code: \"\",\n statusCode: \"\",\n message: \"\",\n type: \"\",\n };\n\n const errorObject = asObject(error);\n if (!errorObject) {\n return parsed;\n }\n\n if (hasProperty(errorObject, \"response\")) {\n const response = asObject(errorObject.response);\n if (response) {\n if (hasProperty(response, \"status\") && response.status != null) {\n parsed.statusCode = String(response.status);\n }\n\n if (hasProperty(response, \"data\")) {\n const data = asObject(response.data);\n const dataCode = data && typeof data.code === \"string\" ? data.code : \"\";\n const dataMessage =\n data && typeof data.message === \"string\" ? data.message : \"\";\n const dataError = data ? asObject(data.error) : null;\n\n if (dataCode) {\n parsed.code = dataCode;\n }\n\n if (dataMessage) {\n parsed.message = dataMessage;\n }\n\n if (!parsed.code && data && typeof data.error === \"string\") {\n // Backward compatibility: older APIs return error as the code field.\n parsed.code = data.error;\n }\n\n if (\n !parsed.message &&\n dataError &&\n typeof dataError.message === \"string\"\n ) {\n parsed.message = dataError.message;\n }\n\n if (!parsed.code && dataError && typeof dataError.code === \"string\") {\n parsed.code = dataError.code;\n }\n }\n\n const responseErrorsMessage = hasProperty(response, \"errors\")\n ? readFirstArrayMessage(response.errors)\n : \"\";\n if (responseErrorsMessage) {\n parsed.message = responseErrorsMessage;\n }\n\n parsed.type = \"response\";\n }\n }\n\n if (typeof errorObject.message === \"string\" && !parsed.message) {\n if (errorObject.message.includes(\"response\")) {\n const result = errorObject.message.match(/([^:]+)/);\n parsed.message = result ? result[0].trim() : \"\";\n } else {\n parsed.message = errorObject.message;\n }\n\n if (!parsed.type) {\n parsed.type = \"message\";\n }\n }\n\n if (hasProperty(errorObject, \"graphQLErrors\")) {\n const graphQLErrors = errorObject.graphQLErrors;\n if (Array.isArray(graphQLErrors) && graphQLErrors.length > 0) {\n const graphQLError = asObject(graphQLErrors[0]);\n if (graphQLError) {\n if (typeof graphQLError.message === \"string\") {\n parsed.message = graphQLError.message;\n }\n\n const extensions = asObject(graphQLError.extensions);\n const response = extensions ? asObject(extensions.response) : null;\n\n if (response) {\n if (response.statusCode != null) {\n parsed.statusCode = String(response.statusCode);\n }\n if (typeof response.message === \"string\") {\n parsed.message = response.message;\n }\n }\n }\n\n parsed.type = \"graphQLErrors\";\n }\n }\n\n if (hasProperty(errorObject, \"networkError\")) {\n const networkError = asObject(errorObject.networkError);\n if (networkError) {\n if (networkError.statusCode != null) {\n parsed.statusCode = String(networkError.statusCode);\n }\n\n const result = asObject(networkError.result);\n const networkErrorsMessage = result\n ? readFirstArrayMessage(result.errors)\n : \"\";\n\n if (networkErrorsMessage) {\n parsed.message = networkErrorsMessage;\n } else if (networkError.statusCode != null) {\n parsed.message = \"common.serverError\";\n }\n }\n\n parsed.type = \"networkError\";\n }\n\n return parsed;\n};\n\nconst translateKey = (translate: TranslateFn, key: string): string => {\n const trimmedKey = key.trim();\n if (!trimmedKey) {\n return \"\";\n }\n\n return translate(trimmedKey, \"\");\n};\n\nexport const resolveApiErrorMessage = (\n error: unknown,\n translate: TranslateFn,\n): string => {\n const parsed = parseApiError(error);\n const translatedCode = translateKey(translate, parsed.code);\n const translatedMessageKey = translateKey(translate, parsed.message);\n\n return (\n translatedCode ||\n translatedMessageKey ||\n parsed.message ||\n (error instanceof Error ? error.message : String(error))\n );\n};\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface ParsedApiError {
|
|
2
|
+
code: string;
|
|
3
|
+
statusCode: string;
|
|
4
|
+
message: string;
|
|
5
|
+
type: string;
|
|
6
|
+
}
|
|
7
|
+
type TranslateFn = (key: string, defaultValue?: string) => string;
|
|
8
|
+
declare const parseApiError: (error: unknown) => ParsedApiError;
|
|
9
|
+
declare const resolveApiErrorMessage: (error: unknown, translate: TranslateFn) => string;
|
|
10
|
+
|
|
11
|
+
export { type ParsedApiError, parseApiError, resolveApiErrorMessage };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface ParsedApiError {
|
|
2
|
+
code: string;
|
|
3
|
+
statusCode: string;
|
|
4
|
+
message: string;
|
|
5
|
+
type: string;
|
|
6
|
+
}
|
|
7
|
+
type TranslateFn = (key: string, defaultValue?: string) => string;
|
|
8
|
+
declare const parseApiError: (error: unknown) => ParsedApiError;
|
|
9
|
+
declare const resolveApiErrorMessage: (error: unknown, translate: TranslateFn) => string;
|
|
10
|
+
|
|
11
|
+
export { type ParsedApiError, parseApiError, resolveApiErrorMessage };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// src/core/utils/error-response.ts
|
|
2
|
+
var hasProperty = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
3
|
+
var asObject = (value) => {
|
|
4
|
+
if (!value || typeof value !== "object") {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
return value;
|
|
8
|
+
};
|
|
9
|
+
var readFirstArrayMessage = (value) => {
|
|
10
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
const first = asObject(value[0]);
|
|
14
|
+
if (!first || typeof first.message !== "string") {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
return first.message;
|
|
18
|
+
};
|
|
19
|
+
var parseApiError = (error) => {
|
|
20
|
+
const parsed = {
|
|
21
|
+
code: "",
|
|
22
|
+
statusCode: "",
|
|
23
|
+
message: "",
|
|
24
|
+
type: ""
|
|
25
|
+
};
|
|
26
|
+
const errorObject = asObject(error);
|
|
27
|
+
if (!errorObject) {
|
|
28
|
+
return parsed;
|
|
29
|
+
}
|
|
30
|
+
if (hasProperty(errorObject, "response")) {
|
|
31
|
+
const response = asObject(errorObject.response);
|
|
32
|
+
if (response) {
|
|
33
|
+
if (hasProperty(response, "status") && response.status != null) {
|
|
34
|
+
parsed.statusCode = String(response.status);
|
|
35
|
+
}
|
|
36
|
+
if (hasProperty(response, "data")) {
|
|
37
|
+
const data = asObject(response.data);
|
|
38
|
+
const dataCode = data && typeof data.code === "string" ? data.code : "";
|
|
39
|
+
const dataMessage = data && typeof data.message === "string" ? data.message : "";
|
|
40
|
+
const dataError = data ? asObject(data.error) : null;
|
|
41
|
+
if (dataCode) {
|
|
42
|
+
parsed.code = dataCode;
|
|
43
|
+
}
|
|
44
|
+
if (dataMessage) {
|
|
45
|
+
parsed.message = dataMessage;
|
|
46
|
+
}
|
|
47
|
+
if (!parsed.code && data && typeof data.error === "string") {
|
|
48
|
+
parsed.code = data.error;
|
|
49
|
+
}
|
|
50
|
+
if (!parsed.message && dataError && typeof dataError.message === "string") {
|
|
51
|
+
parsed.message = dataError.message;
|
|
52
|
+
}
|
|
53
|
+
if (!parsed.code && dataError && typeof dataError.code === "string") {
|
|
54
|
+
parsed.code = dataError.code;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const responseErrorsMessage = hasProperty(response, "errors") ? readFirstArrayMessage(response.errors) : "";
|
|
58
|
+
if (responseErrorsMessage) {
|
|
59
|
+
parsed.message = responseErrorsMessage;
|
|
60
|
+
}
|
|
61
|
+
parsed.type = "response";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (typeof errorObject.message === "string" && !parsed.message) {
|
|
65
|
+
if (errorObject.message.includes("response")) {
|
|
66
|
+
const result = errorObject.message.match(/([^:]+)/);
|
|
67
|
+
parsed.message = result ? result[0].trim() : "";
|
|
68
|
+
} else {
|
|
69
|
+
parsed.message = errorObject.message;
|
|
70
|
+
}
|
|
71
|
+
if (!parsed.type) {
|
|
72
|
+
parsed.type = "message";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (hasProperty(errorObject, "graphQLErrors")) {
|
|
76
|
+
const graphQLErrors = errorObject.graphQLErrors;
|
|
77
|
+
if (Array.isArray(graphQLErrors) && graphQLErrors.length > 0) {
|
|
78
|
+
const graphQLError = asObject(graphQLErrors[0]);
|
|
79
|
+
if (graphQLError) {
|
|
80
|
+
if (typeof graphQLError.message === "string") {
|
|
81
|
+
parsed.message = graphQLError.message;
|
|
82
|
+
}
|
|
83
|
+
const extensions = asObject(graphQLError.extensions);
|
|
84
|
+
const response = extensions ? asObject(extensions.response) : null;
|
|
85
|
+
if (response) {
|
|
86
|
+
if (response.statusCode != null) {
|
|
87
|
+
parsed.statusCode = String(response.statusCode);
|
|
88
|
+
}
|
|
89
|
+
if (typeof response.message === "string") {
|
|
90
|
+
parsed.message = response.message;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
parsed.type = "graphQLErrors";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (hasProperty(errorObject, "networkError")) {
|
|
98
|
+
const networkError = asObject(errorObject.networkError);
|
|
99
|
+
if (networkError) {
|
|
100
|
+
if (networkError.statusCode != null) {
|
|
101
|
+
parsed.statusCode = String(networkError.statusCode);
|
|
102
|
+
}
|
|
103
|
+
const result = asObject(networkError.result);
|
|
104
|
+
const networkErrorsMessage = result ? readFirstArrayMessage(result.errors) : "";
|
|
105
|
+
if (networkErrorsMessage) {
|
|
106
|
+
parsed.message = networkErrorsMessage;
|
|
107
|
+
} else if (networkError.statusCode != null) {
|
|
108
|
+
parsed.message = "common.serverError";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
parsed.type = "networkError";
|
|
112
|
+
}
|
|
113
|
+
return parsed;
|
|
114
|
+
};
|
|
115
|
+
var translateKey = (translate, key) => {
|
|
116
|
+
const trimmedKey = key.trim();
|
|
117
|
+
if (!trimmedKey) {
|
|
118
|
+
return "";
|
|
119
|
+
}
|
|
120
|
+
return translate(trimmedKey, "");
|
|
121
|
+
};
|
|
122
|
+
var resolveApiErrorMessage = (error, translate) => {
|
|
123
|
+
const parsed = parseApiError(error);
|
|
124
|
+
const translatedCode = translateKey(translate, parsed.code);
|
|
125
|
+
const translatedMessageKey = translateKey(translate, parsed.message);
|
|
126
|
+
return translatedCode || translatedMessageKey || parsed.message || (error instanceof Error ? error.message : String(error));
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export { parseApiError, resolveApiErrorMessage };
|
|
130
|
+
//# sourceMappingURL=error-response.js.map
|
|
131
|
+
//# sourceMappingURL=error-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/utils/error-response.ts"],"names":[],"mappings":";AASA,IAAM,WAAA,GAAc,CAClB,KAAA,EACA,GAAA,KAEA,OAAO,SAAA,CAAU,cAAA,CAAe,IAAA,CAAK,KAAA,EAAO,GAAG,CAAA;AAEjD,IAAM,QAAA,GAAW,CAAC,KAAA,KAAmD;AACnE,EAAA,IAAI,CAAC,KAAA,IAAS,OAAO,KAAA,KAAU,QAAA,EAAU;AACvC,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,OAAO,KAAA;AACT,CAAA;AAEA,IAAM,qBAAA,GAAwB,CAAC,KAA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AAa,SAAA,EAAW,MAAA,CAAO,IAAI,CAAA;AAC1D,EAAA,MAAM,oBAAA,GAAuB,YAAA,CAAa,SAAA,EAAW,MAAA,CAAO,OAAO,CAAA;AAEnE,EAAA,OACE,cAAA,IACA,wBACA,MAAA,CAAO,OAAA,KACN,iBAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,MAAA,CAAO,KAAK,CAAA,CAAA;AAE1D","file":"error-response.js","sourcesContent":["export interface ParsedApiError {\n code: string;\n statusCode: string;\n message: string;\n type: string;\n}\n\ntype TranslateFn = (key: string, defaultValue?: string) => string;\n\nconst hasProperty = <K extends string>(\n value: object,\n key: K,\n): value is Record<K, unknown> =>\n Object.prototype.hasOwnProperty.call(value, key);\n\nconst asObject = (value: unknown): Record<string, unknown> | null => {\n if (!value || typeof value !== \"object\") {\n return null;\n }\n\n return value as Record<string, unknown>;\n};\n\nconst readFirstArrayMessage = (value: unknown): string => {\n if (!Array.isArray(value) || value.length === 0) {\n return \"\";\n }\n\n const first = asObject(value[0]);\n if (!first || typeof first.message !== \"string\") {\n return \"\";\n }\n\n return first.message;\n};\n\nexport const parseApiError = (error: unknown): ParsedApiError => {\n const parsed: ParsedApiError = {\n code: \"\",\n statusCode: \"\",\n message: \"\",\n type: \"\",\n };\n\n const errorObject = asObject(error);\n if (!errorObject) {\n return parsed;\n }\n\n if (hasProperty(errorObject, \"response\")) {\n const response = asObject(errorObject.response);\n if (response) {\n if (hasProperty(response, \"status\") && response.status != null) {\n parsed.statusCode = String(response.status);\n }\n\n if (hasProperty(response, \"data\")) {\n const data = asObject(response.data);\n const dataCode = data && typeof data.code === \"string\" ? data.code : \"\";\n const dataMessage =\n data && typeof data.message === \"string\" ? data.message : \"\";\n const dataError = data ? asObject(data.error) : null;\n\n if (dataCode) {\n parsed.code = dataCode;\n }\n\n if (dataMessage) {\n parsed.message = dataMessage;\n }\n\n if (!parsed.code && data && typeof data.error === \"string\") {\n // Backward compatibility: older APIs return error as the code field.\n parsed.code = data.error;\n }\n\n if (\n !parsed.message &&\n dataError &&\n typeof dataError.message === \"string\"\n ) {\n parsed.message = dataError.message;\n }\n\n if (!parsed.code && dataError && typeof dataError.code === \"string\") {\n parsed.code = dataError.code;\n }\n }\n\n const responseErrorsMessage = hasProperty(response, \"errors\")\n ? readFirstArrayMessage(response.errors)\n : \"\";\n if (responseErrorsMessage) {\n parsed.message = responseErrorsMessage;\n }\n\n parsed.type = \"response\";\n }\n }\n\n if (typeof errorObject.message === \"string\" && !parsed.message) {\n if (errorObject.message.includes(\"response\")) {\n const result = errorObject.message.match(/([^:]+)/);\n parsed.message = result ? result[0].trim() : \"\";\n } else {\n parsed.message = errorObject.message;\n }\n\n if (!parsed.type) {\n parsed.type = \"message\";\n }\n }\n\n if (hasProperty(errorObject, \"graphQLErrors\")) {\n const graphQLErrors = errorObject.graphQLErrors;\n if (Array.isArray(graphQLErrors) && graphQLErrors.length > 0) {\n const graphQLError = asObject(graphQLErrors[0]);\n if (graphQLError) {\n if (typeof graphQLError.message === \"string\") {\n parsed.message = graphQLError.message;\n }\n\n const extensions = asObject(graphQLError.extensions);\n const response = extensions ? asObject(extensions.response) : null;\n\n if (response) {\n if (response.statusCode != null) {\n parsed.statusCode = String(response.statusCode);\n }\n if (typeof response.message === \"string\") {\n parsed.message = response.message;\n }\n }\n }\n\n parsed.type = \"graphQLErrors\";\n }\n }\n\n if (hasProperty(errorObject, \"networkError\")) {\n const networkError = asObject(errorObject.networkError);\n if (networkError) {\n if (networkError.statusCode != null) {\n parsed.statusCode = String(networkError.statusCode);\n }\n\n const result = asObject(networkError.result);\n const networkErrorsMessage = result\n ? readFirstArrayMessage(result.errors)\n : \"\";\n\n if (networkErrorsMessage) {\n parsed.message = networkErrorsMessage;\n } else if (networkError.statusCode != null) {\n parsed.message = \"common.serverError\";\n }\n }\n\n parsed.type = \"networkError\";\n }\n\n return parsed;\n};\n\nconst translateKey = (translate: TranslateFn, key: string): string => {\n const trimmedKey = key.trim();\n if (!trimmedKey) {\n return \"\";\n }\n\n return translate(trimmedKey, \"\");\n};\n\nexport const resolveApiErrorMessage = (\n error: unknown,\n translate: TranslateFn,\n): string => {\n const parsed = parseApiError(error);\n const translatedCode = translateKey(translate, parsed.code);\n const translatedMessageKey = translateKey(translate, parsed.message);\n\n return (\n translatedCode ||\n translatedMessageKey ||\n parsed.message ||\n (error instanceof Error ? error.message : String(error))\n );\n};\n"]}
|