@mframework/layer-commerce 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -0
- package/app/cart/useCart.ts +1 -0
- package/app/components/ChevronIcon/ChevronIcon.config.ts +17 -0
- package/app/components/DateSelect/DateSelect.config.ts +15 -0
- package/app/components/Field/Field.config.ts +14 -0
- package/app/components/FieldDate/FieldDate.config.ts +16 -0
- package/app/components/Form/Form.type.ts +8 -0
- package/app/components/Product/Product.config.ts +19 -0
- package/app/components/Product/Stock.config.ts +15 -0
- package/app/components/ProductCustomizableOption/ProductCustomizableOption.config.ts +5 -0
- package/app/components/ProductGallery/ProductGallery.config.ts +15 -0
- package/app/components/ProductReviews/ProductReviews.config.ts +8 -0
- package/app/composables/_types.ts +18 -0
- package/app/composables/adapters/abstract/cartAdapter.ts +0 -0
- package/app/composables/adapters/abstract/categoryAdapter.ts +0 -0
- package/app/composables/adapters/abstract/customerAdapter.ts +0 -0
- package/app/composables/adapters/abstract/inventoryAdapter.ts +0 -0
- package/app/composables/adapters/abstract/orderAdapter.ts +0 -0
- package/app/composables/adapters/abstract/productAdapter.ts +7 -0
- package/app/composables/cart/registry.ts +20 -0
- package/app/composables/cart/types.ts +18 -0
- package/app/composables/cart/useCart.ts +15 -0
- package/app/composables/config.ts +19 -0
- package/app/composables/defs/apiDefinitions.ts +55 -0
- package/app/composables/defs/extension.feature +40 -0
- package/app/composables/defs/extension.mocks.ts +39 -0
- package/app/composables/defs/extension.test.ts +280 -0
- package/app/composables/defs/extension.ts +236 -0
- package/app/composables/defs/index.ts +3 -0
- package/app/composables/defs/typeHelpers.ts +8 -0
- package/app/composables/defs/types.ts +136 -0
- package/app/composables/domain/product.ts +12 -0
- package/app/composables/featured-products.ts +20 -0
- package/app/composables/helpers/contextualizedNormalizers.feature +14 -0
- package/app/composables/helpers/contextualizedNormalizers.test.ts +85 -0
- package/app/composables/helpers/contextualizedNormalizers.ts +20 -0
- package/app/composables/helpers/index.ts +1 -0
- package/app/composables/index.ts +9 -0
- package/app/composables/methods/auth.ts +83 -0
- package/app/composables/methods/cart.ts +119 -0
- package/app/composables/methods/category.ts +27 -0
- package/app/composables/methods/checkout.ts +54 -0
- package/app/composables/methods/customer.ts +52 -0
- package/app/composables/methods/helpers.ts +5 -0
- package/app/composables/methods/index.ts +75 -0
- package/app/composables/methods/order.ts +39 -0
- package/app/composables/methods/product.ts +95 -0
- package/app/composables/methods/settings.ts +16 -0
- package/app/composables/models/cart.ts +95 -0
- package/app/composables/models/category.ts +13 -0
- package/app/composables/models/checkout.ts +17 -0
- package/app/composables/models/customer.ts +16 -0
- package/app/composables/models/facets.ts +25 -0
- package/app/composables/models/index.ts +94 -0
- package/app/composables/models/order.ts +43 -0
- package/app/composables/models/product.ts +73 -0
- package/app/composables/models/shared.ts +75 -0
- package/app/composables/orders.ts +69 -0
- package/app/composables/products/registry.ts +86 -0
- package/app/composables/products/types.ts +8 -0
- package/app/composables/products/useEvents.ts +26 -0
- package/app/composables/products/useGiftCards.ts +29 -0
- package/app/composables/products/useProducts.ts +12 -0
- package/app/composables/products/useSubscriptions.ts +29 -0
- package/app/composables/products.ts +30 -0
- package/app/composables/registry.ts +24 -0
- package/app/composables/useAuth.ts +43 -0
- package/app/composables/useBreakpoints/index.ts +1 -0
- package/app/composables/useBreakpoints/useBreakpoints.ts +28 -0
- package/app/composables/useCache.ts +38 -0
- package/app/composables/useCart/__tests__/useCart.spec.ts +11 -0
- package/app/composables/useCart/index.ts +1 -0
- package/app/composables/useCart/types.ts +17 -0
- package/app/composables/useCart/useCart.ts +46 -0
- package/app/composables/useCartShippingMethods/__tests__/useCartShippingMethods.spec.ts +11 -0
- package/app/composables/useCartShippingMethods/index.ts +1 -0
- package/app/composables/useCartShippingMethods/types.ts +17 -0
- package/app/composables/useCartShippingMethods/useCartShippingMethods.ts +47 -0
- package/app/composables/useCatalog.ts +26 -0
- package/app/composables/useContent.ts +26 -0
- package/app/composables/useCustomer/__tests__/useCustomer.spec.ts +25 -0
- package/app/composables/useCustomer/index.ts +2 -0
- package/app/composables/useCustomer/types.ts +17 -0
- package/app/composables/useCustomer/useCustomer.ts +40 -0
- package/app/composables/useCustomerAddress/__tests__/useCustomerAddress.spec.ts +11 -0
- package/app/composables/useCustomerAddress/index.ts +2 -0
- package/app/composables/useCustomerAddress/types.ts +17 -0
- package/app/composables/useCustomerAddress/useCustomerAddress.ts +55 -0
- package/app/composables/useCustomerOrder/__tests__/useCustomerOrder.spec.ts +11 -0
- package/app/composables/useCustomerOrder/adress.ts +10 -0
- package/app/composables/useCustomerOrder/index.ts +2 -0
- package/app/composables/useCustomerOrder/product.ts +37 -0
- package/app/composables/useCustomerOrder/types.ts +40 -0
- package/app/composables/useCustomerOrder/useCustomerOrder.ts +63 -0
- package/app/composables/useCustomerOrders/__tests__/useCustomerOrders.spec.ts +11 -0
- package/app/composables/useCustomerOrders/index.ts +2 -0
- package/app/composables/useCustomerOrders/types.ts +20 -0
- package/app/composables/useCustomerOrders/useCustomerOrders.ts +56 -0
- package/app/composables/useCustomerReturns/__tests__/useCustomerReturns.spec.ts +11 -0
- package/app/composables/useCustomerReturns/index.ts +2 -0
- package/app/composables/useCustomerReturns/types.ts +17 -0
- package/app/composables/useCustomerReturns/useCustomerReturns.ts +41 -0
- package/app/composables/useHandleError/index.ts +1 -0
- package/app/composables/useHandleError/types.ts +11 -0
- package/app/composables/useHandleError/useHandleError.ts +27 -0
- package/app/composables/useInventory.ts +29 -0
- package/app/composables/useLoading.ts +21 -0
- package/app/composables/useNotification.ts +21 -0
- package/app/composables/usePageTitle.ts +20 -0
- package/app/composables/useProduct/index.ts +2 -0
- package/app/composables/useProduct/types.ts +17 -0
- package/app/composables/useProduct/useProduct.ts +42 -0
- package/app/composables/useProductAttribute/__tests__/useProduct.mock.ts +31 -0
- package/app/composables/useProductAttribute/__tests__/useProductAttribute.spec.ts +14 -0
- package/app/composables/useProductAttribute/index.ts +1 -0
- package/app/composables/useProductAttribute/useProductAttribute.ts +37 -0
- package/app/composables/useProductRecommended/__tests__/useProductRecommended.spec.ts +12 -0
- package/app/composables/useProductRecommended/index.ts +1 -0
- package/app/composables/useProductRecommended/types.ts +17 -0
- package/app/composables/useProductRecommended/useProductRecommended.ts +43 -0
- package/app/composables/useProductReviews/__tests__/productReviews.mock.ts +20 -0
- package/app/composables/useProductReviews/__tests__/useProductReviews.spec.ts +22 -0
- package/app/composables/useProductReviews/index.ts +2 -0
- package/app/composables/useProductReviews/types.ts +17 -0
- package/app/composables/useProductReviews/useProductReviews.ts +46 -0
- package/app/composables/useProducts/__tests__/useProducts.spec.ts +11 -0
- package/app/composables/useProducts/types.ts +22 -0
- package/app/composables/useProducts/useProducts.ts +41 -0
- package/app/composables/useTax.ts +27 -0
- package/app/composables/validationRules/index.ts +1 -0
- package/app/composables/validationRules/password.feature +67 -0
- package/app/composables/validationRules/password.test.ts +89 -0
- package/app/composables/validationRules/password.ts +25 -0
- package/app/normalizers/Cart.query.ts +729 -0
- package/app/normalizers/Cart.type.ts +285 -0
- package/app/normalizers/Category.query.ts +146 -0
- package/app/normalizers/Category.type.ts +55 -0
- package/app/normalizers/CheckEmail.query.ts +28 -0
- package/app/normalizers/Checkout.query.ts +253 -0
- package/app/normalizers/Checkout.type.ts +77 -0
- package/app/normalizers/CmsBlock.query.ts +57 -0
- package/app/normalizers/CmsBlock.type.ts +25 -0
- package/app/normalizers/CmsPage.query.ts +59 -0
- package/app/normalizers/CmsPage.type.ts +26 -0
- package/app/normalizers/Config.query.ts +224 -0
- package/app/normalizers/Config.type.ts +196 -0
- package/app/normalizers/ContactForm.query.ts +49 -0
- package/app/normalizers/CreditMemo.type.ts +49 -0
- package/app/normalizers/GiftCard.type.ts +24 -0
- package/app/normalizers/Invoice.type.ts +58 -0
- package/app/normalizers/Menu.query.ts +54 -0
- package/app/normalizers/Menu.type.ts +22 -0
- package/app/normalizers/MyAccount.query.ts +268 -0
- package/app/normalizers/MyAccount.type.ts +129 -0
- package/app/normalizers/NewsletterSubscription.query.ts +38 -0
- package/app/normalizers/Order.query.ts +741 -0
- package/app/normalizers/Order.type.ts +268 -0
- package/app/normalizers/Payment.type.ts +28 -0
- package/app/normalizers/ProductAlerts.query.ts +23 -0
- package/app/normalizers/ProductCompare.query.ts +226 -0
- package/app/normalizers/ProductCompare.type.ts +90 -0
- package/app/normalizers/ProductList.query.ts +1620 -0
- package/app/normalizers/ProductList.type.ts +726 -0
- package/app/normalizers/Region.query.ts +58 -0
- package/app/normalizers/Region.type.ts +23 -0
- package/app/normalizers/Return.type.ts +50 -0
- package/app/normalizers/Review.query.ts +81 -0
- package/app/normalizers/Review.type.ts +42 -0
- package/app/normalizers/Slider.query.ts +72 -0
- package/app/normalizers/Slider.type.ts +26 -0
- package/app/normalizers/StoreInPickUp.query.ts +54 -0
- package/app/normalizers/StoreInPickUp.type.ts +59 -0
- package/app/normalizers/Subscription.type.ts +25 -0
- package/app/normalizers/Transaction.type.ts +20 -0
- package/app/normalizers/UrlRewrites.query.ts +55 -0
- package/app/normalizers/UrlRewrites.type.ts +25 -0
- package/app/normalizers/Wishlist.query.ts +202 -0
- package/app/normalizers/Wishlist.type.ts +42 -0
- package/app/pages/brand/[...slug].vue +76 -0
- package/app/pages/brands.vue +67 -0
- package/app/pages/cart.vue +142 -0
- package/app/pages/compare.vue +166 -0
- package/app/pages/departments/[...slug].vue +353 -0
- package/app/pages/departments/category/[...slug].vue +114 -0
- package/app/pages/incentive/[...id].vue +66 -0
- package/app/pages/invoice/[id].vue +309 -0
- package/app/pages/order/[id].vue +327 -0
- package/app/pages/product/[...id].vue +309 -0
- package/app/pages/product/showcases/index.vue +86 -0
- package/app/pages/shipment/[...id].vue +176 -0
- package/app/pages/shop/[...slug].vue +158 -0
- package/app/pages/shops.vue +76 -0
- package/app/pages/subscription/[...id].vue +147 -0
- package/app/pages/transaction/[...id].vue +74 -0
- package/app/routes/CategoryPage/CategoryPage.config.ts +28 -0
- package/app/routes/CategoryPage/CategoryPage.type.ts +8 -0
- package/app/routes/Checkout/Checkout.config.ts +3 -0
- package/app/routes/Checkout/Checkout.type.ts +14 -0
- package/app/routes/MyAccount/MyAccount.config.ts +1 -0
- package/app/routes/SearchPage/SearchPage.config.ts +1 -0
- package/app/routes/UrlRewrites/UrlRewrites.config.ts +5 -0
- package/app/stores/Cart/Cart.type.ts +26 -0
- package/app/stores/MyAccount/MyAccount.action.ts +7 -0
- package/app/stores/Notification/Notification.action.ts +40 -0
- package/app/stores/Notification/Notification.type.ts +16 -0
- package/app/stores/Popup/Popup.action.ts +30 -0
- package/app/stores/Product/Product.dispatcher.ts +53 -0
- package/app/stores/Product/Product.reducer.ts +12 -0
- package/app/stores/ProductList/ProductList.dispatcher.ts +35 -0
- package/app/stores/ProductList/ProductList.reducer.ts +13 -0
- package/app/stores/Store.type.ts +31 -0
- package/app/stores/Wishlist/Wishlist.type.ts +12 -0
- package/app/stores/cart.ts +218 -0
- package/app/stores/cartStore.ts +224 -0
- package/app/stores/checkout.ts +18 -0
- package/app/stores/compare.ts +65 -0
- package/app/stores/currency.js +29 -0
- package/app/stores/digital-products.js +11 -0
- package/app/stores/orders.ts +172 -0
- package/app/stores/product.ts +34 -0
- package/app/stores/productList.ts +35 -0
- package/app/stores/productListInfo.ts +0 -0
- package/app/stores/products.ts +118 -0
- package/app/stores/recentlyViewedProducts.ts +56 -0
- package/app/stores/review.ts +33 -0
- package/app/stores/storeInPickUp.ts +21 -0
- package/app/stores/user.ts +20 -0
- package/app/stores/wishlist.ts +46 -0
- package/app/types/Account.type.ts +141 -0
- package/app/types/Breadcrumbs.type.ts +23 -0
- package/app/types/CMS.type.ts +33 -0
- package/app/types/Category.type.ts +67 -0
- package/app/types/Checkout.type.ts +58 -0
- package/app/types/Common.type.ts +77 -0
- package/app/types/Config.type.ts +47 -0
- package/app/types/Device.type.ts +37 -0
- package/app/types/Direction.type.ts +23 -0
- package/app/types/Downloadable.type.ts +24 -0
- package/app/types/Error.type.ts +22 -0
- package/app/types/Field.type.ts +151 -0
- package/app/types/Global.type.ts +156 -0
- package/app/types/Graphql.type.ts +4497 -0
- package/app/types/Layout.type.ts +18 -0
- package/app/types/Menu.type.ts +39 -0
- package/app/types/MiniCart.type.ts +61 -0
- package/app/types/NotificationList.type.ts +34 -0
- package/app/types/Order.type.ts +174 -0
- package/app/types/Price.type.ts +72 -0
- package/app/types/ProductCompare.type.ts +24 -0
- package/app/types/ProductList.type.ts +351 -0
- package/app/types/Rating.type.ts +42 -0
- package/app/types/Router.type.ts +67 -0
- package/app/types/Slider.type.ts +25 -0
- package/app/types/StockStatus.type.ts +21 -0
- package/app/types/domain/index.ts +94 -0
- package/app/types/index.ts +33 -0
- package/app/types/shims.d.ts +52 -0
- package/app/types/tilework-opus.d.ts +48 -0
- package/app/utils/Address/Address.type.ts +28 -0
- package/app/utils/Address/index.ts +325 -0
- package/app/utils/Auth/IsSignedIn.ts +4 -0
- package/app/utils/Auth/Token.ts +9 -0
- package/app/utils/Base64/Base64.ts +16 -0
- package/app/utils/Base64/index.ts +12 -0
- package/app/utils/Browser/Browser.ts +29 -0
- package/app/utils/Browser/index.ts +12 -0
- package/app/utils/BrowserDatabase/BrowserDatabase.ts +70 -0
- package/app/utils/BrowserDatabase/index.ts +12 -0
- package/app/utils/CSS/CSS.ts +65 -0
- package/app/utils/CSS/index.ts +12 -0
- package/app/utils/Cache/Cache.ts +99 -0
- package/app/utils/Cart/Cart.ts +300 -0
- package/app/utils/Cart/Cart.type.ts +76 -0
- package/app/utils/Cart/Token.ts +59 -0
- package/app/utils/Cart/index.ts +13 -0
- package/app/utils/Category/Filters.ts +39 -0
- package/app/utils/Category/index.ts +12 -0
- package/app/utils/Common/index.ts +32 -0
- package/app/utils/Compare/Compare.ts +89 -0
- package/app/utils/Compare/index.ts +12 -0
- package/app/utils/Currency/Currency.ts +84 -0
- package/app/utils/Currency/index.ts +12 -0
- package/app/utils/DynamicReducer/DynamicReducer.type.ts +14 -0
- package/app/utils/DynamicReducer/Helper.ts +30 -0
- package/app/utils/DynamicReducer/index.tsx +35 -0
- package/app/utils/ElementTransition/ElementTransition.ts +100 -0
- package/app/utils/Form/Extract.ts +316 -0
- package/app/utils/Form/Form.ts +46 -0
- package/app/utils/Form/Form.type.ts +60 -0
- package/app/utils/Form/Transform.ts +33 -0
- package/app/utils/FormPortalCollector/index.ts +45 -0
- package/app/utils/History/History.type.ts +31 -0
- package/app/utils/History/index.ts +17 -0
- package/app/utils/Manipulations/Array.ts +18 -0
- package/app/utils/Manipulations/Date.ts +36 -0
- package/app/utils/Manipulations/index.ts +14 -0
- package/app/utils/Media/Media.ts +27 -0
- package/app/utils/Media/index.ts +13 -0
- package/app/utils/Menu/Menu.ts +116 -0
- package/app/utils/Menu/Menu.type.ts +37 -0
- package/app/utils/Menu/index.ts +12 -0
- package/app/utils/Mobile/index.ts +13 -0
- package/app/utils/Mobile/isMobile.ts +34 -0
- package/app/utils/Orders/Orders.ts +71 -0
- package/app/utils/Orders/Orders.type.ts +19 -0
- package/app/utils/Orders/index.ts +13 -0
- package/app/utils/Polyfill/index.ts +336 -0
- package/app/utils/Preload/CategoryPreload.ts +74 -0
- package/app/utils/Preload/ProductPreload.ts +28 -0
- package/app/utils/Preload/index.ts +75 -0
- package/app/utils/Price/Price.config.ts +189 -0
- package/app/utils/Price/Price.ts +63 -0
- package/app/utils/Price/index.ts +12 -0
- package/app/utils/Product/Extract.ts +652 -0
- package/app/utils/Product/Product.ts +575 -0
- package/app/utils/Product/Product.type.ts +260 -0
- package/app/utils/Product/Transform.ts +382 -0
- package/app/utils/Product/index.ts +12 -0
- package/app/utils/Promise/MakeCancelable.ts +44 -0
- package/app/utils/Promise/Promise.type.ts +15 -0
- package/app/utils/Promise/index.ts +13 -0
- package/app/utils/Query/Field.ts +71 -0
- package/app/utils/Query/Fragment.ts +22 -0
- package/app/utils/Query/PrepareDocument.ts +119 -0
- package/app/utils/Query/Query.type.ts +26 -0
- package/app/utils/Query/index.ts +15 -0
- package/app/utils/Request/Config.ts +21 -0
- package/app/utils/Request/DataContainer.ts +102 -0
- package/app/utils/Request/Debounce.ts +48 -0
- package/app/utils/Request/Error.ts +31 -0
- package/app/utils/Request/Hash.ts +88 -0
- package/app/utils/Request/LowPriorityLoad.ts +32 -0
- package/app/utils/Request/LowPriorityRender.ts +55 -0
- package/app/utils/Request/Mutation.ts +25 -0
- package/app/utils/Request/Query.ts +25 -0
- package/app/utils/Request/QueryDispatcher.ts +135 -0
- package/app/utils/Request/Request.ts +310 -0
- package/app/utils/Store/Store.type.ts +26 -0
- package/app/utils/Store/index.ts +71 -0
- package/app/utils/Url/Url.ts +297 -0
- package/app/utils/Url/index.ts +12 -0
- package/app/utils/Validator/Config.ts +96 -0
- package/app/utils/Validator/Validator.ts +268 -0
- package/app/utils/Validator/Validator.type.ts +47 -0
- package/app/utils/Validator/index.ts +12 -0
- package/app/utils/Wishlist/Wishlist.ts +65 -0
- package/app/utils/Wishlist/index.ts +12 -0
- package/app/utils/client.ts +280 -0
- package/app/utils/index.ts +53 -0
- package/app/utils/normalizer.ts +23 -0
- package/app/utils/normalizers/magento.ts +29 -0
- package/app/utils/normalizers/shopify.ts +29 -0
- package/nuxt.config.ts +11 -0
- package/package.json +43 -0
- package/tsconfig.json +45 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
declare module '@tilework/opus' {
|
|
2
|
+
// Keep generics for compatibility in annotations, but use non-generic member types
|
|
3
|
+
// so different generic instantiations remain structurally compatible.
|
|
4
|
+
export class AbstractField<Name extends string = string, T = any, Required extends boolean = boolean> {
|
|
5
|
+
name: string
|
|
6
|
+
alias?: string
|
|
7
|
+
args?: Record<string, any>
|
|
8
|
+
children?: Array<AbstractField | string>
|
|
9
|
+
required: boolean
|
|
10
|
+
constructor(name: string, required?: boolean)
|
|
11
|
+
setAlias(alias: string): this
|
|
12
|
+
addArgument(name: string, type: string, value?: any): this
|
|
13
|
+
addField(field: AbstractField | string): this
|
|
14
|
+
addFieldList(fields: Array<AbstractField | string>): this
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class Field<Name extends string = string, T = any, Required extends boolean = boolean> extends AbstractField<Name, T, Required> {
|
|
18
|
+
constructor(name: string, required?: boolean)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class InlineFragment<Name extends string = string, T = any, Required extends boolean = boolean> extends AbstractField<Name, T, Required> {
|
|
22
|
+
constructor(typeName: string, fields?: Array<AbstractField | string>)
|
|
23
|
+
addFieldList(fields: Array<AbstractField | string>): this
|
|
24
|
+
addField(field: AbstractField | string): this
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class Query<Name extends string = string, T = any, Required extends boolean = boolean> extends AbstractField<Name, T, Required> {
|
|
28
|
+
constructor(name?: string, required?: boolean)
|
|
29
|
+
addFragment(fragment: InlineFragment | string): this
|
|
30
|
+
build(): string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class Mutation<Name extends string = string, T = any, Required extends boolean = boolean> extends AbstractField<Name, T, Required> {
|
|
34
|
+
constructor(name?: string)
|
|
35
|
+
build(): string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class Argument {
|
|
39
|
+
name: string
|
|
40
|
+
type: string
|
|
41
|
+
value?: any
|
|
42
|
+
constructor(name: string, type: string, value?: any)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type GraphQlResponse<T = any> = T
|
|
46
|
+
|
|
47
|
+
export default Query
|
|
48
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M Framework - Flexible backend agnostic framework.
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Meeovi, LTD. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package mframework/mframework-theme
|
|
9
|
+
* @link https://github.com/meeovi/mframework
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { Country } from '../../normalizers/Region.type';
|
|
13
|
+
|
|
14
|
+
export interface ZippopotamResponseResult {
|
|
15
|
+
city: string;
|
|
16
|
+
region: string;
|
|
17
|
+
regionAbbr: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface FormattedRegion {
|
|
21
|
+
country?: string;
|
|
22
|
+
region?: string | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface CountryOption extends Country {
|
|
26
|
+
name: string;
|
|
27
|
+
value: string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M Framework - Flexible backend agnostic framework.
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Meeovi, LTD. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package mframework/mframework
|
|
9
|
+
* @link https://github.com/meeovi/mframework
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { CustomerAddress } from '../../normalizers/MyAccount.type';
|
|
13
|
+
import { OrderAddress } from '../../normalizers/Order.type';
|
|
14
|
+
import { Country, Region } from '../../normalizers/Region.type';
|
|
15
|
+
import { Store } from '../../normalizers/StoreInPickUp.type';
|
|
16
|
+
import { CheckoutAddress } from '../../routes/Checkout/Checkout.type';
|
|
17
|
+
import { GQLCountryCodeEnum, GQLCustomerAddressInput } from '../../types/Graphql.type';
|
|
18
|
+
import { getStoreState } from '../../utils/Store';
|
|
19
|
+
|
|
20
|
+
import { CountryOption, FormattedRegion, ZippopotamResponseResult } from './Address.type';
|
|
21
|
+
|
|
22
|
+
/** @namespace ../../utils/Address/Index/trimCustomerAddress */
|
|
23
|
+
export const trimCustomerAddress = (customerAddress: Partial<CustomerAddress>): GQLCustomerAddressInput => {
|
|
24
|
+
const {
|
|
25
|
+
default_shipping = false,
|
|
26
|
+
default_billing = false,
|
|
27
|
+
company,
|
|
28
|
+
city = '',
|
|
29
|
+
country_id = GQLCountryCodeEnum.US,
|
|
30
|
+
firstname = '',
|
|
31
|
+
lastname = '',
|
|
32
|
+
middlename = '',
|
|
33
|
+
postcode = '',
|
|
34
|
+
street = [''],
|
|
35
|
+
telephone = '',
|
|
36
|
+
region: {
|
|
37
|
+
region_code,
|
|
38
|
+
region,
|
|
39
|
+
region_id = 1,
|
|
40
|
+
} = {},
|
|
41
|
+
prefix = '',
|
|
42
|
+
suffix = '',
|
|
43
|
+
vat_id,
|
|
44
|
+
} = customerAddress;
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
company,
|
|
48
|
+
default_shipping,
|
|
49
|
+
default_billing,
|
|
50
|
+
city,
|
|
51
|
+
country_id,
|
|
52
|
+
firstname,
|
|
53
|
+
lastname,
|
|
54
|
+
middlename,
|
|
55
|
+
postcode,
|
|
56
|
+
street,
|
|
57
|
+
telephone,
|
|
58
|
+
region: {
|
|
59
|
+
region_code,
|
|
60
|
+
region,
|
|
61
|
+
region_id,
|
|
62
|
+
},
|
|
63
|
+
prefix,
|
|
64
|
+
suffix,
|
|
65
|
+
vat_id,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/** @namespace ../../utils/Address/Index/trimCheckoutCustomerAddress */
|
|
70
|
+
export const trimCheckoutCustomerAddress = (customerAddress: CustomerAddress): CheckoutAddress => {
|
|
71
|
+
const {
|
|
72
|
+
company,
|
|
73
|
+
city = '',
|
|
74
|
+
country_id = GQLCountryCodeEnum.US,
|
|
75
|
+
firstname = '',
|
|
76
|
+
lastname = '',
|
|
77
|
+
postcode = '',
|
|
78
|
+
street = [''],
|
|
79
|
+
telephone = '',
|
|
80
|
+
region: {
|
|
81
|
+
region_code,
|
|
82
|
+
region,
|
|
83
|
+
region_id = 1,
|
|
84
|
+
} = {},
|
|
85
|
+
vat_id,
|
|
86
|
+
} = customerAddress;
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
company,
|
|
90
|
+
city,
|
|
91
|
+
country_id,
|
|
92
|
+
firstname,
|
|
93
|
+
lastname,
|
|
94
|
+
postcode,
|
|
95
|
+
street,
|
|
96
|
+
telephone,
|
|
97
|
+
region,
|
|
98
|
+
region_id,
|
|
99
|
+
region_code,
|
|
100
|
+
vat_id,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** @namespace ../../utils/Address/Index/trimCheckoutAddress */
|
|
105
|
+
export const trimCheckoutAddress = (customerAddress: CheckoutAddress & Record<string, unknown>): CheckoutAddress => {
|
|
106
|
+
const {
|
|
107
|
+
company,
|
|
108
|
+
city = '',
|
|
109
|
+
country_id = GQLCountryCodeEnum.US,
|
|
110
|
+
firstname = '',
|
|
111
|
+
lastname = '',
|
|
112
|
+
postcode = '',
|
|
113
|
+
street = [''],
|
|
114
|
+
telephone = '',
|
|
115
|
+
region_string = '',
|
|
116
|
+
region_id = 0,
|
|
117
|
+
region_code,
|
|
118
|
+
vat_id,
|
|
119
|
+
} = customerAddress;
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
company,
|
|
123
|
+
city,
|
|
124
|
+
country_id,
|
|
125
|
+
firstname,
|
|
126
|
+
lastname,
|
|
127
|
+
postcode,
|
|
128
|
+
street,
|
|
129
|
+
telephone,
|
|
130
|
+
region: region_string as any,
|
|
131
|
+
region_id,
|
|
132
|
+
region_code,
|
|
133
|
+
vat_id,
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Removes null values from address.street
|
|
139
|
+
* @param street
|
|
140
|
+
* @returns {*}
|
|
141
|
+
* @namespace ../../utils/Address/Index/removeEmptyStreets
|
|
142
|
+
*/
|
|
143
|
+
export const removeEmptyStreets = (street: Array<string | null>): Array<string | null> => (
|
|
144
|
+
street.filter((line) => line)
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
/** transforming "street[index]" entries into a single "street" object
|
|
148
|
+
for checkout/billing/myAccoutAddress form fields object */
|
|
149
|
+
/** @namespace ../../utils/Address/Index/setAddressesInFormObject */
|
|
150
|
+
export const setAddressesInFormObject = (
|
|
151
|
+
fields: Record<string, unknown>,
|
|
152
|
+
numberOfLines: number,
|
|
153
|
+
prefix = 'street',
|
|
154
|
+
): CheckoutAddress & Record<string, unknown> => {
|
|
155
|
+
const addressKeys = new Array(numberOfLines)
|
|
156
|
+
.fill('')
|
|
157
|
+
.map((_, index) => `${prefix}${index}`);
|
|
158
|
+
|
|
159
|
+
const addressValues = addressKeys.map((key) => fields[key]) as Array<string | null>;
|
|
160
|
+
|
|
161
|
+
// removing street related fields from the form object
|
|
162
|
+
const newFields = Object.keys(fields)
|
|
163
|
+
.filter((key) => !addressKeys.includes(key))
|
|
164
|
+
.reduce((acc, key) => {
|
|
165
|
+
acc[key] = fields[key];
|
|
166
|
+
|
|
167
|
+
return acc;
|
|
168
|
+
}, {} as CheckoutAddress & Record<string, unknown>);
|
|
169
|
+
|
|
170
|
+
// setting single street entry to the form object
|
|
171
|
+
newFields.street = removeEmptyStreets(addressValues);
|
|
172
|
+
|
|
173
|
+
return newFields;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// get Form Fields object depending on addressLinesQty
|
|
177
|
+
/** @namespace ../../utils/Address/Index/getFormFields */
|
|
178
|
+
export const getFormFields = (
|
|
179
|
+
fields: Record<string, unknown>,
|
|
180
|
+
addressLinesQty: number,
|
|
181
|
+
): Record<string, unknown> | CheckoutAddress & Record<string, unknown> => {
|
|
182
|
+
if (addressLinesQty === 1) {
|
|
183
|
+
return fields;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return setAddressesInFormObject(fields, addressLinesQty);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/** @namespace ../../utils/Address/Index/getCityAndRegionFromZipcode */
|
|
190
|
+
export const getCityAndRegionFromZipcode = async (
|
|
191
|
+
countryId: string,
|
|
192
|
+
value: string,
|
|
193
|
+
): Promise<ZippopotamResponseResult | null> => {
|
|
194
|
+
const response = await fetch(`https://api.zippopotam.us/${countryId}/${value}`);
|
|
195
|
+
const data = await response.json();
|
|
196
|
+
|
|
197
|
+
return data && Object.entries(data).length > 0
|
|
198
|
+
? {
|
|
199
|
+
city: data.places[0]['place name'],
|
|
200
|
+
region: data.places[0].state,
|
|
201
|
+
regionAbbr: data.places[0]['state abbreviation'],
|
|
202
|
+
}
|
|
203
|
+
: null;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/** @namespace ../../utils/Address/Index/getDefaultAddressLabel */
|
|
207
|
+
export const getDefaultAddressLabel = (address: CustomerAddress): string => {
|
|
208
|
+
const { default_billing, default_shipping } = address;
|
|
209
|
+
|
|
210
|
+
if (!default_billing && !default_shipping) {
|
|
211
|
+
return '';
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (default_billing && default_shipping) {
|
|
215
|
+
return __(' (default shipping & billing)');
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (default_billing) {
|
|
219
|
+
return __(' (default billing address)');
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return __(' (default shipping address)');
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/** @namespace ../../utils/Address/Index/getAvailableRegions */
|
|
226
|
+
export const getAvailableRegions = (country_id: string, countries: Country[]): Region[] => {
|
|
227
|
+
const country: Country | undefined = countries.find(({ id }) => id === country_id);
|
|
228
|
+
const { available_regions } = country || {};
|
|
229
|
+
|
|
230
|
+
// need to handle null value
|
|
231
|
+
return available_regions || [];
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/** @namespace ../../utils/Address/Index/getFormattedRegion */
|
|
235
|
+
export const getFormattedRegion = (
|
|
236
|
+
address: CustomerAddress | OrderAddress,
|
|
237
|
+
countries: Country[],
|
|
238
|
+
): FormattedRegion => {
|
|
239
|
+
const { country_id, region: regionData } = address;
|
|
240
|
+
|
|
241
|
+
if (!regionData) {
|
|
242
|
+
return {};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const country = countries.find(({ id }) => id === country_id);
|
|
246
|
+
|
|
247
|
+
if (!country) {
|
|
248
|
+
return {};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const { label, available_regions } = country;
|
|
252
|
+
|
|
253
|
+
if (typeof regionData === 'string') {
|
|
254
|
+
return {
|
|
255
|
+
country: label,
|
|
256
|
+
region: regionData,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const regions = available_regions || [];
|
|
261
|
+
const { region_id, region } = regionData;
|
|
262
|
+
const { name } = regions.find(({ id }) => id === region_id) || { name: region };
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
country: label,
|
|
266
|
+
region: name,
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/** @namespace ../../utils/Address/Index/getRegionIdFromAvailableRegions */
|
|
271
|
+
export const getRegionIdFromAvailableRegions = (
|
|
272
|
+
availableRegions: Region[],
|
|
273
|
+
cityAndRegion: ZippopotamResponseResult,
|
|
274
|
+
): number => {
|
|
275
|
+
const { region, regionAbbr } = cityAndRegion;
|
|
276
|
+
const { id: regionId = 1 } = availableRegions.find(
|
|
277
|
+
({ name, code }) => name === region || code === regionAbbr,
|
|
278
|
+
) || {};
|
|
279
|
+
|
|
280
|
+
return regionId;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
/** @namespace ../../utils/Address/Index/getRegionIdOfRegionName */
|
|
284
|
+
export const getRegionIdOfRegionName = (countryId: string, region: string): number => {
|
|
285
|
+
const countries = (getStoreState()).ConfigReducer?.countries || [];
|
|
286
|
+
const availableRegions = getAvailableRegions(countryId, countries) || [];
|
|
287
|
+
const { id: regionId = 0 } = availableRegions.find(
|
|
288
|
+
({ name }) => name === region,
|
|
289
|
+
) || {};
|
|
290
|
+
|
|
291
|
+
return regionId;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
/** @namespace ../../utils/Address/Index/checkIfStoreIncluded */
|
|
295
|
+
export const checkIfStoreIncluded = (stores: Store[], selectedStore: Store): boolean => {
|
|
296
|
+
const selectedStoreInString = JSON.stringify(selectedStore);
|
|
297
|
+
|
|
298
|
+
return !!stores.find((store) => JSON.stringify(store) === selectedStoreInString);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Transforms countries list into select options
|
|
303
|
+
* @param countries
|
|
304
|
+
* @namespace ../../utils/Address/Index/transformCountriesToOptions */
|
|
305
|
+
export const transformCountriesToOptions = (countries: Country[]): CountryOption[] => {
|
|
306
|
+
const options = countries.map((country) => {
|
|
307
|
+
const { id } = country;
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
value: id,
|
|
311
|
+
name: id,
|
|
312
|
+
...country,
|
|
313
|
+
};
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const filtered = options.filter(({ label }) => label);
|
|
317
|
+
|
|
318
|
+
const sorted = filtered.sort(
|
|
319
|
+
({ label }, { label: labelCompare }) => label.localeCompare(labelCompare),
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
return sorted;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
export default transformCountriesToOptions;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M Framework - Flexible backend agnostic framework.
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Meeovi, LTD. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package mframework/mframework-theme
|
|
9
|
+
* @link https://github.com/meeovi/mframework
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** @namespace ../../utils/Base64/encodeBase64 */
|
|
13
|
+
export const encodeBase64 = (data: string): string => btoa(data);
|
|
14
|
+
|
|
15
|
+
/** @namespace ../../utils/Base64/decodeBase64 */
|
|
16
|
+
export const decodeBase64 = (data: string): string => atob(data);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M Framework - Flexible backend agnostic framework.
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Meeovi, LTD. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package mframework/mframework-theme
|
|
9
|
+
* @link https://github.com/meeovi/mframework
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export * from './Base64';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M Framework - Flexible backend agnostic framework.
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Meeovi, LTD. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package mframework/mframework
|
|
9
|
+
* @link https://github.com/meeovi/mframework
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line max-len
|
|
13
|
+
export const crawlerRegEx = /(googlebot|Googlebot-Mobile|Googlebot-Image|Google favicon|Mediapartners-Google|bingbot|slurp|java|wget|curl|Commons-HttpClient|Python-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sitebot|linkdex|Adidxbot|blekkobot|ezooms|dotbot|Mail.RU_Bot|discobot|heritrix|findthatfile|europarchive.org|NerdByNature.Bot|sistrix crawler|ahrefsbot|Aboundex|domaincrawler|wbsearchbot|summify|ccbot|edisterbot|seznambot|ec2linkfinder|gslfbot|aihitbot|intelium_bot|facebookexternalhit|yeti|RetrevoPageAnalyzer|lb-spider|sogou|lssbot|careerbot|wotbox|wocbot|ichiro|DuckDuckBot|lssrocketcrawler|drupact|webcompanycrawler|acoonbot|openindexspider|gnam gnam spider|web-archive-net.com.bot|backlinkcrawler|coccoc|integromedb|content crawler spider|toplistbot|seokicks-robot|it2media-domain-crawler|ip-web-crawler.com|siteexplorer.info|elisabot|proximic|changedetection|blexbot|arabot|WeSEE:Search|niki-bot|CrystalSemanticsBot|rogerbot|360Spider|psbot|InterfaxScanBot|Lipperhey SEO Service|CC Metadata Scaper|g00g1e.net|GrapeshotCrawler|urlappendbot|brainobot|fr-crawler|binlar|SimpleCrawler|Livelapbot|Twitterbot|cXensebot|smtbot|bnf.fr_bot|A6-Indexer|ADmantX|Facebot|Twitterbot|OrangeBot|memorybot|AdvBot|MegaIndex|SemanticScholarBot|ltx71|nerdybot|xovibot|BUbiNG|Qwantify|archive.org_bot|Applebot|TweetmemeBot|crawler4j|findxbot|SemrushBot|yoozBot|lipperhey|y!j-asr|Domain Re-Animator Bot|AddThis|HeadlessChrome|render|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp|scandibot)/i;
|
|
14
|
+
|
|
15
|
+
/** @namespace ../../utils/Browser/isSSR */
|
|
16
|
+
export const isSSR = (): boolean => !globalThis.window || !globalThis.window.document;
|
|
17
|
+
|
|
18
|
+
/** @namespace ../../utils/Browser/isCrawler */
|
|
19
|
+
export const isCrawler = (): boolean => crawlerRegEx.test(navigator.userAgent);
|
|
20
|
+
|
|
21
|
+
/** @namespace ../../utils/Browser/toggleScroll */
|
|
22
|
+
// eslint-disable-next-line max-len
|
|
23
|
+
export const toggleScroll = (state: boolean): boolean => document.documentElement.classList.toggle('scrollDisabled', !state);
|
|
24
|
+
|
|
25
|
+
/** @namespace ../../utils/Browser/isScrollDisabled */
|
|
26
|
+
export const isScrollDisabled = (): boolean => document.documentElement.classList.contains('scrollDisabled');
|
|
27
|
+
|
|
28
|
+
/** @namespace ../../utils/Browser/scrollToTop */
|
|
29
|
+
export const scrollToTop = (options: ScrollToOptions = {}): void => window.scrollTo({ ...options, top: 0 });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M Framework - Flexible backend agnostic framework.
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Meeovi, LTD. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package mframework/mframework
|
|
9
|
+
* @link https://github.com/meeovi/mframework
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export * from './Browser';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M Framework - Flexible backend agnostic framework.
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Meeovi, LTD. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package mframework/mframework
|
|
9
|
+
* @link https://github.com/meeovi/mframework
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// TODO: maybe consider moving to IndexedDB instead of localStorage
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Set of helpers related to Browser Database
|
|
16
|
+
* @class CSS
|
|
17
|
+
* @namespace ../../utils/BrowserDatabase
|
|
18
|
+
*/
|
|
19
|
+
export class BrowserDatabase {
|
|
20
|
+
/**
|
|
21
|
+
* Loads data from browser storage
|
|
22
|
+
* @param {String} location Name of the local storage
|
|
23
|
+
* @return {Object} Object stored in a specified path
|
|
24
|
+
* @memberof BrowserDatabase
|
|
25
|
+
*/
|
|
26
|
+
getItem<T>(location: string): T | null {
|
|
27
|
+
try {
|
|
28
|
+
const entryObject = JSON.parse(localStorage.getItem(location) || '');
|
|
29
|
+
const { data, expiration, createdAt } = entryObject;
|
|
30
|
+
const MILLISECONDS_TO_SECONDS = 1000;
|
|
31
|
+
|
|
32
|
+
if (expiration && Date.now() - createdAt > expiration * MILLISECONDS_TO_SECONDS) {
|
|
33
|
+
localStorage.removeItem(location);
|
|
34
|
+
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return data as T;
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Save data to local storage
|
|
46
|
+
* @param {Any} data The value to save to local storage
|
|
47
|
+
* @param {String} location Name of the local storage
|
|
48
|
+
* @param {Number} expiration Time to store entry (in seconds)
|
|
49
|
+
* @return {Void}
|
|
50
|
+
* @memberof BrowserDatabase
|
|
51
|
+
*/
|
|
52
|
+
setItem<T>(data: T, location: string, expiration?: number): void {
|
|
53
|
+
localStorage.setItem(location, JSON.stringify({
|
|
54
|
+
data,
|
|
55
|
+
expiration,
|
|
56
|
+
createdAt: Date.now(),
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Delete item from local storage
|
|
62
|
+
* @param {String} location
|
|
63
|
+
* @memberof BrowserDatabase
|
|
64
|
+
*/
|
|
65
|
+
deleteItem(location: string): void {
|
|
66
|
+
localStorage.removeItem(location);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default new BrowserDatabase();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M Framework - Flexible backend agnostic framework.
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Meeovi, LTD. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package mframework/mframework
|
|
9
|
+
* @link https://github.com/meeovi/mframework
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export { default } from './BrowserDatabase';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M Framework - Flexible backend agnostic framework.
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Meeovi, LTD. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package mframework/mframework
|
|
9
|
+
* @link https://github.com/meeovi/mframework
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Set of helpers related to CSS
|
|
14
|
+
* @class CSS
|
|
15
|
+
* @namespace ../../utils/CSS
|
|
16
|
+
*/
|
|
17
|
+
export class CSS {
|
|
18
|
+
/**
|
|
19
|
+
* Change CSS custom property in referenced node scope
|
|
20
|
+
* @static
|
|
21
|
+
* @param {HTMLElement} ref React reference to an HTML element (node).
|
|
22
|
+
* @param {String} name CSS variable name (without `--`).
|
|
23
|
+
* @param {String} value CSS variable value.
|
|
24
|
+
* @return {void}
|
|
25
|
+
* @memberof CSS
|
|
26
|
+
*/
|
|
27
|
+
static setVariable(
|
|
28
|
+
ref: React.RefObject<HTMLElement>,
|
|
29
|
+
name: string,
|
|
30
|
+
value: string | number | null,
|
|
31
|
+
): void {
|
|
32
|
+
if (ref && ref.current) {
|
|
33
|
+
ref.current.style.setProperty(
|
|
34
|
+
`--${name}`,
|
|
35
|
+
value === null ? null : String(value),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** @namespace ../../utils/CSS/getElementHeight */
|
|
42
|
+
export const getElementHeight = (id: string): number => Array.from(
|
|
43
|
+
document.getElementsByClassName(id),
|
|
44
|
+
).reduce((acc, item) => {
|
|
45
|
+
const { offsetHeight } = item as HTMLElement;
|
|
46
|
+
|
|
47
|
+
return acc + offsetHeight;
|
|
48
|
+
}, 0);
|
|
49
|
+
|
|
50
|
+
/** @namespace ../../utils/CSS/getFixedElementHeight */
|
|
51
|
+
export const getFixedElementHeight = (): Record<string, number> => {
|
|
52
|
+
const top = getElementHeight('FixedElement-Top');
|
|
53
|
+
const bottom = getElementHeight('FixedElement-Bottom');
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
total: top + bottom,
|
|
57
|
+
top,
|
|
58
|
+
bottom,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** @namespace ../../utils/CSS/isRtl */
|
|
63
|
+
export const isRtl = (): boolean => document.documentElement.getAttribute('dir') === 'rtl';
|
|
64
|
+
|
|
65
|
+
export default CSS;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M Framework - Flexible backend agnostic framework.
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Meeovi, LTD. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package mframework/mframework
|
|
9
|
+
* @link https://github.com/meeovi/mframework
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export { default, getFixedElementHeight, getElementHeight } from './CSS';
|