@vindhq/sloud-payment-sdk 1.0.4 → 1.0.5
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/index.cjs.js +51295 -24
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +3 -268
- package/dist/index.esm.js +51293 -24
- package/dist/index.esm.js.map +1 -0
- package/dist/index.umd.js +83 -3021
- package/dist/index.umd.js.map +1 -0
- package/dist/react/index.esm.js +51440 -0
- package/dist/react/index.esm.js.map +1 -0
- package/dist/react/rollup.config.d.ts +8 -0
- package/dist/react/rollup.config.dts.d.ts +3 -0
- package/dist/react/src/components/Button/Button.types.d.ts +6 -0
- package/dist/react/src/components/Button/index.d.ts +3 -0
- package/dist/react/src/components/CopyToClipboardSpan/CopyToClipboard.types.d.ts +4 -0
- package/dist/react/src/components/CopyToClipboardSpan/index.d.ts +3 -0
- package/dist/react/src/components/Input/Input.types.d.ts +17 -0
- package/dist/react/src/components/Input/index.d.ts +3 -0
- package/dist/react/src/components/Skeleton/PaymentOptionSkeletons.d.ts +6 -0
- package/dist/react/src/components/TextArea/TextArea.types.d.ts +19 -0
- package/dist/react/src/components/TextArea/index.d.ts +3 -0
- package/dist/react/src/components/Widget.d.ts +6 -0
- package/dist/react/src/components/modals/AwaitingPaymentModal/AwaitingPaymentModal.d.ts +2 -0
- package/dist/react/src/components/modals/AwaitingPaymentTimeoutModal/AwaitingPaymentTimeoutModal.d.ts +2 -0
- package/dist/react/src/components/modals/Modal.d.ts +10 -0
- package/dist/react/src/components/modals/PaymentDetailsModal/PaymentDetailsModal.d.ts +2 -0
- package/dist/react/src/components/modals/PaymentDetailsModal/hooks/useTimer.d.ts +7 -0
- package/dist/react/src/components/modals/PaymentOptionsModal/PaymentOptionsModal.d.ts +2 -0
- package/dist/react/src/components/modals/PaymentOptionsModal/RadioButton.d.ts +11 -0
- package/dist/react/src/components/modals/PaymentOptionsModal/paymentOptionsMap.d.ts +5 -0
- package/dist/react/src/components/modals/SuccessModal/SuccessModal.d.ts +2 -0
- package/dist/react/src/components/modals/state/actions/data.d.ts +10 -0
- package/dist/react/src/components/modals/state/actions/index.d.ts +5 -0
- package/dist/react/src/components/modals/state/actions/modal.d.ts +5 -0
- package/dist/react/src/components/modals/state/actions/payment.d.ts +7 -0
- package/dist/react/src/components/modals/state/constants/actionTypes.d.ts +24 -0
- package/dist/react/src/components/modals/state/constants/index.d.ts +2 -0
- package/dist/react/src/components/modals/state/constants/initialState.d.ts +36 -0
- package/dist/react/src/components/modals/state/reducers/data.d.ts +2 -0
- package/dist/react/src/components/modals/state/reducers/index.d.ts +2 -0
- package/dist/react/src/components/modals/state/reducers/modal.d.ts +2 -0
- package/dist/react/src/components/modals/state/reducers/payment.d.ts +2 -0
- package/dist/react/src/components/modals/state/types/common.d.ts +12 -0
- package/dist/react/src/components/modals/state/types/data.d.ts +34 -0
- package/dist/react/src/components/modals/state/types/index.d.ts +8 -0
- package/dist/react/src/components/modals/state/types/modal.d.ts +12 -0
- package/dist/react/src/components/modals/state/types/payment.d.ts +14 -0
- package/dist/react/src/components/modals/state/utils/index.d.ts +37 -0
- package/dist/react/src/context/ModalProvider.d.ts +4 -0
- package/dist/react/src/context/PaymentInfoContext.d.ts +26 -0
- package/dist/react/src/context/PaymentWidgetContext.d.ts +13 -0
- package/dist/react/src/context/modal.d.ts +4 -0
- package/dist/react/src/context/types.d.ts +28 -0
- package/dist/react/src/hooks/types.d.ts +34 -0
- package/dist/react/src/hooks/useModalControl.d.ts +27 -0
- package/dist/react/src/hooks/usePaymentAPI.d.ts +10 -0
- package/dist/react/src/hooks/useShortPolling.d.ts +4 -0
- package/dist/react/src/index.d.ts +2 -0
- package/dist/react/src/services/config/endpoints.d.ts +9 -0
- package/dist/react/src/services/config/error.d.ts +5 -0
- package/dist/react/src/services/index.d.ts +27 -0
- package/dist/react/src/services/payments/index.d.ts +4 -0
- package/dist/react/src/services/payments/types.d.ts +68 -0
- package/dist/react/src/services/products/index.d.ts +1 -0
- package/dist/react/src/services/products/types.d.ts +124 -0
- package/dist/react/src/services/store/index.d.ts +2 -0
- package/dist/react/src/services/store/types.d.ts +57 -0
- package/dist/react/src/services/utils/widgetConfig.d.ts +20 -0
- package/dist/react/src/svg_components/ArrowLeftIcon.d.ts +3 -0
- package/dist/react/src/svg_components/BankTransferIcon.d.ts +2 -0
- package/dist/react/src/svg_components/CancelIcon.d.ts +7 -0
- package/dist/react/src/svg_components/CardIcon.d.ts +2 -0
- package/dist/react/src/svg_components/CloseIcon.d.ts +3 -0
- package/dist/react/src/svg_components/CopyIcon.d.ts +2 -0
- package/dist/react/src/svg_components/EyeCloseIcon.d.ts +5 -0
- package/dist/react/src/svg_components/EyeOpenIcon.d.ts +5 -0
- package/dist/react/src/svg_components/SloudIcon.d.ts +2 -0
- package/dist/react/src/utils/enums/AxiosErrorCodes.d.ts +7 -0
- package/dist/react/src/utils/enums/AxiosMethods.d.ts +7 -0
- package/dist/react/src/utils/helpers/classNames.d.ts +7 -0
- package/dist/react/src/utils/helpers/formatCurrency.d.ts +10 -0
- package/dist/react/src/utils/helpers/phoneDefaults.d.ts +3 -0
- package/dist/react/src/utils/helpers/validatePhone.d.ts +7 -0
- package/dist/react/src/utils/image_utils/index.d.ts +9 -0
- package/dist/react/src/utils/storage/index.d.ts +9 -0
- package/dist/react/src/widget.d.ts +27 -0
- package/dist/rollup.config.d.ts +8 -0
- package/dist/rollup.config.dts.d.ts +3 -0
- package/dist/src/components/Button/Button.types.d.ts +6 -0
- package/dist/src/components/Button/index.d.ts +3 -0
- package/dist/src/components/CopyToClipboardSpan/CopyToClipboard.types.d.ts +4 -0
- package/dist/src/components/CopyToClipboardSpan/index.d.ts +3 -0
- package/dist/src/components/Input/Input.types.d.ts +17 -0
- package/dist/src/components/Input/index.d.ts +3 -0
- package/dist/src/components/Skeleton/PaymentOptionSkeletons.d.ts +6 -0
- package/dist/src/components/TextArea/TextArea.types.d.ts +19 -0
- package/dist/src/components/TextArea/index.d.ts +3 -0
- package/dist/src/components/Widget.d.ts +6 -0
- package/dist/src/components/modals/AwaitingPaymentModal/AwaitingPaymentModal.d.ts +2 -0
- package/dist/src/components/modals/AwaitingPaymentTimeoutModal/AwaitingPaymentTimeoutModal.d.ts +2 -0
- package/dist/src/components/modals/Modal.d.ts +10 -0
- package/dist/src/components/modals/PaymentDetailsModal/PaymentDetailsModal.d.ts +2 -0
- package/dist/src/components/modals/PaymentDetailsModal/hooks/useTimer.d.ts +7 -0
- package/dist/src/components/modals/PaymentOptionsModal/PaymentOptionsModal.d.ts +2 -0
- package/dist/src/components/modals/PaymentOptionsModal/RadioButton.d.ts +11 -0
- package/dist/src/components/modals/PaymentOptionsModal/paymentOptionsMap.d.ts +5 -0
- package/dist/src/components/modals/SuccessModal/SuccessModal.d.ts +2 -0
- package/dist/src/components/modals/state/actions/data.d.ts +10 -0
- package/dist/src/components/modals/state/actions/index.d.ts +5 -0
- package/dist/src/components/modals/state/actions/modal.d.ts +5 -0
- package/dist/src/components/modals/state/actions/payment.d.ts +7 -0
- package/dist/src/components/modals/state/constants/actionTypes.d.ts +24 -0
- package/dist/src/components/modals/state/constants/index.d.ts +2 -0
- package/dist/src/components/modals/state/constants/initialState.d.ts +36 -0
- package/dist/src/components/modals/state/reducers/data.d.ts +2 -0
- package/dist/src/components/modals/state/reducers/index.d.ts +2 -0
- package/dist/src/components/modals/state/reducers/modal.d.ts +2 -0
- package/dist/src/components/modals/state/reducers/payment.d.ts +2 -0
- package/dist/src/components/modals/state/types/common.d.ts +12 -0
- package/dist/src/components/modals/state/types/data.d.ts +34 -0
- package/dist/src/components/modals/state/types/index.d.ts +8 -0
- package/dist/src/components/modals/state/types/modal.d.ts +12 -0
- package/dist/src/components/modals/state/types/payment.d.ts +14 -0
- package/dist/src/components/modals/state/utils/index.d.ts +37 -0
- package/dist/src/context/ModalProvider.d.ts +4 -0
- package/dist/src/context/PaymentInfoContext.d.ts +26 -0
- package/dist/src/context/PaymentWidgetContext.d.ts +13 -0
- package/dist/src/context/modal.d.ts +4 -0
- package/dist/src/context/types.d.ts +28 -0
- package/dist/src/hooks/types.d.ts +34 -0
- package/dist/src/hooks/useModalControl.d.ts +27 -0
- package/dist/src/hooks/usePaymentAPI.d.ts +10 -0
- package/dist/src/hooks/useShortPolling.d.ts +4 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/services/config/endpoints.d.ts +9 -0
- package/dist/src/services/config/error.d.ts +5 -0
- package/dist/src/services/index.d.ts +27 -0
- package/dist/src/services/payments/index.d.ts +4 -0
- package/dist/src/services/payments/types.d.ts +68 -0
- package/dist/src/services/products/index.d.ts +1 -0
- package/dist/src/services/products/types.d.ts +124 -0
- package/dist/src/services/store/index.d.ts +2 -0
- package/dist/src/services/store/types.d.ts +57 -0
- package/dist/src/services/utils/widgetConfig.d.ts +20 -0
- package/dist/src/svg_components/ArrowLeftIcon.d.ts +3 -0
- package/dist/src/svg_components/BankTransferIcon.d.ts +2 -0
- package/dist/src/svg_components/CancelIcon.d.ts +7 -0
- package/dist/src/svg_components/CardIcon.d.ts +2 -0
- package/dist/src/svg_components/CloseIcon.d.ts +3 -0
- package/dist/src/svg_components/CopyIcon.d.ts +2 -0
- package/dist/src/svg_components/EyeCloseIcon.d.ts +5 -0
- package/dist/src/svg_components/EyeOpenIcon.d.ts +5 -0
- package/dist/src/svg_components/SloudIcon.d.ts +2 -0
- package/dist/src/utils/enums/AxiosErrorCodes.d.ts +7 -0
- package/dist/src/utils/enums/AxiosMethods.d.ts +7 -0
- package/dist/src/utils/helpers/classNames.d.ts +7 -0
- package/dist/src/utils/helpers/formatCurrency.d.ts +10 -0
- package/dist/src/utils/helpers/phoneDefaults.d.ts +3 -0
- package/dist/src/utils/helpers/validatePhone.d.ts +7 -0
- package/dist/src/utils/image_utils/index.d.ts +9 -0
- package/dist/src/utils/storage/index.d.ts +9 -0
- package/dist/src/widget.d.ts +27 -0
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
(function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
|
|
3
3
|
(function (global, factory) {
|
|
4
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(
|
|
5
|
-
typeof define === 'function' && define.amd ? define(
|
|
6
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self,
|
|
7
|
-
})(this, (function (
|
|
4
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
5
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
6
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.PaymentWidget = factory());
|
|
7
|
+
})(this, (function () { 'use strict';
|
|
8
8
|
|
|
9
9
|
var global$1 = (typeof global !== "undefined" ? global :
|
|
10
10
|
typeof self !== "undefined" ? self :
|
|
@@ -44435,7 +44435,7 @@ to {
|
|
|
44435
44435
|
return (jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: jsxRuntimeExports.jsx(Fe, {}) }));
|
|
44436
44436
|
};
|
|
44437
44437
|
|
|
44438
|
-
var css_248z$a = ".Modal-module_modal__H-8fj {\n position: fixed;\n top: 0;\n left: 0;\n background: rgba(13, 22, 39, 0.2);\n width: 100%;\n height: 100%;\n backdrop-filter: blur(4px);\n z-index:
|
|
44438
|
+
var css_248z$a = ".Modal-module_modal__H-8fj {\n position: fixed;\n top: 0;\n left: 0;\n background: rgba(13, 22, 39, 0.2);\n width: 100%;\n height: 100%;\n backdrop-filter: blur(4px);\n z-index: 400;\n display: flex;\n justify-content: center;\n align-items: flex-end;\n font-size: 14px;\n}\n.Modal-module_modal__content__RjnlW {\n color: #181a27;\n width: 100%;\n border-radius: 8px 8px 0 0;\n padding: 0px 20px 10px 20px;\n background-color: white;\n animation: Modal-module_fadeInUp__J2Xh4 0.5s ease;\n max-height: 98%;\n overflow: hidden auto;\n}\n@keyframes Modal-module_fadeInUp__J2Xh4 {\n from {\n opacity: 0;\n transform: translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n.Modal-module_modal__header__kFpTR {\n position: sticky;\n top: 0;\n left: 0;\n background: white;\n display: flex;\n justify-content: space-between;\n margin-bottom: 20px;\n padding-top: 30px;\n padding-bottom: 10px;\n z-index: 500;\n}\n.Modal-module_modal__header__title__XJjL8 {\n font-size: 18px;\n font-weight: bold;\n}\n.Modal-module_modal__header__title--center__BlQmX {\n text-align: center;\n width: 100%;\n}\n.Modal-module_modal__header__button__5p1VG {\n background: none;\n border: none;\n cursor: pointer;\n padding: 0;\n}\n@media screen and (min-width: 768px) {\n .Modal-module_modal__H-8fj {\n font-size: 16px;\n align-items: center;\n }\n .Modal-module_modal__header__title__XJjL8 {\n font-size: 20px;\n }\n .Modal-module_modal__content__RjnlW {\n width: 500px;\n max-width: 500px;\n border-radius: 15px;\n padding: 0px 30px 15px 30px;\n }\n}\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIk1vZGFsLm1vZHVsZS5zY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0VBQ0UsZUFBZTtFQUNmLE1BQU07RUFDTixPQUFPO0VBQ1AsaUNBQWlDO0VBQ2pDLFdBQVc7RUFDWCxZQUFZO0VBQ1osMEJBQTBCO0VBQzFCLFlBQVk7RUFDWixhQUFhO0VBQ2IsdUJBQXVCO0VBQ3ZCLHFCQUFxQjtFQUNyQixlQUFlO0FBQ2pCO0FBQ0E7RUFDRSxjQUFjO0VBQ2QsV0FBVztFQUNYLDBCQUEwQjtFQUMxQiwyQkFBMkI7RUFDM0IsdUJBQXVCO0VBQ3ZCLGlEQUE2QjtFQUM3QixlQUFlO0VBQ2YscUJBQXFCO0FBQ3ZCO0FBQ0E7RUFDRTtJQUNFLFVBQVU7SUFDViwyQkFBMkI7RUFDN0I7RUFDQTtJQUNFLFVBQVU7SUFDVix3QkFBd0I7RUFDMUI7QUFDRjtBQUNBO0VBQ0UsZ0JBQWdCO0VBQ2hCLE1BQU07RUFDTixPQUFPO0VBQ1AsaUJBQWlCO0VBQ2pCLGFBQWE7RUFDYiw4QkFBOEI7RUFDOUIsbUJBQW1CO0VBQ25CLGlCQUFpQjtFQUNqQixvQkFBb0I7RUFDcEIsWUFBWTtBQUNkO0FBQ0E7RUFDRSxlQUFlO0VBQ2YsaUJBQWlCO0FBQ25CO0FBQ0E7RUFDRSxrQkFBa0I7RUFDbEIsV0FBVztBQUNiO0FBQ0E7RUFDRSxnQkFBZ0I7RUFDaEIsWUFBWTtFQUNaLGVBQWU7RUFDZixVQUFVO0FBQ1o7QUFDQTtFQUNFO0lBQ0UsZUFBZTtJQUNmLG1CQUFtQjtFQUNyQjtFQUNBO0lBQ0UsZUFBZTtFQUNqQjtFQUNBO0lBQ0UsWUFBWTtJQUNaLGdCQUFnQjtJQUNoQixtQkFBbUI7SUFDbkIsMkJBQTJCO0VBQzdCO0FBQ0YiLCJmaWxlIjoiTW9kYWwubW9kdWxlLnNjc3MiLCJzb3VyY2VzQ29udGVudCI6WyIubW9kYWwge1xuICBwb3NpdGlvbjogZml4ZWQ7XG4gIHRvcDogMDtcbiAgbGVmdDogMDtcbiAgYmFja2dyb3VuZDogcmdiYSgxMywgMjIsIDM5LCAwLjIpO1xuICB3aWR0aDogMTAwJTtcbiAgaGVpZ2h0OiAxMDAlO1xuICBiYWNrZHJvcC1maWx0ZXI6IGJsdXIoNHB4KTtcbiAgei1pbmRleDogNDAwO1xuICBkaXNwbGF5OiBmbGV4O1xuICBqdXN0aWZ5LWNvbnRlbnQ6IGNlbnRlcjtcbiAgYWxpZ24taXRlbXM6IGZsZXgtZW5kO1xuICBmb250LXNpemU6IDE0cHg7XG59XG4ubW9kYWxfX2NvbnRlbnQge1xuICBjb2xvcjogIzE4MWEyNztcbiAgd2lkdGg6IDEwMCU7XG4gIGJvcmRlci1yYWRpdXM6IDhweCA4cHggMCAwO1xuICBwYWRkaW5nOiAwcHggMjBweCAxMHB4IDIwcHg7XG4gIGJhY2tncm91bmQtY29sb3I6IHdoaXRlO1xuICBhbmltYXRpb246IGZhZGVJblVwIDAuNXMgZWFzZTtcbiAgbWF4LWhlaWdodDogOTglO1xuICBvdmVyZmxvdzogaGlkZGVuIGF1dG87XG59XG5Aa2V5ZnJhbWVzIGZhZGVJblVwIHtcbiAgZnJvbSB7XG4gICAgb3BhY2l0eTogMDtcbiAgICB0cmFuc2Zvcm06IHRyYW5zbGF0ZVkoMjBweCk7XG4gIH1cbiAgdG8ge1xuICAgIG9wYWNpdHk6IDE7XG4gICAgdHJhbnNmb3JtOiB0cmFuc2xhdGVZKDApO1xuICB9XG59XG4ubW9kYWxfX2hlYWRlciB7XG4gIHBvc2l0aW9uOiBzdGlja3k7XG4gIHRvcDogMDtcbiAgbGVmdDogMDtcbiAgYmFja2dyb3VuZDogd2hpdGU7XG4gIGRpc3BsYXk6IGZsZXg7XG4gIGp1c3RpZnktY29udGVudDogc3BhY2UtYmV0d2VlbjtcbiAgbWFyZ2luLWJvdHRvbTogMjBweDtcbiAgcGFkZGluZy10b3A6IDMwcHg7XG4gIHBhZGRpbmctYm90dG9tOiAxMHB4O1xuICB6LWluZGV4OiA1MDA7XG59XG4ubW9kYWxfX2hlYWRlcl9fdGl0bGUge1xuICBmb250LXNpemU6IDE4cHg7XG4gIGZvbnQtd2VpZ2h0OiBib2xkO1xufVxuLm1vZGFsX19oZWFkZXJfX3RpdGxlLS1jZW50ZXIge1xuICB0ZXh0LWFsaWduOiBjZW50ZXI7XG4gIHdpZHRoOiAxMDAlO1xufVxuLm1vZGFsX19oZWFkZXJfX2J1dHRvbiB7XG4gIGJhY2tncm91bmQ6IG5vbmU7XG4gIGJvcmRlcjogbm9uZTtcbiAgY3Vyc29yOiBwb2ludGVyO1xuICBwYWRkaW5nOiAwO1xufVxuQG1lZGlhIHNjcmVlbiBhbmQgKG1pbi13aWR0aDogNzY4cHgpIHtcbiAgLm1vZGFsIHtcbiAgICBmb250LXNpemU6IDE2cHg7XG4gICAgYWxpZ24taXRlbXM6IGNlbnRlcjtcbiAgfVxuICAubW9kYWxfX2hlYWRlcl9fdGl0bGUge1xuICAgIGZvbnQtc2l6ZTogMjBweDtcbiAgfVxuICAubW9kYWxfX2NvbnRlbnQge1xuICAgIHdpZHRoOiA1MDBweDtcbiAgICBtYXgtd2lkdGg6IDUwMHB4O1xuICAgIGJvcmRlci1yYWRpdXM6IDE1cHg7XG4gICAgcGFkZGluZzogMHB4IDMwcHggMTVweCAzMHB4O1xuICB9XG59Il19 */";
|
|
44439
44439
|
var styles$5 = {"modal":"Modal-module_modal__H-8fj","modal__content":"Modal-module_modal__content__RjnlW","modal__header":"Modal-module_modal__header__kFpTR","modal__header__title":"Modal-module_modal__header__title__XJjL8","modal__header__title--center":"Modal-module_modal__header__title--center__BlQmX","modal__header__button":"Modal-module_modal__header__button__5p1VG"};
|
|
44440
44440
|
styleInject(css_248z$a);
|
|
44441
44441
|
|
|
@@ -44467,7 +44467,7 @@ to {
|
|
|
44467
44467
|
};
|
|
44468
44468
|
|
|
44469
44469
|
const useTimer = ({ start, restart = false, callback }) => {
|
|
44470
|
-
const initialTime =
|
|
44470
|
+
const initialTime = 180;
|
|
44471
44471
|
const [timeLeft, setTimeLeft] = reactExports.useState(initialTime);
|
|
44472
44472
|
const intervalRef = reactExports.useRef(null);
|
|
44473
44473
|
const startTimer = () => {
|
|
@@ -44614,12 +44614,12 @@ to {
|
|
|
44614
44614
|
|
|
44615
44615
|
// utils is a library of generic helper functions non-specific to axios
|
|
44616
44616
|
|
|
44617
|
-
const {toString: toString$
|
|
44617
|
+
const {toString: toString$1} = Object.prototype;
|
|
44618
44618
|
const {getPrototypeOf} = Object;
|
|
44619
44619
|
const {iterator, toStringTag} = Symbol;
|
|
44620
44620
|
|
|
44621
44621
|
const kindOf = (cache => thing => {
|
|
44622
|
-
const str = toString$
|
|
44622
|
+
const str = toString$1.call(thing);
|
|
44623
44623
|
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
|
44624
44624
|
})(Object.create(null));
|
|
44625
44625
|
|
|
@@ -44720,7 +44720,7 @@ to {
|
|
|
44720
44720
|
*
|
|
44721
44721
|
* @returns {boolean} True if value is an Object, otherwise false
|
|
44722
44722
|
*/
|
|
44723
|
-
const isObject
|
|
44723
|
+
const isObject = (thing) => thing !== null && typeof thing === 'object';
|
|
44724
44724
|
|
|
44725
44725
|
/**
|
|
44726
44726
|
* Determine if a value is a Boolean
|
|
@@ -44755,7 +44755,7 @@ to {
|
|
|
44755
44755
|
*/
|
|
44756
44756
|
const isEmptyObject = (val) => {
|
|
44757
44757
|
// Early return for non-objects or Buffers to prevent RangeError
|
|
44758
|
-
if (!isObject
|
|
44758
|
+
if (!isObject(val) || isBuffer$1(val)) {
|
|
44759
44759
|
return false;
|
|
44760
44760
|
}
|
|
44761
44761
|
|
|
@@ -44774,7 +44774,7 @@ to {
|
|
|
44774
44774
|
*
|
|
44775
44775
|
* @returns {boolean} True if value is a Date, otherwise false
|
|
44776
44776
|
*/
|
|
44777
|
-
const isDate
|
|
44777
|
+
const isDate = kindOfTest('Date');
|
|
44778
44778
|
|
|
44779
44779
|
/**
|
|
44780
44780
|
* Determine if a value is a File
|
|
@@ -44810,7 +44810,7 @@ to {
|
|
|
44810
44810
|
*
|
|
44811
44811
|
* @returns {boolean} True if value is a Stream, otherwise false
|
|
44812
44812
|
*/
|
|
44813
|
-
const isStream = (val) => isObject
|
|
44813
|
+
const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
|
|
44814
44814
|
|
|
44815
44815
|
/**
|
|
44816
44816
|
* Determine if a value is a FormData
|
|
@@ -44868,7 +44868,7 @@ to {
|
|
|
44868
44868
|
* @param {Boolean} [allOwnKeys = false]
|
|
44869
44869
|
* @returns {any}
|
|
44870
44870
|
*/
|
|
44871
|
-
function forEach
|
|
44871
|
+
function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
|
44872
44872
|
// Don't bother if no value provided
|
|
44873
44873
|
if (obj === null || typeof obj === 'undefined') {
|
|
44874
44874
|
return;
|
|
@@ -44967,7 +44967,7 @@ to {
|
|
|
44967
44967
|
};
|
|
44968
44968
|
|
|
44969
44969
|
for (let i = 0, l = arguments.length; i < l; i++) {
|
|
44970
|
-
arguments[i] && forEach
|
|
44970
|
+
arguments[i] && forEach(arguments[i], assignValue);
|
|
44971
44971
|
}
|
|
44972
44972
|
return result;
|
|
44973
44973
|
}
|
|
@@ -44983,7 +44983,7 @@ to {
|
|
|
44983
44983
|
* @returns {Object} The resulting value of object a
|
|
44984
44984
|
*/
|
|
44985
44985
|
const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
|
|
44986
|
-
forEach
|
|
44986
|
+
forEach(b, (val, key) => {
|
|
44987
44987
|
if (thisArg && isFunction$1(val)) {
|
|
44988
44988
|
a[key] = bind(val, thisArg);
|
|
44989
44989
|
} else {
|
|
@@ -45087,7 +45087,7 @@ to {
|
|
|
45087
45087
|
*
|
|
45088
45088
|
* @returns {?Array}
|
|
45089
45089
|
*/
|
|
45090
|
-
const toArray
|
|
45090
|
+
const toArray = (thing) => {
|
|
45091
45091
|
if (!thing) return null;
|
|
45092
45092
|
if (isArray$1(thing)) return thing;
|
|
45093
45093
|
let i = thing.length;
|
|
@@ -45182,7 +45182,7 @@ to {
|
|
|
45182
45182
|
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
|
45183
45183
|
const reducedDescriptors = {};
|
|
45184
45184
|
|
|
45185
|
-
forEach
|
|
45185
|
+
forEach(descriptors, (descriptor, name) => {
|
|
45186
45186
|
let ret;
|
|
45187
45187
|
if ((ret = reducer(descriptor, name, obj)) !== false) {
|
|
45188
45188
|
reducedDescriptors[name] = ret || descriptor;
|
|
@@ -45261,7 +45261,7 @@ to {
|
|
|
45261
45261
|
|
|
45262
45262
|
const visit = (source, i) => {
|
|
45263
45263
|
|
|
45264
|
-
if (isObject
|
|
45264
|
+
if (isObject(source)) {
|
|
45265
45265
|
if (stack.indexOf(source) >= 0) {
|
|
45266
45266
|
return;
|
|
45267
45267
|
}
|
|
@@ -45275,7 +45275,7 @@ to {
|
|
|
45275
45275
|
stack[i] = source;
|
|
45276
45276
|
const target = isArray$1(source) ? [] : {};
|
|
45277
45277
|
|
|
45278
|
-
forEach
|
|
45278
|
+
forEach(source, (value, key) => {
|
|
45279
45279
|
const reducedValue = visit(value, i + 1);
|
|
45280
45280
|
!isUndefined(reducedValue) && (target[key] = reducedValue);
|
|
45281
45281
|
});
|
|
@@ -45295,7 +45295,7 @@ to {
|
|
|
45295
45295
|
const isAsyncFn = kindOfTest('AsyncFunction');
|
|
45296
45296
|
|
|
45297
45297
|
const isThenable = (thing) =>
|
|
45298
|
-
thing && (isObject
|
|
45298
|
+
thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
|
|
45299
45299
|
|
|
45300
45300
|
// original code
|
|
45301
45301
|
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
|
@@ -45340,7 +45340,7 @@ to {
|
|
|
45340
45340
|
isString,
|
|
45341
45341
|
isNumber,
|
|
45342
45342
|
isBoolean,
|
|
45343
|
-
isObject
|
|
45343
|
+
isObject,
|
|
45344
45344
|
isPlainObject,
|
|
45345
45345
|
isEmptyObject,
|
|
45346
45346
|
isReadableStream,
|
|
@@ -45348,7 +45348,7 @@ to {
|
|
|
45348
45348
|
isResponse,
|
|
45349
45349
|
isHeaders,
|
|
45350
45350
|
isUndefined,
|
|
45351
|
-
isDate
|
|
45351
|
+
isDate,
|
|
45352
45352
|
isFile,
|
|
45353
45353
|
isBlob,
|
|
45354
45354
|
isRegExp,
|
|
@@ -45357,7 +45357,7 @@ to {
|
|
|
45357
45357
|
isURLSearchParams,
|
|
45358
45358
|
isTypedArray,
|
|
45359
45359
|
isFileList,
|
|
45360
|
-
forEach
|
|
45360
|
+
forEach,
|
|
45361
45361
|
merge,
|
|
45362
45362
|
extend,
|
|
45363
45363
|
trim,
|
|
@@ -45367,7 +45367,7 @@ to {
|
|
|
45367
45367
|
kindOf,
|
|
45368
45368
|
kindOfTest,
|
|
45369
45369
|
endsWith,
|
|
45370
|
-
toArray
|
|
45370
|
+
toArray,
|
|
45371
45371
|
forEachEntry,
|
|
45372
45372
|
matchAll,
|
|
45373
45373
|
isHTMLForm,
|
|
@@ -45586,10 +45586,10 @@ to {
|
|
|
45586
45586
|
buffer[offset + i - d] |= s * 128;
|
|
45587
45587
|
}
|
|
45588
45588
|
|
|
45589
|
-
var toString
|
|
45589
|
+
var toString = {}.toString;
|
|
45590
45590
|
|
|
45591
45591
|
var isArray = Array.isArray || function (arr) {
|
|
45592
|
-
return toString
|
|
45592
|
+
return toString.call(arr) == '[object Array]';
|
|
45593
45593
|
};
|
|
45594
45594
|
|
|
45595
45595
|
/*!
|
|
@@ -50626,7 +50626,6 @@ to {
|
|
|
50626
50626
|
const PaymentWidgetProvider = ({ children, options, }) => {
|
|
50627
50627
|
const value = {
|
|
50628
50628
|
options,
|
|
50629
|
-
onSuccess: options.onSuccess,
|
|
50630
50629
|
};
|
|
50631
50630
|
// Initialize services with widget options when provider mounts
|
|
50632
50631
|
reactExports.useEffect(() => {
|
|
@@ -50635,172 +50634,6 @@ to {
|
|
|
50635
50634
|
return (jsxRuntimeExports.jsx(PaymentWidgetContext.Provider, { value: value, children: children }));
|
|
50636
50635
|
};
|
|
50637
50636
|
|
|
50638
|
-
/**
|
|
50639
|
-
* Builder for external payment payloads
|
|
50640
|
-
*/
|
|
50641
|
-
class ExternalPaymentPayloadBuilder {
|
|
50642
|
-
build(options, payment_method) {
|
|
50643
|
-
return {
|
|
50644
|
-
type: "external",
|
|
50645
|
-
amount: options.amount,
|
|
50646
|
-
customer: options.customer,
|
|
50647
|
-
};
|
|
50648
|
-
}
|
|
50649
|
-
}
|
|
50650
|
-
/**
|
|
50651
|
-
* Builder for storefront payment payloads
|
|
50652
|
-
*/
|
|
50653
|
-
class StorefrontPaymentPayloadBuilder {
|
|
50654
|
-
build(options, payment_method) {
|
|
50655
|
-
return {
|
|
50656
|
-
type: "storefront",
|
|
50657
|
-
slug: options.slug,
|
|
50658
|
-
order: {
|
|
50659
|
-
additional_amount: Math.round(options.amount) || 0,
|
|
50660
|
-
discount: options.discount || 0,
|
|
50661
|
-
items: options.products.map((product) => ({
|
|
50662
|
-
product_id: product.product_id,
|
|
50663
|
-
quantity: product.quantity,
|
|
50664
|
-
variation: product.variation,
|
|
50665
|
-
})),
|
|
50666
|
-
payment_method: payment_method || "",
|
|
50667
|
-
channel: options.channel,
|
|
50668
|
-
buyer_details: {
|
|
50669
|
-
first_name: options.customer.first_name,
|
|
50670
|
-
last_name: options.customer.last_name,
|
|
50671
|
-
email: options.customer.email,
|
|
50672
|
-
phone_number: options.customer.phone_number,
|
|
50673
|
-
},
|
|
50674
|
-
delivery_details: options.delivery_details,
|
|
50675
|
-
},
|
|
50676
|
-
};
|
|
50677
|
-
}
|
|
50678
|
-
}
|
|
50679
|
-
/**
|
|
50680
|
-
* Builder for storefront payment payloads
|
|
50681
|
-
*/
|
|
50682
|
-
class SloudfrontPaymentPayloadBuilder {
|
|
50683
|
-
build(options, payment_method) {
|
|
50684
|
-
({
|
|
50685
|
-
manual_order: {
|
|
50686
|
-
additional_amount: Math.round(options.amount) || 0,
|
|
50687
|
-
discount: options.discount || 0,
|
|
50688
|
-
items: options.products.map((product) => ({
|
|
50689
|
-
product_id: product.product_id,
|
|
50690
|
-
quantity: product.quantity,
|
|
50691
|
-
variation: product.variation,
|
|
50692
|
-
})),
|
|
50693
|
-
channel: options.channel,
|
|
50694
|
-
// transaction_id: options.transaction_id,
|
|
50695
|
-
customer_id: options.customer_id,
|
|
50696
|
-
business_id: options.business_id,
|
|
50697
|
-
},
|
|
50698
|
-
});
|
|
50699
|
-
return {
|
|
50700
|
-
type: "sloudfront",
|
|
50701
|
-
manual_order: {
|
|
50702
|
-
additional_amount: Math.round(options.amount) || 0,
|
|
50703
|
-
discount: options.discount || 0,
|
|
50704
|
-
items: options.products.map((product) => ({
|
|
50705
|
-
product_id: product.product_id,
|
|
50706
|
-
quantity: product.quantity,
|
|
50707
|
-
variation: product.variation,
|
|
50708
|
-
})),
|
|
50709
|
-
payment_method: payment_method || "",
|
|
50710
|
-
channel: options.channel,
|
|
50711
|
-
buyer_details: {
|
|
50712
|
-
first_name: options.customer.first_name,
|
|
50713
|
-
last_name: options.customer.last_name,
|
|
50714
|
-
email: options.customer.email,
|
|
50715
|
-
phone_number: options.customer.phone_number,
|
|
50716
|
-
},
|
|
50717
|
-
delivery_details: options.delivery_details,
|
|
50718
|
-
// transaction_id: options.transaction_id,
|
|
50719
|
-
customer_id: options.customer_id,
|
|
50720
|
-
business_id: options.business_id,
|
|
50721
|
-
},
|
|
50722
|
-
};
|
|
50723
|
-
}
|
|
50724
|
-
}
|
|
50725
|
-
/**
|
|
50726
|
-
* Registry of payload builders by payment type
|
|
50727
|
-
*/
|
|
50728
|
-
const payloadBuilders = {
|
|
50729
|
-
external: new ExternalPaymentPayloadBuilder(),
|
|
50730
|
-
storefront: new StorefrontPaymentPayloadBuilder(),
|
|
50731
|
-
sloudfront: new SloudfrontPaymentPayloadBuilder(),
|
|
50732
|
-
};
|
|
50733
|
-
/**
|
|
50734
|
-
* Factory function to build payment instrument payload based on options type
|
|
50735
|
-
*
|
|
50736
|
-
* @param options - Payment widget options
|
|
50737
|
-
* @returns Constructed payload for the payment instrument API
|
|
50738
|
-
* @throws Error if the payment type is not supported
|
|
50739
|
-
*
|
|
50740
|
-
* @example
|
|
50741
|
-
* // External payment
|
|
50742
|
-
* const payload = buildPaymentInstrumentPayload({
|
|
50743
|
-
* type: "external",
|
|
50744
|
-
* amount: 25000,
|
|
50745
|
-
* // ... other options
|
|
50746
|
-
* });
|
|
50747
|
-
*
|
|
50748
|
-
* @example
|
|
50749
|
-
* // Storefront payment
|
|
50750
|
-
* const payload = buildPaymentInstrumentPayload({
|
|
50751
|
-
* type: "storefront",
|
|
50752
|
-
* slug: "my-store",
|
|
50753
|
-
* products: [...],
|
|
50754
|
-
* // ... other options
|
|
50755
|
-
* });
|
|
50756
|
-
*/
|
|
50757
|
-
function buildPaymentInstrumentPayload(options, payment_method) {
|
|
50758
|
-
const builder = payloadBuilders[options.type];
|
|
50759
|
-
if (!builder) {
|
|
50760
|
-
throw new Error(`Unsupported payment type: ${options.type}. Available types: ${Object.keys(payloadBuilders).join(", ")}`);
|
|
50761
|
-
}
|
|
50762
|
-
// TypeScript will narrow the type based on options.type
|
|
50763
|
-
return builder.build(options, payment_method);
|
|
50764
|
-
}
|
|
50765
|
-
/**
|
|
50766
|
-
* Register a new payload builder for a custom payment type
|
|
50767
|
-
* This allows for extending the system with new payment types without modifying existing code
|
|
50768
|
-
*
|
|
50769
|
-
* @param type - The payment type identifier
|
|
50770
|
-
* @param builder - The payload builder instance
|
|
50771
|
-
*
|
|
50772
|
-
* @example
|
|
50773
|
-
* class SubscriptionPaymentPayloadBuilder implements PayloadBuilder<ISubscriptionPaymentPayload> {
|
|
50774
|
-
* build(options: PaymentWidgetOptions): ISubscriptionPaymentPayload {
|
|
50775
|
-
* return {
|
|
50776
|
-
* type: "subscription",
|
|
50777
|
-
* plan_id: options.plan_id,
|
|
50778
|
-
* // ... other fields
|
|
50779
|
-
* };
|
|
50780
|
-
* }
|
|
50781
|
-
* }
|
|
50782
|
-
*
|
|
50783
|
-
* registerPayloadBuilder("subscription", new SubscriptionPaymentPayloadBuilder());
|
|
50784
|
-
*/
|
|
50785
|
-
function registerPayloadBuilder(type, builder) {
|
|
50786
|
-
payloadBuilders[type] = builder;
|
|
50787
|
-
}
|
|
50788
|
-
/**
|
|
50789
|
-
* Get all registered payment types
|
|
50790
|
-
*
|
|
50791
|
-
* @returns Array of registered payment type identifiers
|
|
50792
|
-
*/
|
|
50793
|
-
function getRegisteredPaymentTypes() {
|
|
50794
|
-
return Object.keys(payloadBuilders);
|
|
50795
|
-
}
|
|
50796
|
-
|
|
50797
|
-
const getAxiosErrorMessage = (err) => {
|
|
50798
|
-
const error = err;
|
|
50799
|
-
const responseError = error?.response?.data?.message;
|
|
50800
|
-
const requestError = error?.message;
|
|
50801
|
-
return responseError ?? requestError;
|
|
50802
|
-
};
|
|
50803
|
-
|
|
50804
50637
|
const usePaymentAPI = () => {
|
|
50805
50638
|
const { updateCollectionAccount, updateTransactionDetails } = usePaymentInfoContext();
|
|
50806
50639
|
const [isFetchingMethods, setIsFetchingMethods] = reactExports.useState(false);
|
|
@@ -50826,26 +50659,25 @@ to {
|
|
|
50826
50659
|
}
|
|
50827
50660
|
}
|
|
50828
50661
|
catch (error) {
|
|
50829
|
-
zt.error(String(getAxiosErrorMessage(error)));
|
|
50830
50662
|
}
|
|
50831
50663
|
finally {
|
|
50832
50664
|
setIsFetchingMethods(false);
|
|
50833
50665
|
}
|
|
50834
50666
|
}, [options.public_key]);
|
|
50835
|
-
const generatePaymentInstrument = reactExports.useCallback(async (
|
|
50667
|
+
const generatePaymentInstrument = reactExports.useCallback(async () => {
|
|
50836
50668
|
setIsLoading(true);
|
|
50837
|
-
|
|
50669
|
+
const payload = {
|
|
50670
|
+
amount: options.amount,
|
|
50671
|
+
customer: {
|
|
50672
|
+
first_name: options.first_name,
|
|
50673
|
+
last_name: options.last_name,
|
|
50674
|
+
phone_number: options.phone_number,
|
|
50675
|
+
email: options.email,
|
|
50676
|
+
},
|
|
50677
|
+
};
|
|
50838
50678
|
try {
|
|
50839
|
-
const
|
|
50840
|
-
|
|
50841
|
-
if (error) {
|
|
50842
|
-
const errorMessage = error.response?.data?.message ||
|
|
50843
|
-
error.message ||
|
|
50844
|
-
"Failed to generate payment instrument";
|
|
50845
|
-
zt.error(errorMessage);
|
|
50846
|
-
setIsLoading(false);
|
|
50847
|
-
return;
|
|
50848
|
-
}
|
|
50679
|
+
const { response } = await generatePaymentInstrumentService(options.public_key, payload);
|
|
50680
|
+
setIsLoading(false);
|
|
50849
50681
|
if (response?.status === "success" && response?.data) {
|
|
50850
50682
|
const collectionAccount = {
|
|
50851
50683
|
accountName: response.data.account_name,
|
|
@@ -50865,12 +50697,13 @@ to {
|
|
|
50865
50697
|
}
|
|
50866
50698
|
}
|
|
50867
50699
|
catch (error) {
|
|
50868
|
-
|
|
50700
|
+
console.error(error);
|
|
50869
50701
|
}
|
|
50870
50702
|
finally {
|
|
50871
50703
|
setIsLoading(false);
|
|
50704
|
+
setSuccess(true);
|
|
50872
50705
|
}
|
|
50873
|
-
}, [options
|
|
50706
|
+
}, [options.public_key]);
|
|
50874
50707
|
reactExports.useEffect(() => {
|
|
50875
50708
|
fetchPaymentMethods$1();
|
|
50876
50709
|
}, []);
|
|
@@ -50943,8 +50776,8 @@ to {
|
|
|
50943
50776
|
return (jsxRuntimeExports.jsxs("label", { className: getClassName(disabled), children: [jsxRuntimeExports.jsxs("div", { className: styles$1.radioButton__item, children: [jsxRuntimeExports.jsx("div", { children: jsxRuntimeExports.jsx("input", { className: styles$1.radioButton__input, type: "radio", name: name, value: value, disabled: disabled, id: id, checked: checked, onChange: onChange }) }), jsxRuntimeExports.jsx("div", { children: jsxRuntimeExports.jsx("p", { className: styles$1.radioButton__label, children: label }) })] }), jsxRuntimeExports.jsx("div", { className: styles$1.radioButton__icon, children: Icons[value] })] }));
|
|
50944
50777
|
};
|
|
50945
50778
|
|
|
50946
|
-
var css_248z$3 = ".PaymentOptionsModal-module_paymentOptionsModal__body__u2eOb {\n margin-bottom: 30px;\n}\n.PaymentOptionsModal-
|
|
50947
|
-
var PayOptionsStyles = {"paymentOptionsModal__body":"PaymentOptionsModal-module_paymentOptionsModal__body__u2eOb","
|
|
50779
|
+
var css_248z$3 = ".PaymentOptionsModal-module_paymentOptionsModal__body__u2eOb {\n margin-bottom: 30px;\n}\n.PaymentOptionsModal-module_paymentOptionsModal__bodyOptions__SfvwI p {\n font-size: 0.875rem;\n}\n.PaymentOptionsModal-module_paymentOptionsModal__continueButton__-2Nry {\n background: rgb(19, 18, 18);\n width: 100%;\n color: white;\n margin-top: 50px;\n padding: 15px;\n border-radius: 30px;\n border: none;\n cursor: pointer;\n font-weight: bold;\n font-family: inherit;\n}\n.PaymentOptionsModal-module_paymentOptionsModal__continueButton__-2Nry:disabled {\n cursor: not-allowed;\n}\n.PaymentOptionsModal-module_paymentOptionsModal__skeleton__ElGQb {\n height: 60px;\n width: 100%;\n}\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIlBheW1lbnRPcHRpb25zTW9kYWwubW9kdWxlLnNjc3MiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7RUFDRSxtQkFBbUI7QUFDckI7QUFDQTtFQUNFLG1CQUFtQjtBQUNyQjtBQUNBO0VBQ0UsMkJBQTJCO0VBQzNCLFdBQVc7RUFDWCxZQUFZO0VBQ1osZ0JBQWdCO0VBQ2hCLGFBQWE7RUFDYixtQkFBbUI7RUFDbkIsWUFBWTtFQUNaLGVBQWU7RUFDZixpQkFBaUI7RUFDakIsb0JBQW9CO0FBQ3RCO0FBQ0E7RUFDRSxtQkFBbUI7QUFDckI7QUFDQTtFQUNFLFlBQVk7RUFDWixXQUFXO0FBQ2IiLCJmaWxlIjoiUGF5bWVudE9wdGlvbnNNb2RhbC5tb2R1bGUuc2NzcyIsInNvdXJjZXNDb250ZW50IjpbIi5wYXltZW50T3B0aW9uc01vZGFsX19ib2R5IHtcbiAgbWFyZ2luLWJvdHRvbTogMzBweDtcbn1cbi5wYXltZW50T3B0aW9uc01vZGFsX19ib2R5T3B0aW9ucyBwIHtcbiAgZm9udC1zaXplOiAwLjg3NXJlbTtcbn1cbi5wYXltZW50T3B0aW9uc01vZGFsX19jb250aW51ZUJ1dHRvbiB7XG4gIGJhY2tncm91bmQ6IHJnYigxOSwgMTgsIDE4KTtcbiAgd2lkdGg6IDEwMCU7XG4gIGNvbG9yOiB3aGl0ZTtcbiAgbWFyZ2luLXRvcDogNTBweDtcbiAgcGFkZGluZzogMTVweDtcbiAgYm9yZGVyLXJhZGl1czogMzBweDtcbiAgYm9yZGVyOiBub25lO1xuICBjdXJzb3I6IHBvaW50ZXI7XG4gIGZvbnQtd2VpZ2h0OiBib2xkO1xuICBmb250LWZhbWlseTogaW5oZXJpdDtcbn1cbi5wYXltZW50T3B0aW9uc01vZGFsX19jb250aW51ZUJ1dHRvbjpkaXNhYmxlZCB7XG4gIGN1cnNvcjogbm90LWFsbG93ZWQ7XG59XG4ucGF5bWVudE9wdGlvbnNNb2RhbF9fc2tlbGV0b24ge1xuICBoZWlnaHQ6IDYwcHg7XG4gIHdpZHRoOiAxMDAlO1xufSJdfQ== */";
|
|
50780
|
+
var PayOptionsStyles = {"paymentOptionsModal__body":"PaymentOptionsModal-module_paymentOptionsModal__body__u2eOb","paymentOptionsModal__continueButton":"PaymentOptionsModal-module_paymentOptionsModal__continueButton__-2Nry"};
|
|
50948
50781
|
styleInject(css_248z$3);
|
|
50949
50782
|
|
|
50950
50783
|
/**
|
|
@@ -51060,7 +50893,7 @@ to {
|
|
|
51060
50893
|
};
|
|
51061
50894
|
|
|
51062
50895
|
const PaymentOptionsModal = () => {
|
|
51063
|
-
const { open, currentModal, moveNext
|
|
50896
|
+
const { open, currentModal, moveNext } = useModalContext();
|
|
51064
50897
|
const { paymentMethods, isFetchingMethods, generatePaymentInstrument, isLoading, isSuccess, } = usePaymentAPI();
|
|
51065
50898
|
const [selectedOption, setSelectedOption] = reactExports.useState("");
|
|
51066
50899
|
const isModalOpen = open && currentModal === ModalNames.Payment;
|
|
@@ -51073,19 +50906,13 @@ to {
|
|
|
51073
50906
|
setSelectedOption(e.target.value);
|
|
51074
50907
|
};
|
|
51075
50908
|
const handleSubmit = async () => {
|
|
51076
|
-
|
|
51077
|
-
await generatePaymentInstrument(selectedOption);
|
|
50909
|
+
await generatePaymentInstrument();
|
|
51078
50910
|
};
|
|
51079
50911
|
const renderPaymentOptions = reactExports.useMemo(() => {
|
|
51080
|
-
const availableOptions = Object.entries(paymentOptionsMap);
|
|
50912
|
+
const availableOptions = Object.entries(paymentOptionsMap).filter(([key]) => paymentMethods[key]);
|
|
51081
50913
|
if (availableOptions.length === 0)
|
|
51082
50914
|
return null;
|
|
51083
|
-
|
|
51084
|
-
const firstDisabledIndex = availableOptions.findIndex(([, option]) => option.disabled);
|
|
51085
|
-
return availableOptions.map(([key, { label, value, disabled }], i) => {
|
|
51086
|
-
const showComingSoon = i === firstDisabledIndex && firstDisabledIndex !== -1;
|
|
51087
|
-
return (jsxRuntimeExports.jsxs(React.Fragment, { children: [showComingSoon ? (jsxRuntimeExports.jsx("p", { className: PayOptionsStyles.paymentOptionsModal__comingSoonText, children: "Coming Soon" })) : null, jsxRuntimeExports.jsx(RadioButton, { label: label, name: "payment-options", id: key, value: value, disabled: disabled, checked: selectedOption === value, onChange: handleChange })] }, key));
|
|
51088
|
-
});
|
|
50915
|
+
return availableOptions.map(([key, { label, value, disabled }]) => (jsxRuntimeExports.jsx(RadioButton, { label: label, name: "payment-options", id: key, value: value, disabled: disabled, checked: selectedOption === value, onChange: handleChange }, key)));
|
|
51089
50916
|
}, [paymentMethods, selectedOption]);
|
|
51090
50917
|
return (jsxRuntimeExports.jsx(Modal, { title: "Payment Options", isOpen: isModalOpen, children: jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsxs("div", { className: PayOptionsStyles.paymentOptionsModal__body, children: [isFetchingMethods && (jsxRuntimeExports.jsx(PaymentOptionsSkeleton, { numberOfSkeletons: 3 })), !isFetchingMethods && renderPaymentOptions] }), jsxRuntimeExports.jsx(Button, { type: "button", disabled: !selectedOption || isLoading, className: PayOptionsStyles.paymentOptionsModal__continueButton, onClick: handleSubmit, mode: "solid", loading: isLoading, children: "Continue" })] }) }));
|
|
51091
50918
|
};
|
|
@@ -51101,29 +50928,28 @@ to {
|
|
|
51101
50928
|
};
|
|
51102
50929
|
|
|
51103
50930
|
const PAYMENT_ACTIONS = {
|
|
51104
|
-
SET_PAYMENT_STATUS:
|
|
51105
|
-
SET_PAYMENT_DETAILS:
|
|
51106
|
-
SET_ADDITIONAL_AMOUNT:
|
|
51107
|
-
RESET_PAYMENT:
|
|
50931
|
+
SET_PAYMENT_STATUS: 'SET_PAYMENT_STATUS',
|
|
50932
|
+
SET_PAYMENT_DETAILS: 'SET_PAYMENT_DETAILS',
|
|
50933
|
+
SET_ADDITIONAL_AMOUNT: 'SET_ADDITIONAL_AMOUNT',
|
|
50934
|
+
RESET_PAYMENT: 'RESET_PAYMENT',
|
|
51108
50935
|
};
|
|
51109
50936
|
const MODAL_ACTIONS = {
|
|
51110
|
-
SET_OPEN:
|
|
51111
|
-
SET_CURRENT_INDEX:
|
|
51112
|
-
SET_ABOUT_MODAL:
|
|
51113
|
-
RESET_MODAL:
|
|
50937
|
+
SET_OPEN: 'SET_OPEN',
|
|
50938
|
+
SET_CURRENT_INDEX: 'SET_CURRENT_INDEX',
|
|
50939
|
+
SET_ABOUT_MODAL: 'SET_ABOUT_MODAL',
|
|
50940
|
+
RESET_MODAL: 'RESET_MODAL',
|
|
51114
50941
|
};
|
|
51115
50942
|
const DATA_ACTIONS = {
|
|
51116
|
-
SET_DATA:
|
|
51117
|
-
SET_STORE:
|
|
51118
|
-
SET_LOADING:
|
|
51119
|
-
SET_DELIVERY_DETAILS:
|
|
51120
|
-
EDIT_ITEM:
|
|
51121
|
-
REMOVE_ITEM:
|
|
51122
|
-
RESET_DATA:
|
|
51123
|
-
SET_PAYMENT_METHOD: "SET_PAYMENT_METHOD",
|
|
50943
|
+
SET_DATA: 'SET_DATA',
|
|
50944
|
+
SET_STORE: 'SET_STORE',
|
|
50945
|
+
SET_LOADING: 'SET_LOADING',
|
|
50946
|
+
SET_DELIVERY_DETAILS: 'SET_DELIVERY_DETAILS',
|
|
50947
|
+
EDIT_ITEM: 'EDIT_ITEM',
|
|
50948
|
+
REMOVE_ITEM: 'REMOVE_ITEM',
|
|
50949
|
+
RESET_DATA: 'RESET_DATA',
|
|
51124
50950
|
};
|
|
51125
50951
|
const GLOBAL_ACTIONS = {
|
|
51126
|
-
RESET_ALL:
|
|
50952
|
+
RESET_ALL: 'RESET_ALL',
|
|
51127
50953
|
};
|
|
51128
50954
|
|
|
51129
50955
|
/* eslint-disable no-console */
|
|
@@ -51219,7 +51045,6 @@ to {
|
|
|
51219
51045
|
data: loadCartFromStorage(),
|
|
51220
51046
|
store: undefined,
|
|
51221
51047
|
isLoading: false,
|
|
51222
|
-
payment_method: "",
|
|
51223
51048
|
deliveryDetails: {
|
|
51224
51049
|
channel: "pickup",
|
|
51225
51050
|
first_name: "",
|
|
@@ -51240,42 +51065,37 @@ to {
|
|
|
51240
51065
|
saveCartToStorage(action.payload);
|
|
51241
51066
|
return {
|
|
51242
51067
|
...state,
|
|
51243
|
-
data: action.payload
|
|
51068
|
+
data: action.payload
|
|
51244
51069
|
};
|
|
51245
51070
|
case DATA_ACTIONS.SET_STORE:
|
|
51246
51071
|
return {
|
|
51247
51072
|
...state,
|
|
51248
|
-
store: action.payload
|
|
51073
|
+
store: action.payload
|
|
51249
51074
|
};
|
|
51250
51075
|
case DATA_ACTIONS.SET_LOADING:
|
|
51251
51076
|
return {
|
|
51252
51077
|
...state,
|
|
51253
|
-
isLoading: action.payload
|
|
51254
|
-
};
|
|
51255
|
-
case DATA_ACTIONS.SET_PAYMENT_METHOD:
|
|
51256
|
-
return {
|
|
51257
|
-
...state,
|
|
51258
|
-
payment_method: action.payload,
|
|
51078
|
+
isLoading: action.payload
|
|
51259
51079
|
};
|
|
51260
51080
|
case DATA_ACTIONS.SET_DELIVERY_DETAILS:
|
|
51261
51081
|
return {
|
|
51262
51082
|
...state,
|
|
51263
51083
|
deliveryDetails: {
|
|
51264
51084
|
...state.deliveryDetails,
|
|
51265
|
-
...action.payload
|
|
51266
|
-
}
|
|
51085
|
+
...action.payload
|
|
51086
|
+
}
|
|
51267
51087
|
};
|
|
51268
51088
|
case DATA_ACTIONS.EDIT_ITEM: {
|
|
51269
51089
|
const { index, quantity } = action.payload;
|
|
51270
51090
|
const updatedData = [...state.data];
|
|
51271
51091
|
updatedData[index] = {
|
|
51272
51092
|
...updatedData[index],
|
|
51273
|
-
quantity: quantity ?? updatedData[index].quantity
|
|
51093
|
+
quantity: quantity ?? updatedData[index].quantity
|
|
51274
51094
|
};
|
|
51275
51095
|
saveCartToStorage(updatedData);
|
|
51276
51096
|
return {
|
|
51277
51097
|
...state,
|
|
51278
|
-
data: updatedData
|
|
51098
|
+
data: updatedData
|
|
51279
51099
|
};
|
|
51280
51100
|
}
|
|
51281
51101
|
case DATA_ACTIONS.REMOVE_ITEM: {
|
|
@@ -51283,7 +51103,7 @@ to {
|
|
|
51283
51103
|
saveCartToStorage(filteredData);
|
|
51284
51104
|
return {
|
|
51285
51105
|
...state,
|
|
51286
|
-
data: filteredData
|
|
51106
|
+
data: filteredData
|
|
51287
51107
|
};
|
|
51288
51108
|
}
|
|
51289
51109
|
case DATA_ACTIONS.RESET_DATA:
|
|
@@ -51364,27 +51184,23 @@ to {
|
|
|
51364
51184
|
|
|
51365
51185
|
const setData = (data) => ({
|
|
51366
51186
|
type: DATA_ACTIONS.SET_DATA,
|
|
51367
|
-
payload: data
|
|
51187
|
+
payload: data
|
|
51368
51188
|
});
|
|
51369
51189
|
const setLoading = (isLoading) => ({
|
|
51370
51190
|
type: DATA_ACTIONS.SET_LOADING,
|
|
51371
|
-
payload: isLoading
|
|
51372
|
-
});
|
|
51373
|
-
const setPaymentMethod = (method) => ({
|
|
51374
|
-
type: DATA_ACTIONS.SET_PAYMENT_METHOD,
|
|
51375
|
-
payload: method,
|
|
51191
|
+
payload: isLoading
|
|
51376
51192
|
});
|
|
51377
51193
|
const setDeliveryDetails = (details) => ({
|
|
51378
51194
|
type: DATA_ACTIONS.SET_DELIVERY_DETAILS,
|
|
51379
|
-
payload: details
|
|
51195
|
+
payload: details
|
|
51380
51196
|
});
|
|
51381
51197
|
const editItemQuantity = (index, quantity) => ({
|
|
51382
51198
|
type: DATA_ACTIONS.EDIT_ITEM,
|
|
51383
|
-
payload: { index, quantity }
|
|
51199
|
+
payload: { index, quantity }
|
|
51384
51200
|
});
|
|
51385
51201
|
const removeItem = (index) => ({
|
|
51386
51202
|
type: DATA_ACTIONS.REMOVE_ITEM,
|
|
51387
|
-
payload: index
|
|
51203
|
+
payload: index
|
|
51388
51204
|
});
|
|
51389
51205
|
|
|
51390
51206
|
const setOpen = (isOpen) => ({
|
|
@@ -51410,14 +51226,14 @@ to {
|
|
|
51410
51226
|
payload: undefined,
|
|
51411
51227
|
});
|
|
51412
51228
|
|
|
51413
|
-
const useModalControl = (
|
|
51229
|
+
const useModalControl = () => {
|
|
51414
51230
|
const initialState = {
|
|
51415
51231
|
payment: initialPaymentState,
|
|
51416
51232
|
modal: initialModalState,
|
|
51417
51233
|
data: initialDataState,
|
|
51418
51234
|
};
|
|
51419
51235
|
const [state, dispatch] = reactExports.useReducer(rootReducer, initialState);
|
|
51420
|
-
const { payment: { paymentStatus, paymentDetails, additionalAmount }, modal: { open, currentIndex, isOpenAboutModal }, data: { data, store, isLoading, deliveryDetails
|
|
51236
|
+
const { payment: { paymentStatus, paymentDetails, additionalAmount }, modal: { open, currentIndex, isOpenAboutModal }, data: { data, store, isLoading, deliveryDetails }, } = state;
|
|
51421
51237
|
const currentModal = ModalNames[Object.values(ModalNames)[currentIndex]];
|
|
51422
51238
|
// const router = useRouter();
|
|
51423
51239
|
const openModal = () => {
|
|
@@ -51471,11 +51287,6 @@ to {
|
|
|
51471
51287
|
}
|
|
51472
51288
|
};
|
|
51473
51289
|
const completeOperation = () => {
|
|
51474
|
-
onSuccess?.({
|
|
51475
|
-
reference: paymentDetails?.reference ?? "",
|
|
51476
|
-
amount: paymentDetails?.amount ?? 0,
|
|
51477
|
-
currency: paymentDetails?.currency ?? "",
|
|
51478
|
-
});
|
|
51479
51290
|
reset();
|
|
51480
51291
|
};
|
|
51481
51292
|
const orderProducts = async () => {
|
|
@@ -51519,9 +51330,6 @@ to {
|
|
|
51519
51330
|
const setPaymentStatus$1 = (status) => {
|
|
51520
51331
|
dispatch(setPaymentStatus(status));
|
|
51521
51332
|
};
|
|
51522
|
-
const setPaymentMethod$1 = (method) => {
|
|
51523
|
-
dispatch(setPaymentMethod(method));
|
|
51524
|
-
};
|
|
51525
51333
|
const setAdditionalAmount$1 = (amount) => {
|
|
51526
51334
|
dispatch(setAdditionalAmount(amount));
|
|
51527
51335
|
};
|
|
@@ -51545,7 +51353,6 @@ to {
|
|
|
51545
51353
|
paymentDetails,
|
|
51546
51354
|
paymentStatus,
|
|
51547
51355
|
setPaymentStatus: setPaymentStatus$1,
|
|
51548
|
-
setPaymentMethod: setPaymentMethod$1,
|
|
51549
51356
|
additionalAmount,
|
|
51550
51357
|
setAdditionalAmount: setAdditionalAmount$1,
|
|
51551
51358
|
editItemQuantity: editItemQuantity$1,
|
|
@@ -51570,7 +51377,6 @@ to {
|
|
|
51570
51377
|
paymentDetails,
|
|
51571
51378
|
paymentStatus,
|
|
51572
51379
|
setPaymentStatus$1,
|
|
51573
|
-
setPaymentMethod$1,
|
|
51574
51380
|
additionalAmount,
|
|
51575
51381
|
setAdditionalAmount$1,
|
|
51576
51382
|
editItemQuantity$1,
|
|
@@ -51586,2747 +51392,19 @@ to {
|
|
|
51586
51392
|
return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(PaymentOptionsModal, {}), jsxRuntimeExports.jsx(PaymentDetailsModal, {}), jsxRuntimeExports.jsx(AwaitingPaymentModal, {}), jsxRuntimeExports.jsx(SuccessModal, {}), jsxRuntimeExports.jsx(AwaitingPaymentTimeoutModal, {})] }));
|
|
51587
51393
|
};
|
|
51588
51394
|
const ModalProvider = ({ children }) => {
|
|
51589
|
-
const
|
|
51590
|
-
const value = useModalControl({ onSuccess });
|
|
51395
|
+
const value = useModalControl();
|
|
51591
51396
|
return (jsxRuntimeExports.jsx(ModalContext.Provider, { value: value, children: jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(Modals, {}), children] }) }));
|
|
51592
51397
|
};
|
|
51593
51398
|
|
|
51594
|
-
/**
|
|
51595
|
-
* Based on Kendo UI Core expression code <https://github.com/telerik/kendo-ui-core#license-information>
|
|
51596
|
-
*/
|
|
51597
|
-
|
|
51598
|
-
function Cache(maxSize) {
|
|
51599
|
-
this._maxSize = maxSize;
|
|
51600
|
-
this.clear();
|
|
51601
|
-
}
|
|
51602
|
-
Cache.prototype.clear = function () {
|
|
51603
|
-
this._size = 0;
|
|
51604
|
-
this._values = Object.create(null);
|
|
51605
|
-
};
|
|
51606
|
-
Cache.prototype.get = function (key) {
|
|
51607
|
-
return this._values[key]
|
|
51608
|
-
};
|
|
51609
|
-
Cache.prototype.set = function (key, value) {
|
|
51610
|
-
this._size >= this._maxSize && this.clear();
|
|
51611
|
-
if (!(key in this._values)) this._size++;
|
|
51612
|
-
|
|
51613
|
-
return (this._values[key] = value)
|
|
51614
|
-
};
|
|
51615
|
-
|
|
51616
|
-
var SPLIT_REGEX = /[^.^\]^[]+|(?=\[\]|\.\.)/g,
|
|
51617
|
-
DIGIT_REGEX = /^\d+$/,
|
|
51618
|
-
LEAD_DIGIT_REGEX = /^\d/,
|
|
51619
|
-
SPEC_CHAR_REGEX = /[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g,
|
|
51620
|
-
CLEAN_QUOTES_REGEX = /^\s*(['"]?)(.*?)(\1)\s*$/,
|
|
51621
|
-
MAX_CACHE_SIZE = 512;
|
|
51622
|
-
|
|
51623
|
-
var pathCache = new Cache(MAX_CACHE_SIZE),
|
|
51624
|
-
setCache = new Cache(MAX_CACHE_SIZE),
|
|
51625
|
-
getCache = new Cache(MAX_CACHE_SIZE);
|
|
51626
|
-
|
|
51627
|
-
var propertyExpr = {
|
|
51628
|
-
Cache: Cache,
|
|
51629
|
-
|
|
51630
|
-
split: split,
|
|
51631
|
-
|
|
51632
|
-
normalizePath: normalizePath,
|
|
51633
|
-
|
|
51634
|
-
setter: function (path) {
|
|
51635
|
-
var parts = normalizePath(path);
|
|
51636
|
-
|
|
51637
|
-
return (
|
|
51638
|
-
setCache.get(path) ||
|
|
51639
|
-
setCache.set(path, function setter(obj, value) {
|
|
51640
|
-
var index = 0;
|
|
51641
|
-
var len = parts.length;
|
|
51642
|
-
var data = obj;
|
|
51643
|
-
|
|
51644
|
-
while (index < len - 1) {
|
|
51645
|
-
var part = parts[index];
|
|
51646
|
-
if (
|
|
51647
|
-
part === '__proto__' ||
|
|
51648
|
-
part === 'constructor' ||
|
|
51649
|
-
part === 'prototype'
|
|
51650
|
-
) {
|
|
51651
|
-
return obj
|
|
51652
|
-
}
|
|
51653
|
-
|
|
51654
|
-
data = data[parts[index++]];
|
|
51655
|
-
}
|
|
51656
|
-
data[parts[index]] = value;
|
|
51657
|
-
})
|
|
51658
|
-
)
|
|
51659
|
-
},
|
|
51660
|
-
|
|
51661
|
-
getter: function (path, safe) {
|
|
51662
|
-
var parts = normalizePath(path);
|
|
51663
|
-
return (
|
|
51664
|
-
getCache.get(path) ||
|
|
51665
|
-
getCache.set(path, function getter(data) {
|
|
51666
|
-
var index = 0,
|
|
51667
|
-
len = parts.length;
|
|
51668
|
-
while (index < len) {
|
|
51669
|
-
if (data != null || !safe) data = data[parts[index++]];
|
|
51670
|
-
else return
|
|
51671
|
-
}
|
|
51672
|
-
return data
|
|
51673
|
-
})
|
|
51674
|
-
)
|
|
51675
|
-
},
|
|
51676
|
-
|
|
51677
|
-
join: function (segments) {
|
|
51678
|
-
return segments.reduce(function (path, part) {
|
|
51679
|
-
return (
|
|
51680
|
-
path +
|
|
51681
|
-
(isQuoted(part) || DIGIT_REGEX.test(part)
|
|
51682
|
-
? '[' + part + ']'
|
|
51683
|
-
: (path ? '.' : '') + part)
|
|
51684
|
-
)
|
|
51685
|
-
}, '')
|
|
51686
|
-
},
|
|
51687
|
-
|
|
51688
|
-
forEach: function (path, cb, thisArg) {
|
|
51689
|
-
forEach(Array.isArray(path) ? path : split(path), cb, thisArg);
|
|
51690
|
-
},
|
|
51691
|
-
};
|
|
51692
|
-
|
|
51693
|
-
function normalizePath(path) {
|
|
51694
|
-
return (
|
|
51695
|
-
pathCache.get(path) ||
|
|
51696
|
-
pathCache.set(
|
|
51697
|
-
path,
|
|
51698
|
-
split(path).map(function (part) {
|
|
51699
|
-
return part.replace(CLEAN_QUOTES_REGEX, '$2')
|
|
51700
|
-
})
|
|
51701
|
-
)
|
|
51702
|
-
)
|
|
51703
|
-
}
|
|
51704
|
-
|
|
51705
|
-
function split(path) {
|
|
51706
|
-
return path.match(SPLIT_REGEX) || ['']
|
|
51707
|
-
}
|
|
51708
|
-
|
|
51709
|
-
function forEach(parts, iter, thisArg) {
|
|
51710
|
-
var len = parts.length,
|
|
51711
|
-
part,
|
|
51712
|
-
idx,
|
|
51713
|
-
isArray,
|
|
51714
|
-
isBracket;
|
|
51715
|
-
|
|
51716
|
-
for (idx = 0; idx < len; idx++) {
|
|
51717
|
-
part = parts[idx];
|
|
51718
|
-
|
|
51719
|
-
if (part) {
|
|
51720
|
-
if (shouldBeQuoted(part)) {
|
|
51721
|
-
part = '"' + part + '"';
|
|
51722
|
-
}
|
|
51723
|
-
|
|
51724
|
-
isBracket = isQuoted(part);
|
|
51725
|
-
isArray = !isBracket && /^\d+$/.test(part);
|
|
51726
|
-
|
|
51727
|
-
iter.call(thisArg, part, isBracket, isArray, idx, parts);
|
|
51728
|
-
}
|
|
51729
|
-
}
|
|
51730
|
-
}
|
|
51731
|
-
|
|
51732
|
-
function isQuoted(str) {
|
|
51733
|
-
return (
|
|
51734
|
-
typeof str === 'string' && str && ["'", '"'].indexOf(str.charAt(0)) !== -1
|
|
51735
|
-
)
|
|
51736
|
-
}
|
|
51737
|
-
|
|
51738
|
-
function hasLeadingNumber(part) {
|
|
51739
|
-
return part.match(LEAD_DIGIT_REGEX) && !part.match(DIGIT_REGEX)
|
|
51740
|
-
}
|
|
51741
|
-
|
|
51742
|
-
function hasSpecialChars(part) {
|
|
51743
|
-
return SPEC_CHAR_REGEX.test(part)
|
|
51744
|
-
}
|
|
51745
|
-
|
|
51746
|
-
function shouldBeQuoted(part) {
|
|
51747
|
-
return !isQuoted(part) && (hasLeadingNumber(part) || hasSpecialChars(part))
|
|
51748
|
-
}
|
|
51749
|
-
|
|
51750
|
-
const reWords = /[A-Z\xc0-\xd6\xd8-\xde]?[a-z\xdf-\xf6\xf8-\xff]+(?:['’](?:d|ll|m|re|s|t|ve))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde]|$)|(?:[A-Z\xc0-\xd6\xd8-\xde]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:D|LL|M|RE|S|T|VE))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde](?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])|$)|[A-Z\xc0-\xd6\xd8-\xde]?(?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:d|ll|m|re|s|t|ve))?|[A-Z\xc0-\xd6\xd8-\xde]+(?:['’](?:D|LL|M|RE|S|T|VE))?|\d*(?:1ST|2ND|3RD|(?![123])\dTH)(?=\b|[a-z_])|\d*(?:1st|2nd|3rd|(?![123])\dth)(?=\b|[A-Z_])|\d+|(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?)*/g;
|
|
51751
|
-
|
|
51752
|
-
const words = (str) => str.match(reWords) || [];
|
|
51753
|
-
|
|
51754
|
-
const upperFirst = (str) => str[0].toUpperCase() + str.slice(1);
|
|
51755
|
-
|
|
51756
|
-
const join = (str, d) => words(str).join(d).toLowerCase();
|
|
51757
|
-
|
|
51758
|
-
const camelCase = (str) =>
|
|
51759
|
-
words(str).reduce(
|
|
51760
|
-
(acc, next) =>
|
|
51761
|
-
`${acc}${
|
|
51762
|
-
!acc
|
|
51763
|
-
? next.toLowerCase()
|
|
51764
|
-
: next[0].toUpperCase() + next.slice(1).toLowerCase()
|
|
51765
|
-
}`,
|
|
51766
|
-
'',
|
|
51767
|
-
);
|
|
51768
|
-
|
|
51769
|
-
const pascalCase = (str) => upperFirst(camelCase(str));
|
|
51770
|
-
|
|
51771
|
-
const snakeCase = (str) => join(str, '_');
|
|
51772
|
-
|
|
51773
|
-
const kebabCase = (str) => join(str, '-');
|
|
51774
|
-
|
|
51775
|
-
const sentenceCase = (str) => upperFirst(join(str, ' '));
|
|
51776
|
-
|
|
51777
|
-
const titleCase = (str) => words(str).map(upperFirst).join(' ');
|
|
51778
|
-
|
|
51779
|
-
var tinyCase = {
|
|
51780
|
-
words,
|
|
51781
|
-
upperFirst,
|
|
51782
|
-
camelCase,
|
|
51783
|
-
pascalCase,
|
|
51784
|
-
snakeCase,
|
|
51785
|
-
kebabCase,
|
|
51786
|
-
sentenceCase,
|
|
51787
|
-
titleCase,
|
|
51788
|
-
};
|
|
51789
|
-
|
|
51790
|
-
var toposort$2 = {exports: {}};
|
|
51791
|
-
|
|
51792
|
-
/**
|
|
51793
|
-
* Topological sorting function
|
|
51794
|
-
*
|
|
51795
|
-
* @param {Array} edges
|
|
51796
|
-
* @returns {Array}
|
|
51797
|
-
*/
|
|
51798
|
-
|
|
51799
|
-
toposort$2.exports = function(edges) {
|
|
51800
|
-
return toposort(uniqueNodes(edges), edges)
|
|
51801
|
-
};
|
|
51802
|
-
|
|
51803
|
-
toposort$2.exports.array = toposort;
|
|
51804
|
-
|
|
51805
|
-
function toposort(nodes, edges) {
|
|
51806
|
-
var cursor = nodes.length
|
|
51807
|
-
, sorted = new Array(cursor)
|
|
51808
|
-
, visited = {}
|
|
51809
|
-
, i = cursor
|
|
51810
|
-
// Better data structures make algorithm much faster.
|
|
51811
|
-
, outgoingEdges = makeOutgoingEdges(edges)
|
|
51812
|
-
, nodesHash = makeNodesHash(nodes);
|
|
51813
|
-
|
|
51814
|
-
// check for unknown nodes
|
|
51815
|
-
edges.forEach(function(edge) {
|
|
51816
|
-
if (!nodesHash.has(edge[0]) || !nodesHash.has(edge[1])) {
|
|
51817
|
-
throw new Error('Unknown node. There is an unknown node in the supplied edges.')
|
|
51818
|
-
}
|
|
51819
|
-
});
|
|
51820
|
-
|
|
51821
|
-
while (i--) {
|
|
51822
|
-
if (!visited[i]) visit(nodes[i], i, new Set());
|
|
51823
|
-
}
|
|
51824
|
-
|
|
51825
|
-
return sorted
|
|
51826
|
-
|
|
51827
|
-
function visit(node, i, predecessors) {
|
|
51828
|
-
if(predecessors.has(node)) {
|
|
51829
|
-
var nodeRep;
|
|
51830
|
-
try {
|
|
51831
|
-
nodeRep = ", node was:" + JSON.stringify(node);
|
|
51832
|
-
} catch(e) {
|
|
51833
|
-
nodeRep = "";
|
|
51834
|
-
}
|
|
51835
|
-
throw new Error('Cyclic dependency' + nodeRep)
|
|
51836
|
-
}
|
|
51837
|
-
|
|
51838
|
-
if (!nodesHash.has(node)) {
|
|
51839
|
-
throw new Error('Found unknown node. Make sure to provided all involved nodes. Unknown node: '+JSON.stringify(node))
|
|
51840
|
-
}
|
|
51841
|
-
|
|
51842
|
-
if (visited[i]) return;
|
|
51843
|
-
visited[i] = true;
|
|
51844
|
-
|
|
51845
|
-
var outgoing = outgoingEdges.get(node) || new Set();
|
|
51846
|
-
outgoing = Array.from(outgoing);
|
|
51847
|
-
|
|
51848
|
-
if (i = outgoing.length) {
|
|
51849
|
-
predecessors.add(node);
|
|
51850
|
-
do {
|
|
51851
|
-
var child = outgoing[--i];
|
|
51852
|
-
visit(child, nodesHash.get(child), predecessors);
|
|
51853
|
-
} while (i)
|
|
51854
|
-
predecessors.delete(node);
|
|
51855
|
-
}
|
|
51856
|
-
|
|
51857
|
-
sorted[--cursor] = node;
|
|
51858
|
-
}
|
|
51859
|
-
}
|
|
51860
|
-
|
|
51861
|
-
function uniqueNodes(arr){
|
|
51862
|
-
var res = new Set();
|
|
51863
|
-
for (var i = 0, len = arr.length; i < len; i++) {
|
|
51864
|
-
var edge = arr[i];
|
|
51865
|
-
res.add(edge[0]);
|
|
51866
|
-
res.add(edge[1]);
|
|
51867
|
-
}
|
|
51868
|
-
return Array.from(res)
|
|
51869
|
-
}
|
|
51870
|
-
|
|
51871
|
-
function makeOutgoingEdges(arr){
|
|
51872
|
-
var edges = new Map();
|
|
51873
|
-
for (var i = 0, len = arr.length; i < len; i++) {
|
|
51874
|
-
var edge = arr[i];
|
|
51875
|
-
if (!edges.has(edge[0])) edges.set(edge[0], new Set());
|
|
51876
|
-
if (!edges.has(edge[1])) edges.set(edge[1], new Set());
|
|
51877
|
-
edges.get(edge[0]).add(edge[1]);
|
|
51878
|
-
}
|
|
51879
|
-
return edges
|
|
51880
|
-
}
|
|
51881
|
-
|
|
51882
|
-
function makeNodesHash(arr){
|
|
51883
|
-
var res = new Map();
|
|
51884
|
-
for (var i = 0, len = arr.length; i < len; i++) {
|
|
51885
|
-
res.set(arr[i], i);
|
|
51886
|
-
}
|
|
51887
|
-
return res
|
|
51888
|
-
}
|
|
51889
|
-
|
|
51890
|
-
var toposortExports = toposort$2.exports;
|
|
51891
|
-
var toposort$1 = /*@__PURE__*/getDefaultExportFromCjs(toposortExports);
|
|
51892
|
-
|
|
51893
|
-
const toString = Object.prototype.toString;
|
|
51894
|
-
const errorToString = Error.prototype.toString;
|
|
51895
|
-
const regExpToString = RegExp.prototype.toString;
|
|
51896
|
-
const symbolToString = typeof Symbol !== 'undefined' ? Symbol.prototype.toString : () => '';
|
|
51897
|
-
const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
|
|
51898
|
-
function printNumber(val) {
|
|
51899
|
-
if (val != +val) return 'NaN';
|
|
51900
|
-
const isNegativeZero = val === 0 && 1 / val < 0;
|
|
51901
|
-
return isNegativeZero ? '-0' : '' + val;
|
|
51902
|
-
}
|
|
51903
|
-
function printSimpleValue(val, quoteStrings = false) {
|
|
51904
|
-
if (val == null || val === true || val === false) return '' + val;
|
|
51905
|
-
const typeOf = typeof val;
|
|
51906
|
-
if (typeOf === 'number') return printNumber(val);
|
|
51907
|
-
if (typeOf === 'string') return quoteStrings ? `"${val}"` : val;
|
|
51908
|
-
if (typeOf === 'function') return '[Function ' + (val.name || 'anonymous') + ']';
|
|
51909
|
-
if (typeOf === 'symbol') return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)');
|
|
51910
|
-
const tag = toString.call(val).slice(8, -1);
|
|
51911
|
-
if (tag === 'Date') return isNaN(val.getTime()) ? '' + val : val.toISOString(val);
|
|
51912
|
-
if (tag === 'Error' || val instanceof Error) return '[' + errorToString.call(val) + ']';
|
|
51913
|
-
if (tag === 'RegExp') return regExpToString.call(val);
|
|
51914
|
-
return null;
|
|
51915
|
-
}
|
|
51916
|
-
function printValue(value, quoteStrings) {
|
|
51917
|
-
let result = printSimpleValue(value, quoteStrings);
|
|
51918
|
-
if (result !== null) return result;
|
|
51919
|
-
return JSON.stringify(value, function (key, value) {
|
|
51920
|
-
let result = printSimpleValue(this[key], quoteStrings);
|
|
51921
|
-
if (result !== null) return result;
|
|
51922
|
-
return value;
|
|
51923
|
-
}, 2);
|
|
51924
|
-
}
|
|
51925
|
-
|
|
51926
|
-
function toArray(value) {
|
|
51927
|
-
return value == null ? [] : [].concat(value);
|
|
51928
|
-
}
|
|
51929
|
-
|
|
51930
|
-
let _Symbol$toStringTag, _Symbol$hasInstance, _Symbol$toStringTag2;
|
|
51931
|
-
let strReg = /\$\{\s*(\w+)\s*\}/g;
|
|
51932
|
-
_Symbol$toStringTag = Symbol.toStringTag;
|
|
51933
|
-
class ValidationErrorNoStack {
|
|
51934
|
-
constructor(errorOrErrors, value, field, type) {
|
|
51935
|
-
this.name = void 0;
|
|
51936
|
-
this.message = void 0;
|
|
51937
|
-
this.value = void 0;
|
|
51938
|
-
this.path = void 0;
|
|
51939
|
-
this.type = void 0;
|
|
51940
|
-
this.params = void 0;
|
|
51941
|
-
this.errors = void 0;
|
|
51942
|
-
this.inner = void 0;
|
|
51943
|
-
this[_Symbol$toStringTag] = 'Error';
|
|
51944
|
-
this.name = 'ValidationError';
|
|
51945
|
-
this.value = value;
|
|
51946
|
-
this.path = field;
|
|
51947
|
-
this.type = type;
|
|
51948
|
-
this.errors = [];
|
|
51949
|
-
this.inner = [];
|
|
51950
|
-
toArray(errorOrErrors).forEach(err => {
|
|
51951
|
-
if (ValidationError.isError(err)) {
|
|
51952
|
-
this.errors.push(...err.errors);
|
|
51953
|
-
const innerErrors = err.inner.length ? err.inner : [err];
|
|
51954
|
-
this.inner.push(...innerErrors);
|
|
51955
|
-
} else {
|
|
51956
|
-
this.errors.push(err);
|
|
51957
|
-
}
|
|
51958
|
-
});
|
|
51959
|
-
this.message = this.errors.length > 1 ? `${this.errors.length} errors occurred` : this.errors[0];
|
|
51960
|
-
}
|
|
51961
|
-
}
|
|
51962
|
-
_Symbol$hasInstance = Symbol.hasInstance;
|
|
51963
|
-
_Symbol$toStringTag2 = Symbol.toStringTag;
|
|
51964
|
-
class ValidationError extends Error {
|
|
51965
|
-
static formatError(message, params) {
|
|
51966
|
-
// Attempt to make the path more friendly for error message interpolation.
|
|
51967
|
-
const path = params.label || params.path || 'this';
|
|
51968
|
-
// Store the original path under `originalPath` so it isn't lost to custom
|
|
51969
|
-
// message functions; e.g., ones provided in `setLocale()` calls.
|
|
51970
|
-
params = Object.assign({}, params, {
|
|
51971
|
-
path,
|
|
51972
|
-
originalPath: params.path
|
|
51973
|
-
});
|
|
51974
|
-
if (typeof message === 'string') return message.replace(strReg, (_, key) => printValue(params[key]));
|
|
51975
|
-
if (typeof message === 'function') return message(params);
|
|
51976
|
-
return message;
|
|
51977
|
-
}
|
|
51978
|
-
static isError(err) {
|
|
51979
|
-
return err && err.name === 'ValidationError';
|
|
51980
|
-
}
|
|
51981
|
-
constructor(errorOrErrors, value, field, type, disableStack) {
|
|
51982
|
-
const errorNoStack = new ValidationErrorNoStack(errorOrErrors, value, field, type);
|
|
51983
|
-
if (disableStack) {
|
|
51984
|
-
return errorNoStack;
|
|
51985
|
-
}
|
|
51986
|
-
super();
|
|
51987
|
-
this.value = void 0;
|
|
51988
|
-
this.path = void 0;
|
|
51989
|
-
this.type = void 0;
|
|
51990
|
-
this.params = void 0;
|
|
51991
|
-
this.errors = [];
|
|
51992
|
-
this.inner = [];
|
|
51993
|
-
this[_Symbol$toStringTag2] = 'Error';
|
|
51994
|
-
this.name = errorNoStack.name;
|
|
51995
|
-
this.message = errorNoStack.message;
|
|
51996
|
-
this.type = errorNoStack.type;
|
|
51997
|
-
this.value = errorNoStack.value;
|
|
51998
|
-
this.path = errorNoStack.path;
|
|
51999
|
-
this.errors = errorNoStack.errors;
|
|
52000
|
-
this.inner = errorNoStack.inner;
|
|
52001
|
-
if (Error.captureStackTrace) {
|
|
52002
|
-
Error.captureStackTrace(this, ValidationError);
|
|
52003
|
-
}
|
|
52004
|
-
}
|
|
52005
|
-
static [_Symbol$hasInstance](inst) {
|
|
52006
|
-
return ValidationErrorNoStack[Symbol.hasInstance](inst) || super[Symbol.hasInstance](inst);
|
|
52007
|
-
}
|
|
52008
|
-
}
|
|
52009
|
-
|
|
52010
|
-
let mixed = {
|
|
52011
|
-
default: '${path} is invalid',
|
|
52012
|
-
required: '${path} is a required field',
|
|
52013
|
-
defined: '${path} must be defined',
|
|
52014
|
-
notNull: '${path} cannot be null',
|
|
52015
|
-
oneOf: '${path} must be one of the following values: ${values}',
|
|
52016
|
-
notOneOf: '${path} must not be one of the following values: ${values}',
|
|
52017
|
-
notType: ({
|
|
52018
|
-
path,
|
|
52019
|
-
type,
|
|
52020
|
-
value,
|
|
52021
|
-
originalValue
|
|
52022
|
-
}) => {
|
|
52023
|
-
const castMsg = originalValue != null && originalValue !== value ? ` (cast from the value \`${printValue(originalValue, true)}\`).` : '.';
|
|
52024
|
-
return type !== 'mixed' ? `${path} must be a \`${type}\` type, ` + `but the final value was: \`${printValue(value, true)}\`` + castMsg : `${path} must match the configured type. ` + `The validated value was: \`${printValue(value, true)}\`` + castMsg;
|
|
52025
|
-
}
|
|
52026
|
-
};
|
|
52027
|
-
let string = {
|
|
52028
|
-
length: '${path} must be exactly ${length} characters',
|
|
52029
|
-
min: '${path} must be at least ${min} characters',
|
|
52030
|
-
max: '${path} must be at most ${max} characters',
|
|
52031
|
-
matches: '${path} must match the following: "${regex}"',
|
|
52032
|
-
email: '${path} must be a valid email',
|
|
52033
|
-
url: '${path} must be a valid URL',
|
|
52034
|
-
uuid: '${path} must be a valid UUID',
|
|
52035
|
-
datetime: '${path} must be a valid ISO date-time',
|
|
52036
|
-
datetime_precision: '${path} must be a valid ISO date-time with a sub-second precision of exactly ${precision} digits',
|
|
52037
|
-
datetime_offset: '${path} must be a valid ISO date-time with UTC "Z" timezone',
|
|
52038
|
-
trim: '${path} must be a trimmed string',
|
|
52039
|
-
lowercase: '${path} must be a lowercase string',
|
|
52040
|
-
uppercase: '${path} must be a upper case string'
|
|
52041
|
-
};
|
|
52042
|
-
let number = {
|
|
52043
|
-
min: '${path} must be greater than or equal to ${min}',
|
|
52044
|
-
max: '${path} must be less than or equal to ${max}',
|
|
52045
|
-
lessThan: '${path} must be less than ${less}',
|
|
52046
|
-
moreThan: '${path} must be greater than ${more}',
|
|
52047
|
-
positive: '${path} must be a positive number',
|
|
52048
|
-
negative: '${path} must be a negative number',
|
|
52049
|
-
integer: '${path} must be an integer'
|
|
52050
|
-
};
|
|
52051
|
-
let date = {
|
|
52052
|
-
min: '${path} field must be later than ${min}',
|
|
52053
|
-
max: '${path} field must be at earlier than ${max}'
|
|
52054
|
-
};
|
|
52055
|
-
let boolean = {
|
|
52056
|
-
isValue: '${path} field must be ${value}'
|
|
52057
|
-
};
|
|
52058
|
-
let object = {
|
|
52059
|
-
noUnknown: '${path} field has unspecified keys: ${unknown}',
|
|
52060
|
-
exact: '${path} object contains unknown properties: ${properties}'
|
|
52061
|
-
};
|
|
52062
|
-
let array = {
|
|
52063
|
-
min: '${path} field must have at least ${min} items',
|
|
52064
|
-
max: '${path} field must have less than or equal to ${max} items',
|
|
52065
|
-
length: '${path} must have ${length} items'
|
|
52066
|
-
};
|
|
52067
|
-
let tuple = {
|
|
52068
|
-
notType: params => {
|
|
52069
|
-
const {
|
|
52070
|
-
path,
|
|
52071
|
-
value,
|
|
52072
|
-
spec
|
|
52073
|
-
} = params;
|
|
52074
|
-
const typeLen = spec.types.length;
|
|
52075
|
-
if (Array.isArray(value)) {
|
|
52076
|
-
if (value.length < typeLen) return `${path} tuple value has too few items, expected a length of ${typeLen} but got ${value.length} for value: \`${printValue(value, true)}\``;
|
|
52077
|
-
if (value.length > typeLen) return `${path} tuple value has too many items, expected a length of ${typeLen} but got ${value.length} for value: \`${printValue(value, true)}\``;
|
|
52078
|
-
}
|
|
52079
|
-
return ValidationError.formatError(mixed.notType, params);
|
|
52080
|
-
}
|
|
52081
|
-
};
|
|
52082
|
-
Object.assign(Object.create(null), {
|
|
52083
|
-
mixed,
|
|
52084
|
-
string,
|
|
52085
|
-
number,
|
|
52086
|
-
date,
|
|
52087
|
-
object,
|
|
52088
|
-
array,
|
|
52089
|
-
boolean,
|
|
52090
|
-
tuple
|
|
52091
|
-
});
|
|
52092
|
-
|
|
52093
|
-
const isSchema = obj => obj && obj.__isYupSchema__;
|
|
52094
|
-
|
|
52095
|
-
class Condition {
|
|
52096
|
-
static fromOptions(refs, config) {
|
|
52097
|
-
if (!config.then && !config.otherwise) throw new TypeError('either `then:` or `otherwise:` is required for `when()` conditions');
|
|
52098
|
-
let {
|
|
52099
|
-
is,
|
|
52100
|
-
then,
|
|
52101
|
-
otherwise
|
|
52102
|
-
} = config;
|
|
52103
|
-
let check = typeof is === 'function' ? is : (...values) => values.every(value => value === is);
|
|
52104
|
-
return new Condition(refs, (values, schema) => {
|
|
52105
|
-
var _branch;
|
|
52106
|
-
let branch = check(...values) ? then : otherwise;
|
|
52107
|
-
return (_branch = branch == null ? void 0 : branch(schema)) != null ? _branch : schema;
|
|
52108
|
-
});
|
|
52109
|
-
}
|
|
52110
|
-
constructor(refs, builder) {
|
|
52111
|
-
this.fn = void 0;
|
|
52112
|
-
this.refs = refs;
|
|
52113
|
-
this.refs = refs;
|
|
52114
|
-
this.fn = builder;
|
|
52115
|
-
}
|
|
52116
|
-
resolve(base, options) {
|
|
52117
|
-
let values = this.refs.map(ref =>
|
|
52118
|
-
// TODO: ? operator here?
|
|
52119
|
-
ref.getValue(options == null ? void 0 : options.value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context));
|
|
52120
|
-
let schema = this.fn(values, base, options);
|
|
52121
|
-
if (schema === undefined ||
|
|
52122
|
-
// @ts-ignore this can be base
|
|
52123
|
-
schema === base) {
|
|
52124
|
-
return base;
|
|
52125
|
-
}
|
|
52126
|
-
if (!isSchema(schema)) throw new TypeError('conditions must return a schema object');
|
|
52127
|
-
return schema.resolve(options);
|
|
52128
|
-
}
|
|
52129
|
-
}
|
|
52130
|
-
|
|
52131
|
-
const prefixes = {
|
|
52132
|
-
context: '$',
|
|
52133
|
-
value: '.'
|
|
52134
|
-
};
|
|
52135
|
-
class Reference {
|
|
52136
|
-
constructor(key, options = {}) {
|
|
52137
|
-
this.key = void 0;
|
|
52138
|
-
this.isContext = void 0;
|
|
52139
|
-
this.isValue = void 0;
|
|
52140
|
-
this.isSibling = void 0;
|
|
52141
|
-
this.path = void 0;
|
|
52142
|
-
this.getter = void 0;
|
|
52143
|
-
this.map = void 0;
|
|
52144
|
-
if (typeof key !== 'string') throw new TypeError('ref must be a string, got: ' + key);
|
|
52145
|
-
this.key = key.trim();
|
|
52146
|
-
if (key === '') throw new TypeError('ref must be a non-empty string');
|
|
52147
|
-
this.isContext = this.key[0] === prefixes.context;
|
|
52148
|
-
this.isValue = this.key[0] === prefixes.value;
|
|
52149
|
-
this.isSibling = !this.isContext && !this.isValue;
|
|
52150
|
-
let prefix = this.isContext ? prefixes.context : this.isValue ? prefixes.value : '';
|
|
52151
|
-
this.path = this.key.slice(prefix.length);
|
|
52152
|
-
this.getter = this.path && propertyExpr.getter(this.path, true);
|
|
52153
|
-
this.map = options.map;
|
|
52154
|
-
}
|
|
52155
|
-
getValue(value, parent, context) {
|
|
52156
|
-
let result = this.isContext ? context : this.isValue ? value : parent;
|
|
52157
|
-
if (this.getter) result = this.getter(result || {});
|
|
52158
|
-
if (this.map) result = this.map(result);
|
|
52159
|
-
return result;
|
|
52160
|
-
}
|
|
52161
|
-
|
|
52162
|
-
/**
|
|
52163
|
-
*
|
|
52164
|
-
* @param {*} value
|
|
52165
|
-
* @param {Object} options
|
|
52166
|
-
* @param {Object=} options.context
|
|
52167
|
-
* @param {Object=} options.parent
|
|
52168
|
-
*/
|
|
52169
|
-
cast(value, options) {
|
|
52170
|
-
return this.getValue(value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context);
|
|
52171
|
-
}
|
|
52172
|
-
resolve() {
|
|
52173
|
-
return this;
|
|
52174
|
-
}
|
|
52175
|
-
describe() {
|
|
52176
|
-
return {
|
|
52177
|
-
type: 'ref',
|
|
52178
|
-
key: this.key
|
|
52179
|
-
};
|
|
52180
|
-
}
|
|
52181
|
-
toString() {
|
|
52182
|
-
return `Ref(${this.key})`;
|
|
52183
|
-
}
|
|
52184
|
-
static isRef(value) {
|
|
52185
|
-
return value && value.__isYupRef;
|
|
52186
|
-
}
|
|
52187
|
-
}
|
|
52188
|
-
|
|
52189
|
-
// @ts-ignore
|
|
52190
|
-
Reference.prototype.__isYupRef = true;
|
|
52191
|
-
|
|
52192
|
-
const isAbsent = value => value == null;
|
|
52193
|
-
|
|
52194
|
-
function createValidation(config) {
|
|
52195
|
-
function validate({
|
|
52196
|
-
value,
|
|
52197
|
-
path = '',
|
|
52198
|
-
options,
|
|
52199
|
-
originalValue,
|
|
52200
|
-
schema
|
|
52201
|
-
}, panic, next) {
|
|
52202
|
-
const {
|
|
52203
|
-
name,
|
|
52204
|
-
test,
|
|
52205
|
-
params,
|
|
52206
|
-
message,
|
|
52207
|
-
skipAbsent
|
|
52208
|
-
} = config;
|
|
52209
|
-
let {
|
|
52210
|
-
parent,
|
|
52211
|
-
context,
|
|
52212
|
-
abortEarly = schema.spec.abortEarly,
|
|
52213
|
-
disableStackTrace = schema.spec.disableStackTrace
|
|
52214
|
-
} = options;
|
|
52215
|
-
const resolveOptions = {
|
|
52216
|
-
value,
|
|
52217
|
-
parent,
|
|
52218
|
-
context
|
|
52219
|
-
};
|
|
52220
|
-
function createError(overrides = {}) {
|
|
52221
|
-
const nextParams = resolveParams(Object.assign({
|
|
52222
|
-
value,
|
|
52223
|
-
originalValue,
|
|
52224
|
-
label: schema.spec.label,
|
|
52225
|
-
path: overrides.path || path,
|
|
52226
|
-
spec: schema.spec,
|
|
52227
|
-
disableStackTrace: overrides.disableStackTrace || disableStackTrace
|
|
52228
|
-
}, params, overrides.params), resolveOptions);
|
|
52229
|
-
const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name, nextParams.disableStackTrace);
|
|
52230
|
-
error.params = nextParams;
|
|
52231
|
-
return error;
|
|
52232
|
-
}
|
|
52233
|
-
const invalid = abortEarly ? panic : next;
|
|
52234
|
-
let ctx = {
|
|
52235
|
-
path,
|
|
52236
|
-
parent,
|
|
52237
|
-
type: name,
|
|
52238
|
-
from: options.from,
|
|
52239
|
-
createError,
|
|
52240
|
-
resolve(item) {
|
|
52241
|
-
return resolveMaybeRef(item, resolveOptions);
|
|
52242
|
-
},
|
|
52243
|
-
options,
|
|
52244
|
-
originalValue,
|
|
52245
|
-
schema
|
|
52246
|
-
};
|
|
52247
|
-
const handleResult = validOrError => {
|
|
52248
|
-
if (ValidationError.isError(validOrError)) invalid(validOrError);else if (!validOrError) invalid(createError());else next(null);
|
|
52249
|
-
};
|
|
52250
|
-
const handleError = err => {
|
|
52251
|
-
if (ValidationError.isError(err)) invalid(err);else panic(err);
|
|
52252
|
-
};
|
|
52253
|
-
const shouldSkip = skipAbsent && isAbsent(value);
|
|
52254
|
-
if (shouldSkip) {
|
|
52255
|
-
return handleResult(true);
|
|
52256
|
-
}
|
|
52257
|
-
let result;
|
|
52258
|
-
try {
|
|
52259
|
-
var _result;
|
|
52260
|
-
result = test.call(ctx, value, ctx);
|
|
52261
|
-
if (typeof ((_result = result) == null ? void 0 : _result.then) === 'function') {
|
|
52262
|
-
if (options.sync) {
|
|
52263
|
-
throw new Error(`Validation test of type: "${ctx.type}" returned a Promise during a synchronous validate. ` + `This test will finish after the validate call has returned`);
|
|
52264
|
-
}
|
|
52265
|
-
return Promise.resolve(result).then(handleResult, handleError);
|
|
52266
|
-
}
|
|
52267
|
-
} catch (err) {
|
|
52268
|
-
handleError(err);
|
|
52269
|
-
return;
|
|
52270
|
-
}
|
|
52271
|
-
handleResult(result);
|
|
52272
|
-
}
|
|
52273
|
-
validate.OPTIONS = config;
|
|
52274
|
-
return validate;
|
|
52275
|
-
}
|
|
52276
|
-
|
|
52277
|
-
// Warning: mutates the input
|
|
52278
|
-
function resolveParams(params, options) {
|
|
52279
|
-
if (!params) return params;
|
|
52280
|
-
for (const key of Object.keys(params)) {
|
|
52281
|
-
params[key] = resolveMaybeRef(params[key], options);
|
|
52282
|
-
}
|
|
52283
|
-
return params;
|
|
52284
|
-
}
|
|
52285
|
-
function resolveMaybeRef(item, options) {
|
|
52286
|
-
return Reference.isRef(item) ? item.getValue(options.value, options.parent, options.context) : item;
|
|
52287
|
-
}
|
|
52288
|
-
|
|
52289
|
-
function getIn(schema, path, value, context = value) {
|
|
52290
|
-
let parent, lastPart, lastPartDebug;
|
|
52291
|
-
|
|
52292
|
-
// root path: ''
|
|
52293
|
-
if (!path) return {
|
|
52294
|
-
parent,
|
|
52295
|
-
parentPath: path,
|
|
52296
|
-
schema
|
|
52297
|
-
};
|
|
52298
|
-
propertyExpr.forEach(path, (_part, isBracket, isArray) => {
|
|
52299
|
-
let part = isBracket ? _part.slice(1, _part.length - 1) : _part;
|
|
52300
|
-
schema = schema.resolve({
|
|
52301
|
-
context,
|
|
52302
|
-
parent,
|
|
52303
|
-
value
|
|
52304
|
-
});
|
|
52305
|
-
let isTuple = schema.type === 'tuple';
|
|
52306
|
-
let idx = isArray ? parseInt(part, 10) : 0;
|
|
52307
|
-
if (schema.innerType || isTuple) {
|
|
52308
|
-
if (isTuple && !isArray) throw new Error(`Yup.reach cannot implicitly index into a tuple type. the path part "${lastPartDebug}" must contain an index to the tuple element, e.g. "${lastPartDebug}[0]"`);
|
|
52309
|
-
if (value && idx >= value.length) {
|
|
52310
|
-
throw new Error(`Yup.reach cannot resolve an array item at index: ${_part}, in the path: ${path}. ` + `because there is no value at that index. `);
|
|
52311
|
-
}
|
|
52312
|
-
parent = value;
|
|
52313
|
-
value = value && value[idx];
|
|
52314
|
-
schema = isTuple ? schema.spec.types[idx] : schema.innerType;
|
|
52315
|
-
}
|
|
52316
|
-
|
|
52317
|
-
// sometimes the array index part of a path doesn't exist: "nested.arr.child"
|
|
52318
|
-
// in these cases the current part is the next schema and should be processed
|
|
52319
|
-
// in this iteration. For cases where the index signature is included this
|
|
52320
|
-
// check will fail and we'll handle the `child` part on the next iteration like normal
|
|
52321
|
-
if (!isArray) {
|
|
52322
|
-
if (!schema.fields || !schema.fields[part]) throw new Error(`The schema does not contain the path: ${path}. ` + `(failed at: ${lastPartDebug} which is a type: "${schema.type}")`);
|
|
52323
|
-
parent = value;
|
|
52324
|
-
value = value && value[part];
|
|
52325
|
-
schema = schema.fields[part];
|
|
52326
|
-
}
|
|
52327
|
-
lastPart = part;
|
|
52328
|
-
lastPartDebug = isBracket ? '[' + _part + ']' : '.' + _part;
|
|
52329
|
-
});
|
|
52330
|
-
return {
|
|
52331
|
-
schema,
|
|
52332
|
-
parent,
|
|
52333
|
-
parentPath: lastPart
|
|
52334
|
-
};
|
|
52335
|
-
}
|
|
52336
|
-
|
|
52337
|
-
class ReferenceSet extends Set {
|
|
52338
|
-
describe() {
|
|
52339
|
-
const description = [];
|
|
52340
|
-
for (const item of this.values()) {
|
|
52341
|
-
description.push(Reference.isRef(item) ? item.describe() : item);
|
|
52342
|
-
}
|
|
52343
|
-
return description;
|
|
52344
|
-
}
|
|
52345
|
-
resolveAll(resolve) {
|
|
52346
|
-
let result = [];
|
|
52347
|
-
for (const item of this.values()) {
|
|
52348
|
-
result.push(resolve(item));
|
|
52349
|
-
}
|
|
52350
|
-
return result;
|
|
52351
|
-
}
|
|
52352
|
-
clone() {
|
|
52353
|
-
return new ReferenceSet(this.values());
|
|
52354
|
-
}
|
|
52355
|
-
merge(newItems, removeItems) {
|
|
52356
|
-
const next = this.clone();
|
|
52357
|
-
newItems.forEach(value => next.add(value));
|
|
52358
|
-
removeItems.forEach(value => next.delete(value));
|
|
52359
|
-
return next;
|
|
52360
|
-
}
|
|
52361
|
-
}
|
|
52362
|
-
|
|
52363
|
-
// tweaked from https://github.com/Kelin2025/nanoclone/blob/0abeb7635bda9b68ef2277093f76dbe3bf3948e1/src/index.js
|
|
52364
|
-
function clone(src, seen = new Map()) {
|
|
52365
|
-
if (isSchema(src) || !src || typeof src !== 'object') return src;
|
|
52366
|
-
if (seen.has(src)) return seen.get(src);
|
|
52367
|
-
let copy;
|
|
52368
|
-
if (src instanceof Date) {
|
|
52369
|
-
// Date
|
|
52370
|
-
copy = new Date(src.getTime());
|
|
52371
|
-
seen.set(src, copy);
|
|
52372
|
-
} else if (src instanceof RegExp) {
|
|
52373
|
-
// RegExp
|
|
52374
|
-
copy = new RegExp(src);
|
|
52375
|
-
seen.set(src, copy);
|
|
52376
|
-
} else if (Array.isArray(src)) {
|
|
52377
|
-
// Array
|
|
52378
|
-
copy = new Array(src.length);
|
|
52379
|
-
seen.set(src, copy);
|
|
52380
|
-
for (let i = 0; i < src.length; i++) copy[i] = clone(src[i], seen);
|
|
52381
|
-
} else if (src instanceof Map) {
|
|
52382
|
-
// Map
|
|
52383
|
-
copy = new Map();
|
|
52384
|
-
seen.set(src, copy);
|
|
52385
|
-
for (const [k, v] of src.entries()) copy.set(k, clone(v, seen));
|
|
52386
|
-
} else if (src instanceof Set) {
|
|
52387
|
-
// Set
|
|
52388
|
-
copy = new Set();
|
|
52389
|
-
seen.set(src, copy);
|
|
52390
|
-
for (const v of src) copy.add(clone(v, seen));
|
|
52391
|
-
} else if (src instanceof Object) {
|
|
52392
|
-
// Object
|
|
52393
|
-
copy = {};
|
|
52394
|
-
seen.set(src, copy);
|
|
52395
|
-
for (const [k, v] of Object.entries(src)) copy[k] = clone(v, seen);
|
|
52396
|
-
} else {
|
|
52397
|
-
throw Error(`Unable to clone ${src}`);
|
|
52398
|
-
}
|
|
52399
|
-
return copy;
|
|
52400
|
-
}
|
|
52401
|
-
|
|
52402
|
-
/**
|
|
52403
|
-
* Copied from @standard-schema/spec to avoid having a dependency on it.
|
|
52404
|
-
* https://github.com/standard-schema/standard-schema/blob/main/packages/spec/src/index.ts
|
|
52405
|
-
*/
|
|
52406
|
-
|
|
52407
|
-
function createStandardPath(path) {
|
|
52408
|
-
if (!(path != null && path.length)) {
|
|
52409
|
-
return undefined;
|
|
52410
|
-
}
|
|
52411
|
-
|
|
52412
|
-
// Array to store the final path segments
|
|
52413
|
-
const segments = [];
|
|
52414
|
-
// Buffer for building the current segment
|
|
52415
|
-
let currentSegment = '';
|
|
52416
|
-
// Track if we're inside square brackets (array/property access)
|
|
52417
|
-
let inBrackets = false;
|
|
52418
|
-
// Track if we're inside quotes (for property names with special chars)
|
|
52419
|
-
let inQuotes = false;
|
|
52420
|
-
for (let i = 0; i < path.length; i++) {
|
|
52421
|
-
const char = path[i];
|
|
52422
|
-
if (char === '[' && !inQuotes) {
|
|
52423
|
-
// When entering brackets, push any accumulated segment after splitting on dots
|
|
52424
|
-
if (currentSegment) {
|
|
52425
|
-
segments.push(...currentSegment.split('.').filter(Boolean));
|
|
52426
|
-
currentSegment = '';
|
|
52427
|
-
}
|
|
52428
|
-
inBrackets = true;
|
|
52429
|
-
continue;
|
|
52430
|
-
}
|
|
52431
|
-
if (char === ']' && !inQuotes) {
|
|
52432
|
-
if (currentSegment) {
|
|
52433
|
-
// Handle numeric indices (e.g. arr[0])
|
|
52434
|
-
if (/^\d+$/.test(currentSegment)) {
|
|
52435
|
-
segments.push(currentSegment);
|
|
52436
|
-
} else {
|
|
52437
|
-
// Handle quoted property names (e.g. obj["foo.bar"])
|
|
52438
|
-
segments.push(currentSegment.replace(/^"|"$/g, ''));
|
|
52439
|
-
}
|
|
52440
|
-
currentSegment = '';
|
|
52441
|
-
}
|
|
52442
|
-
inBrackets = false;
|
|
52443
|
-
continue;
|
|
52444
|
-
}
|
|
52445
|
-
if (char === '"') {
|
|
52446
|
-
// Toggle quote state for handling quoted property names
|
|
52447
|
-
inQuotes = !inQuotes;
|
|
52448
|
-
continue;
|
|
52449
|
-
}
|
|
52450
|
-
if (char === '.' && !inBrackets && !inQuotes) {
|
|
52451
|
-
// On dots outside brackets/quotes, push current segment
|
|
52452
|
-
if (currentSegment) {
|
|
52453
|
-
segments.push(currentSegment);
|
|
52454
|
-
currentSegment = '';
|
|
52455
|
-
}
|
|
52456
|
-
continue;
|
|
52457
|
-
}
|
|
52458
|
-
currentSegment += char;
|
|
52459
|
-
}
|
|
52460
|
-
|
|
52461
|
-
// Push any remaining segment after splitting on dots
|
|
52462
|
-
if (currentSegment) {
|
|
52463
|
-
segments.push(...currentSegment.split('.').filter(Boolean));
|
|
52464
|
-
}
|
|
52465
|
-
return segments;
|
|
52466
|
-
}
|
|
52467
|
-
function createStandardIssues(error, parentPath) {
|
|
52468
|
-
const path = parentPath ? `${parentPath}.${error.path}` : error.path;
|
|
52469
|
-
return error.errors.map(err => ({
|
|
52470
|
-
message: err,
|
|
52471
|
-
path: createStandardPath(path)
|
|
52472
|
-
}));
|
|
52473
|
-
}
|
|
52474
|
-
function issuesFromValidationError(error, parentPath) {
|
|
52475
|
-
var _error$inner;
|
|
52476
|
-
if (!((_error$inner = error.inner) != null && _error$inner.length) && error.errors.length) {
|
|
52477
|
-
return createStandardIssues(error, parentPath);
|
|
52478
|
-
}
|
|
52479
|
-
const path = parentPath ? `${parentPath}.${error.path}` : error.path;
|
|
52480
|
-
return error.inner.flatMap(err => issuesFromValidationError(err, path));
|
|
52481
|
-
}
|
|
52482
|
-
|
|
52483
|
-
// If `CustomSchemaMeta` isn't extended with any keys, we'll fall back to a
|
|
52484
|
-
// loose Record definition allowing free form usage.
|
|
52485
|
-
class Schema {
|
|
52486
|
-
constructor(options) {
|
|
52487
|
-
this.type = void 0;
|
|
52488
|
-
this.deps = [];
|
|
52489
|
-
this.tests = void 0;
|
|
52490
|
-
this.transforms = void 0;
|
|
52491
|
-
this.conditions = [];
|
|
52492
|
-
this._mutate = void 0;
|
|
52493
|
-
this.internalTests = {};
|
|
52494
|
-
this._whitelist = new ReferenceSet();
|
|
52495
|
-
this._blacklist = new ReferenceSet();
|
|
52496
|
-
this.exclusiveTests = Object.create(null);
|
|
52497
|
-
this._typeCheck = void 0;
|
|
52498
|
-
this.spec = void 0;
|
|
52499
|
-
this.tests = [];
|
|
52500
|
-
this.transforms = [];
|
|
52501
|
-
this.withMutation(() => {
|
|
52502
|
-
this.typeError(mixed.notType);
|
|
52503
|
-
});
|
|
52504
|
-
this.type = options.type;
|
|
52505
|
-
this._typeCheck = options.check;
|
|
52506
|
-
this.spec = Object.assign({
|
|
52507
|
-
strip: false,
|
|
52508
|
-
strict: false,
|
|
52509
|
-
abortEarly: true,
|
|
52510
|
-
recursive: true,
|
|
52511
|
-
disableStackTrace: false,
|
|
52512
|
-
nullable: false,
|
|
52513
|
-
optional: true,
|
|
52514
|
-
coerce: true
|
|
52515
|
-
}, options == null ? void 0 : options.spec);
|
|
52516
|
-
this.withMutation(s => {
|
|
52517
|
-
s.nonNullable();
|
|
52518
|
-
});
|
|
52519
|
-
}
|
|
52520
|
-
|
|
52521
|
-
// TODO: remove
|
|
52522
|
-
get _type() {
|
|
52523
|
-
return this.type;
|
|
52524
|
-
}
|
|
52525
|
-
clone(spec) {
|
|
52526
|
-
if (this._mutate) {
|
|
52527
|
-
if (spec) Object.assign(this.spec, spec);
|
|
52528
|
-
return this;
|
|
52529
|
-
}
|
|
52530
|
-
|
|
52531
|
-
// if the nested value is a schema we can skip cloning, since
|
|
52532
|
-
// they are already immutable
|
|
52533
|
-
const next = Object.create(Object.getPrototypeOf(this));
|
|
52534
|
-
|
|
52535
|
-
// @ts-expect-error this is readonly
|
|
52536
|
-
next.type = this.type;
|
|
52537
|
-
next._typeCheck = this._typeCheck;
|
|
52538
|
-
next._whitelist = this._whitelist.clone();
|
|
52539
|
-
next._blacklist = this._blacklist.clone();
|
|
52540
|
-
next.internalTests = Object.assign({}, this.internalTests);
|
|
52541
|
-
next.exclusiveTests = Object.assign({}, this.exclusiveTests);
|
|
52542
|
-
|
|
52543
|
-
// @ts-expect-error this is readonly
|
|
52544
|
-
next.deps = [...this.deps];
|
|
52545
|
-
next.conditions = [...this.conditions];
|
|
52546
|
-
next.tests = [...this.tests];
|
|
52547
|
-
next.transforms = [...this.transforms];
|
|
52548
|
-
next.spec = clone(Object.assign({}, this.spec, spec));
|
|
52549
|
-
return next;
|
|
52550
|
-
}
|
|
52551
|
-
label(label) {
|
|
52552
|
-
let next = this.clone();
|
|
52553
|
-
next.spec.label = label;
|
|
52554
|
-
return next;
|
|
52555
|
-
}
|
|
52556
|
-
meta(...args) {
|
|
52557
|
-
if (args.length === 0) return this.spec.meta;
|
|
52558
|
-
let next = this.clone();
|
|
52559
|
-
next.spec.meta = Object.assign(next.spec.meta || {}, args[0]);
|
|
52560
|
-
return next;
|
|
52561
|
-
}
|
|
52562
|
-
withMutation(fn) {
|
|
52563
|
-
let before = this._mutate;
|
|
52564
|
-
this._mutate = true;
|
|
52565
|
-
let result = fn(this);
|
|
52566
|
-
this._mutate = before;
|
|
52567
|
-
return result;
|
|
52568
|
-
}
|
|
52569
|
-
concat(schema) {
|
|
52570
|
-
if (!schema || schema === this) return this;
|
|
52571
|
-
if (schema.type !== this.type && this.type !== 'mixed') throw new TypeError(`You cannot \`concat()\` schema's of different types: ${this.type} and ${schema.type}`);
|
|
52572
|
-
let base = this;
|
|
52573
|
-
let combined = schema.clone();
|
|
52574
|
-
const mergedSpec = Object.assign({}, base.spec, combined.spec);
|
|
52575
|
-
combined.spec = mergedSpec;
|
|
52576
|
-
combined.internalTests = Object.assign({}, base.internalTests, combined.internalTests);
|
|
52577
|
-
|
|
52578
|
-
// manually merge the blacklist/whitelist (the other `schema` takes
|
|
52579
|
-
// precedence in case of conflicts)
|
|
52580
|
-
combined._whitelist = base._whitelist.merge(schema._whitelist, schema._blacklist);
|
|
52581
|
-
combined._blacklist = base._blacklist.merge(schema._blacklist, schema._whitelist);
|
|
52582
|
-
|
|
52583
|
-
// start with the current tests
|
|
52584
|
-
combined.tests = base.tests;
|
|
52585
|
-
combined.exclusiveTests = base.exclusiveTests;
|
|
52586
|
-
|
|
52587
|
-
// manually add the new tests to ensure
|
|
52588
|
-
// the deduping logic is consistent
|
|
52589
|
-
combined.withMutation(next => {
|
|
52590
|
-
schema.tests.forEach(fn => {
|
|
52591
|
-
next.test(fn.OPTIONS);
|
|
52592
|
-
});
|
|
52593
|
-
});
|
|
52594
|
-
combined.transforms = [...base.transforms, ...combined.transforms];
|
|
52595
|
-
return combined;
|
|
52596
|
-
}
|
|
52597
|
-
isType(v) {
|
|
52598
|
-
if (v == null) {
|
|
52599
|
-
if (this.spec.nullable && v === null) return true;
|
|
52600
|
-
if (this.spec.optional && v === undefined) return true;
|
|
52601
|
-
return false;
|
|
52602
|
-
}
|
|
52603
|
-
return this._typeCheck(v);
|
|
52604
|
-
}
|
|
52605
|
-
resolve(options) {
|
|
52606
|
-
let schema = this;
|
|
52607
|
-
if (schema.conditions.length) {
|
|
52608
|
-
let conditions = schema.conditions;
|
|
52609
|
-
schema = schema.clone();
|
|
52610
|
-
schema.conditions = [];
|
|
52611
|
-
schema = conditions.reduce((prevSchema, condition) => condition.resolve(prevSchema, options), schema);
|
|
52612
|
-
schema = schema.resolve(options);
|
|
52613
|
-
}
|
|
52614
|
-
return schema;
|
|
52615
|
-
}
|
|
52616
|
-
resolveOptions(options) {
|
|
52617
|
-
var _options$strict, _options$abortEarly, _options$recursive, _options$disableStack;
|
|
52618
|
-
return Object.assign({}, options, {
|
|
52619
|
-
from: options.from || [],
|
|
52620
|
-
strict: (_options$strict = options.strict) != null ? _options$strict : this.spec.strict,
|
|
52621
|
-
abortEarly: (_options$abortEarly = options.abortEarly) != null ? _options$abortEarly : this.spec.abortEarly,
|
|
52622
|
-
recursive: (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive,
|
|
52623
|
-
disableStackTrace: (_options$disableStack = options.disableStackTrace) != null ? _options$disableStack : this.spec.disableStackTrace
|
|
52624
|
-
});
|
|
52625
|
-
}
|
|
52626
|
-
|
|
52627
|
-
/**
|
|
52628
|
-
* Run the configured transform pipeline over an input value.
|
|
52629
|
-
*/
|
|
52630
|
-
|
|
52631
|
-
cast(value, options = {}) {
|
|
52632
|
-
let resolvedSchema = this.resolve(Object.assign({}, options, {
|
|
52633
|
-
value
|
|
52634
|
-
// parent: options.parent,
|
|
52635
|
-
// context: options.context,
|
|
52636
|
-
}));
|
|
52637
|
-
|
|
52638
|
-
let allowOptionality = options.assert === 'ignore-optionality';
|
|
52639
|
-
let result = resolvedSchema._cast(value, options);
|
|
52640
|
-
if (options.assert !== false && !resolvedSchema.isType(result)) {
|
|
52641
|
-
if (allowOptionality && isAbsent(result)) {
|
|
52642
|
-
return result;
|
|
52643
|
-
}
|
|
52644
|
-
let formattedValue = printValue(value);
|
|
52645
|
-
let formattedResult = printValue(result);
|
|
52646
|
-
throw new TypeError(`The value of ${options.path || 'field'} could not be cast to a value ` + `that satisfies the schema type: "${resolvedSchema.type}". \n\n` + `attempted value: ${formattedValue} \n` + (formattedResult !== formattedValue ? `result of cast: ${formattedResult}` : ''));
|
|
52647
|
-
}
|
|
52648
|
-
return result;
|
|
52649
|
-
}
|
|
52650
|
-
_cast(rawValue, options) {
|
|
52651
|
-
let value = rawValue === undefined ? rawValue : this.transforms.reduce((prevValue, fn) => fn.call(this, prevValue, rawValue, this, options), rawValue);
|
|
52652
|
-
if (value === undefined) {
|
|
52653
|
-
value = this.getDefault(options);
|
|
52654
|
-
}
|
|
52655
|
-
return value;
|
|
52656
|
-
}
|
|
52657
|
-
_validate(_value, options = {}, panic, next) {
|
|
52658
|
-
let {
|
|
52659
|
-
path,
|
|
52660
|
-
originalValue = _value,
|
|
52661
|
-
strict = this.spec.strict
|
|
52662
|
-
} = options;
|
|
52663
|
-
let value = _value;
|
|
52664
|
-
if (!strict) {
|
|
52665
|
-
value = this._cast(value, Object.assign({
|
|
52666
|
-
assert: false
|
|
52667
|
-
}, options));
|
|
52668
|
-
}
|
|
52669
|
-
let initialTests = [];
|
|
52670
|
-
for (let test of Object.values(this.internalTests)) {
|
|
52671
|
-
if (test) initialTests.push(test);
|
|
52672
|
-
}
|
|
52673
|
-
this.runTests({
|
|
52674
|
-
path,
|
|
52675
|
-
value,
|
|
52676
|
-
originalValue,
|
|
52677
|
-
options,
|
|
52678
|
-
tests: initialTests
|
|
52679
|
-
}, panic, initialErrors => {
|
|
52680
|
-
// even if we aren't ending early we can't proceed further if the types aren't correct
|
|
52681
|
-
if (initialErrors.length) {
|
|
52682
|
-
return next(initialErrors, value);
|
|
52683
|
-
}
|
|
52684
|
-
this.runTests({
|
|
52685
|
-
path,
|
|
52686
|
-
value,
|
|
52687
|
-
originalValue,
|
|
52688
|
-
options,
|
|
52689
|
-
tests: this.tests
|
|
52690
|
-
}, panic, next);
|
|
52691
|
-
});
|
|
52692
|
-
}
|
|
52693
|
-
|
|
52694
|
-
/**
|
|
52695
|
-
* Executes a set of validations, either schema, produced Tests or a nested
|
|
52696
|
-
* schema validate result.
|
|
52697
|
-
*/
|
|
52698
|
-
runTests(runOptions, panic, next) {
|
|
52699
|
-
let fired = false;
|
|
52700
|
-
let {
|
|
52701
|
-
tests,
|
|
52702
|
-
value,
|
|
52703
|
-
originalValue,
|
|
52704
|
-
path,
|
|
52705
|
-
options
|
|
52706
|
-
} = runOptions;
|
|
52707
|
-
let panicOnce = arg => {
|
|
52708
|
-
if (fired) return;
|
|
52709
|
-
fired = true;
|
|
52710
|
-
panic(arg, value);
|
|
52711
|
-
};
|
|
52712
|
-
let nextOnce = arg => {
|
|
52713
|
-
if (fired) return;
|
|
52714
|
-
fired = true;
|
|
52715
|
-
next(arg, value);
|
|
52716
|
-
};
|
|
52717
|
-
let count = tests.length;
|
|
52718
|
-
let nestedErrors = [];
|
|
52719
|
-
if (!count) return nextOnce([]);
|
|
52720
|
-
let args = {
|
|
52721
|
-
value,
|
|
52722
|
-
originalValue,
|
|
52723
|
-
path,
|
|
52724
|
-
options,
|
|
52725
|
-
schema: this
|
|
52726
|
-
};
|
|
52727
|
-
for (let i = 0; i < tests.length; i++) {
|
|
52728
|
-
const test = tests[i];
|
|
52729
|
-
test(args, panicOnce, function finishTestRun(err) {
|
|
52730
|
-
if (err) {
|
|
52731
|
-
Array.isArray(err) ? nestedErrors.push(...err) : nestedErrors.push(err);
|
|
52732
|
-
}
|
|
52733
|
-
if (--count <= 0) {
|
|
52734
|
-
nextOnce(nestedErrors);
|
|
52735
|
-
}
|
|
52736
|
-
});
|
|
52737
|
-
}
|
|
52738
|
-
}
|
|
52739
|
-
asNestedTest({
|
|
52740
|
-
key,
|
|
52741
|
-
index,
|
|
52742
|
-
parent,
|
|
52743
|
-
parentPath,
|
|
52744
|
-
originalParent,
|
|
52745
|
-
options
|
|
52746
|
-
}) {
|
|
52747
|
-
const k = key != null ? key : index;
|
|
52748
|
-
if (k == null) {
|
|
52749
|
-
throw TypeError('Must include `key` or `index` for nested validations');
|
|
52750
|
-
}
|
|
52751
|
-
const isIndex = typeof k === 'number';
|
|
52752
|
-
let value = parent[k];
|
|
52753
|
-
const testOptions = Object.assign({}, options, {
|
|
52754
|
-
// Nested validations fields are always strict:
|
|
52755
|
-
// 1. parent isn't strict so the casting will also have cast inner values
|
|
52756
|
-
// 2. parent is strict in which case the nested values weren't cast either
|
|
52757
|
-
strict: true,
|
|
52758
|
-
parent,
|
|
52759
|
-
value,
|
|
52760
|
-
originalValue: originalParent[k],
|
|
52761
|
-
// FIXME: tests depend on `index` being passed around deeply,
|
|
52762
|
-
// we should not let the options.key/index bleed through
|
|
52763
|
-
key: undefined,
|
|
52764
|
-
// index: undefined,
|
|
52765
|
-
[isIndex ? 'index' : 'key']: k,
|
|
52766
|
-
path: isIndex || k.includes('.') ? `${parentPath || ''}[${isIndex ? k : `"${k}"`}]` : (parentPath ? `${parentPath}.` : '') + key
|
|
52767
|
-
});
|
|
52768
|
-
return (_, panic, next) => this.resolve(testOptions)._validate(value, testOptions, panic, next);
|
|
52769
|
-
}
|
|
52770
|
-
validate(value, options) {
|
|
52771
|
-
var _options$disableStack2;
|
|
52772
|
-
let schema = this.resolve(Object.assign({}, options, {
|
|
52773
|
-
value
|
|
52774
|
-
}));
|
|
52775
|
-
let disableStackTrace = (_options$disableStack2 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack2 : schema.spec.disableStackTrace;
|
|
52776
|
-
return new Promise((resolve, reject) => schema._validate(value, options, (error, parsed) => {
|
|
52777
|
-
if (ValidationError.isError(error)) error.value = parsed;
|
|
52778
|
-
reject(error);
|
|
52779
|
-
}, (errors, validated) => {
|
|
52780
|
-
if (errors.length) reject(new ValidationError(errors, validated, undefined, undefined, disableStackTrace));else resolve(validated);
|
|
52781
|
-
}));
|
|
52782
|
-
}
|
|
52783
|
-
validateSync(value, options) {
|
|
52784
|
-
var _options$disableStack3;
|
|
52785
|
-
let schema = this.resolve(Object.assign({}, options, {
|
|
52786
|
-
value
|
|
52787
|
-
}));
|
|
52788
|
-
let result;
|
|
52789
|
-
let disableStackTrace = (_options$disableStack3 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack3 : schema.spec.disableStackTrace;
|
|
52790
|
-
schema._validate(value, Object.assign({}, options, {
|
|
52791
|
-
sync: true
|
|
52792
|
-
}), (error, parsed) => {
|
|
52793
|
-
if (ValidationError.isError(error)) error.value = parsed;
|
|
52794
|
-
throw error;
|
|
52795
|
-
}, (errors, validated) => {
|
|
52796
|
-
if (errors.length) throw new ValidationError(errors, value, undefined, undefined, disableStackTrace);
|
|
52797
|
-
result = validated;
|
|
52798
|
-
});
|
|
52799
|
-
return result;
|
|
52800
|
-
}
|
|
52801
|
-
isValid(value, options) {
|
|
52802
|
-
return this.validate(value, options).then(() => true, err => {
|
|
52803
|
-
if (ValidationError.isError(err)) return false;
|
|
52804
|
-
throw err;
|
|
52805
|
-
});
|
|
52806
|
-
}
|
|
52807
|
-
isValidSync(value, options) {
|
|
52808
|
-
try {
|
|
52809
|
-
this.validateSync(value, options);
|
|
52810
|
-
return true;
|
|
52811
|
-
} catch (err) {
|
|
52812
|
-
if (ValidationError.isError(err)) return false;
|
|
52813
|
-
throw err;
|
|
52814
|
-
}
|
|
52815
|
-
}
|
|
52816
|
-
_getDefault(options) {
|
|
52817
|
-
let defaultValue = this.spec.default;
|
|
52818
|
-
if (defaultValue == null) {
|
|
52819
|
-
return defaultValue;
|
|
52820
|
-
}
|
|
52821
|
-
return typeof defaultValue === 'function' ? defaultValue.call(this, options) : clone(defaultValue);
|
|
52822
|
-
}
|
|
52823
|
-
getDefault(options
|
|
52824
|
-
// If schema is defaulted we know it's at least not undefined
|
|
52825
|
-
) {
|
|
52826
|
-
let schema = this.resolve(options || {});
|
|
52827
|
-
return schema._getDefault(options);
|
|
52828
|
-
}
|
|
52829
|
-
default(def) {
|
|
52830
|
-
if (arguments.length === 0) {
|
|
52831
|
-
return this._getDefault();
|
|
52832
|
-
}
|
|
52833
|
-
let next = this.clone({
|
|
52834
|
-
default: def
|
|
52835
|
-
});
|
|
52836
|
-
return next;
|
|
52837
|
-
}
|
|
52838
|
-
strict(isStrict = true) {
|
|
52839
|
-
return this.clone({
|
|
52840
|
-
strict: isStrict
|
|
52841
|
-
});
|
|
52842
|
-
}
|
|
52843
|
-
nullability(nullable, message) {
|
|
52844
|
-
const next = this.clone({
|
|
52845
|
-
nullable
|
|
52846
|
-
});
|
|
52847
|
-
next.internalTests.nullable = createValidation({
|
|
52848
|
-
message,
|
|
52849
|
-
name: 'nullable',
|
|
52850
|
-
test(value) {
|
|
52851
|
-
return value === null ? this.schema.spec.nullable : true;
|
|
52852
|
-
}
|
|
52853
|
-
});
|
|
52854
|
-
return next;
|
|
52855
|
-
}
|
|
52856
|
-
optionality(optional, message) {
|
|
52857
|
-
const next = this.clone({
|
|
52858
|
-
optional
|
|
52859
|
-
});
|
|
52860
|
-
next.internalTests.optionality = createValidation({
|
|
52861
|
-
message,
|
|
52862
|
-
name: 'optionality',
|
|
52863
|
-
test(value) {
|
|
52864
|
-
return value === undefined ? this.schema.spec.optional : true;
|
|
52865
|
-
}
|
|
52866
|
-
});
|
|
52867
|
-
return next;
|
|
52868
|
-
}
|
|
52869
|
-
optional() {
|
|
52870
|
-
return this.optionality(true);
|
|
52871
|
-
}
|
|
52872
|
-
defined(message = mixed.defined) {
|
|
52873
|
-
return this.optionality(false, message);
|
|
52874
|
-
}
|
|
52875
|
-
nullable() {
|
|
52876
|
-
return this.nullability(true);
|
|
52877
|
-
}
|
|
52878
|
-
nonNullable(message = mixed.notNull) {
|
|
52879
|
-
return this.nullability(false, message);
|
|
52880
|
-
}
|
|
52881
|
-
required(message = mixed.required) {
|
|
52882
|
-
return this.clone().withMutation(next => next.nonNullable(message).defined(message));
|
|
52883
|
-
}
|
|
52884
|
-
notRequired() {
|
|
52885
|
-
return this.clone().withMutation(next => next.nullable().optional());
|
|
52886
|
-
}
|
|
52887
|
-
transform(fn) {
|
|
52888
|
-
let next = this.clone();
|
|
52889
|
-
next.transforms.push(fn);
|
|
52890
|
-
return next;
|
|
52891
|
-
}
|
|
52892
|
-
|
|
52893
|
-
/**
|
|
52894
|
-
* Adds a test function to the schema's queue of tests.
|
|
52895
|
-
* tests can be exclusive or non-exclusive.
|
|
52896
|
-
*
|
|
52897
|
-
* - exclusive tests, will replace any existing tests of the same name.
|
|
52898
|
-
* - non-exclusive: can be stacked
|
|
52899
|
-
*
|
|
52900
|
-
* If a non-exclusive test is added to a schema with an exclusive test of the same name
|
|
52901
|
-
* the exclusive test is removed and further tests of the same name will be stacked.
|
|
52902
|
-
*
|
|
52903
|
-
* If an exclusive test is added to a schema with non-exclusive tests of the same name
|
|
52904
|
-
* the previous tests are removed and further tests of the same name will replace each other.
|
|
52905
|
-
*/
|
|
52906
|
-
|
|
52907
|
-
test(...args) {
|
|
52908
|
-
let opts;
|
|
52909
|
-
if (args.length === 1) {
|
|
52910
|
-
if (typeof args[0] === 'function') {
|
|
52911
|
-
opts = {
|
|
52912
|
-
test: args[0]
|
|
52913
|
-
};
|
|
52914
|
-
} else {
|
|
52915
|
-
opts = args[0];
|
|
52916
|
-
}
|
|
52917
|
-
} else if (args.length === 2) {
|
|
52918
|
-
opts = {
|
|
52919
|
-
name: args[0],
|
|
52920
|
-
test: args[1]
|
|
52921
|
-
};
|
|
52922
|
-
} else {
|
|
52923
|
-
opts = {
|
|
52924
|
-
name: args[0],
|
|
52925
|
-
message: args[1],
|
|
52926
|
-
test: args[2]
|
|
52927
|
-
};
|
|
52928
|
-
}
|
|
52929
|
-
if (opts.message === undefined) opts.message = mixed.default;
|
|
52930
|
-
if (typeof opts.test !== 'function') throw new TypeError('`test` is a required parameters');
|
|
52931
|
-
let next = this.clone();
|
|
52932
|
-
let validate = createValidation(opts);
|
|
52933
|
-
let isExclusive = opts.exclusive || opts.name && next.exclusiveTests[opts.name] === true;
|
|
52934
|
-
if (opts.exclusive) {
|
|
52935
|
-
if (!opts.name) throw new TypeError('Exclusive tests must provide a unique `name` identifying the test');
|
|
52936
|
-
}
|
|
52937
|
-
if (opts.name) next.exclusiveTests[opts.name] = !!opts.exclusive;
|
|
52938
|
-
next.tests = next.tests.filter(fn => {
|
|
52939
|
-
if (fn.OPTIONS.name === opts.name) {
|
|
52940
|
-
if (isExclusive) return false;
|
|
52941
|
-
if (fn.OPTIONS.test === validate.OPTIONS.test) return false;
|
|
52942
|
-
}
|
|
52943
|
-
return true;
|
|
52944
|
-
});
|
|
52945
|
-
next.tests.push(validate);
|
|
52946
|
-
return next;
|
|
52947
|
-
}
|
|
52948
|
-
when(keys, options) {
|
|
52949
|
-
if (!Array.isArray(keys) && typeof keys !== 'string') {
|
|
52950
|
-
options = keys;
|
|
52951
|
-
keys = '.';
|
|
52952
|
-
}
|
|
52953
|
-
let next = this.clone();
|
|
52954
|
-
let deps = toArray(keys).map(key => new Reference(key));
|
|
52955
|
-
deps.forEach(dep => {
|
|
52956
|
-
// @ts-ignore readonly array
|
|
52957
|
-
if (dep.isSibling) next.deps.push(dep.key);
|
|
52958
|
-
});
|
|
52959
|
-
next.conditions.push(typeof options === 'function' ? new Condition(deps, options) : Condition.fromOptions(deps, options));
|
|
52960
|
-
return next;
|
|
52961
|
-
}
|
|
52962
|
-
typeError(message) {
|
|
52963
|
-
let next = this.clone();
|
|
52964
|
-
next.internalTests.typeError = createValidation({
|
|
52965
|
-
message,
|
|
52966
|
-
name: 'typeError',
|
|
52967
|
-
skipAbsent: true,
|
|
52968
|
-
test(value) {
|
|
52969
|
-
if (!this.schema._typeCheck(value)) return this.createError({
|
|
52970
|
-
params: {
|
|
52971
|
-
type: this.schema.type
|
|
52972
|
-
}
|
|
52973
|
-
});
|
|
52974
|
-
return true;
|
|
52975
|
-
}
|
|
52976
|
-
});
|
|
52977
|
-
return next;
|
|
52978
|
-
}
|
|
52979
|
-
oneOf(enums, message = mixed.oneOf) {
|
|
52980
|
-
let next = this.clone();
|
|
52981
|
-
enums.forEach(val => {
|
|
52982
|
-
next._whitelist.add(val);
|
|
52983
|
-
next._blacklist.delete(val);
|
|
52984
|
-
});
|
|
52985
|
-
next.internalTests.whiteList = createValidation({
|
|
52986
|
-
message,
|
|
52987
|
-
name: 'oneOf',
|
|
52988
|
-
skipAbsent: true,
|
|
52989
|
-
test(value) {
|
|
52990
|
-
let valids = this.schema._whitelist;
|
|
52991
|
-
let resolved = valids.resolveAll(this.resolve);
|
|
52992
|
-
return resolved.includes(value) ? true : this.createError({
|
|
52993
|
-
params: {
|
|
52994
|
-
values: Array.from(valids).join(', '),
|
|
52995
|
-
resolved
|
|
52996
|
-
}
|
|
52997
|
-
});
|
|
52998
|
-
}
|
|
52999
|
-
});
|
|
53000
|
-
return next;
|
|
53001
|
-
}
|
|
53002
|
-
notOneOf(enums, message = mixed.notOneOf) {
|
|
53003
|
-
let next = this.clone();
|
|
53004
|
-
enums.forEach(val => {
|
|
53005
|
-
next._blacklist.add(val);
|
|
53006
|
-
next._whitelist.delete(val);
|
|
53007
|
-
});
|
|
53008
|
-
next.internalTests.blacklist = createValidation({
|
|
53009
|
-
message,
|
|
53010
|
-
name: 'notOneOf',
|
|
53011
|
-
test(value) {
|
|
53012
|
-
let invalids = this.schema._blacklist;
|
|
53013
|
-
let resolved = invalids.resolveAll(this.resolve);
|
|
53014
|
-
if (resolved.includes(value)) return this.createError({
|
|
53015
|
-
params: {
|
|
53016
|
-
values: Array.from(invalids).join(', '),
|
|
53017
|
-
resolved
|
|
53018
|
-
}
|
|
53019
|
-
});
|
|
53020
|
-
return true;
|
|
53021
|
-
}
|
|
53022
|
-
});
|
|
53023
|
-
return next;
|
|
53024
|
-
}
|
|
53025
|
-
strip(strip = true) {
|
|
53026
|
-
let next = this.clone();
|
|
53027
|
-
next.spec.strip = strip;
|
|
53028
|
-
return next;
|
|
53029
|
-
}
|
|
53030
|
-
|
|
53031
|
-
/**
|
|
53032
|
-
* Return a serialized description of the schema including validations, flags, types etc.
|
|
53033
|
-
*
|
|
53034
|
-
* @param options Provide any needed context for resolving runtime schema alterations (lazy, when conditions, etc).
|
|
53035
|
-
*/
|
|
53036
|
-
describe(options) {
|
|
53037
|
-
const next = (options ? this.resolve(options) : this).clone();
|
|
53038
|
-
const {
|
|
53039
|
-
label,
|
|
53040
|
-
meta,
|
|
53041
|
-
optional,
|
|
53042
|
-
nullable
|
|
53043
|
-
} = next.spec;
|
|
53044
|
-
const description = {
|
|
53045
|
-
meta,
|
|
53046
|
-
label,
|
|
53047
|
-
optional,
|
|
53048
|
-
nullable,
|
|
53049
|
-
default: next.getDefault(options),
|
|
53050
|
-
type: next.type,
|
|
53051
|
-
oneOf: next._whitelist.describe(),
|
|
53052
|
-
notOneOf: next._blacklist.describe(),
|
|
53053
|
-
tests: next.tests.filter((n, idx, list) => list.findIndex(c => c.OPTIONS.name === n.OPTIONS.name) === idx).map(fn => {
|
|
53054
|
-
const params = fn.OPTIONS.params && options ? resolveParams(Object.assign({}, fn.OPTIONS.params), options) : fn.OPTIONS.params;
|
|
53055
|
-
return {
|
|
53056
|
-
name: fn.OPTIONS.name,
|
|
53057
|
-
params
|
|
53058
|
-
};
|
|
53059
|
-
})
|
|
53060
|
-
};
|
|
53061
|
-
return description;
|
|
53062
|
-
}
|
|
53063
|
-
get ['~standard']() {
|
|
53064
|
-
const schema = this;
|
|
53065
|
-
const standard = {
|
|
53066
|
-
version: 1,
|
|
53067
|
-
vendor: 'yup',
|
|
53068
|
-
async validate(value) {
|
|
53069
|
-
try {
|
|
53070
|
-
const result = await schema.validate(value, {
|
|
53071
|
-
abortEarly: false
|
|
53072
|
-
});
|
|
53073
|
-
return {
|
|
53074
|
-
value: result
|
|
53075
|
-
};
|
|
53076
|
-
} catch (err) {
|
|
53077
|
-
if (err instanceof ValidationError) {
|
|
53078
|
-
return {
|
|
53079
|
-
issues: issuesFromValidationError(err)
|
|
53080
|
-
};
|
|
53081
|
-
}
|
|
53082
|
-
throw err;
|
|
53083
|
-
}
|
|
53084
|
-
}
|
|
53085
|
-
};
|
|
53086
|
-
return standard;
|
|
53087
|
-
}
|
|
53088
|
-
}
|
|
53089
|
-
// @ts-expect-error
|
|
53090
|
-
Schema.prototype.__isYupSchema__ = true;
|
|
53091
|
-
for (const method of ['validate', 'validateSync']) Schema.prototype[`${method}At`] = function (path, value, options = {}) {
|
|
53092
|
-
const {
|
|
53093
|
-
parent,
|
|
53094
|
-
parentPath,
|
|
53095
|
-
schema
|
|
53096
|
-
} = getIn(this, path, value, options.context);
|
|
53097
|
-
return schema[method](parent && parent[parentPath], Object.assign({}, options, {
|
|
53098
|
-
parent,
|
|
53099
|
-
path
|
|
53100
|
-
}));
|
|
53101
|
-
};
|
|
53102
|
-
for (const alias of ['equals', 'is']) Schema.prototype[alias] = Schema.prototype.oneOf;
|
|
53103
|
-
for (const alias of ['not', 'nope']) Schema.prototype[alias] = Schema.prototype.notOneOf;
|
|
53104
|
-
|
|
53105
|
-
const returnsTrue = () => true;
|
|
53106
|
-
function create$8(spec) {
|
|
53107
|
-
return new MixedSchema(spec);
|
|
53108
|
-
}
|
|
53109
|
-
class MixedSchema extends Schema {
|
|
53110
|
-
constructor(spec) {
|
|
53111
|
-
super(typeof spec === 'function' ? {
|
|
53112
|
-
type: 'mixed',
|
|
53113
|
-
check: spec
|
|
53114
|
-
} : Object.assign({
|
|
53115
|
-
type: 'mixed',
|
|
53116
|
-
check: returnsTrue
|
|
53117
|
-
}, spec));
|
|
53118
|
-
}
|
|
53119
|
-
}
|
|
53120
|
-
create$8.prototype = MixedSchema.prototype;
|
|
53121
|
-
|
|
53122
|
-
/**
|
|
53123
|
-
* This file is a modified version of the file from the following repository:
|
|
53124
|
-
* Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
|
|
53125
|
-
* NON-CONFORMANT EDITION.
|
|
53126
|
-
* © 2011 Colin Snover <http://zetafleet.com>
|
|
53127
|
-
* Released under MIT license.
|
|
53128
|
-
*/
|
|
53129
|
-
|
|
53130
|
-
// prettier-ignore
|
|
53131
|
-
// 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm
|
|
53132
|
-
const isoReg = /^(\d{4}|[+-]\d{6})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[ T]?(\d{2}):?(\d{2})(?::?(\d{2})(?:[,.](\d{1,}))?)?(?:(Z)|([+-])(\d{2})(?::?(\d{2}))?)?)?$/;
|
|
53133
|
-
function parseIsoDate(date) {
|
|
53134
|
-
const struct = parseDateStruct(date);
|
|
53135
|
-
if (!struct) return Date.parse ? Date.parse(date) : Number.NaN;
|
|
53136
|
-
|
|
53137
|
-
// timestamps without timezone identifiers should be considered local time
|
|
53138
|
-
if (struct.z === undefined && struct.plusMinus === undefined) {
|
|
53139
|
-
return new Date(struct.year, struct.month, struct.day, struct.hour, struct.minute, struct.second, struct.millisecond).valueOf();
|
|
53140
|
-
}
|
|
53141
|
-
let totalMinutesOffset = 0;
|
|
53142
|
-
if (struct.z !== 'Z' && struct.plusMinus !== undefined) {
|
|
53143
|
-
totalMinutesOffset = struct.hourOffset * 60 + struct.minuteOffset;
|
|
53144
|
-
if (struct.plusMinus === '+') totalMinutesOffset = 0 - totalMinutesOffset;
|
|
53145
|
-
}
|
|
53146
|
-
return Date.UTC(struct.year, struct.month, struct.day, struct.hour, struct.minute + totalMinutesOffset, struct.second, struct.millisecond);
|
|
53147
|
-
}
|
|
53148
|
-
function parseDateStruct(date) {
|
|
53149
|
-
var _regexResult$7$length, _regexResult$;
|
|
53150
|
-
const regexResult = isoReg.exec(date);
|
|
53151
|
-
if (!regexResult) return null;
|
|
53152
|
-
|
|
53153
|
-
// use of toNumber() avoids NaN timestamps caused by “undefined”
|
|
53154
|
-
// values being passed to Date constructor
|
|
53155
|
-
return {
|
|
53156
|
-
year: toNumber(regexResult[1]),
|
|
53157
|
-
month: toNumber(regexResult[2], 1) - 1,
|
|
53158
|
-
day: toNumber(regexResult[3], 1),
|
|
53159
|
-
hour: toNumber(regexResult[4]),
|
|
53160
|
-
minute: toNumber(regexResult[5]),
|
|
53161
|
-
second: toNumber(regexResult[6]),
|
|
53162
|
-
millisecond: regexResult[7] ?
|
|
53163
|
-
// allow arbitrary sub-second precision beyond milliseconds
|
|
53164
|
-
toNumber(regexResult[7].substring(0, 3)) : 0,
|
|
53165
|
-
precision: (_regexResult$7$length = (_regexResult$ = regexResult[7]) == null ? void 0 : _regexResult$.length) != null ? _regexResult$7$length : undefined,
|
|
53166
|
-
z: regexResult[8] || undefined,
|
|
53167
|
-
plusMinus: regexResult[9] || undefined,
|
|
53168
|
-
hourOffset: toNumber(regexResult[10]),
|
|
53169
|
-
minuteOffset: toNumber(regexResult[11])
|
|
53170
|
-
};
|
|
53171
|
-
}
|
|
53172
|
-
function toNumber(str, defaultValue = 0) {
|
|
53173
|
-
return Number(str) || defaultValue;
|
|
53174
|
-
}
|
|
53175
|
-
|
|
53176
|
-
// Taken from HTML spec: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
|
|
53177
|
-
let rEmail =
|
|
53178
|
-
// eslint-disable-next-line
|
|
53179
|
-
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
53180
|
-
let rUrl =
|
|
53181
|
-
// eslint-disable-next-line
|
|
53182
|
-
/^((https?|ftp):)?\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
|
|
53183
|
-
|
|
53184
|
-
// eslint-disable-next-line
|
|
53185
|
-
let rUUID = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
53186
|
-
let yearMonthDay = '^\\d{4}-\\d{2}-\\d{2}';
|
|
53187
|
-
let hourMinuteSecond = '\\d{2}:\\d{2}:\\d{2}';
|
|
53188
|
-
let zOrOffset = '(([+-]\\d{2}(:?\\d{2})?)|Z)';
|
|
53189
|
-
let rIsoDateTime = new RegExp(`${yearMonthDay}T${hourMinuteSecond}(\\.\\d+)?${zOrOffset}$`);
|
|
53190
|
-
let isTrimmed = value => isAbsent(value) || value === value.trim();
|
|
53191
|
-
let objStringTag = {}.toString();
|
|
53192
|
-
function create$6() {
|
|
53193
|
-
return new StringSchema();
|
|
53194
|
-
}
|
|
53195
|
-
class StringSchema extends Schema {
|
|
53196
|
-
constructor() {
|
|
53197
|
-
super({
|
|
53198
|
-
type: 'string',
|
|
53199
|
-
check(value) {
|
|
53200
|
-
if (value instanceof String) value = value.valueOf();
|
|
53201
|
-
return typeof value === 'string';
|
|
53202
|
-
}
|
|
53203
|
-
});
|
|
53204
|
-
this.withMutation(() => {
|
|
53205
|
-
this.transform((value, _raw) => {
|
|
53206
|
-
if (!this.spec.coerce || this.isType(value)) return value;
|
|
53207
|
-
|
|
53208
|
-
// don't ever convert arrays
|
|
53209
|
-
if (Array.isArray(value)) return value;
|
|
53210
|
-
const strValue = value != null && value.toString ? value.toString() : value;
|
|
53211
|
-
|
|
53212
|
-
// no one wants plain objects converted to [Object object]
|
|
53213
|
-
if (strValue === objStringTag) return value;
|
|
53214
|
-
return strValue;
|
|
53215
|
-
});
|
|
53216
|
-
});
|
|
53217
|
-
}
|
|
53218
|
-
required(message) {
|
|
53219
|
-
return super.required(message).withMutation(schema => schema.test({
|
|
53220
|
-
message: message || mixed.required,
|
|
53221
|
-
name: 'required',
|
|
53222
|
-
skipAbsent: true,
|
|
53223
|
-
test: value => !!value.length
|
|
53224
|
-
}));
|
|
53225
|
-
}
|
|
53226
|
-
notRequired() {
|
|
53227
|
-
return super.notRequired().withMutation(schema => {
|
|
53228
|
-
schema.tests = schema.tests.filter(t => t.OPTIONS.name !== 'required');
|
|
53229
|
-
return schema;
|
|
53230
|
-
});
|
|
53231
|
-
}
|
|
53232
|
-
length(length, message = string.length) {
|
|
53233
|
-
return this.test({
|
|
53234
|
-
message,
|
|
53235
|
-
name: 'length',
|
|
53236
|
-
exclusive: true,
|
|
53237
|
-
params: {
|
|
53238
|
-
length
|
|
53239
|
-
},
|
|
53240
|
-
skipAbsent: true,
|
|
53241
|
-
test(value) {
|
|
53242
|
-
return value.length === this.resolve(length);
|
|
53243
|
-
}
|
|
53244
|
-
});
|
|
53245
|
-
}
|
|
53246
|
-
min(min, message = string.min) {
|
|
53247
|
-
return this.test({
|
|
53248
|
-
message,
|
|
53249
|
-
name: 'min',
|
|
53250
|
-
exclusive: true,
|
|
53251
|
-
params: {
|
|
53252
|
-
min
|
|
53253
|
-
},
|
|
53254
|
-
skipAbsent: true,
|
|
53255
|
-
test(value) {
|
|
53256
|
-
return value.length >= this.resolve(min);
|
|
53257
|
-
}
|
|
53258
|
-
});
|
|
53259
|
-
}
|
|
53260
|
-
max(max, message = string.max) {
|
|
53261
|
-
return this.test({
|
|
53262
|
-
name: 'max',
|
|
53263
|
-
exclusive: true,
|
|
53264
|
-
message,
|
|
53265
|
-
params: {
|
|
53266
|
-
max
|
|
53267
|
-
},
|
|
53268
|
-
skipAbsent: true,
|
|
53269
|
-
test(value) {
|
|
53270
|
-
return value.length <= this.resolve(max);
|
|
53271
|
-
}
|
|
53272
|
-
});
|
|
53273
|
-
}
|
|
53274
|
-
matches(regex, options) {
|
|
53275
|
-
let excludeEmptyString = false;
|
|
53276
|
-
let message;
|
|
53277
|
-
let name;
|
|
53278
|
-
if (options) {
|
|
53279
|
-
if (typeof options === 'object') {
|
|
53280
|
-
({
|
|
53281
|
-
excludeEmptyString = false,
|
|
53282
|
-
message,
|
|
53283
|
-
name
|
|
53284
|
-
} = options);
|
|
53285
|
-
} else {
|
|
53286
|
-
message = options;
|
|
53287
|
-
}
|
|
53288
|
-
}
|
|
53289
|
-
return this.test({
|
|
53290
|
-
name: name || 'matches',
|
|
53291
|
-
message: message || string.matches,
|
|
53292
|
-
params: {
|
|
53293
|
-
regex
|
|
53294
|
-
},
|
|
53295
|
-
skipAbsent: true,
|
|
53296
|
-
test: value => value === '' && excludeEmptyString || value.search(regex) !== -1
|
|
53297
|
-
});
|
|
53298
|
-
}
|
|
53299
|
-
email(message = string.email) {
|
|
53300
|
-
return this.matches(rEmail, {
|
|
53301
|
-
name: 'email',
|
|
53302
|
-
message,
|
|
53303
|
-
excludeEmptyString: true
|
|
53304
|
-
});
|
|
53305
|
-
}
|
|
53306
|
-
url(message = string.url) {
|
|
53307
|
-
return this.matches(rUrl, {
|
|
53308
|
-
name: 'url',
|
|
53309
|
-
message,
|
|
53310
|
-
excludeEmptyString: true
|
|
53311
|
-
});
|
|
53312
|
-
}
|
|
53313
|
-
uuid(message = string.uuid) {
|
|
53314
|
-
return this.matches(rUUID, {
|
|
53315
|
-
name: 'uuid',
|
|
53316
|
-
message,
|
|
53317
|
-
excludeEmptyString: false
|
|
53318
|
-
});
|
|
53319
|
-
}
|
|
53320
|
-
datetime(options) {
|
|
53321
|
-
let message = '';
|
|
53322
|
-
let allowOffset;
|
|
53323
|
-
let precision;
|
|
53324
|
-
if (options) {
|
|
53325
|
-
if (typeof options === 'object') {
|
|
53326
|
-
({
|
|
53327
|
-
message = '',
|
|
53328
|
-
allowOffset = false,
|
|
53329
|
-
precision = undefined
|
|
53330
|
-
} = options);
|
|
53331
|
-
} else {
|
|
53332
|
-
message = options;
|
|
53333
|
-
}
|
|
53334
|
-
}
|
|
53335
|
-
return this.matches(rIsoDateTime, {
|
|
53336
|
-
name: 'datetime',
|
|
53337
|
-
message: message || string.datetime,
|
|
53338
|
-
excludeEmptyString: true
|
|
53339
|
-
}).test({
|
|
53340
|
-
name: 'datetime_offset',
|
|
53341
|
-
message: message || string.datetime_offset,
|
|
53342
|
-
params: {
|
|
53343
|
-
allowOffset
|
|
53344
|
-
},
|
|
53345
|
-
skipAbsent: true,
|
|
53346
|
-
test: value => {
|
|
53347
|
-
if (!value || allowOffset) return true;
|
|
53348
|
-
const struct = parseDateStruct(value);
|
|
53349
|
-
if (!struct) return false;
|
|
53350
|
-
return !!struct.z;
|
|
53351
|
-
}
|
|
53352
|
-
}).test({
|
|
53353
|
-
name: 'datetime_precision',
|
|
53354
|
-
message: message || string.datetime_precision,
|
|
53355
|
-
params: {
|
|
53356
|
-
precision
|
|
53357
|
-
},
|
|
53358
|
-
skipAbsent: true,
|
|
53359
|
-
test: value => {
|
|
53360
|
-
if (!value || precision == undefined) return true;
|
|
53361
|
-
const struct = parseDateStruct(value);
|
|
53362
|
-
if (!struct) return false;
|
|
53363
|
-
return struct.precision === precision;
|
|
53364
|
-
}
|
|
53365
|
-
});
|
|
53366
|
-
}
|
|
53367
|
-
|
|
53368
|
-
//-- transforms --
|
|
53369
|
-
ensure() {
|
|
53370
|
-
return this.default('').transform(val => val === null ? '' : val);
|
|
53371
|
-
}
|
|
53372
|
-
trim(message = string.trim) {
|
|
53373
|
-
return this.transform(val => val != null ? val.trim() : val).test({
|
|
53374
|
-
message,
|
|
53375
|
-
name: 'trim',
|
|
53376
|
-
test: isTrimmed
|
|
53377
|
-
});
|
|
53378
|
-
}
|
|
53379
|
-
lowercase(message = string.lowercase) {
|
|
53380
|
-
return this.transform(value => !isAbsent(value) ? value.toLowerCase() : value).test({
|
|
53381
|
-
message,
|
|
53382
|
-
name: 'string_case',
|
|
53383
|
-
exclusive: true,
|
|
53384
|
-
skipAbsent: true,
|
|
53385
|
-
test: value => isAbsent(value) || value === value.toLowerCase()
|
|
53386
|
-
});
|
|
53387
|
-
}
|
|
53388
|
-
uppercase(message = string.uppercase) {
|
|
53389
|
-
return this.transform(value => !isAbsent(value) ? value.toUpperCase() : value).test({
|
|
53390
|
-
message,
|
|
53391
|
-
name: 'string_case',
|
|
53392
|
-
exclusive: true,
|
|
53393
|
-
skipAbsent: true,
|
|
53394
|
-
test: value => isAbsent(value) || value === value.toUpperCase()
|
|
53395
|
-
});
|
|
53396
|
-
}
|
|
53397
|
-
}
|
|
53398
|
-
create$6.prototype = StringSchema.prototype;
|
|
53399
|
-
|
|
53400
|
-
//
|
|
53401
|
-
// String Interfaces
|
|
53402
|
-
//
|
|
53403
|
-
|
|
53404
|
-
let isNaN$1 = value => value != +value;
|
|
53405
|
-
function create$5() {
|
|
53406
|
-
return new NumberSchema();
|
|
53407
|
-
}
|
|
53408
|
-
class NumberSchema extends Schema {
|
|
53409
|
-
constructor() {
|
|
53410
|
-
super({
|
|
53411
|
-
type: 'number',
|
|
53412
|
-
check(value) {
|
|
53413
|
-
if (value instanceof Number) value = value.valueOf();
|
|
53414
|
-
return typeof value === 'number' && !isNaN$1(value);
|
|
53415
|
-
}
|
|
53416
|
-
});
|
|
53417
|
-
this.withMutation(() => {
|
|
53418
|
-
this.transform((value, _raw) => {
|
|
53419
|
-
if (!this.spec.coerce) return value;
|
|
53420
|
-
let parsed = value;
|
|
53421
|
-
if (typeof parsed === 'string') {
|
|
53422
|
-
parsed = parsed.replace(/\s/g, '');
|
|
53423
|
-
if (parsed === '') return NaN;
|
|
53424
|
-
// don't use parseFloat to avoid positives on alpha-numeric strings
|
|
53425
|
-
parsed = +parsed;
|
|
53426
|
-
}
|
|
53427
|
-
|
|
53428
|
-
// null -> NaN isn't useful; treat all nulls as null and let it fail on
|
|
53429
|
-
// nullability check vs TypeErrors
|
|
53430
|
-
if (this.isType(parsed) || parsed === null) return parsed;
|
|
53431
|
-
return parseFloat(parsed);
|
|
53432
|
-
});
|
|
53433
|
-
});
|
|
53434
|
-
}
|
|
53435
|
-
min(min, message = number.min) {
|
|
53436
|
-
return this.test({
|
|
53437
|
-
message,
|
|
53438
|
-
name: 'min',
|
|
53439
|
-
exclusive: true,
|
|
53440
|
-
params: {
|
|
53441
|
-
min
|
|
53442
|
-
},
|
|
53443
|
-
skipAbsent: true,
|
|
53444
|
-
test(value) {
|
|
53445
|
-
return value >= this.resolve(min);
|
|
53446
|
-
}
|
|
53447
|
-
});
|
|
53448
|
-
}
|
|
53449
|
-
max(max, message = number.max) {
|
|
53450
|
-
return this.test({
|
|
53451
|
-
message,
|
|
53452
|
-
name: 'max',
|
|
53453
|
-
exclusive: true,
|
|
53454
|
-
params: {
|
|
53455
|
-
max
|
|
53456
|
-
},
|
|
53457
|
-
skipAbsent: true,
|
|
53458
|
-
test(value) {
|
|
53459
|
-
return value <= this.resolve(max);
|
|
53460
|
-
}
|
|
53461
|
-
});
|
|
53462
|
-
}
|
|
53463
|
-
lessThan(less, message = number.lessThan) {
|
|
53464
|
-
return this.test({
|
|
53465
|
-
message,
|
|
53466
|
-
name: 'max',
|
|
53467
|
-
exclusive: true,
|
|
53468
|
-
params: {
|
|
53469
|
-
less
|
|
53470
|
-
},
|
|
53471
|
-
skipAbsent: true,
|
|
53472
|
-
test(value) {
|
|
53473
|
-
return value < this.resolve(less);
|
|
53474
|
-
}
|
|
53475
|
-
});
|
|
53476
|
-
}
|
|
53477
|
-
moreThan(more, message = number.moreThan) {
|
|
53478
|
-
return this.test({
|
|
53479
|
-
message,
|
|
53480
|
-
name: 'min',
|
|
53481
|
-
exclusive: true,
|
|
53482
|
-
params: {
|
|
53483
|
-
more
|
|
53484
|
-
},
|
|
53485
|
-
skipAbsent: true,
|
|
53486
|
-
test(value) {
|
|
53487
|
-
return value > this.resolve(more);
|
|
53488
|
-
}
|
|
53489
|
-
});
|
|
53490
|
-
}
|
|
53491
|
-
positive(msg = number.positive) {
|
|
53492
|
-
return this.moreThan(0, msg);
|
|
53493
|
-
}
|
|
53494
|
-
negative(msg = number.negative) {
|
|
53495
|
-
return this.lessThan(0, msg);
|
|
53496
|
-
}
|
|
53497
|
-
integer(message = number.integer) {
|
|
53498
|
-
return this.test({
|
|
53499
|
-
name: 'integer',
|
|
53500
|
-
message,
|
|
53501
|
-
skipAbsent: true,
|
|
53502
|
-
test: val => Number.isInteger(val)
|
|
53503
|
-
});
|
|
53504
|
-
}
|
|
53505
|
-
truncate() {
|
|
53506
|
-
return this.transform(value => !isAbsent(value) ? value | 0 : value);
|
|
53507
|
-
}
|
|
53508
|
-
round(method) {
|
|
53509
|
-
var _method;
|
|
53510
|
-
let avail = ['ceil', 'floor', 'round', 'trunc'];
|
|
53511
|
-
method = ((_method = method) == null ? void 0 : _method.toLowerCase()) || 'round';
|
|
53512
|
-
|
|
53513
|
-
// this exists for symemtry with the new Math.trunc
|
|
53514
|
-
if (method === 'trunc') return this.truncate();
|
|
53515
|
-
if (avail.indexOf(method.toLowerCase()) === -1) throw new TypeError('Only valid options for round() are: ' + avail.join(', '));
|
|
53516
|
-
return this.transform(value => !isAbsent(value) ? Math[method](value) : value);
|
|
53517
|
-
}
|
|
53518
|
-
}
|
|
53519
|
-
create$5.prototype = NumberSchema.prototype;
|
|
53520
|
-
|
|
53521
|
-
//
|
|
53522
|
-
// Number Interfaces
|
|
53523
|
-
//
|
|
53524
|
-
|
|
53525
|
-
let invalidDate = new Date('');
|
|
53526
|
-
let isDate = obj => Object.prototype.toString.call(obj) === '[object Date]';
|
|
53527
|
-
class DateSchema extends Schema {
|
|
53528
|
-
constructor() {
|
|
53529
|
-
super({
|
|
53530
|
-
type: 'date',
|
|
53531
|
-
check(v) {
|
|
53532
|
-
return isDate(v) && !isNaN(v.getTime());
|
|
53533
|
-
}
|
|
53534
|
-
});
|
|
53535
|
-
this.withMutation(() => {
|
|
53536
|
-
this.transform((value, _raw) => {
|
|
53537
|
-
// null -> InvalidDate isn't useful; treat all nulls as null and let it fail on
|
|
53538
|
-
// nullability check vs TypeErrors
|
|
53539
|
-
if (!this.spec.coerce || this.isType(value) || value === null) return value;
|
|
53540
|
-
value = parseIsoDate(value);
|
|
53541
|
-
|
|
53542
|
-
// 0 is a valid timestamp equivalent to 1970-01-01T00:00:00Z(unix epoch) or before.
|
|
53543
|
-
return !isNaN(value) ? new Date(value) : DateSchema.INVALID_DATE;
|
|
53544
|
-
});
|
|
53545
|
-
});
|
|
53546
|
-
}
|
|
53547
|
-
prepareParam(ref, name) {
|
|
53548
|
-
let param;
|
|
53549
|
-
if (!Reference.isRef(ref)) {
|
|
53550
|
-
let cast = this.cast(ref);
|
|
53551
|
-
if (!this._typeCheck(cast)) throw new TypeError(`\`${name}\` must be a Date or a value that can be \`cast()\` to a Date`);
|
|
53552
|
-
param = cast;
|
|
53553
|
-
} else {
|
|
53554
|
-
param = ref;
|
|
53555
|
-
}
|
|
53556
|
-
return param;
|
|
53557
|
-
}
|
|
53558
|
-
min(min, message = date.min) {
|
|
53559
|
-
let limit = this.prepareParam(min, 'min');
|
|
53560
|
-
return this.test({
|
|
53561
|
-
message,
|
|
53562
|
-
name: 'min',
|
|
53563
|
-
exclusive: true,
|
|
53564
|
-
params: {
|
|
53565
|
-
min
|
|
53566
|
-
},
|
|
53567
|
-
skipAbsent: true,
|
|
53568
|
-
test(value) {
|
|
53569
|
-
return value >= this.resolve(limit);
|
|
53570
|
-
}
|
|
53571
|
-
});
|
|
53572
|
-
}
|
|
53573
|
-
max(max, message = date.max) {
|
|
53574
|
-
let limit = this.prepareParam(max, 'max');
|
|
53575
|
-
return this.test({
|
|
53576
|
-
message,
|
|
53577
|
-
name: 'max',
|
|
53578
|
-
exclusive: true,
|
|
53579
|
-
params: {
|
|
53580
|
-
max
|
|
53581
|
-
},
|
|
53582
|
-
skipAbsent: true,
|
|
53583
|
-
test(value) {
|
|
53584
|
-
return value <= this.resolve(limit);
|
|
53585
|
-
}
|
|
53586
|
-
});
|
|
53587
|
-
}
|
|
53588
|
-
}
|
|
53589
|
-
DateSchema.INVALID_DATE = invalidDate;
|
|
53590
|
-
|
|
53591
|
-
// @ts-expect-error
|
|
53592
|
-
function sortFields(fields, excludedEdges = []) {
|
|
53593
|
-
let edges = [];
|
|
53594
|
-
let nodes = new Set();
|
|
53595
|
-
let excludes = new Set(excludedEdges.map(([a, b]) => `${a}-${b}`));
|
|
53596
|
-
function addNode(depPath, key) {
|
|
53597
|
-
let node = propertyExpr.split(depPath)[0];
|
|
53598
|
-
nodes.add(node);
|
|
53599
|
-
if (!excludes.has(`${key}-${node}`)) edges.push([key, node]);
|
|
53600
|
-
}
|
|
53601
|
-
for (const key of Object.keys(fields)) {
|
|
53602
|
-
let value = fields[key];
|
|
53603
|
-
nodes.add(key);
|
|
53604
|
-
if (Reference.isRef(value) && value.isSibling) addNode(value.path, key);else if (isSchema(value) && 'deps' in value) value.deps.forEach(path => addNode(path, key));
|
|
53605
|
-
}
|
|
53606
|
-
return toposort$1.array(Array.from(nodes), edges).reverse();
|
|
53607
|
-
}
|
|
53608
|
-
|
|
53609
|
-
function findIndex(arr, err) {
|
|
53610
|
-
let idx = Infinity;
|
|
53611
|
-
arr.some((key, ii) => {
|
|
53612
|
-
var _err$path;
|
|
53613
|
-
if ((_err$path = err.path) != null && _err$path.includes(key)) {
|
|
53614
|
-
idx = ii;
|
|
53615
|
-
return true;
|
|
53616
|
-
}
|
|
53617
|
-
});
|
|
53618
|
-
return idx;
|
|
53619
|
-
}
|
|
53620
|
-
function sortByKeyOrder(keys) {
|
|
53621
|
-
return (a, b) => {
|
|
53622
|
-
return findIndex(keys, a) - findIndex(keys, b);
|
|
53623
|
-
};
|
|
53624
|
-
}
|
|
53625
|
-
|
|
53626
|
-
const parseJson = (value, _, schema) => {
|
|
53627
|
-
if (typeof value !== 'string') {
|
|
53628
|
-
return value;
|
|
53629
|
-
}
|
|
53630
|
-
let parsed = value;
|
|
53631
|
-
try {
|
|
53632
|
-
parsed = JSON.parse(value);
|
|
53633
|
-
} catch (err) {
|
|
53634
|
-
/* */
|
|
53635
|
-
}
|
|
53636
|
-
return schema.isType(parsed) ? parsed : value;
|
|
53637
|
-
};
|
|
53638
|
-
|
|
53639
|
-
// @ts-ignore
|
|
53640
|
-
function deepPartial(schema) {
|
|
53641
|
-
if ('fields' in schema) {
|
|
53642
|
-
const partial = {};
|
|
53643
|
-
for (const [key, fieldSchema] of Object.entries(schema.fields)) {
|
|
53644
|
-
partial[key] = deepPartial(fieldSchema);
|
|
53645
|
-
}
|
|
53646
|
-
return schema.setFields(partial);
|
|
53647
|
-
}
|
|
53648
|
-
if (schema.type === 'array') {
|
|
53649
|
-
const nextArray = schema.optional();
|
|
53650
|
-
if (nextArray.innerType) nextArray.innerType = deepPartial(nextArray.innerType);
|
|
53651
|
-
return nextArray;
|
|
53652
|
-
}
|
|
53653
|
-
if (schema.type === 'tuple') {
|
|
53654
|
-
return schema.optional().clone({
|
|
53655
|
-
types: schema.spec.types.map(deepPartial)
|
|
53656
|
-
});
|
|
53657
|
-
}
|
|
53658
|
-
if ('optional' in schema) {
|
|
53659
|
-
return schema.optional();
|
|
53660
|
-
}
|
|
53661
|
-
return schema;
|
|
53662
|
-
}
|
|
53663
|
-
const deepHas = (obj, p) => {
|
|
53664
|
-
const path = [...propertyExpr.normalizePath(p)];
|
|
53665
|
-
if (path.length === 1) return path[0] in obj;
|
|
53666
|
-
let last = path.pop();
|
|
53667
|
-
let parent = propertyExpr.getter(propertyExpr.join(path), true)(obj);
|
|
53668
|
-
return !!(parent && last in parent);
|
|
53669
|
-
};
|
|
53670
|
-
let isObject = obj => Object.prototype.toString.call(obj) === '[object Object]';
|
|
53671
|
-
function unknown(ctx, value) {
|
|
53672
|
-
let known = Object.keys(ctx.fields);
|
|
53673
|
-
return Object.keys(value).filter(key => known.indexOf(key) === -1);
|
|
53674
|
-
}
|
|
53675
|
-
const defaultSort = sortByKeyOrder([]);
|
|
53676
|
-
function create$3(spec) {
|
|
53677
|
-
return new ObjectSchema(spec);
|
|
53678
|
-
}
|
|
53679
|
-
class ObjectSchema extends Schema {
|
|
53680
|
-
constructor(spec) {
|
|
53681
|
-
super({
|
|
53682
|
-
type: 'object',
|
|
53683
|
-
check(value) {
|
|
53684
|
-
return isObject(value) || typeof value === 'function';
|
|
53685
|
-
}
|
|
53686
|
-
});
|
|
53687
|
-
this.fields = Object.create(null);
|
|
53688
|
-
this._sortErrors = defaultSort;
|
|
53689
|
-
this._nodes = [];
|
|
53690
|
-
this._excludedEdges = [];
|
|
53691
|
-
this.withMutation(() => {
|
|
53692
|
-
if (spec) {
|
|
53693
|
-
this.shape(spec);
|
|
53694
|
-
}
|
|
53695
|
-
});
|
|
53696
|
-
}
|
|
53697
|
-
_cast(_value, options = {}) {
|
|
53698
|
-
var _options$stripUnknown;
|
|
53699
|
-
let value = super._cast(_value, options);
|
|
53700
|
-
|
|
53701
|
-
//should ignore nulls here
|
|
53702
|
-
if (value === undefined) return this.getDefault(options);
|
|
53703
|
-
if (!this._typeCheck(value)) return value;
|
|
53704
|
-
let fields = this.fields;
|
|
53705
|
-
let strip = (_options$stripUnknown = options.stripUnknown) != null ? _options$stripUnknown : this.spec.noUnknown;
|
|
53706
|
-
let props = [].concat(this._nodes, Object.keys(value).filter(v => !this._nodes.includes(v)));
|
|
53707
|
-
let intermediateValue = {}; // is filled during the transform below
|
|
53708
|
-
let innerOptions = Object.assign({}, options, {
|
|
53709
|
-
parent: intermediateValue,
|
|
53710
|
-
__validating: options.__validating || false
|
|
53711
|
-
});
|
|
53712
|
-
let isChanged = false;
|
|
53713
|
-
for (const prop of props) {
|
|
53714
|
-
let field = fields[prop];
|
|
53715
|
-
let exists = (prop in value);
|
|
53716
|
-
let inputValue = value[prop];
|
|
53717
|
-
if (field) {
|
|
53718
|
-
let fieldValue;
|
|
53719
|
-
|
|
53720
|
-
// safe to mutate since this is fired in sequence
|
|
53721
|
-
innerOptions.path = (options.path ? `${options.path}.` : '') + prop;
|
|
53722
|
-
field = field.resolve({
|
|
53723
|
-
value: inputValue,
|
|
53724
|
-
context: options.context,
|
|
53725
|
-
parent: intermediateValue
|
|
53726
|
-
});
|
|
53727
|
-
let fieldSpec = field instanceof Schema ? field.spec : undefined;
|
|
53728
|
-
let strict = fieldSpec == null ? void 0 : fieldSpec.strict;
|
|
53729
|
-
if (fieldSpec != null && fieldSpec.strip) {
|
|
53730
|
-
isChanged = isChanged || prop in value;
|
|
53731
|
-
continue;
|
|
53732
|
-
}
|
|
53733
|
-
fieldValue = !options.__validating || !strict ? field.cast(inputValue, innerOptions) : inputValue;
|
|
53734
|
-
if (fieldValue !== undefined) {
|
|
53735
|
-
intermediateValue[prop] = fieldValue;
|
|
53736
|
-
}
|
|
53737
|
-
} else if (exists && !strip) {
|
|
53738
|
-
intermediateValue[prop] = inputValue;
|
|
53739
|
-
}
|
|
53740
|
-
if (exists !== prop in intermediateValue || intermediateValue[prop] !== inputValue) {
|
|
53741
|
-
isChanged = true;
|
|
53742
|
-
}
|
|
53743
|
-
}
|
|
53744
|
-
return isChanged ? intermediateValue : value;
|
|
53745
|
-
}
|
|
53746
|
-
_validate(_value, options = {}, panic, next) {
|
|
53747
|
-
let {
|
|
53748
|
-
from = [],
|
|
53749
|
-
originalValue = _value,
|
|
53750
|
-
recursive = this.spec.recursive
|
|
53751
|
-
} = options;
|
|
53752
|
-
options.from = [{
|
|
53753
|
-
schema: this,
|
|
53754
|
-
value: originalValue
|
|
53755
|
-
}, ...from];
|
|
53756
|
-
// this flag is needed for handling `strict` correctly in the context of
|
|
53757
|
-
// validation vs just casting. e.g strict() on a field is only used when validating
|
|
53758
|
-
options.__validating = true;
|
|
53759
|
-
options.originalValue = originalValue;
|
|
53760
|
-
super._validate(_value, options, panic, (objectErrors, value) => {
|
|
53761
|
-
if (!recursive || !isObject(value)) {
|
|
53762
|
-
next(objectErrors, value);
|
|
53763
|
-
return;
|
|
53764
|
-
}
|
|
53765
|
-
originalValue = originalValue || value;
|
|
53766
|
-
let tests = [];
|
|
53767
|
-
for (let key of this._nodes) {
|
|
53768
|
-
let field = this.fields[key];
|
|
53769
|
-
if (!field || Reference.isRef(field)) {
|
|
53770
|
-
continue;
|
|
53771
|
-
}
|
|
53772
|
-
tests.push(field.asNestedTest({
|
|
53773
|
-
options,
|
|
53774
|
-
key,
|
|
53775
|
-
parent: value,
|
|
53776
|
-
parentPath: options.path,
|
|
53777
|
-
originalParent: originalValue
|
|
53778
|
-
}));
|
|
53779
|
-
}
|
|
53780
|
-
this.runTests({
|
|
53781
|
-
tests,
|
|
53782
|
-
value,
|
|
53783
|
-
originalValue,
|
|
53784
|
-
options
|
|
53785
|
-
}, panic, fieldErrors => {
|
|
53786
|
-
next(fieldErrors.sort(this._sortErrors).concat(objectErrors), value);
|
|
53787
|
-
});
|
|
53788
|
-
});
|
|
53789
|
-
}
|
|
53790
|
-
clone(spec) {
|
|
53791
|
-
const next = super.clone(spec);
|
|
53792
|
-
next.fields = Object.assign({}, this.fields);
|
|
53793
|
-
next._nodes = this._nodes;
|
|
53794
|
-
next._excludedEdges = this._excludedEdges;
|
|
53795
|
-
next._sortErrors = this._sortErrors;
|
|
53796
|
-
return next;
|
|
53797
|
-
}
|
|
53798
|
-
concat(schema) {
|
|
53799
|
-
let next = super.concat(schema);
|
|
53800
|
-
let nextFields = next.fields;
|
|
53801
|
-
for (let [field, schemaOrRef] of Object.entries(this.fields)) {
|
|
53802
|
-
const target = nextFields[field];
|
|
53803
|
-
nextFields[field] = target === undefined ? schemaOrRef : target;
|
|
53804
|
-
}
|
|
53805
|
-
return next.withMutation(s =>
|
|
53806
|
-
// XXX: excludes here is wrong
|
|
53807
|
-
s.setFields(nextFields, [...this._excludedEdges, ...schema._excludedEdges]));
|
|
53808
|
-
}
|
|
53809
|
-
_getDefault(options) {
|
|
53810
|
-
if ('default' in this.spec) {
|
|
53811
|
-
return super._getDefault(options);
|
|
53812
|
-
}
|
|
53813
|
-
|
|
53814
|
-
// if there is no default set invent one
|
|
53815
|
-
if (!this._nodes.length) {
|
|
53816
|
-
return undefined;
|
|
53817
|
-
}
|
|
53818
|
-
let dft = {};
|
|
53819
|
-
this._nodes.forEach(key => {
|
|
53820
|
-
var _innerOptions;
|
|
53821
|
-
const field = this.fields[key];
|
|
53822
|
-
let innerOptions = options;
|
|
53823
|
-
if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
|
|
53824
|
-
innerOptions = Object.assign({}, innerOptions, {
|
|
53825
|
-
parent: innerOptions.value,
|
|
53826
|
-
value: innerOptions.value[key]
|
|
53827
|
-
});
|
|
53828
|
-
}
|
|
53829
|
-
dft[key] = field && 'getDefault' in field ? field.getDefault(innerOptions) : undefined;
|
|
53830
|
-
});
|
|
53831
|
-
return dft;
|
|
53832
|
-
}
|
|
53833
|
-
setFields(shape, excludedEdges) {
|
|
53834
|
-
let next = this.clone();
|
|
53835
|
-
next.fields = shape;
|
|
53836
|
-
next._nodes = sortFields(shape, excludedEdges);
|
|
53837
|
-
next._sortErrors = sortByKeyOrder(Object.keys(shape));
|
|
53838
|
-
// XXX: this carries over edges which may not be what you want
|
|
53839
|
-
if (excludedEdges) next._excludedEdges = excludedEdges;
|
|
53840
|
-
return next;
|
|
53841
|
-
}
|
|
53842
|
-
shape(additions, excludes = []) {
|
|
53843
|
-
return this.clone().withMutation(next => {
|
|
53844
|
-
let edges = next._excludedEdges;
|
|
53845
|
-
if (excludes.length) {
|
|
53846
|
-
if (!Array.isArray(excludes[0])) excludes = [excludes];
|
|
53847
|
-
edges = [...next._excludedEdges, ...excludes];
|
|
53848
|
-
}
|
|
53849
|
-
|
|
53850
|
-
// XXX: excludes here is wrong
|
|
53851
|
-
return next.setFields(Object.assign(next.fields, additions), edges);
|
|
53852
|
-
});
|
|
53853
|
-
}
|
|
53854
|
-
partial() {
|
|
53855
|
-
const partial = {};
|
|
53856
|
-
for (const [key, schema] of Object.entries(this.fields)) {
|
|
53857
|
-
partial[key] = 'optional' in schema && schema.optional instanceof Function ? schema.optional() : schema;
|
|
53858
|
-
}
|
|
53859
|
-
return this.setFields(partial);
|
|
53860
|
-
}
|
|
53861
|
-
deepPartial() {
|
|
53862
|
-
const next = deepPartial(this);
|
|
53863
|
-
return next;
|
|
53864
|
-
}
|
|
53865
|
-
pick(keys) {
|
|
53866
|
-
const picked = {};
|
|
53867
|
-
for (const key of keys) {
|
|
53868
|
-
if (this.fields[key]) picked[key] = this.fields[key];
|
|
53869
|
-
}
|
|
53870
|
-
return this.setFields(picked, this._excludedEdges.filter(([a, b]) => keys.includes(a) && keys.includes(b)));
|
|
53871
|
-
}
|
|
53872
|
-
omit(keys) {
|
|
53873
|
-
const remaining = [];
|
|
53874
|
-
for (const key of Object.keys(this.fields)) {
|
|
53875
|
-
if (keys.includes(key)) continue;
|
|
53876
|
-
remaining.push(key);
|
|
53877
|
-
}
|
|
53878
|
-
return this.pick(remaining);
|
|
53879
|
-
}
|
|
53880
|
-
from(from, to, alias) {
|
|
53881
|
-
let fromGetter = propertyExpr.getter(from, true);
|
|
53882
|
-
return this.transform(obj => {
|
|
53883
|
-
if (!obj) return obj;
|
|
53884
|
-
let newObj = obj;
|
|
53885
|
-
if (deepHas(obj, from)) {
|
|
53886
|
-
newObj = Object.assign({}, obj);
|
|
53887
|
-
if (!alias) delete newObj[from];
|
|
53888
|
-
newObj[to] = fromGetter(obj);
|
|
53889
|
-
}
|
|
53890
|
-
return newObj;
|
|
53891
|
-
});
|
|
53892
|
-
}
|
|
53893
|
-
|
|
53894
|
-
/** Parse an input JSON string to an object */
|
|
53895
|
-
json() {
|
|
53896
|
-
return this.transform(parseJson);
|
|
53897
|
-
}
|
|
53898
|
-
|
|
53899
|
-
/**
|
|
53900
|
-
* Similar to `noUnknown` but only validates that an object is the right shape without stripping the unknown keys
|
|
53901
|
-
*/
|
|
53902
|
-
exact(message) {
|
|
53903
|
-
return this.test({
|
|
53904
|
-
name: 'exact',
|
|
53905
|
-
exclusive: true,
|
|
53906
|
-
message: message || object.exact,
|
|
53907
|
-
test(value) {
|
|
53908
|
-
if (value == null) return true;
|
|
53909
|
-
const unknownKeys = unknown(this.schema, value);
|
|
53910
|
-
return unknownKeys.length === 0 || this.createError({
|
|
53911
|
-
params: {
|
|
53912
|
-
properties: unknownKeys.join(', ')
|
|
53913
|
-
}
|
|
53914
|
-
});
|
|
53915
|
-
}
|
|
53916
|
-
});
|
|
53917
|
-
}
|
|
53918
|
-
stripUnknown() {
|
|
53919
|
-
return this.clone({
|
|
53920
|
-
noUnknown: true
|
|
53921
|
-
});
|
|
53922
|
-
}
|
|
53923
|
-
noUnknown(noAllow = true, message = object.noUnknown) {
|
|
53924
|
-
if (typeof noAllow !== 'boolean') {
|
|
53925
|
-
message = noAllow;
|
|
53926
|
-
noAllow = true;
|
|
53927
|
-
}
|
|
53928
|
-
let next = this.test({
|
|
53929
|
-
name: 'noUnknown',
|
|
53930
|
-
exclusive: true,
|
|
53931
|
-
message: message,
|
|
53932
|
-
test(value) {
|
|
53933
|
-
if (value == null) return true;
|
|
53934
|
-
const unknownKeys = unknown(this.schema, value);
|
|
53935
|
-
return !noAllow || unknownKeys.length === 0 || this.createError({
|
|
53936
|
-
params: {
|
|
53937
|
-
unknown: unknownKeys.join(', ')
|
|
53938
|
-
}
|
|
53939
|
-
});
|
|
53940
|
-
}
|
|
53941
|
-
});
|
|
53942
|
-
next.spec.noUnknown = noAllow;
|
|
53943
|
-
return next;
|
|
53944
|
-
}
|
|
53945
|
-
unknown(allow = true, message = object.noUnknown) {
|
|
53946
|
-
return this.noUnknown(!allow, message);
|
|
53947
|
-
}
|
|
53948
|
-
transformKeys(fn) {
|
|
53949
|
-
return this.transform(obj => {
|
|
53950
|
-
if (!obj) return obj;
|
|
53951
|
-
const result = {};
|
|
53952
|
-
for (const key of Object.keys(obj)) result[fn(key)] = obj[key];
|
|
53953
|
-
return result;
|
|
53954
|
-
});
|
|
53955
|
-
}
|
|
53956
|
-
camelCase() {
|
|
53957
|
-
return this.transformKeys(tinyCase.camelCase);
|
|
53958
|
-
}
|
|
53959
|
-
snakeCase() {
|
|
53960
|
-
return this.transformKeys(tinyCase.snakeCase);
|
|
53961
|
-
}
|
|
53962
|
-
constantCase() {
|
|
53963
|
-
return this.transformKeys(key => tinyCase.snakeCase(key).toUpperCase());
|
|
53964
|
-
}
|
|
53965
|
-
describe(options) {
|
|
53966
|
-
const next = (options ? this.resolve(options) : this).clone();
|
|
53967
|
-
const base = super.describe(options);
|
|
53968
|
-
base.fields = {};
|
|
53969
|
-
for (const [key, value] of Object.entries(next.fields)) {
|
|
53970
|
-
var _innerOptions2;
|
|
53971
|
-
let innerOptions = options;
|
|
53972
|
-
if ((_innerOptions2 = innerOptions) != null && _innerOptions2.value) {
|
|
53973
|
-
innerOptions = Object.assign({}, innerOptions, {
|
|
53974
|
-
parent: innerOptions.value,
|
|
53975
|
-
value: innerOptions.value[key]
|
|
53976
|
-
});
|
|
53977
|
-
}
|
|
53978
|
-
base.fields[key] = value.describe(innerOptions);
|
|
53979
|
-
}
|
|
53980
|
-
return base;
|
|
53981
|
-
}
|
|
53982
|
-
}
|
|
53983
|
-
create$3.prototype = ObjectSchema.prototype;
|
|
53984
|
-
|
|
53985
|
-
function create$2(type) {
|
|
53986
|
-
return new ArraySchema(type);
|
|
53987
|
-
}
|
|
53988
|
-
class ArraySchema extends Schema {
|
|
53989
|
-
constructor(type) {
|
|
53990
|
-
super({
|
|
53991
|
-
type: 'array',
|
|
53992
|
-
spec: {
|
|
53993
|
-
types: type
|
|
53994
|
-
},
|
|
53995
|
-
check(v) {
|
|
53996
|
-
return Array.isArray(v);
|
|
53997
|
-
}
|
|
53998
|
-
});
|
|
53999
|
-
|
|
54000
|
-
// `undefined` specifically means uninitialized, as opposed to "no subtype"
|
|
54001
|
-
this.innerType = void 0;
|
|
54002
|
-
this.innerType = type;
|
|
54003
|
-
}
|
|
54004
|
-
_cast(_value, _opts) {
|
|
54005
|
-
const value = super._cast(_value, _opts);
|
|
54006
|
-
|
|
54007
|
-
// should ignore nulls here
|
|
54008
|
-
if (!this._typeCheck(value) || !this.innerType) {
|
|
54009
|
-
return value;
|
|
54010
|
-
}
|
|
54011
|
-
let isChanged = false;
|
|
54012
|
-
const castArray = value.map((v, idx) => {
|
|
54013
|
-
const castElement = this.innerType.cast(v, Object.assign({}, _opts, {
|
|
54014
|
-
path: `${_opts.path || ''}[${idx}]`,
|
|
54015
|
-
parent: value,
|
|
54016
|
-
originalValue: v,
|
|
54017
|
-
value: v,
|
|
54018
|
-
index: idx
|
|
54019
|
-
}));
|
|
54020
|
-
if (castElement !== v) {
|
|
54021
|
-
isChanged = true;
|
|
54022
|
-
}
|
|
54023
|
-
return castElement;
|
|
54024
|
-
});
|
|
54025
|
-
return isChanged ? castArray : value;
|
|
54026
|
-
}
|
|
54027
|
-
_validate(_value, options = {}, panic, next) {
|
|
54028
|
-
var _options$recursive;
|
|
54029
|
-
// let sync = options.sync;
|
|
54030
|
-
// let path = options.path;
|
|
54031
|
-
let innerType = this.innerType;
|
|
54032
|
-
// let endEarly = options.abortEarly ?? this.spec.abortEarly;
|
|
54033
|
-
let recursive = (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive;
|
|
54034
|
-
options.originalValue != null ? options.originalValue : _value;
|
|
54035
|
-
super._validate(_value, options, panic, (arrayErrors, value) => {
|
|
54036
|
-
var _options$originalValu2;
|
|
54037
|
-
if (!recursive || !innerType || !this._typeCheck(value)) {
|
|
54038
|
-
next(arrayErrors, value);
|
|
54039
|
-
return;
|
|
54040
|
-
}
|
|
54041
|
-
|
|
54042
|
-
// #950 Ensure that sparse array empty slots are validated
|
|
54043
|
-
let tests = new Array(value.length);
|
|
54044
|
-
for (let index = 0; index < value.length; index++) {
|
|
54045
|
-
var _options$originalValu;
|
|
54046
|
-
tests[index] = innerType.asNestedTest({
|
|
54047
|
-
options,
|
|
54048
|
-
index,
|
|
54049
|
-
parent: value,
|
|
54050
|
-
parentPath: options.path,
|
|
54051
|
-
originalParent: (_options$originalValu = options.originalValue) != null ? _options$originalValu : _value
|
|
54052
|
-
});
|
|
54053
|
-
}
|
|
54054
|
-
this.runTests({
|
|
54055
|
-
value,
|
|
54056
|
-
tests,
|
|
54057
|
-
originalValue: (_options$originalValu2 = options.originalValue) != null ? _options$originalValu2 : _value,
|
|
54058
|
-
options
|
|
54059
|
-
}, panic, innerTypeErrors => next(innerTypeErrors.concat(arrayErrors), value));
|
|
54060
|
-
});
|
|
54061
|
-
}
|
|
54062
|
-
clone(spec) {
|
|
54063
|
-
const next = super.clone(spec);
|
|
54064
|
-
// @ts-expect-error readonly
|
|
54065
|
-
next.innerType = this.innerType;
|
|
54066
|
-
return next;
|
|
54067
|
-
}
|
|
54068
|
-
|
|
54069
|
-
/** Parse an input JSON string to an object */
|
|
54070
|
-
json() {
|
|
54071
|
-
return this.transform(parseJson);
|
|
54072
|
-
}
|
|
54073
|
-
concat(schema) {
|
|
54074
|
-
let next = super.concat(schema);
|
|
54075
|
-
|
|
54076
|
-
// @ts-expect-error readonly
|
|
54077
|
-
next.innerType = this.innerType;
|
|
54078
|
-
if (schema.innerType)
|
|
54079
|
-
// @ts-expect-error readonly
|
|
54080
|
-
next.innerType = next.innerType ?
|
|
54081
|
-
// @ts-expect-error Lazy doesn't have concat and will break
|
|
54082
|
-
next.innerType.concat(schema.innerType) : schema.innerType;
|
|
54083
|
-
return next;
|
|
54084
|
-
}
|
|
54085
|
-
of(schema) {
|
|
54086
|
-
// FIXME: this should return a new instance of array without the default to be
|
|
54087
|
-
let next = this.clone();
|
|
54088
|
-
if (!isSchema(schema)) throw new TypeError('`array.of()` sub-schema must be a valid yup schema not: ' + printValue(schema));
|
|
54089
|
-
|
|
54090
|
-
// @ts-expect-error readonly
|
|
54091
|
-
next.innerType = schema;
|
|
54092
|
-
next.spec = Object.assign({}, next.spec, {
|
|
54093
|
-
types: schema
|
|
54094
|
-
});
|
|
54095
|
-
return next;
|
|
54096
|
-
}
|
|
54097
|
-
length(length, message = array.length) {
|
|
54098
|
-
return this.test({
|
|
54099
|
-
message,
|
|
54100
|
-
name: 'length',
|
|
54101
|
-
exclusive: true,
|
|
54102
|
-
params: {
|
|
54103
|
-
length
|
|
54104
|
-
},
|
|
54105
|
-
skipAbsent: true,
|
|
54106
|
-
test(value) {
|
|
54107
|
-
return value.length === this.resolve(length);
|
|
54108
|
-
}
|
|
54109
|
-
});
|
|
54110
|
-
}
|
|
54111
|
-
min(min, message) {
|
|
54112
|
-
message = message || array.min;
|
|
54113
|
-
return this.test({
|
|
54114
|
-
message,
|
|
54115
|
-
name: 'min',
|
|
54116
|
-
exclusive: true,
|
|
54117
|
-
params: {
|
|
54118
|
-
min
|
|
54119
|
-
},
|
|
54120
|
-
skipAbsent: true,
|
|
54121
|
-
// FIXME(ts): Array<typeof T>
|
|
54122
|
-
test(value) {
|
|
54123
|
-
return value.length >= this.resolve(min);
|
|
54124
|
-
}
|
|
54125
|
-
});
|
|
54126
|
-
}
|
|
54127
|
-
max(max, message) {
|
|
54128
|
-
message = message || array.max;
|
|
54129
|
-
return this.test({
|
|
54130
|
-
message,
|
|
54131
|
-
name: 'max',
|
|
54132
|
-
exclusive: true,
|
|
54133
|
-
params: {
|
|
54134
|
-
max
|
|
54135
|
-
},
|
|
54136
|
-
skipAbsent: true,
|
|
54137
|
-
test(value) {
|
|
54138
|
-
return value.length <= this.resolve(max);
|
|
54139
|
-
}
|
|
54140
|
-
});
|
|
54141
|
-
}
|
|
54142
|
-
ensure() {
|
|
54143
|
-
return this.default(() => []).transform((val, original) => {
|
|
54144
|
-
// We don't want to return `null` for nullable schema
|
|
54145
|
-
if (this._typeCheck(val)) return val;
|
|
54146
|
-
return original == null ? [] : [].concat(original);
|
|
54147
|
-
});
|
|
54148
|
-
}
|
|
54149
|
-
compact(rejector) {
|
|
54150
|
-
let reject = !rejector ? v => !!v : (v, i, a) => !rejector(v, i, a);
|
|
54151
|
-
return this.transform(values => values != null ? values.filter(reject) : values);
|
|
54152
|
-
}
|
|
54153
|
-
describe(options) {
|
|
54154
|
-
const next = (options ? this.resolve(options) : this).clone();
|
|
54155
|
-
const base = super.describe(options);
|
|
54156
|
-
if (next.innerType) {
|
|
54157
|
-
var _innerOptions;
|
|
54158
|
-
let innerOptions = options;
|
|
54159
|
-
if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
|
|
54160
|
-
innerOptions = Object.assign({}, innerOptions, {
|
|
54161
|
-
parent: innerOptions.value,
|
|
54162
|
-
value: innerOptions.value[0]
|
|
54163
|
-
});
|
|
54164
|
-
}
|
|
54165
|
-
base.innerType = next.innerType.describe(innerOptions);
|
|
54166
|
-
}
|
|
54167
|
-
return base;
|
|
54168
|
-
}
|
|
54169
|
-
}
|
|
54170
|
-
create$2.prototype = ArraySchema.prototype;
|
|
54171
|
-
|
|
54172
|
-
class PaymentWidgetValidationError extends Error {
|
|
54173
|
-
constructor(message) {
|
|
54174
|
-
super(message);
|
|
54175
|
-
this.name = "PaymentWidgetValidationError";
|
|
54176
|
-
}
|
|
54177
|
-
}
|
|
54178
|
-
// Common schemas
|
|
54179
|
-
const phoneRegex = /^\+?[1-9]\d{1,14}$/;
|
|
54180
|
-
const customerSchema = create$3({
|
|
54181
|
-
first_name: create$6().trim().required("first_name is required"),
|
|
54182
|
-
last_name: create$6().trim().required("last_name is required"),
|
|
54183
|
-
email: create$6()
|
|
54184
|
-
.trim()
|
|
54185
|
-
.email("Invalid email format")
|
|
54186
|
-
.required("email is required"),
|
|
54187
|
-
phone_number: create$6()
|
|
54188
|
-
.trim()
|
|
54189
|
-
.required("phone_number is required")
|
|
54190
|
-
.test("phone-format", "Invalid phone_number format. Should start with + and contain digits", (value) => {
|
|
54191
|
-
if (!value)
|
|
54192
|
-
return false;
|
|
54193
|
-
return phoneRegex.test(value.replace(/[\s-]/g, ""));
|
|
54194
|
-
}),
|
|
54195
|
-
});
|
|
54196
|
-
const optionalCustomerSchema = create$3({
|
|
54197
|
-
first_name: create$6().trim(),
|
|
54198
|
-
last_name: create$6().trim(),
|
|
54199
|
-
email: create$6().trim().email("Invalid email format"),
|
|
54200
|
-
phone_number: create$6()
|
|
54201
|
-
.trim()
|
|
54202
|
-
.test("phone-format", "Invalid phone_number format. Should start with + and contain digits", (value) => {
|
|
54203
|
-
if (!value)
|
|
54204
|
-
return true; // Allow empty for optional
|
|
54205
|
-
return phoneRegex.test(value.replace(/[\s-]/g, ""));
|
|
54206
|
-
}),
|
|
54207
|
-
})
|
|
54208
|
-
.nullable()
|
|
54209
|
-
.notRequired();
|
|
54210
|
-
const productSchema = create$3({
|
|
54211
|
-
product_id: create$6().trim().required("product_id is required"),
|
|
54212
|
-
quantity: create$5().integer().required("quantity is required"),
|
|
54213
|
-
});
|
|
54214
|
-
const deliveryDetailsSchema = create$3({
|
|
54215
|
-
street: create$6().trim().required("delivery_details.street is required"),
|
|
54216
|
-
city: create$6().trim().required("delivery_details.city is required"),
|
|
54217
|
-
state: create$6().trim().required("delivery_details.state is required"),
|
|
54218
|
-
country: create$6().trim().required("delivery_details.country is required"),
|
|
54219
|
-
});
|
|
54220
|
-
const optionalDeliveryDetailsSchema = create$3({
|
|
54221
|
-
street: create$6().trim(),
|
|
54222
|
-
city: create$6().trim(),
|
|
54223
|
-
state: create$6().trim(),
|
|
54224
|
-
country: create$6().trim(),
|
|
54225
|
-
})
|
|
54226
|
-
.nullable()
|
|
54227
|
-
.notRequired();
|
|
54228
|
-
// Type-specific schemas
|
|
54229
|
-
const externalSchema = create$3({
|
|
54230
|
-
public_key: create$6()
|
|
54231
|
-
.trim()
|
|
54232
|
-
.required("public_key is required and cannot be empty"),
|
|
54233
|
-
type: create$6().oneOf(["external"]).required("type is required"),
|
|
54234
|
-
amount: create$5()
|
|
54235
|
-
.required("amount is required and must be a positive number for external payment type"),
|
|
54236
|
-
customer: customerSchema.required(),
|
|
54237
|
-
});
|
|
54238
|
-
const storefrontSchema = create$3({
|
|
54239
|
-
public_key: create$6()
|
|
54240
|
-
.trim()
|
|
54241
|
-
.required("public_key is required and cannot be empty"),
|
|
54242
|
-
type: create$6().oneOf(["storefront"]).required("type is required"),
|
|
54243
|
-
slug: create$6()
|
|
54244
|
-
.trim()
|
|
54245
|
-
.required("slug is required for storefront payment type"),
|
|
54246
|
-
channel: create$6()
|
|
54247
|
-
.oneOf(["pickup", "delivery"])
|
|
54248
|
-
.required("channel is required for storefront payment type"),
|
|
54249
|
-
customer: optionalCustomerSchema,
|
|
54250
|
-
products: create$2()
|
|
54251
|
-
.of(productSchema)
|
|
54252
|
-
.min(1, "At least one product is required for storefront payment type")
|
|
54253
|
-
.required("products array is required for storefront payment type"),
|
|
54254
|
-
delivery_details: create$8().when("channel", {
|
|
54255
|
-
is: "delivery",
|
|
54256
|
-
then: () => deliveryDetailsSchema.required("delivery_details is required when channel is delivery"),
|
|
54257
|
-
otherwise: () => optionalDeliveryDetailsSchema,
|
|
54258
|
-
}),
|
|
54259
|
-
});
|
|
54260
|
-
const sloudfrontSchema = create$3({
|
|
54261
|
-
public_key: create$6()
|
|
54262
|
-
.trim()
|
|
54263
|
-
.required("public_key is required and cannot be empty"),
|
|
54264
|
-
type: create$6().oneOf(["sloudfront"]).required("type is required"),
|
|
54265
|
-
// transaction_id: yup
|
|
54266
|
-
// .string()
|
|
54267
|
-
// .trim()
|
|
54268
|
-
// .required("transaction_id is required for sloudfront payment type"),
|
|
54269
|
-
customer_id: create$6()
|
|
54270
|
-
.trim()
|
|
54271
|
-
.required("customer_id is required for sloudfront payment type"),
|
|
54272
|
-
business_id: create$6()
|
|
54273
|
-
.trim()
|
|
54274
|
-
.required("business_id is required for sloudfront payment type"),
|
|
54275
|
-
amount: create$5()
|
|
54276
|
-
.required("amount is required and must be a positive number for sloudfront payment type"),
|
|
54277
|
-
channel: create$6()
|
|
54278
|
-
.oneOf(["pickup", "delivery"])
|
|
54279
|
-
.required("channel is required for sloudfront payment type"),
|
|
54280
|
-
customer: optionalCustomerSchema,
|
|
54281
|
-
products: create$2()
|
|
54282
|
-
.of(productSchema)
|
|
54283
|
-
.min(1, "At least one product is required for sloudfront payment type")
|
|
54284
|
-
.required("products array is required for sloudfront payment type"),
|
|
54285
|
-
delivery_details: create$8().when("channel", {
|
|
54286
|
-
is: "delivery",
|
|
54287
|
-
then: () => deliveryDetailsSchema.required("delivery_details is required when channel is delivery"),
|
|
54288
|
-
otherwise: () => optionalDeliveryDetailsSchema,
|
|
54289
|
-
}),
|
|
54290
|
-
});
|
|
54291
|
-
/**
|
|
54292
|
-
* Validates payment widget options based on the type
|
|
54293
|
-
* @throws {PaymentWidgetValidationError} if validation fails
|
|
54294
|
-
*/
|
|
54295
|
-
function validatePaymentWidgetOptions(options) {
|
|
54296
|
-
try {
|
|
54297
|
-
// Validate based on type
|
|
54298
|
-
if (options.type === "external") {
|
|
54299
|
-
externalSchema.validateSync(options, { abortEarly: false });
|
|
54300
|
-
}
|
|
54301
|
-
else if (options.type === "storefront") {
|
|
54302
|
-
storefrontSchema.validateSync(options, { abortEarly: false });
|
|
54303
|
-
}
|
|
54304
|
-
else if (options.type === "sloudfront") {
|
|
54305
|
-
sloudfrontSchema.validateSync(options, { abortEarly: false });
|
|
54306
|
-
}
|
|
54307
|
-
else {
|
|
54308
|
-
throw new PaymentWidgetValidationError(`Invalid type: ${options.type}. Must be "external", "storefront", or "sloudfront"`);
|
|
54309
|
-
}
|
|
54310
|
-
}
|
|
54311
|
-
catch (error) {
|
|
54312
|
-
if (error instanceof ValidationError) {
|
|
54313
|
-
// Throw the first validation error message
|
|
54314
|
-
throw new PaymentWidgetValidationError(error.errors[0] || "Validation failed");
|
|
54315
|
-
}
|
|
54316
|
-
throw error;
|
|
54317
|
-
}
|
|
54318
|
-
}
|
|
54319
|
-
|
|
54320
51399
|
class PaymentWidget {
|
|
54321
51400
|
options;
|
|
54322
51401
|
container = null;
|
|
54323
51402
|
root = null;
|
|
54324
51403
|
constructor(options) {
|
|
54325
|
-
// Validate options before proceeding
|
|
54326
|
-
validatePaymentWidgetOptions(options);
|
|
54327
51404
|
this.options = options;
|
|
54328
51405
|
// Set widget options immediately for services to use
|
|
54329
51406
|
setWidgetOptions(options);
|
|
51407
|
+
console.log("PaymentWidget initialized with key:", this.options.public_key);
|
|
54330
51408
|
}
|
|
54331
51409
|
/**
|
|
54332
51410
|
* Creates the container div if it doesn’t exist.
|
|
@@ -54348,6 +51426,7 @@ to {
|
|
|
54348
51426
|
this.ensureContainer();
|
|
54349
51427
|
if (this.root && this.container) {
|
|
54350
51428
|
this.root.render(jsxRuntimeExports.jsx(PaymentWidgetProvider, { options: this.options, children: jsxRuntimeExports.jsx(PaymentInfoProvider, { children: jsxRuntimeExports.jsx(ModalProvider, { children: jsxRuntimeExports.jsx(Widget, { isOpen: true }, Date.now()) }) }) }));
|
|
51429
|
+
console.log(`PaymentWidget popup shown [env=${this.options.isLocalEnv ? "local" : "prod"}]`);
|
|
54351
51430
|
}
|
|
54352
51431
|
}
|
|
54353
51432
|
/**
|
|
@@ -54363,24 +51442,7 @@ to {
|
|
|
54363
51442
|
}
|
|
54364
51443
|
}
|
|
54365
51444
|
|
|
54366
|
-
|
|
54367
|
-
* Enum for backward compatibility and convenience
|
|
54368
|
-
* Use either string literals or enum values
|
|
54369
|
-
*/
|
|
54370
|
-
exports.ModeType = void 0;
|
|
54371
|
-
(function (ModeType) {
|
|
54372
|
-
ModeType["Storefront"] = "storefront";
|
|
54373
|
-
ModeType["External"] = "external";
|
|
54374
|
-
ModeType["Sloudfront"] = "sloudfront";
|
|
54375
|
-
})(exports.ModeType || (exports.ModeType = {}));
|
|
54376
|
-
|
|
54377
|
-
exports.PaymentWidgetValidationError = PaymentWidgetValidationError;
|
|
54378
|
-
exports.buildPaymentInstrumentPayload = buildPaymentInstrumentPayload;
|
|
54379
|
-
exports.default = PaymentWidget;
|
|
54380
|
-
exports.getRegisteredPaymentTypes = getRegisteredPaymentTypes;
|
|
54381
|
-
exports.registerPayloadBuilder = registerPayloadBuilder;
|
|
54382
|
-
exports.validatePaymentWidgetOptions = validatePaymentWidgetOptions;
|
|
54383
|
-
|
|
54384
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
51445
|
+
return PaymentWidget;
|
|
54385
51446
|
|
|
54386
51447
|
}));
|
|
51448
|
+
//# sourceMappingURL=index.umd.js.map
|