From bc1fee555210fca6b439c83af5a7453f250fecee Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Wed, 25 May 2022 11:29:01 +0200 Subject: [PATCH 01/33] refactor: add typing for dompurify plugin --- packages/theme/plugins/dompurify.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/theme/plugins/dompurify.ts b/packages/theme/plugins/dompurify.ts index d04e72b7d..3ed6dcf18 100644 --- a/packages/theme/plugins/dompurify.ts +++ b/packages/theme/plugins/dompurify.ts @@ -1,5 +1,6 @@ import _unescape from 'lodash.unescape'; import DOMPurify from 'isomorphic-dompurify'; +import type { Plugin } from '@nuxt/types'; declare module 'vue/types/vue' { interface Vue { @@ -7,6 +8,8 @@ declare module 'vue/types/vue' { } } -export default (_, inject) => { +const plugin : Plugin = (_, inject) => { inject('dompurify', (html: string): string => _unescape(DOMPurify.sanitize(html))); }; + +export default plugin; From 558fb8dfa1d174961f00d0c2262c49fb00ebc7b9 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Wed, 25 May 2022 11:29:45 +0200 Subject: [PATCH 02/33] refactor: remove unused parts of types/core.ts --- packages/theme/types/core.ts | 897 +---------------------------------- 1 file changed, 5 insertions(+), 892 deletions(-) diff --git a/packages/theme/types/core.ts b/packages/theme/types/core.ts index 093c60a83..a62f2d729 100644 --- a/packages/theme/types/core.ts +++ b/packages/theme/types/core.ts @@ -1,863 +1,5 @@ -/* istanbul ignore file */ - -import type { Ref } from '@nuxtjs/composition-api'; -import type { Request, Response } from 'express'; - -/** - * Default name of the cookie storing active localization code - */ -export const VSF_LOCALE_COOKIE = 'vsf-locale'; - -/** - * Default name of the cookie storing active currency code - */ -export const VSF_CURRENCY_COOKIE = 'vsf-currency'; - -/** - * Default name of the cookie storing active country code - */ -export const VSF_COUNTRY_COOKIE = 'vsf-country'; - -/** - * Default name of the cookie storing active store code - */ -export const VSF_STORE_COOKIE = 'vsf-store'; - -/** - * Default name of the cookie storing active channel code - */ -export const VSF_CHANNEL_COOKIE = 'vsf-channel'; - -export type ComputedProperty = Readonly>>; - export type CustomQuery = Record; -export type ComposableFunctionArgs = T & { customQuery?: CustomQuery }; - -export interface UseProductErrors { - search: Error; -} - -export interface UseSearchErrors { - search: Error; -} - -export interface IntegrationContext { - client: CLIENT; - config: CONFIG; - api: API; - [x: string]: any; -} - -export interface Context { - [x: string]: IntegrationContext | any; -} - -export type PlatformApi = { - [functionName: string]: (context: Context, ...args: any[]) => Promise -}; - -export type ContextedPlatformApi = { - [P in keyof T]: T[P] extends (context: Context, ...arg: infer X) => Promise - ? (...arg: X) => Promise - : never -}; - -export interface Composable { - api?: ContextedPlatformApi -} - -export interface UseProduct< - PRODUCTS, - PRODUCT_SEARCH_PARAMS, - API extends PlatformApi = any, -> extends Composable { - products: ComputedProperty; - loading: ComputedProperty; - error: ComputedProperty; - search(params: ComposableFunctionArgs): Promise; - [x: string]: any; -} - -export interface UseForgotPasswordErrors { - request: Error; - setNew: Error; -} - -export interface UseForgotPassword { - result: ComputedProperty; - loading: ComputedProperty; - error: ComputedProperty; - setNew(params: ComposableFunctionArgs<{ tokenValue: string, newPassword: string }>): Promise; - request(params: ComposableFunctionArgs<{ email: string }>): Promise; -} - -export interface UseSearch { - result: ComputedProperty; - loading: ComputedProperty; - error: ComputedProperty; - search(params: ComposableFunctionArgs): Promise; -} - -export interface UseUserRegisterParams { - email: string; - password: string; - firstName?: string; - lastName?: string; - [x: string]: any; -} - -export interface UseUserLoginParams { - username: string; - password: string; - [x: string]: any; -} -export interface UseUserErrors { - updateUser: Error; - register: Error; - login: Error; - logout: Error; - changePassword: Error; - load: Error; -} - -export interface UseUser -< - USER, - UPDATE_USER_PARAMS, - API extends PlatformApi = any, -> extends Composable { - user: ComputedProperty; - setUser: (user: USER) => void; - updateUser: (params: { user: UPDATE_USER_PARAMS; customQuery?: CustomQuery }) => Promise; - register: (params: { user: UseUserRegisterParams; customQuery?: CustomQuery }) => Promise; - login: (params: { user: UseUserLoginParams; customQuery?: CustomQuery }) => Promise; - logout: (params?: { customQuery: CustomQuery }) => Promise; - changePassword: (params: { current: string; new: string, customQuery?: CustomQuery }) => Promise; - load: (params?: { customQuery: CustomQuery }) => Promise; - isAuthenticated: Ref; - loading: ComputedProperty; - error: ComputedProperty; -} - -export interface UseUserOrderSearchParams { - id?: any; - page?: number; - perPage?: number; - [x: string]: any; -} -export interface UseUserOrderErrors { - search: Error; -} -export interface UseUserOrder< - ORDERS, - ORDER_SEARCH_PARAMS, - API extends PlatformApi = any, -> extends Composable { - orders: ComputedProperty; - search(params: ComposableFunctionArgs): Promise; - loading: ComputedProperty; - error: ComputedProperty; -} - -export interface UseUserAddress extends Composable { - addresses: ComputedProperty; - totalAddresses: ComputedProperty; - addAddress: (address: ADDRESS) => Promise; - deleteAddress: (address: ADDRESS) => Promise; - updateAddress: (address: ADDRESS) => Promise; - searchAddresses: (params?: { [x: string]: any }) => Promise; - loading: ComputedProperty; -} -export interface UseUserShippingErrors { - addAddress: Error; - deleteAddress: Error; - updateAddress: Error; - load: Error; - setDefaultAddress: Error; -} -export interface UseUserShipping< - USER_SHIPPING, - USER_SHIPPING_ITEM, - API extends PlatformApi = any, -> extends Composable { - shipping: ComputedProperty; - addAddress: (params: { address: USER_SHIPPING_ITEM, customQuery?: CustomQuery }) => Promise; - deleteAddress: (params: { address: USER_SHIPPING_ITEM, customQuery?: CustomQuery }) => Promise; - updateAddress: (params: { address: USER_SHIPPING_ITEM, customQuery?: CustomQuery }) => Promise; - load: () => Promise; - setDefaultAddress: (params: { address: USER_SHIPPING_ITEM, customQuery?: CustomQuery }) => Promise; - loading: ComputedProperty; - error: ComputedProperty; -} - -export interface UserShippingGetters { - getAddresses: (shipping: USER_SHIPPING, criteria?: Record) => USER_SHIPPING_ITEM[]; - getDefault: (shipping: USER_SHIPPING) => USER_SHIPPING_ITEM; - getTotal: (shipping: USER_SHIPPING) => number; - getPostCode: (address: USER_SHIPPING_ITEM) => string; - getStreetName: (address: USER_SHIPPING_ITEM) => string; - getStreetNumber: (address: USER_SHIPPING_ITEM) => string | number; - getCity: (address: USER_SHIPPING_ITEM) => string; - getFirstName: (address: USER_SHIPPING_ITEM) => string; - getLastName: (address: USER_SHIPPING_ITEM) => string; - getCountry: (address: USER_SHIPPING_ITEM) => string; - getPhone: (address: USER_SHIPPING_ITEM) => string; - getEmail: (address: USER_SHIPPING_ITEM) => string; - getProvince: (address: USER_SHIPPING_ITEM) => string; - getCompanyName: (address: USER_SHIPPING_ITEM) => string; - getTaxNumber: (address: USER_SHIPPING_ITEM) => string; - getId: (address: USER_SHIPPING_ITEM) => string | number; - getApartmentNumber: (address: USER_SHIPPING_ITEM) => string | number; - isDefault: (address: USER_SHIPPING_ITEM) => boolean; -} - -export interface UseUserBillingErrors { - addAddress: Error; - deleteAddress: Error; - updateAddress: Error; - load: Error; - setDefaultAddress: Error; -} -export interface UseUserBilling< - USER_BILLING, - USER_BILLING_ITEM, - API extends PlatformApi = any, -> extends Composable { - billing: ComputedProperty; - addAddress: (params: { address: USER_BILLING_ITEM, customQuery?: CustomQuery }) => Promise; - deleteAddress: (params: { address: USER_BILLING_ITEM, customQuery?: CustomQuery }) => Promise; - updateAddress: (params: { address: USER_BILLING_ITEM, customQuery?: CustomQuery }) => Promise; - load: () => Promise; - setDefaultAddress: (params: { address: USER_BILLING_ITEM, customQuery?: CustomQuery }) => Promise; - loading: ComputedProperty; - error: ComputedProperty; -} - -export interface UserBillingGetters { - getAddresses: (billing: USER_BILLING, criteria?: Record) => USER_BILLING_ITEM[]; - getDefault: (billing: USER_BILLING) => USER_BILLING_ITEM; - getTotal: (billing: USER_BILLING) => number; - getPostCode: (address: USER_BILLING_ITEM) => string; - getStreetName: (address: USER_BILLING_ITEM) => string; - getStreetNumber: (address: USER_BILLING_ITEM) => string | number; - getCity: (address: USER_BILLING_ITEM) => string; - getFirstName: (address: USER_BILLING_ITEM) => string; - getLastName: (address: USER_BILLING_ITEM) => string; - getCountry: (address: USER_BILLING_ITEM) => string; - getPhone: (address: USER_BILLING_ITEM) => string; - getEmail: (address: USER_BILLING_ITEM) => string; - getProvince: (address: USER_BILLING_ITEM) => string; - getCompanyName: (address: USER_BILLING_ITEM) => string; - getTaxNumber: (address: USER_BILLING_ITEM) => string; - getId: (address: USER_BILLING_ITEM) => string; - getApartmentNumber: (address: USER_BILLING_ITEM) => string | number; - isDefault: (address: USER_BILLING_ITEM) => boolean; -} - -export interface UseCategoryErrors { - search: Error; -} -export interface UseCategory< - CATEGORY, - CATEGORY_SEARCH_PARAMS, - API extends PlatformApi = any, -> extends Composable { - categories: ComputedProperty; - search(params: ComposableFunctionArgs): Promise; - loading: ComputedProperty; - error: ComputedProperty; -} - -export interface UseCartErrors { - addItem: Error; - removeItem: Error; - updateItemQty: Error; - load: Error; - clear: Error; - applyCoupon: Error; - removeCoupon: Error; -} -export interface UseCart -< - CART, - CART_ITEM, - PRODUCT, - API extends PlatformApi = any, -> extends Composable { - cart: ComputedProperty; - setCart(cart: CART): void; - addItem(params: { product: PRODUCT; quantity: number; customQuery?: CustomQuery }): Promise; - isInCart: ({ product: PRODUCT }) => boolean; - removeItem(params: { product: CART_ITEM; customQuery?: CustomQuery }): Promise; - updateItemQty(params: { product: CART_ITEM; quantity?: number; customQuery?: CustomQuery }): Promise; - clear(): Promise; - applyCoupon(params: { couponCode: string; customQuery?: CustomQuery }): Promise; - removeCoupon(params: { couponCode: string; customQuery?: CustomQuery }): Promise; - load(): Promise; - load(params: { customQuery?: CustomQuery }): Promise; - error: ComputedProperty; - loading: ComputedProperty; -} -export interface UseWishlistErrors { - addItem: Error; - removeItem: Error; - load: Error; - clear: Error; -} -export interface UseWishlist -< - WISHLIST, - WISHLIST_ITEM, - PRODUCT, - API extends PlatformApi = any, -> extends Composable { - wishlist: ComputedProperty; - loading: ComputedProperty; - addItem(params: { product: PRODUCT; customQuery?: CustomQuery }): Promise; - removeItem(params: { product: WISHLIST_ITEM; customQuery?: CustomQuery }): Promise; - load(): Promise; - load(params: { customQuery?: CustomQuery }): Promise; - clear(): Promise; - setWishlist: (wishlist: WISHLIST) => void; - isInWishlist({ product: PRODUCT }): boolean; - error: ComputedProperty; -} - -export interface UseCompare { - compare: ComputedProperty; - addToCompare: (product: PRODUCT) => Promise; - removeFromCompare: (product: PRODUCT) => Promise; - clearCompare: () => Promise; - loading: ComputedProperty; -} - -export interface UseMakeOrderErrors { - make: Error; -} - -export interface UseMakeOrder extends Composable { - order: Ref; - make(params: { customQuery?: CustomQuery }): Promise; - error: ComputedProperty; - loading: ComputedProperty; -} - -export interface UseCheckout -< - PAYMENT_METHODS, - SHIPPING_METHODS, - PERSONAL_DETAILS, - SHIPPING_DETAILS, - BILLING_DETAILS, - CHOOSEN_PAYMENT_METHOD, - CHOOSEN_SHIPPING_METHOD, - PLACE_ORDER, - API extends PlatformApi = any, -> extends Composable { - paymentMethods: Ref; - shippingMethods: Ref; - personalDetails: PERSONAL_DETAILS; - shippingDetails: SHIPPING_DETAILS; - billingDetails: BILLING_DETAILS; - chosenPaymentMethod: CHOOSEN_PAYMENT_METHOD; - chosenShippingMethod: CHOOSEN_SHIPPING_METHOD; - placeOrder: PLACE_ORDER; - loading: ComputedProperty; -} -export interface UseReviewErrors { - search: Error; - addReview: Error; -} -export interface UseReview< - REVIEW, - REVIEWS_SEARCH_PARAMS, - REVIEW_ADD_PARAMS, - API extends PlatformApi = any, -> extends Composable { - search(params: ComposableFunctionArgs): Promise; - addReview(params: ComposableFunctionArgs): Promise; - error: ComputedProperty; - reviews: ComputedProperty; - loading: ComputedProperty; - [x: string]: any; -} - -export interface UseShippingErrors { - load: Error; - save: Error; -} -export interface UseShipping< - SHIPPING, - SHIPPING_PARAMS, - API extends PlatformApi = any, -> extends Composable { - error: ComputedProperty; - loading: ComputedProperty; - shipping: ComputedProperty; - load(): Promise; - load(params: { customQuery?: CustomQuery }): Promise; - save: (params: { params: SHIPPING_PARAMS; shippingDetails: SHIPPING; customQuery?: CustomQuery }) => Promise; -} -export interface UseShippingProviderErrors { - load: Error; - save: Error; -} -export interface UseShippingProvider< - STATE, - SHIPPING_METHOD, - API extends PlatformApi = any, -> extends Composable { - error: ComputedProperty; - loading: ComputedProperty; - state: ComputedProperty; - setState(state: STATE): void; - load(): Promise; - load(params: { customQuery?: CustomQuery }): Promise; - save(params: { shippingMethod: SHIPPING_METHOD, customQuery?: CustomQuery }): Promise; -} - -export interface UseBillingErrors { - load: Error; - save: Error; -} - -export interface UseBilling< - BILLING, - BILLING_PARAMS, - API extends PlatformApi = any, -> extends Composable { - error: ComputedProperty; - loading: ComputedProperty; - billing: ComputedProperty; - load(): Promise; - load(params: { customQuery?: CustomQuery }): Promise; - save: (params: { params: BILLING_PARAMS; billingDetails: BILLING; customQuery?: CustomQuery }) => Promise; -} -export interface UseFacetErrors { - search: Error; -} - -export interface AgnosticFacetSearchParams { - categorySlug?: string; - rootCatSlug?: string; - term?: string; - page?: number; - itemsPerPage?: number; - sort?: string; - filters?: Record; - metadata?: any; - [x: string]: any; -} - -export interface FacetSearchResult { - data: S; - input: AgnosticFacetSearchParams; -} -export interface UseFacet { - result: ComputedProperty>; - loading: ComputedProperty; - search: (params?: AgnosticFacetSearchParams) => Promise; - error: ComputedProperty; -} -export interface UseContentErrors { - search: Error; -} -export interface UseContent< - CONTENT, - CONTENT_SEARCH_PARAMS, - API extends PlatformApi = any, -> extends Composable { - search: (params: CONTENT_SEARCH_PARAMS) => Promise; - content: ComputedProperty; - loading: ComputedProperty; - error: ComputedProperty; -} - -export interface RenderComponent { - componentName: string; - props?: any; -} - -export interface AgnosticPrice { - regular: number | null; - special?: number | null; -} - -export interface AgnosticMediaGalleryItem { - small: string; - normal: string; - big: string; -} - -export interface AgnosticAttribute { - name?: string; - value: string | Record; - label: string; -} - -export interface AgnosticBreadcrumb { - text: string; - link: string; -} - -export interface AgnosticTotals { - total: number; - subtotal: number; - special?: number; - [x: string]: unknown; -} - -export interface AgnosticCoupon { - id: string; - name: string; - code: string; - value: number; -} - -export interface AgnosticDiscount { - id: string; - name: string; - description: string; - value: number; - code?: string; -} - -export interface AgnosticCategoryTree { - label: string; - slug?: string; - items: AgnosticCategoryTree[]; - isCurrent: boolean; - count?: number; - [x: string]: unknown; -} - -export interface AgnosticFilter { - id: string; - label: string; - values: { - id: string; - isSlected?: boolean; - count?: number; - label: string; - value: string; - }[] -} - -export interface AgnosticProductReview { - id: string; - author: string; - date: Date; - message: string | null; - rating: number | null; -} - -export interface AgnosticLocale { - code: string; - label: string; - [x: string]: unknown; -} - -export interface AgnosticCountry { - code: string; - label: string; - [x: string]: unknown; -} - -export interface AgnosticCurrency { - code: string; - label: string; - prefixSign: boolean; - sign: string; - [x: string]: unknown; -} - -export interface AgnosticSortByOption { - label: string; - value: string; - [x: string]: unknown; -} - -export interface AgnosticRateCount { - rate: number; - count: number; -} - -// TODO - remove this interface -export enum AgnosticOrderStatus { - Open = 'Open', - Pending = 'Pending', - Confirmed = 'Confirmed', - Shipped = 'Shipped', - Complete = 'Complete', - Cancelled = 'Cancelled', - Refunded = 'Refunded', -} - -export interface AgnosticFacet { - type: string; - id: string; - value: any; - attrName?: string; - count?: number; - selected?: boolean; - metadata?: any; -} - -export interface AgnosticGroupedFacet { - id: string; - label: string; - count?: number; - options: AgnosticFacet[]; -} - -export interface AgnosticSort { - options: AgnosticFacet[]; - selected: string; -} - -export interface AgnosticPagination { - currentPage: number; - totalPages: number; - totalItems: number; - itemsPerPage: number; - pageOptions: number[]; -} - -export interface AgnosticAddress { - addressLine1: string; - addressLine2: string; - [x: string]: unknown; -} - -export interface AgnosticGeoLocation { - type: string; - coordinates?: unknown; - [x: string]: unknown; -} - -export interface AgnosticStore { - name: string; - id: string; - description?: string; - locales?: AgnosticLocale[]; - currencies?: AgnosticCurrency[] - address?: AgnosticAddress; - geoLocation?: AgnosticGeoLocation; - [x: string]: unknown; -} - -export interface ProductGetters { - getName: (product: PRODUCT) => string; - getSlug: (product: PRODUCT) => string; - getPrice: (product: PRODUCT) => AgnosticPrice; - getGallery: (product: PRODUCT) => AgnosticMediaGalleryItem[]; - getCoverImage: (product: PRODUCT) => string; - getAttributes: (products: PRODUCT[] | PRODUCT, filters?: Array) => Record; - getDescription: (product: PRODUCT) => string; - getCategoryIds: (product: PRODUCT) => string[]; - getId: (product: PRODUCT) => string; - getFormattedPrice: (price: number) => string; - getTotalReviews: (product: PRODUCT) => number; - getAverageRating: (product: PRODUCT) => number; - getBreadcrumbs?: (product: PRODUCT) => AgnosticBreadcrumb[]; - [getterName: string]: any; -} - -export interface CartGetters { - getItems: (cart: CART) => CART_ITEM[]; - getItemName: (cartItem: CART_ITEM) => string; - getItemImage: (cartItem: CART_ITEM) => string; - getItemPrice: (cartItem: CART_ITEM) => AgnosticPrice; - getItemQty: (cartItem: CART_ITEM) => number; - getItemAttributes: (cartItem: CART_ITEM, filters?: Array) => Record; - getItemSku: (cartItem: CART_ITEM) => string; - getTotals: (cart: CART) => AgnosticTotals; - getShippingPrice: (cart: CART) => number; - getTotalItems: (cart: CART) => number; - getFormattedPrice: (price: number) => string; - // @deprecated - use getDiscounts instead - getCoupons: (cart: CART) => AgnosticCoupon[]; - getDiscounts: (cart: CART) => AgnosticDiscount[]; - [getterName: string]: (element: any, options?: any) => unknown; -} - -export interface WishlistGetters { - getItems: (wishlist: WISHLIST) => WISHLIST_ITEM[]; - getItemName: (wishlistItem: WISHLIST_ITEM) => string; - getItemImage: (wishlistItem: WISHLIST_ITEM) => string; - getItemPrice: (wishlistItem: WISHLIST_ITEM) => AgnosticPrice; - getItemAttributes: (wishlistItem: WISHLIST_ITEM, filters?: Array) => Record; - getItemSku: (wishlistItem: WISHLIST_ITEM) => string; - getTotals: (wishlist: WISHLIST) => AgnosticTotals; - getTotalItems: (wishlist: WISHLIST) => number; - getFormattedPrice: (price: number) => string; - [getterName: string]: (element: any, options?: any) => unknown; -} - -export interface UserGetters { - getFirstName: (customer: USER) => string; - getLastName: (customer: USER) => string; - getFullName: (customer: USER) => string; - getEmailAddress: (customer: USER) => string; - [getterName: string]: (element: any, options?: any) => unknown; -} - -export interface UserOrderGetters { - getDate: (order: ORDER) => string; - getId: (order: ORDER) => string; - getStatus: (order: ORDER) => string; - getPrice: (order: ORDER) => number; - getItems: (order: ORDER) => ORDER_ITEM[]; - getItemSku: (item: ORDER_ITEM) => string; - getItemName: (item: ORDER_ITEM) => string; - getItemQty: (item: ORDER_ITEM) => number; - getItemPrice: (item: ORDER_ITEM) => number; - getFormattedPrice: (price: number) => string; - getOrdersTotal: (orders: { - offset: number; - count: number; - total: number; - results: Array; - }) => number; - [getterName: string]: (element: any, options?: any) => unknown; -} - -export interface ReviewGetters { - getItems: (review: REVIEW) => REVIEW_ITEM[]; - getReviewId: (item: REVIEW_ITEM) => string; - getReviewAuthor: (item: REVIEW_ITEM) => string; - getReviewMessage: (item: REVIEW_ITEM) => string; - getReviewRating: (item: REVIEW_ITEM) => number; - getReviewDate: (item: REVIEW_ITEM) => string; - getTotalReviews: (review: REVIEW) => number; - getAverageRating: (review: REVIEW) => number; - getRatesCount: (review: REVIEW) => AgnosticRateCount[]; - getReviewsPage: (review: REVIEW) => number; -} - -export interface FacetsGetters { - getAll: (searchData: FacetSearchResult, criteria?: CRITERIA) => AgnosticFacet[]; - getGrouped: (searchData: FacetSearchResult, criteria?: CRITERIA) => AgnosticGroupedFacet[]; - getCategoryTree: (searchData: FacetSearchResult) => AgnosticCategoryTree; - getSortOptions: (searchData: FacetSearchResult) => AgnosticSort; - getProducts: (searchData: FacetSearchResult) => RESULTS; - getPagination: (searchData: FacetSearchResult) => AgnosticPagination; - getBreadcrumbs: (searchData: FacetSearchResult) => AgnosticBreadcrumb[]; - [getterName: string]: (element: any, options?: any) => unknown; -} - -export interface ForgotPasswordGetters { - getResetPasswordToken: (result: FORGOT_PASSWORD_RESULT) => string - isPasswordChanged: (result: FORGOT_PASSWORD_RESULT) => boolean -} - -export interface UseSearchGetters { - getItems: (result: RESULT) => ITEM[]; - getCategoryTree: (result: RESULT) => AgnosticCategoryTree; - getPagination: (result: RESULT) => AgnosticPagination; - getItemPrice: (item: ITEM) => AgnosticPrice; - getSortOptions: (result: RESULT) => AgnosticSort; - getBreadcrumbs: (result: RESULT) => AgnosticBreadcrumb[]; - getItemImages: (item: ITEM) => AgnosticMediaGalleryItem[] - getFilters: (result: RESULT) => AgnosticFilter[]; - getItemName: (item: ITEM) => string; - getItemId: (item: ITEM) => string; - getItemSlug: (item: ITEM) => string; -} - -export interface VSFLogger { - debug(message?: any, ...args: any): void; - info(message?: any, ...args: any): void; - warn(message?: any, ...args: any): void; - error(message?: any, ...args: any): void; -} - -export interface FactoryParams { - provide?: (context: Context) => any; - api?: Partial; -} - -export interface HookParams { - configuration: C; -} - -export interface CallHookParams extends HookParams { - callName: string; -} - -export type BeforeCallArgs = any; -export type AfterCallArgs = any; - -export interface BeforeCallParams< C> extends CallHookParams { - args: BeforeCallArgs; -} - -export interface AfterCallParams extends CallHookParams { - response: AfterCallArgs; -} - -export interface ApiClientExtensionHooks { - beforeCreate?: (params: HookParams) => C; - afterCreate?: (params: HookParams) => C; - beforeCall?: (params: BeforeCallParams) => BeforeCallArgs; - afterCall?: (params: AfterCallParams) => AfterCallArgs; -} - -export type CustomQueryFn = (query: any, variables: T) => { - query?: any; - variables?: T; - metadata: any; -}; - -export type ApiClientMethod = (...args: any) => Promise; - -export interface ApiClientExtension { - name: string; - extendApiMethods?: Record; - extendApp?: ({ app: Express, configuration: any }) => void; - hooks?: (req: Request, res: Response) => ApiClientExtensionHooks; -} - -export interface Integration { - location: string; - configuration: any; - extensions?: (extensions: ApiClientExtension[]) => ApiClientExtension[]; - customQueries?: Record; -} - -export type IntegrationsSection = Record; - -export interface MiddlewareConfig { - integrations: Record; -} - -export interface ApiClientFactoryParams { - api: F; - isProxy?: boolean; - onCreate: (config: T, headers?: Record) => { config: T; client: any }; - extensions?: ApiClientExtension[]; -} - -export interface ApiInstance { - api: any; - client: any; - settings: any; -} - -export type CreateApiProxyFn = (givenConfig: any, customApi?: any) => ApiInstance; -export type CreateApiClientFn = (givenConfig: any, customApi?: any) => ApiInstance; - -export interface ApiClientFactory { - createApiClient: CreateApiClientFn; -} - -export interface ApiClientConfig { - [x: string]: any; - client?: any; - extensions?: ApiClientExtension[]; -} - export type ApiClientMethods = { [K in keyof T]: T[K] extends (...args: any) => any ? @@ -865,38 +7,9 @@ export type ApiClientMethods = { T[K] }; -export interface UseStoreErrors { - load: Error | null; - change: Error | null; -} - -export interface UseStoreFactoryChangeParamArguments { - currentStore: AgnosticStore; - store: AgnosticStore; - customQuery?: CustomQuery; -} - -export interface UseStoreFactoryLoadParamArguments { - customQuery: CustomQuery; -} - -export interface UseStoreFactoryParams extends FactoryParams { - load(context: Context, params: UseStoreFactoryLoadParamArguments): Promise - change(context: Context, params: UseStoreFactoryChangeParamArguments): Promise -} -export interface UseStoreInterface { - change(params: UseStoreFactoryChangeParamArguments): Promise; - load(params?: UseStoreFactoryLoadParamArguments): Promise; - loading: ComputedProperty; - response: ComputedProperty; - error: ComputedProperty; -} - -export interface UseStore { - (): UseStoreInterface; -} - -export interface UseStoreGetters { - getItems(stores: STORES, criteria?: CRITERIA): AgnosticStore[]; - getSelected(stores: STORES): AgnosticStore | undefined +export interface IntegrationContext { + client: CLIENT; + config: CONFIG; + api: API; + [x: string]: any; } From 119ce6323160b5fe378368d75ad7c4ca980b012d Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Wed, 25 May 2022 11:30:05 +0200 Subject: [PATCH 03/33] refactor: do not use symbol for indexing object --- packages/theme/plugins/graphqlClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/theme/plugins/graphqlClient.ts b/packages/theme/plugins/graphqlClient.ts index 6db59263c..3e497e4b0 100644 --- a/packages/theme/plugins/graphqlClient.ts +++ b/packages/theme/plugins/graphqlClient.ts @@ -26,7 +26,7 @@ const getHeaderProxy = (ctx: NuxtContext) => { Authorization: `Bearer ${getCustomerToken()}`, store: getStore(), 'Content-Currency': getCurrency(), - }[key] ?? undefined; + }[key as string] ?? undefined; }, ownKeys() { // Important to get fresh values on each read of ownKeys From 6fefe098a4d34e8cc6b2b141eef6872b9cb212bd Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Wed, 25 May 2022 11:30:24 +0200 Subject: [PATCH 04/33] refactor: add explicit any for useTraverseCategoryMock --- packages/theme/test-utils/mocks/useTraverseCategoryMock.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/theme/test-utils/mocks/useTraverseCategoryMock.ts b/packages/theme/test-utils/mocks/useTraverseCategoryMock.ts index 3bac772b5..ef61ad902 100644 --- a/packages/theme/test-utils/mocks/useTraverseCategoryMock.ts +++ b/packages/theme/test-utils/mocks/useTraverseCategoryMock.ts @@ -185,7 +185,7 @@ export const categoryAncestorsThirdLevelMock = [ } as CategoryTree, ]; -export const useTraverseCategoryMock = (categoryAncestors = [], extend = []) => ({ +export const useTraverseCategoryMock = (categoryAncestors : CategoryTree[] = [], extend : any[] = []) => ({ loadCategoryTree: jest.fn(), isCategoryTreeLoaded: ref(true), categoryAncestors: ref(categoryAncestors), From c569ffcd6dfed83baa5be3be6a220f10dafe32bb Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Wed, 25 May 2022 11:41:09 +0200 Subject: [PATCH 05/33] refactor: add lodash typing --- packages/theme/package.json | 3 +++ yarn.lock | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/theme/package.json b/packages/theme/package.json index e70423467..b56a6fe03 100644 --- a/packages/theme/package.json +++ b/packages/theme/package.json @@ -69,6 +69,9 @@ "@testing-library/jest-dom": "^5.16.1", "@testing-library/user-event": "^14.1.1", "@testing-library/vue": "^5.8.2", + "@types/lodash.debounce": "^4.0.6", + "@types/lodash.merge": "^4.6.7", + "@types/lodash.unescape": "^4.0.7", "@vue/test-utils": "^1.3.0", "babel-core": "7.0.0-bridge.0", "babel-jest": "^27.4.6", diff --git a/yarn.lock b/yarn.lock index f918e5fe8..14db6c7b1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3961,6 +3961,32 @@ resolved "https://registry.yarnpkg.com/@types/less/-/less-3.0.2.tgz#2761d477678c8374cb9897666871662eb1d1115e" integrity sha512-62vfe65cMSzYaWmpmhqCMMNl0khen89w57mByPi1OseGfcV/LV03fO8YVrNj7rFQsRWNJo650WWyh6m7p8vZmA== +"@types/lodash.debounce@^4.0.6": + version "4.0.7" + resolved "https://registry.yarnpkg.com/@types/lodash.debounce/-/lodash.debounce-4.0.7.tgz#0285879defb7cdb156ae633cecd62d5680eded9f" + integrity sha512-X1T4wMZ+gT000M2/91SYj0d/7JfeNZ9PeeOldSNoE/lunLeQXKvkmIumI29IaKMotU/ln/McOIvgzZcQ/3TrSA== + dependencies: + "@types/lodash" "*" + +"@types/lodash.merge@^4.6.7": + version "4.6.7" + resolved "https://registry.yarnpkg.com/@types/lodash.merge/-/lodash.merge-4.6.7.tgz#0af6555dd8bc6568ef73e5e0d820a027362946b1" + integrity sha512-OwxUJ9E50gw3LnAefSHJPHaBLGEKmQBQ7CZe/xflHkyy/wH2zVyEIAKReHvVrrn7zKdF58p16We9kMfh7v0RRQ== + dependencies: + "@types/lodash" "*" + +"@types/lodash.unescape@^4.0.7": + version "4.0.7" + resolved "https://registry.yarnpkg.com/@types/lodash.unescape/-/lodash.unescape-4.0.7.tgz#69f1cab2e755b824151346a44faeaaf93702972b" + integrity sha512-KGxcfHpWcOnLeK5g71YErXL6m947wQC9XfhVjENlCku85C6WxsqNIxwxpqDCpL06rY5ExQiXZH50KgJDFLzc7Q== + dependencies: + "@types/lodash" "*" + +"@types/lodash@*": + version "4.14.182" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2" + integrity sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q== + "@types/mime@^1": version "1.3.2" resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a" From e226c2927cd5e6805a14cc1e83d0dafb424fd65f Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Wed, 25 May 2022 15:05:14 +0200 Subject: [PATCH 06/33] refactor: fix implicit any in wishlist-related files --- .../wishlist/components/WishlistSidebar.vue | 6 +- .../wishlist/composables/useWishlist/index.ts | 20 ++--- .../wishlist/getters/wishlistGetters.ts | 73 +++++++++---------- 3 files changed, 47 insertions(+), 52 deletions(-) diff --git a/packages/theme/modules/wishlist/components/WishlistSidebar.vue b/packages/theme/modules/wishlist/components/WishlistSidebar.vue index d618719a1..070613b29 100644 --- a/packages/theme/modules/wishlist/components/WishlistSidebar.vue +++ b/packages/theme/modules/wishlist/components/WishlistSidebar.vue @@ -155,7 +155,7 @@ import EmptyWishlist from '~/modules/wishlist/components/EmptyWishlist.vue'; import SvgImage from '~/components/General/SvgImage.vue'; -import type { WishlistItemInterface } from '~/modules/GraphQL/types'; +import type { WishlistItemInterface, ConfigurableProduct, BundleProduct } from '~/modules/GraphQL/types'; export default defineComponent({ name: 'WishlistSidebar', @@ -217,8 +217,8 @@ export default defineComponent({ () => wishlistStore.wishlist?.items_count ?? 0, ); - const getAttributes = (product) => product?.product?.configurable_options || []; - const getBundles = (product) => product?.product?.items?.map((b) => b.title).flat() || []; + const getAttributes = (product: ConfigurableProduct) => product?.product?.configurable_options || []; + const getBundles = (product: BundleProduct) => product?.product?.items?.map((b) => b.title).flat() || []; const getItemLink = (item: WishlistItemInterface) => localeRoute({ path: `/p/${item.product.sku}${productGetters.getSlug( item.product, diff --git a/packages/theme/modules/wishlist/composables/useWishlist/index.ts b/packages/theme/modules/wishlist/composables/useWishlist/index.ts index 4f1d86026..01bbade72 100644 --- a/packages/theme/modules/wishlist/composables/useWishlist/index.ts +++ b/packages/theme/modules/wishlist/composables/useWishlist/index.ts @@ -24,8 +24,7 @@ export function useWishlist(): UseWishlistInterface { const { app } = useContext(); const { send: sendNotification } = useUiNotification(); const loading = ref(false); - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands - const calculateWishlistTotal = (wishlists) => wishlists.reduce((prev, next) => (prev?.items_count ?? 0) + (next?.items_count ?? 0), 0); + const calculateWishlistTotal = (wishlists: Wishlist[]) => wishlists.reduce((acc, current) => acc + (current?.items_count ?? 0), 0); const error = ref({ addItem: null, removeItem: null, @@ -35,21 +34,23 @@ export function useWishlist(): UseWishlistInterface { afterAddingWishlistItemToCart: null, }); - // eslint-disable-next-line consistent-return const load = async (params?: UseWishlistLoadParams) => { Logger.debug('useWishlist/load'); try { loading.value = true; Logger.debug('[Magento Storefront]: useWishlist.load params->', params); - const apiState = app.context.$vsf.$magento.config.state; + const apiState = app.$vsf.$magento.config.state; if (apiState.getCustomerToken()) { - const { data } = await app.context.$vsf.$magento.api.wishlist(params?.searchParams, params?.customQuery); + const { data } = await app.$vsf.$magento.api.wishlist(params?.searchParams, params?.customQuery); Logger.debug('[Result]:', { data }); const loadedWishlist = data?.customer?.wishlists ?? []; - wishlistStore.wishlist = loadedWishlist[0] ?? {}; + if (loadedWishlist[0]) { + // @ts-expect-error M2-579 + [wishlistStore.wishlist] = loadedWishlist; + } } error.value.load = null; @@ -109,7 +110,8 @@ export function useWishlist(): UseWishlistInterface { const loadItemsCount = async (): Promise => { Logger.debug('useWishlist/wishlistItemsCount'); const apiState = app.context.$vsf.$magento.config.state; - let itemsCount = null; + + let itemsCount : number | null = null; try { loading.value = true; @@ -118,7 +120,7 @@ export function useWishlist(): UseWishlistInterface { const { data } = await app.context.$vsf.$magento.api.wishlistItemsCount(); Logger.debug('[Result]:', { data }); - const loadedWishlist = data?.customer?.wishlists ?? []; + const loadedWishlist : Wishlist[] = data?.customer?.wishlists ?? []; itemsCount = calculateWishlistTotal(loadedWishlist); wishlistStore.$patch((state) => { state.wishlist.items_count = itemsCount; @@ -159,7 +161,7 @@ export function useWishlist(): UseWishlistInterface { }); } - if (!app.$vsf.$magento.config.state.getCustomerToken()) { // TODO: replace by value from pinia store after sueCart composable will be refactored + if (!app.$vsf.$magento.config.state.getCustomerToken()) { // TODO: replace by value from pinia store after useCart composable will be refactored Logger.error('Need to be authenticated to add a product to wishlist'); } diff --git a/packages/theme/modules/wishlist/getters/wishlistGetters.ts b/packages/theme/modules/wishlist/getters/wishlistGetters.ts index 6bdd7d791..8f7873c58 100644 --- a/packages/theme/modules/wishlist/getters/wishlistGetters.ts +++ b/packages/theme/modules/wishlist/getters/wishlistGetters.ts @@ -5,18 +5,17 @@ import { } from '~/composables/types'; import { WishlistGetters as BaseWishlistGetters } from '~/getters/types'; -import { Wishlist, WishlistQuery } from '~/modules/GraphQL/types'; - -export type WishlistProduct = WishlistQuery['customer']['wishlists'][0]['items_v2']['items'][0] & { variant: any }; +import { + Wishlist, ProductInterface, WishlistItemInterface, +} from '~/modules/GraphQL/types'; -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export const getItems = (wishlist): WishlistProduct[] => wishlist.items_v2.items; +export const getItems = (wishlist: Wishlist): WishlistItemInterface[] => wishlist.items_v2.items; -export const getItemName = (product: WishlistProduct): string => product?.product?.name || ''; +export const getItemName = (product: WishlistItemInterface): string => product?.product?.name || ''; -export const getItemImage = (product: WishlistProduct): string => product?.product?.thumbnail.url || ''; +export const getItemImage = (product: WishlistItemInterface): string => product?.product?.thumbnail.url || ''; -export const getItemPrice = (product: WishlistProduct): AgnosticPrice => { +export const getItemPrice = (product: WishlistItemInterface): AgnosticPrice => { let regular = 0; let special = null; @@ -35,42 +34,32 @@ export const getItemPrice = (product: WishlistProduct): AgnosticPrice => { }; }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export const getItemQty = (product: WishlistProduct): number => product.quantity; +export const getItemQty = (product: WishlistItemInterface): number => product.quantity; -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export const getItemAttributes = (product: WishlistProduct, filterByAttributeName?: string[]) => ({ '': '' }); +export const getItemAttributes = (_product: WishlistItemInterface, _filterByAttributeName?: string[]) => ({ '': '' }); -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export const getItemSku = (product: WishlistProduct): string => product?.product?.sku || ''; +export const getItemSku = (product: WishlistItemInterface): string => product?.product?.sku || ''; -// eslint-disable-next-line @typescript-eslint/no-unused-vars -// @ts-ignore -export const getTotals = (wishlist): AgnosticTotals => { +export const getTotals = (wishlist: Wishlist[] | Wishlist): AgnosticTotals => { if (Array.isArray(wishlist)) { return wishlist[0]?.items_v2?.items.reduce((acc, curr) => ({ - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands,@typescript-eslint/no-unsafe-argument total: acc.total + getItemPrice(curr).special, - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands,@typescript-eslint/no-unsafe-argument subtotal: acc.subtotal + getItemPrice(curr).regular, }), ({ total: 0, subtotal: 0 })); } return wishlist?.items_v2?.items.reduce((acc, curr) => ({ - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/restrict-plus-operands total: acc.total + getItemPrice(curr).special, - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/restrict-plus-operands subtotal: acc.subtotal + getItemPrice(curr).regular, }), ({ total: 0, subtotal: 0 })); }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export const getShippingPrice = (wishlist: Wishlist): number => 0; +export const getShippingPrice = (_wishlist: Wishlist): number => 0; -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export const getTotalItems = (wishlist: Wishlist): number => (Array.isArray(wishlist) ? wishlist[0]?.items_count : (wishlist?.items_count || 0)); +export const getTotalItems = (wishlist: Wishlist | Wishlist[]): number => (Array.isArray(wishlist) + ? wishlist[0]?.items_count + : (wishlist?.items_count || 0)); -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export const getFormattedPrice = (price: number): string => ''; +export const getFormattedPrice = (_price: number): string => ''; const getPagination = (wishlistData: Wishlist): AgnosticPagination => ({ currentPage: wishlistData?.items_v2?.page_info?.current_page || 1, @@ -80,23 +69,26 @@ const getPagination = (wishlistData: Wishlist): AgnosticPagination => ({ pageOptions: [10, 50, 100], }); -const getProducts = (wishlistData: Wishlist[] | Wishlist): { - product: WishlistProduct; - quantity: number; - added_at: string; -}[] => { +type MappedProduct = { + product: ProductInterface, + quantity: number, + added_at: string, + id: string, +}; + +const getProducts = (wishlistData: Wishlist[] | Wishlist): MappedProduct[] => { if (!wishlistData || (Array.isArray(wishlistData) && wishlistData.length === 0)) { return []; } - const reducer = (acc, curr) => [...acc, ...curr?.items_v2?.items.map((item) => ({ + const reducer = (acc: MappedProduct[], curr: Wishlist) : MappedProduct[] => [...acc, ...curr?.items_v2?.items.map((item) => ({ product: item.product, quantity: item.quantity, added_at: item.added_at, id: item.id, })) ?? []]; - const mapper = (item) => ({ + const mapper = (item: WishlistItemInterface): MappedProduct => ({ product: item.product, quantity: item.quantity, added_at: item.added_at, @@ -104,21 +96,22 @@ const getProducts = (wishlistData: Wishlist[] | Wishlist): { }); return Array.isArray(wishlistData) - ? wishlistData.reduce((acc, curr) => reducer(acc, curr), []) + ? wishlistData.reduce((acc, curr) => reducer(acc, curr), [] as MappedProduct[]) : wishlistData?.items_v2?.items.map((e) => mapper(e)); }; -export interface WishlistGetters extends BaseWishlistGetters { +export interface WishlistGetters extends BaseWishlistGetters { getShippingPrice(wishlist: Wishlist): number; - getItemQty(product: WishlistProduct): number; + getItemQty(product: WishlistItemInterface): number; - getPagination(wishlistData): AgnosticPagination; + getPagination(wishlistData: Wishlist | Wishlist[]): AgnosticPagination; - getProducts(wishlistData): { - product: WishlistProduct; + getProducts(wishlistData: Wishlist | Wishlist[]): { + product: ProductInterface; quantity: number; added_at: string; + id: string; }[]; } From 54276c489bc17ba84335fd8055b1caea81bda2ba Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Wed, 25 May 2022 15:51:02 +0200 Subject: [PATCH 07/33] refactor: fix implicit any in magento module --- packages/theme/modules/magento/defaultConfig.ts | 6 +++--- packages/theme/modules/magento/helpers/index.ts | 6 ++++-- packages/theme/modules/magento/plugin.ts | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/theme/modules/magento/defaultConfig.ts b/packages/theme/modules/magento/defaultConfig.ts index c73080c9e..8a30f32b0 100644 --- a/packages/theme/modules/magento/defaultConfig.ts +++ b/packages/theme/modules/magento/defaultConfig.ts @@ -8,7 +8,7 @@ export const defaultConfig = { storeCookieName: 'vsf-store', messageCookieName: 'vsf-message', }, - locale: undefined, - country: undefined, - currency: undefined, + locale: undefined as undefined, + country: undefined as undefined, + currency: undefined as undefined, } as const; diff --git a/packages/theme/modules/magento/helpers/index.ts b/packages/theme/modules/magento/helpers/index.ts index d629284c2..361ee4c0c 100644 --- a/packages/theme/modules/magento/helpers/index.ts +++ b/packages/theme/modules/magento/helpers/index.ts @@ -1,6 +1,7 @@ +import { NuxtAppOptions } from '@nuxt/types'; import { defaultConfig } from '~/modules/magento/defaultConfig'; -export const getLocaleSettings = (app, moduleOptions, additionalProperties) => { +export const getLocaleSettings = (app: NuxtAppOptions, moduleOptions: Record, additionalProperties: any) => { const localeSettings = moduleOptions.cookies ? { currency: additionalProperties.state.getCurrency(), @@ -16,7 +17,8 @@ export const getLocaleSettings = (app, moduleOptions, additionalProperties) => { }; }; -export const mapConfigToSetupObject = ({ app, moduleOptions, additionalProperties = {} }) => ({ +export const mapConfigToSetupObject = ({ app, moduleOptions, additionalProperties = {} } : +{ app: NuxtAppOptions, moduleOptions: Record, additionalProperties: Record }) => ({ ...defaultConfig, ...moduleOptions, ...additionalProperties, diff --git a/packages/theme/modules/magento/plugin.ts b/packages/theme/modules/magento/plugin.ts index c8916d726..65c15ecfe 100644 --- a/packages/theme/modules/magento/plugin.ts +++ b/packages/theme/modules/magento/plugin.ts @@ -7,7 +7,7 @@ import { defaultConfig } from '~/modules/magento/defaultConfig'; const moduleOptions = JSON.parse('<%= JSON.stringify(options) %>'); export default integrationPlugin((plugin) => { - const getCookieName = (property: string) : string => moduleOptions.cookies?.[property] ?? defaultConfig.cookies[property]; + const getCookieName = (property: keyof typeof defaultConfig['cookies']) : string => moduleOptions.cookies?.[property] ?? defaultConfig.cookies[property]; const cookieNames = { cart: getCookieName('cartCookieName'), From 228711e3be98f6d97b39c71af7bf817f19e8fc28 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Wed, 25 May 2022 16:24:06 +0200 Subject: [PATCH 08/33] refactor: fix user-related implicit any issues --- .../modules/customer/composables/useUser/useUser.ts | 4 ++-- .../modules/customer/getters/userBillingGetters.ts | 10 +++++----- .../theme/modules/customer/helpers/generateUserData.ts | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/theme/modules/customer/composables/useUser/useUser.ts b/packages/theme/modules/customer/composables/useUser/useUser.ts index b2cdc36ca..b3ae73b62 100644 --- a/packages/theme/modules/customer/composables/useUser/useUser.ts +++ b/packages/theme/modules/customer/composables/useUser/useUser.ts @@ -25,14 +25,14 @@ export type UseUserUpdateUserParams = ComposableFunctionArgs<{ * Parameters accepted by the `register` method in the `useUser` composable */ export type UseUserRegisterParams = ComposableFunctionArgs<{ - user: any; // TODO: Neither `Customer`, nor `CustomerCreateInput` match expected data + user: any; // TODO: Neither `Customer`, nor `CustomerCreateInput` match expected data, M2-664 }>; /** * Parameters accepted by the `login` method in the `useUser` composable */ export type UseUserLoginParams = ComposableFunctionArgs<{ - user: any; // TODO: Neither `Customer`, nor `CustomerCreateInput` match expected data + user: any; // TODO: Neither `Customer`, nor `CustomerCreateInput` match expected data, M2-664 }>; /** diff --git a/packages/theme/modules/customer/getters/userBillingGetters.ts b/packages/theme/modules/customer/getters/userBillingGetters.ts index 73d4f3e3e..2c8e6db0b 100644 --- a/packages/theme/modules/customer/getters/userBillingGetters.ts +++ b/packages/theme/modules/customer/getters/userBillingGetters.ts @@ -1,4 +1,5 @@ import { UserBillingGetters as BaseGetters } from '~/modules/customer/getters/types'; +import type { Customer, CustomerAddress } from '~/modules/GraphQL/types'; interface UserBillingGetters extends BaseGetters{ getNeighborhood: (address: any) => string @@ -6,17 +7,16 @@ interface UserBillingGetters extends BaseGetters{ } const userBillingGetters: UserBillingGetters = { - getAddresses: (billing, criteria?: Record) => { + getAddresses: (billing: Customer, criteria?: Record) => { if (!criteria || Object.keys(criteria).length === 0) { return billing.addresses; } const entries = Object.entries(criteria); - return billing.addresses.filter((address) => entries.every(([key, value]) => address[key] === value)); + return billing.addresses.filter((address) => entries.every(([key, value]) => address[key as keyof CustomerAddress] === value)); }, - getDefault: (billing) => billing.addresses.find(({ isDefault }) => isDefault), - getTotal: (billing) => billing.addresses.length, - + getDefault: (billing: Customer) => billing.addresses.find(({ default_billing }) => default_billing), + getTotal: (billing: Customer) => billing.addresses.length, getPostCode: (address) => address?.postcode || '', getStreetName: (address) => (Array.isArray(address?.street) ? address?.street[0] : ''), getStreetNumber: (address) => address?.streetNumber || '', diff --git a/packages/theme/modules/customer/helpers/generateUserData.ts b/packages/theme/modules/customer/helpers/generateUserData.ts index 13c0cf88a..73c293711 100644 --- a/packages/theme/modules/customer/helpers/generateUserData.ts +++ b/packages/theme/modules/customer/helpers/generateUserData.ts @@ -1,6 +1,6 @@ import type { CustomerCreateInput } from '~/modules/GraphQL/types'; -export const generateUserData = (userData): CustomerCreateInput => { +export const generateUserData = (userData: any): CustomerCreateInput => { const baseData = { email: userData.email, firstname: userData.firstName || userData.firstname, From 69ad107ca82d58747268c7622f62b42e23dd3b8a Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Wed, 25 May 2022 16:32:18 +0200 Subject: [PATCH 09/33] refactor: createAddCustomerCommand context type --- .../commands/createCustomerAddressCommand.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/theme/modules/customer/composables/useUserAddress/commands/createCustomerAddressCommand.ts b/packages/theme/modules/customer/composables/useUserAddress/commands/createCustomerAddressCommand.ts index 8ec6b2326..b3178e381 100644 --- a/packages/theme/modules/customer/composables/useUserAddress/commands/createCustomerAddressCommand.ts +++ b/packages/theme/modules/customer/composables/useUserAddress/commands/createCustomerAddressCommand.ts @@ -1,8 +1,11 @@ +import type { useContext } from '@nuxtjs/composition-api'; import { CustomerAddressInput } from '~/modules/GraphQL/types'; +type Context = ReturnType; + export const createCustomerAddressCommand = { - execute: async (context, params: CustomerAddressInput) => { - const { data } = await context.$vsf.$magento.api.createCustomerAddress(params); + execute: async (context: Context, params: CustomerAddressInput) => { + const { data } = await context.app.$vsf.$magento.api.createCustomerAddress(params); return data?.createCustomerAddress ?? {}; }, From 2973a7f99a5f1f83615b11c480c12fbaab220765 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Wed, 25 May 2022 16:40:02 +0200 Subject: [PATCH 10/33] refactor: remove context implicit any --- .../commands/deleteCustomerAddressCommand.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/theme/modules/customer/composables/useUserAddress/commands/deleteCustomerAddressCommand.ts b/packages/theme/modules/customer/composables/useUserAddress/commands/deleteCustomerAddressCommand.ts index 3e8d56faa..e34c8363b 100644 --- a/packages/theme/modules/customer/composables/useUserAddress/commands/deleteCustomerAddressCommand.ts +++ b/packages/theme/modules/customer/composables/useUserAddress/commands/deleteCustomerAddressCommand.ts @@ -1,8 +1,11 @@ +import type { useContext } from '@nuxtjs/composition-api'; import { CustomerAddress } from '~/modules/GraphQL/types'; +type Context = ReturnType; + export const deleteCustomerAddressCommand = { - execute: async (context, address: CustomerAddress) => { - const { data } = await context.$vsf.$magento.api.deleteCustomerAddress(address.id); + execute: async (context: Context, address: CustomerAddress) => { + const { data } = await context.app.$vsf.$magento.api.deleteCustomerAddress(address.id); return data?.deleteCustomerAddress ?? {}; }, From 11e1fd5370ec5cb6a6ebd16c362ee06c5b67a81d Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 08:49:45 +0200 Subject: [PATCH 11/33] refactor: remove implicit any from Shipping.vue --- .../modules/checkout/pages/Checkout/Shipping.vue | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/theme/modules/checkout/pages/Checkout/Shipping.vue b/packages/theme/modules/checkout/pages/Checkout/Shipping.vue index 13a4e077f..3d2693cee 100644 --- a/packages/theme/modules/checkout/pages/Checkout/Shipping.vue +++ b/packages/theme/modules/checkout/pages/Checkout/Shipping.vue @@ -277,7 +277,9 @@ import addressGetter from '~/modules/customer/getters/addressGetter'; import { useCountrySearch, } from '~/composables'; -import type { Country, AvailableShippingMethod, ShippingCartAddress } from '~/modules/GraphQL/types'; +import type { + Country, AvailableShippingMethod, ShippingCartAddress, CustomerAddress, +} from '~/modules/GraphQL/types'; import useShipping from '~/modules/checkout/composables/useShipping'; import useUser from '~/modules/customer/composables/useUser'; import useUserAddress from '~/modules/customer/composables/useUserAddress'; @@ -361,7 +363,7 @@ export default defineComponent({ const regionInformation = computed(() => addressGetter.regionList(country.value)); - const handleAddressSubmit = (reset) => async () => { + const handleAddressSubmit = (reset: () => void) => async () => { const addressId = currentAddressId.value; const shippingDetailsData = { ...shippingDetails.value, @@ -395,14 +397,14 @@ export default defineComponent({ isShippingDetailsStepCompleted.value = false; }; - const handleSetCurrentAddress = (addr) => { + const handleSetCurrentAddress = (addr: CustomerAddress) => { shippingDetails.value = { ...addressFromApiToForm(addr) }; - currentAddressId.value = addr?.id; + currentAddressId.value = String(addr?.id); canAddNewAddress.value = false; isShippingDetailsStepCompleted.value = false; }; - const changeShippingDetails = (field, value) => { + const changeShippingDetails = (field: string, value: unknown) => { shippingDetails.value = { ...shippingDetails.value, [field]: value, @@ -415,13 +417,13 @@ export default defineComponent({ const defaultAddress = userShippingGetters.getAddresses( userShipping.value, { default_shipping: true }, - ); + ) as [CustomerAddress] || []; if (defaultAddress && defaultAddress.length > 0) { handleSetCurrentAddress(defaultAddress[0]); } }; - const changeCountry = async (id) => { + const changeCountry = async (id: string) => { changeShippingDetails('country_code', id); country.value = await searchCountry({ id }); }; From 3c79e9faa071636aa0f7217a01559e656a85b8bc Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 08:55:49 +0200 Subject: [PATCH 12/33] refactor: remove implicit any from LoginModal.vue --- packages/theme/components/LoginModal.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/theme/components/LoginModal.vue b/packages/theme/components/LoginModal.vue index 7dff5d0d9..0af554d7c 100644 --- a/packages/theme/components/LoginModal.vue +++ b/packages/theme/components/LoginModal.vue @@ -394,12 +394,12 @@ export default defineComponent({ } }); - const setIsLoginValue = (value) => { + const setIsLoginValue = (value: boolean) => { resetErrorValues(); isLogin.value = value; }; - const setIsForgottenValue = (value) => { + const setIsForgottenValue = (value: boolean) => { resetErrorValues(); isForgotten.value = value; isLogin.value = !value; @@ -412,7 +412,7 @@ export default defineComponent({ toggleLoginModal(); }; - const handleForm = (fn) => async () => { + const handleForm = (fn: typeof register) => async () => { resetErrorValues(); if (isRecaptchaEnabled.value) { From 80d69d1a13a2743fef1491ae4c55434e37616e4e Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 09:08:20 +0200 Subject: [PATCH 13/33] refactor: remove implicit any in SearchResults.vue --- packages/theme/components/Header/SearchBar/SearchResults.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/theme/components/Header/SearchBar/SearchResults.vue b/packages/theme/components/Header/SearchBar/SearchResults.vue index 212fb4a3b..9f848c2c0 100644 --- a/packages/theme/components/Header/SearchBar/SearchResults.vue +++ b/packages/theme/components/Header/SearchBar/SearchResults.vue @@ -162,6 +162,7 @@ import { import useWishlist from '~/modules/wishlist/composables/useWishlist'; import { useUser } from '~/modules/customer/composables/useUser'; import SvgImage from '~/components/General/SvgImage.vue'; +import type { Product } from '~/modules/wishlist/composables/useWishlist/useWishlist'; export default defineComponent({ name: 'SearchResults', @@ -191,7 +192,7 @@ export default defineComponent({ const isSearchOpen = ref(props.visible); const products = computed(() => props.result?.products); - const addItemToWishlist = async (product) => { + const addItemToWishlist = async (product: Product) => { await (isInWishlist({ product }) ? removeItem({ product }) : addItem({ product })); From d5e4ab0889a31353fe32f327cacde7cba78b3059 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 09:11:35 +0200 Subject: [PATCH 14/33] refactor: remove implicit any from SearchBar.vue --- packages/theme/components/Header/SearchBar/SearchBar.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/theme/components/Header/SearchBar/SearchBar.vue b/packages/theme/components/Header/SearchBar/SearchBar.vue index 07a2c0052..17d8e7b4d 100644 --- a/packages/theme/components/Header/SearchBar/SearchBar.vue +++ b/packages/theme/components/Header/SearchBar/SearchBar.vue @@ -117,7 +117,7 @@ export default defineComponent({ } }; - const closeSearch = (event) => { + const closeSearch = (event: MouseEvent) => { if (document) { const searchResultsEl = document.querySelectorAll('.search'); const closeTriggerElement = event.target as HTMLElement; From ff774562374ed1b0dfc8e70c30917004b3f603e3 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 09:47:11 +0200 Subject: [PATCH 15/33] refactor: updatecustomeraddress useContext --- .../commands/updateCustomerAddressCommand.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/theme/modules/customer/composables/useUserAddress/commands/updateCustomerAddressCommand.ts b/packages/theme/modules/customer/composables/useUserAddress/commands/updateCustomerAddressCommand.ts index 185c9f63e..f8b52f02c 100644 --- a/packages/theme/modules/customer/composables/useUserAddress/commands/updateCustomerAddressCommand.ts +++ b/packages/theme/modules/customer/composables/useUserAddress/commands/updateCustomerAddressCommand.ts @@ -1,11 +1,14 @@ +import type { useContext } from '@nuxtjs/composition-api'; import { CustomerAddressInput } from '~/modules/GraphQL/types'; +type Context = ReturnType; + export const updateCustomerAddressCommand = { - execute: async (context, params: { + execute: async (context: Context, params: { addressId: number; input: CustomerAddressInput; }) => { - const { data } = await context.$vsf.$magento.api.updateCustomerAddress(params); + const { data } = await context.app.$vsf.$magento.api.updateCustomerAddress(params); return data?.updateCustomerAddress ?? {}; }, From 0cc1364f52f595c008415dce2b1a1e1bd75c29ff Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 09:47:45 +0200 Subject: [PATCH 16/33] refactor: add billing form type --- packages/theme/modules/checkout/pages/Checkout/Billing.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/theme/modules/checkout/pages/Checkout/Billing.vue b/packages/theme/modules/checkout/pages/Checkout/Billing.vue index 9629108fa..544c4c0e9 100644 --- a/packages/theme/modules/checkout/pages/Checkout/Billing.vue +++ b/packages/theme/modules/checkout/pages/Checkout/Billing.vue @@ -450,7 +450,7 @@ export default defineComponent({ isBillingDetailsStepCompleted.value = false; }; - const changeBillingDetails = (field, value) => { + const changeBillingDetails = (field: string, value: unknown) => { billingDetails.value = { ...billingDetails.value, [field]: value, From d8dc6f59763e010bf58d5b72cab25af6ad790fd3 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 10:05:46 +0200 Subject: [PATCH 17/33] refactor: remove implicit any in ProductsCarousel --- .../modules/catalog/product/components/ProductsCarousel.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/theme/modules/catalog/product/components/ProductsCarousel.vue b/packages/theme/modules/catalog/product/components/ProductsCarousel.vue index a38d24c58..f0feadf07 100644 --- a/packages/theme/modules/catalog/product/components/ProductsCarousel.vue +++ b/packages/theme/modules/catalog/product/components/ProductsCarousel.vue @@ -134,7 +134,7 @@ export default defineComponent({ isInWishlist: isInWishlist({ product }), }))); - const addItemToWishlist = async (product) => { + const addItemToWishlist = async (product: Product) => { await (isInWishlist({ product }) ? removeItem({ product }) : addItem({ product })); From 04329f8f1e945e431fc9c64bc1d519d17c98d20d Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 10:31:17 +0200 Subject: [PATCH 18/33] refactor: add reset arg type --- packages/theme/modules/checkout/pages/Checkout/UserAccount.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/theme/modules/checkout/pages/Checkout/UserAccount.vue b/packages/theme/modules/checkout/pages/Checkout/UserAccount.vue index eda2b7533..63417d87a 100644 --- a/packages/theme/modules/checkout/pages/Checkout/UserAccount.vue +++ b/packages/theme/modules/checkout/pages/Checkout/UserAccount.vue @@ -236,7 +236,7 @@ export default defineComponent({ is_subscribed: false, }); - const handleFormSubmit = (reset) => async () => { + const handleFormSubmit = (reset: () => void) => async () => { if (isRecaptchaEnabled.value) { $recaptcha.init(); } From cd975501a2471e3431e8eaea70a27bd1373ab625 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 10:42:19 +0200 Subject: [PATCH 19/33] refactor: fix implicit any in Payment.vue --- packages/theme/modules/checkout/pages/Checkout/Payment.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/theme/modules/checkout/pages/Checkout/Payment.vue b/packages/theme/modules/checkout/pages/Checkout/Payment.vue index d1bc81337..fe7da4295 100644 --- a/packages/theme/modules/checkout/pages/Checkout/Payment.vue +++ b/packages/theme/modules/checkout/pages/Checkout/Payment.vue @@ -185,6 +185,7 @@ import useCart from '~/modules/checkout/composables/useCart'; import getShippingMethodPrice from '~/helpers/checkout/getShippingMethodPrice'; import { removeItem } from '~/helpers/asyncLocalStorage'; import { isPreviousStepValid } from '~/helpers/checkout/steps'; +import type { BundleCartItem, ConfigurableCartItem } from '~/modules/GraphQL/types'; export default defineComponent({ name: 'ReviewOrderAndPayment', @@ -208,8 +209,8 @@ export default defineComponent({ const router = useRouter(); const isPaymentReady = ref(false); const terms = ref(false); - const getAttributes = (product) => product.configurable_options || []; - const getBundles = (product) => product.bundle_options?.map((b) => b.values).flat() || []; + const getAttributes = (product: ConfigurableCartItem) => product.configurable_options || []; + const getBundles = (product: BundleCartItem) => product.bundle_options?.map((b) => b.values).flat() || []; onMounted(async () => { const validStep = await isPreviousStepValid('billing'); From 96bab33068fec005bce247db98f2f4251b41ee0b Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 10:46:50 +0200 Subject: [PATCH 20/33] refactor: add types to Billing.vue --- .../modules/checkout/pages/Checkout/Billing.vue | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/theme/modules/checkout/pages/Checkout/Billing.vue b/packages/theme/modules/checkout/pages/Checkout/Billing.vue index 544c4c0e9..f8b5af3ad 100644 --- a/packages/theme/modules/checkout/pages/Checkout/Billing.vue +++ b/packages/theme/modules/checkout/pages/Checkout/Billing.vue @@ -303,7 +303,7 @@ import { import { mergeItem } from '~/helpers/asyncLocalStorage'; import { isPreviousStepValid } from '~/helpers/checkout/steps'; -import type { ShippingCartAddress, Customer } from '~/modules/GraphQL/types'; +import type { ShippingCartAddress, Customer, Country } from '~/modules/GraphQL/types'; const NOT_SELECTED_ADDRESS = ''; @@ -355,8 +355,8 @@ export default defineComponent({ search: searchCountry, } = useCountrySearch(); - const countries = ref([]); - const country = ref(null); + const countries = ref([]); + const country = ref(null); const { isAuthenticated } = useUser(); let oldBilling = null; const sameAsShipping = ref(false); @@ -381,13 +381,10 @@ export default defineComponent({ return addresses.value.length > 0; }); - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument const countriesList = computed(() => addressGetter.countriesList(countries.value)); - - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument const regionInformation = computed(() => addressGetter.regionList(country.value)); - const handleAddressSubmit = (reset) => async () => { + const handleAddressSubmit = (reset: () => void) => async () => { const addressId = currentAddressId.value; const billingDetailsData = { billingDetails: { @@ -469,7 +466,7 @@ export default defineComponent({ } }; - const changeCountry = async (id) => { + const changeCountry = async (id: string) => { changeBillingDetails('country_code', id); country.value = await searchCountry({ id }); }; From 3805a69f0b818c4e1f011abca58545b5047ee0f9 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 10:49:12 +0200 Subject: [PATCH 21/33] refactor: fix missing context --- .../useGuestUser/commands/attachToCartCommand.ts | 7 +++++-- .../modules/customer/composables/useGuestUser/index.ts | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/theme/modules/customer/composables/useGuestUser/commands/attachToCartCommand.ts b/packages/theme/modules/customer/composables/useGuestUser/commands/attachToCartCommand.ts index 3813475ab..93d93d71e 100644 --- a/packages/theme/modules/customer/composables/useGuestUser/commands/attachToCartCommand.ts +++ b/packages/theme/modules/customer/composables/useGuestUser/commands/attachToCartCommand.ts @@ -1,8 +1,11 @@ +import type { useContext } from '@nuxtjs/composition-api'; import { Logger } from '~/helpers/logger'; import { SetGuestEmailOnCartInput } from '~/modules/GraphQL/types'; +type Context = ReturnType; + export const attachToCartCommand = { - execute: async (context, params): Promise => { + execute: async (context: Context, params): Promise => { Logger.debug('[Magento]: Attach guest cart to user'); const emailOnCartInput: SetGuestEmailOnCartInput = { @@ -10,7 +13,7 @@ export const attachToCartCommand = { cart_id: params?.cart?.value?.id, }; - await context.$magento.api.setGuestEmailOnCart({ + await context.app.$vsf.$magento.api.setGuestEmailOnCart({ ...emailOnCartInput, }); }, diff --git a/packages/theme/modules/customer/composables/useGuestUser/index.ts b/packages/theme/modules/customer/composables/useGuestUser/index.ts index a91c58170..630127bdc 100644 --- a/packages/theme/modules/customer/composables/useGuestUser/index.ts +++ b/packages/theme/modules/customer/composables/useGuestUser/index.ts @@ -12,8 +12,7 @@ import { attachToCartCommand } from '~/modules/customer/composables/useGuestUser export function useGuestUser(): UseGuestUserInterface { const loading = ref(false); const error = ref({ attachToCart: null }); - const { app } = useContext(); - const context = app.$vsf; + const context = useContext(); const attachToCart = async (params: ComposableFunctionArgs) => { Logger.debug('useGuestUserFactory.attachToCart', { params }); From fafbdd5c3b0d3fccb1039334b9819740cd862778 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 11:02:47 +0200 Subject: [PATCH 22/33] refactor: improve checkout module entrypoint types --- packages/theme/modules/checkout/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/theme/modules/checkout/index.ts b/packages/theme/modules/checkout/index.ts index c091eed38..89220faf2 100644 --- a/packages/theme/modules/checkout/index.ts +++ b/packages/theme/modules/checkout/index.ts @@ -1,11 +1,12 @@ -import { Module } from '@nuxt/types'; import path from 'node:path'; import url from 'node:url'; +import type { Module } from '@nuxt/types'; +import type { NuxtRouteConfig } from '@nuxt/types/config/router'; const nuxtModule : Module = function checkoutModule() { const moduleDir = path.dirname(url.fileURLToPath(import.meta.url)); - this.extendRoutes((routes) => { + this.extendRoutes((routes: NuxtRouteConfig[]) => { routes.unshift( { name: 'checkout', From 8a17c86a3e8f5195d0bc4087cc472389c3b95795 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 11:09:50 +0200 Subject: [PATCH 23/33] chore: declare typeless packages as any --- packages/theme/types/packages.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 packages/theme/types/packages.d.ts diff --git a/packages/theme/types/packages.d.ts b/packages/theme/types/packages.d.ts new file mode 100644 index 000000000..1958d0f69 --- /dev/null +++ b/packages/theme/types/packages.d.ts @@ -0,0 +1,8 @@ +// SFUI doesn't ship types and no @types package available +declare module '@storefront-ui/vue'; + +// omit-deep doesn't ship types and no @types package available +declare module 'omit-deep'; + +// https://github.com/maoberlehner/vue-lazy-hydration/pull/28 +declare module 'vue-lazy-hydration'; From c9da42e1547b8c24aa272c5d43de3a40beed59bb Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 11:15:08 +0200 Subject: [PATCH 24/33] refactor: add reset void --- .../modules/catalog/product/components/ProductAddReviewForm.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/theme/modules/catalog/product/components/ProductAddReviewForm.vue b/packages/theme/modules/catalog/product/components/ProductAddReviewForm.vue index 6e7a28d90..79bb2e2de 100644 --- a/packages/theme/modules/catalog/product/components/ProductAddReviewForm.vue +++ b/packages/theme/modules/catalog/product/components/ProductAddReviewForm.vue @@ -205,7 +205,7 @@ export default defineComponent({ }; }); - const submitForm = (reset) => async () => { + const submitForm = (reset: () => void) => async () => { if ( !( formSubmitValue.value.ratings[0].value_id From 3f931fba2e9eb458bdc1d36bf4dfa3338f1aa93d Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 11:16:50 +0200 Subject: [PATCH 25/33] refactor: remove createProductAttributeFilterInput implicit any --- .../useFacet/input/createProductAttributeFilterInput.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/theme/modules/catalog/category/composables/useFacet/input/createProductAttributeFilterInput.ts b/packages/theme/modules/catalog/category/composables/useFacet/input/createProductAttributeFilterInput.ts index 2d2f7df41..88b79d502 100644 --- a/packages/theme/modules/catalog/category/composables/useFacet/input/createProductAttributeFilterInput.ts +++ b/packages/theme/modules/catalog/category/composables/useFacet/input/createProductAttributeFilterInput.ts @@ -5,7 +5,7 @@ import type { FacetSearchParams } from '../useFacet'; export const rangeFilters = ['price']; export function createProductAttributeFilterInput(params: ComposableFunctionArgs): ProductAttributeFilterInput { - const attributeFilter = {}; + const attributeFilter : Record = {}; const inputFilters = params?.filters ?? {}; const categoryFilter = { From f652d440609a1d014c5ffb91de8fc61f215dcbd1 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 11:17:45 +0200 Subject: [PATCH 26/33] refactor: remove integarationPlugin implicit any --- packages/theme/helpers/integrationPlugin/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/theme/helpers/integrationPlugin/index.ts b/packages/theme/helpers/integrationPlugin/index.ts index fa66a6d14..19cd7590a 100644 --- a/packages/theme/helpers/integrationPlugin/index.ts +++ b/packages/theme/helpers/integrationPlugin/index.ts @@ -51,7 +51,7 @@ export const integrationPlugin = (pluginFn: NuxtPluginWithIntegration) => (nuxtC injectInContext({ api, client, config }); }; - const extend = (tag, integrationProperties: Record) => { + const extend = (tag: string, integrationProperties: Record) => { createExtendIntegrationInCtx({ tag, nuxtCtx, inject })(integrationProperties); }; From c480a4f0e8ebaf545d1ca87012220a3703e1cfb3 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 11:36:53 +0200 Subject: [PATCH 27/33] refactor: remove implicit any from CartSidebar.vue --- packages/theme/components/CartSidebar.vue | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/theme/components/CartSidebar.vue b/packages/theme/components/CartSidebar.vue index 06f3f7481..7dbc88ead 100644 --- a/packages/theme/components/CartSidebar.vue +++ b/packages/theme/components/CartSidebar.vue @@ -273,10 +273,9 @@ import useCart from '~/modules/checkout/composables/useCart'; import { useUser } from '~/modules/customer/composables/useUser'; import stockStatusEnum from '~/enums/stockStatusEnum'; import SvgImage from '~/components/General/SvgImage.vue'; +import type { ConfigurableCartItem, BundleCartItem, CartItemInterface } from '~/modules/GraphQL/types'; import CouponCode from './CouponCode.vue'; -import type { ConfigurableCartItem } from '~/modules/GraphQL/types'; - export default defineComponent({ name: 'CartSidebar', components: { @@ -324,8 +323,8 @@ export default defineComponent({ }))); const totals = computed(() => cartGetters.getTotals(cart.value)); const totalItems = computed(() => cartGetters.getTotalItems(cart.value)); - const getAttributes = (product) => product.configurable_options || []; - const getBundles = (product) => product.bundle_options?.map((b) => b.values).flat() || []; + const getAttributes = (product: ConfigurableCartItem) => product.configurable_options || []; + const getBundles = (product: BundleCartItem) => product.bundle_options?.map((b) => b.values).flat() || []; const visible = ref(false); const tempProduct = ref(); @@ -342,7 +341,7 @@ export default defineComponent({ await router.push(`${app.localePath(redirectUrl)}`); }; - const sendToRemove = ({ product }) => { + const sendToRemove = ({ product }: { product: CartItemInterface }) => { if (notifications.value.length > 0) { notifications.value[0].dismiss(); } @@ -351,7 +350,7 @@ export default defineComponent({ tempProduct.value = product; }; - const actionRemoveItem = async (product) => { + const actionRemoveItem = async (product: CartItemInterface) => { await removeItem({ product }); visible.value = false; @@ -370,7 +369,7 @@ export default defineComponent({ (params) => updateItemQty(params), 1000, ); - const isInStock = (product) => cartGetters.getStockStatus(product) === stockStatusEnum.inStock; + const isInStock = (product: CartItemInterface) => cartGetters.getStockStatus(product) === stockStatusEnum.inStock; return { sendToRemove, From a17dbdf0875723253204af41e3f287329794b3f7 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 11:50:01 +0200 Subject: [PATCH 28/33] refactor: fix implicit any issues in context.ts --- .../theme/helpers/integrationPlugin/context.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/theme/helpers/integrationPlugin/context.ts b/packages/theme/helpers/integrationPlugin/context.ts index c94e9171a..7ac6bbee9 100644 --- a/packages/theme/helpers/integrationPlugin/context.ts +++ b/packages/theme/helpers/integrationPlugin/context.ts @@ -1,29 +1,35 @@ /* eslint-disable no-param-reassign */ + +import { Context as NuxtContext } from '@nuxt/types'; +import { Inject } from '@nuxt/types/app'; + +type Argument = { tag: string, nuxtCtx: NuxtContext, inject: Inject }; + /** * It extends given integartion, defined by `tag` in the context. */ -export const createExtendIntegrationInCtx = ({ tag, nuxtCtx, inject }) => (integrationProperties: Record) => { +export const createExtendIntegrationInCtx = ({ tag, nuxtCtx, inject } : Argument) => (integrationProperties: Record) => { const integrationKey = `$${tag}`; - if (!nuxtCtx.$vsf || !nuxtCtx.$vsf[integrationKey]) { + if (!nuxtCtx.$vsf || !(nuxtCtx.$vsf as Record)[integrationKey]) { inject('vsf', { [integrationKey]: {} }); } Object.keys(integrationProperties) .filter((k) => !['api', 'client', 'config'].includes(k)) .forEach((key) => { - nuxtCtx.$vsf[integrationKey][key] = integrationProperties[key]; + (nuxtCtx.$vsf as Record)[integrationKey][key] = integrationProperties[key]; }); }; /** * It creates a function that adds an integration to the context under the given name, defined by `tag`. */ -export const createAddIntegrationToCtx = ({ tag, nuxtCtx, inject }) => (integrationProperties: Record) => { +export const createAddIntegrationToCtx = ({ tag, nuxtCtx, inject } : Argument) => (integrationProperties: Record) => { const integrationKey = `$${tag}`; - if (nuxtCtx.$vsf && !nuxtCtx.$vsf[integrationKey]) { - nuxtCtx.$vsf[integrationKey] = integrationProperties; + if (nuxtCtx.$vsf && !(nuxtCtx.$vsf as Record)[integrationKey]) { + (nuxtCtx.$vsf as Record)[integrationKey] = integrationProperties; return; } From a92cba6fd6a1bce85732c159010d8cc07f80333e Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 11:54:10 +0200 Subject: [PATCH 29/33] refactor: add explicit types for useUser errors --- packages/theme/modules/customer/composables/useUser/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/theme/modules/customer/composables/useUser/index.ts b/packages/theme/modules/customer/composables/useUser/index.ts index e319bf4e6..968e60b27 100644 --- a/packages/theme/modules/customer/composables/useUser/index.ts +++ b/packages/theme/modules/customer/composables/useUser/index.ts @@ -13,6 +13,7 @@ import { generateUserData } from '~/modules/customer/helpers/generateUserData'; import { Customer } from '~/modules/GraphQL/types'; import type { UseUserInterface, + UseUserErrors, UseUserLoadParams, UseUserLoginParams, UseUserLogoutParams, @@ -31,7 +32,7 @@ export function useUser(): UseUserInterface { const { app } = useContext(); const { setCart } = useCart(); const loading: Ref = ref(false); - const errorsFactory = () => ({ + const errorsFactory = () : UseUserErrors => ({ updateUser: null, register: null, login: null, From a17cde34eb5a17dbccca3a0d8766892c46befd44 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 12:26:21 +0200 Subject: [PATCH 30/33] refactor: add missing properties to clientconfig --- packages/api-client/src/types/setup.ts | 2 ++ packages/theme/composables/context.ts | 3 +++ packages/theme/composables/useImage/index.ts | 5 ++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/api-client/src/types/setup.ts b/packages/api-client/src/types/setup.ts index cebc7b295..7fe7f2fd0 100644 --- a/packages/api-client/src/types/setup.ts +++ b/packages/api-client/src/types/setup.ts @@ -96,6 +96,8 @@ export interface Config extends ClientConfig { magentoApiEndpoint: string; overrides: MagentoApiMethods; recaptcha: RecaptchaConfig; + imageProvider: string; + magentoBaseUrl: string; } export interface ClientInstance extends ApolloClient { diff --git a/packages/theme/composables/context.ts b/packages/theme/composables/context.ts index 3fb7a3ffd..747cbc3aa 100644 --- a/packages/theme/composables/context.ts +++ b/packages/theme/composables/context.ts @@ -10,4 +10,7 @@ declare module '@nuxt/types' { interface NuxtAppOptions { $vsf: VsfContext } + interface Context { + $vsf: VsfContext + } } diff --git a/packages/theme/composables/useImage/index.ts b/packages/theme/composables/useImage/index.ts index 6117abcd0..fcbba5f52 100644 --- a/packages/theme/composables/useImage/index.ts +++ b/packages/theme/composables/useImage/index.ts @@ -8,8 +8,7 @@ import { UseImageInterface } from './useImage'; * See the {@link UseImageInterface} for a list of methods and values available in this composable. * */ export function useImage(): UseImageInterface { - // @ts-ignore - const { $vsf } = useContext(); + const context = useContext(); /** * Extract image path from Magento URL. * @@ -18,7 +17,7 @@ export function useImage(): UseImageInterface { * @return {string} */ const getMagentoImage = (fullImageUrl: string) => { - const { imageProvider, magentoBaseUrl } = $vsf.$magento.config; + const { imageProvider, magentoBaseUrl } = context.$vsf.$magento.config; if (imageProvider !== 'ipx') { const url = fullImageUrl.split(`${magentoBaseUrl}`); From 7b8bedcba50b6c530336329c9dfdf662354b209f Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 12:30:31 +0200 Subject: [PATCH 31/33] chore: use ts syntax instead of js logic operator --- packages/theme/modules/checkout/pages/Checkout/Shipping.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/theme/modules/checkout/pages/Checkout/Shipping.vue b/packages/theme/modules/checkout/pages/Checkout/Shipping.vue index 3d2693cee..8a0d200af 100644 --- a/packages/theme/modules/checkout/pages/Checkout/Shipping.vue +++ b/packages/theme/modules/checkout/pages/Checkout/Shipping.vue @@ -417,7 +417,7 @@ export default defineComponent({ const defaultAddress = userShippingGetters.getAddresses( userShipping.value, { default_shipping: true }, - ) as [CustomerAddress] || []; + ) as [CustomerAddress] | []; if (defaultAddress && defaultAddress.length > 0) { handleSetCurrentAddress(defaultAddress[0]); } From 9b44e15789dee98bf643f40803647c5134c75a0e Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 12:39:02 +0200 Subject: [PATCH 32/33] refactor: remove UseContext return type duplication --- packages/theme/composables/types.ts | 4 +++- .../useNewsletter/commands/updateSubscriptionCommand.ts | 6 ++---- .../useProduct/commands/getProductDetailsCommand.ts | 6 ++---- .../useProduct/commands/getProductListCommand.ts | 6 ++---- .../composables/useMakeOrder/commands/placeOrderCommand.ts | 6 ++---- .../commands/getAvailablePaymentMethodsCommand.ts | 6 ++---- .../commands/setPaymentMethodOnCartCommand.ts | 6 ++---- .../commands/setShippingMethodsOnCartCommand.ts | 6 ++---- .../useGuestUser/commands/attachToCartCommand.ts | 6 ++---- .../useUserAddress/commands/createCustomerAddressCommand.ts | 6 ++---- .../useUserAddress/commands/deleteCustomerAddressCommand.ts | 6 ++---- .../useUserAddress/commands/updateCustomerAddressCommand.ts | 6 ++---- 12 files changed, 25 insertions(+), 45 deletions(-) diff --git a/packages/theme/composables/types.ts b/packages/theme/composables/types.ts index 6cc16a7b1..2344598f9 100644 --- a/packages/theme/composables/types.ts +++ b/packages/theme/composables/types.ts @@ -1,4 +1,4 @@ -import type { DeepReadonly, Ref } from '@nuxtjs/composition-api'; +import type { DeepReadonly, Ref, useContext } from '@nuxtjs/composition-api'; import type { AvailableStoresQuery, CountriesListQuery, @@ -233,3 +233,5 @@ export interface AgnosticReviewMetadata { id: string; }[]; } + +export type UseContextReturn = ReturnType; diff --git a/packages/theme/composables/useNewsletter/commands/updateSubscriptionCommand.ts b/packages/theme/composables/useNewsletter/commands/updateSubscriptionCommand.ts index 3a15a4fba..0efe3b76c 100644 --- a/packages/theme/composables/useNewsletter/commands/updateSubscriptionCommand.ts +++ b/packages/theme/composables/useNewsletter/commands/updateSubscriptionCommand.ts @@ -1,11 +1,9 @@ -import type { useContext } from '@nuxtjs/composition-api'; +import { UseContextReturn } from '~/composables/types'; import type { SubscriptionStatusesEnum } from '~/modules/GraphQL/types'; import type { UseNewsletterUpdateSubscriptionParams } from '../useNewsletter'; -type Context = ReturnType; - export const updateSubscriptionCommand = { - execute: async (context: Context, params: UseNewsletterUpdateSubscriptionParams): Promise => { + execute: async (context: UseContextReturn, params: UseNewsletterUpdateSubscriptionParams): Promise => { const { data } = await context.app.$vsf.$magento.api.subscribeEmailToNewsletter({ email: params.email, }); diff --git a/packages/theme/modules/catalog/product/composables/useProduct/commands/getProductDetailsCommand.ts b/packages/theme/modules/catalog/product/composables/useProduct/commands/getProductDetailsCommand.ts index 247288f30..3b844a6d2 100644 --- a/packages/theme/modules/catalog/product/composables/useProduct/commands/getProductDetailsCommand.ts +++ b/packages/theme/modules/catalog/product/composables/useProduct/commands/getProductDetailsCommand.ts @@ -1,10 +1,8 @@ -import type { useContext } from '@nuxtjs/composition-api'; +import { UseContextReturn } from '~/composables/types'; import type { GetProductSearchParams } from '~/modules/catalog/product/types'; -type Context = ReturnType; - export const getProductDetailsCommand = { - execute: async (context: Context, searchParams: GetProductSearchParams, customQuery = { productDetail: 'productDetail' }) => { + execute: async (context: UseContextReturn, searchParams: GetProductSearchParams, customQuery = { productDetail: 'productDetail' }) => { const { data } = await context.app.$vsf.$magento.api.productDetail(searchParams, customQuery); return data?.products ?? null; diff --git a/packages/theme/modules/catalog/product/composables/useProduct/commands/getProductListCommand.ts b/packages/theme/modules/catalog/product/composables/useProduct/commands/getProductListCommand.ts index 44a30cbe8..f4757a8c4 100644 --- a/packages/theme/modules/catalog/product/composables/useProduct/commands/getProductListCommand.ts +++ b/packages/theme/modules/catalog/product/composables/useProduct/commands/getProductListCommand.ts @@ -1,10 +1,8 @@ -import type { useContext } from '@nuxtjs/composition-api'; +import { UseContextReturn } from '~/composables/types'; import type { GetProductSearchParams } from '~/modules/catalog/product/types'; -type Context = ReturnType; - export const getProductListCommand = { - execute: async (context: Context, searchParams: GetProductSearchParams, customQuery = { products: 'products' }) => { + execute: async (context: UseContextReturn, searchParams: GetProductSearchParams, customQuery = { products: 'products' }) => { const { data } = await context.app.$vsf.$magento.api.products(searchParams, customQuery); return data?.products ?? null; diff --git a/packages/theme/modules/checkout/composables/useMakeOrder/commands/placeOrderCommand.ts b/packages/theme/modules/checkout/composables/useMakeOrder/commands/placeOrderCommand.ts index 4a23c95c3..5221a978b 100644 --- a/packages/theme/modules/checkout/composables/useMakeOrder/commands/placeOrderCommand.ts +++ b/packages/theme/modules/checkout/composables/useMakeOrder/commands/placeOrderCommand.ts @@ -1,10 +1,8 @@ -import type { useContext } from '@nuxtjs/composition-api'; +import { UseContextReturn } from '~/composables/types'; import type { PlaceOrderOutput } from '~/modules/GraphQL/types'; -type Context = ReturnType; - export const placeOrderCommand = { - execute: async (context: Context, cartId: string): Promise => { + execute: async (context: UseContextReturn, cartId: string): Promise => { const { data } = await context.app.$vsf.$magento.api.placeOrder({ cart_id: cartId }); return data?.placeOrder ?? null; diff --git a/packages/theme/modules/checkout/composables/usePaymentProvider/commands/getAvailablePaymentMethodsCommand.ts b/packages/theme/modules/checkout/composables/usePaymentProvider/commands/getAvailablePaymentMethodsCommand.ts index 5ef6e89f0..07b318825 100644 --- a/packages/theme/modules/checkout/composables/usePaymentProvider/commands/getAvailablePaymentMethodsCommand.ts +++ b/packages/theme/modules/checkout/composables/usePaymentProvider/commands/getAvailablePaymentMethodsCommand.ts @@ -1,10 +1,8 @@ -import type { useContext } from '@nuxtjs/composition-api'; +import { UseContextReturn } from '~/composables/types'; import type { AvailablePaymentMethod } from '~/modules/GraphQL/types'; -type Context = ReturnType; - export const getAvailablePaymentMethodsCommand = { - execute: async (context: Context, cartId: string): Promise => { + execute: async (context: UseContextReturn, cartId: string): Promise => { const { data } = await context.app.$vsf.$magento.api.getAvailablePaymentMethods({ cartId }); return data?.cart?.available_payment_methods ?? []; diff --git a/packages/theme/modules/checkout/composables/usePaymentProvider/commands/setPaymentMethodOnCartCommand.ts b/packages/theme/modules/checkout/composables/usePaymentProvider/commands/setPaymentMethodOnCartCommand.ts index 190b27d36..a827366b0 100644 --- a/packages/theme/modules/checkout/composables/usePaymentProvider/commands/setPaymentMethodOnCartCommand.ts +++ b/packages/theme/modules/checkout/composables/usePaymentProvider/commands/setPaymentMethodOnCartCommand.ts @@ -1,11 +1,9 @@ -import type { useContext } from '@nuxtjs/composition-api'; +import { UseContextReturn } from '~/composables/types'; import type { AvailablePaymentMethod } from '~/modules/GraphQL/types'; import type { PaymentMethodParams } from '../usePaymentProvider'; -type Context = ReturnType; - export const setPaymentMethodOnCartCommand = { - execute: async (context: Context, params: PaymentMethodParams): Promise => { + execute: async (context: UseContextReturn, params: PaymentMethodParams): Promise => { const { data } = await context.app.$vsf.$magento.api.setPaymentMethodOnCart(params); return data?.setPaymentMethodOnCart?.cart.available_payment_methods ?? []; diff --git a/packages/theme/modules/checkout/composables/useShippingProvider/commands/setShippingMethodsOnCartCommand.ts b/packages/theme/modules/checkout/composables/useShippingProvider/commands/setShippingMethodsOnCartCommand.ts index 24768512b..949a53dc7 100644 --- a/packages/theme/modules/checkout/composables/useShippingProvider/commands/setShippingMethodsOnCartCommand.ts +++ b/packages/theme/modules/checkout/composables/useShippingProvider/commands/setShippingMethodsOnCartCommand.ts @@ -1,10 +1,8 @@ -import type { useContext } from '@nuxtjs/composition-api'; +import { UseContextReturn } from '~/composables/types'; import type { SetShippingMethodsOnCartInput, Cart } from '~/modules/GraphQL/types'; -type Context = ReturnType; - export const setShippingMethodsOnCartCommand = { - execute: async (context: Context, shippingMethodParams: SetShippingMethodsOnCartInput): Promise => { + execute: async (context: UseContextReturn, shippingMethodParams: SetShippingMethodsOnCartInput): Promise => { const { data } = await context.app.$vsf.$magento.api.setShippingMethodsOnCart(shippingMethodParams); // TODO: Find out why 'Cart' doesn't match the type of the response data. diff --git a/packages/theme/modules/customer/composables/useGuestUser/commands/attachToCartCommand.ts b/packages/theme/modules/customer/composables/useGuestUser/commands/attachToCartCommand.ts index 93d93d71e..fd4489f54 100644 --- a/packages/theme/modules/customer/composables/useGuestUser/commands/attachToCartCommand.ts +++ b/packages/theme/modules/customer/composables/useGuestUser/commands/attachToCartCommand.ts @@ -1,11 +1,9 @@ -import type { useContext } from '@nuxtjs/composition-api'; +import { UseContextReturn } from '~/composables/types'; import { Logger } from '~/helpers/logger'; import { SetGuestEmailOnCartInput } from '~/modules/GraphQL/types'; -type Context = ReturnType; - export const attachToCartCommand = { - execute: async (context: Context, params): Promise => { + execute: async (context: UseContextReturn, params): Promise => { Logger.debug('[Magento]: Attach guest cart to user'); const emailOnCartInput: SetGuestEmailOnCartInput = { diff --git a/packages/theme/modules/customer/composables/useUserAddress/commands/createCustomerAddressCommand.ts b/packages/theme/modules/customer/composables/useUserAddress/commands/createCustomerAddressCommand.ts index b3178e381..6775ac279 100644 --- a/packages/theme/modules/customer/composables/useUserAddress/commands/createCustomerAddressCommand.ts +++ b/packages/theme/modules/customer/composables/useUserAddress/commands/createCustomerAddressCommand.ts @@ -1,10 +1,8 @@ -import type { useContext } from '@nuxtjs/composition-api'; +import { UseContextReturn } from '~/composables/types'; import { CustomerAddressInput } from '~/modules/GraphQL/types'; -type Context = ReturnType; - export const createCustomerAddressCommand = { - execute: async (context: Context, params: CustomerAddressInput) => { + execute: async (context: UseContextReturn, params: CustomerAddressInput) => { const { data } = await context.app.$vsf.$magento.api.createCustomerAddress(params); return data?.createCustomerAddress ?? {}; diff --git a/packages/theme/modules/customer/composables/useUserAddress/commands/deleteCustomerAddressCommand.ts b/packages/theme/modules/customer/composables/useUserAddress/commands/deleteCustomerAddressCommand.ts index e34c8363b..2417fee1d 100644 --- a/packages/theme/modules/customer/composables/useUserAddress/commands/deleteCustomerAddressCommand.ts +++ b/packages/theme/modules/customer/composables/useUserAddress/commands/deleteCustomerAddressCommand.ts @@ -1,10 +1,8 @@ -import type { useContext } from '@nuxtjs/composition-api'; +import { UseContextReturn } from '~/composables/types'; import { CustomerAddress } from '~/modules/GraphQL/types'; -type Context = ReturnType; - export const deleteCustomerAddressCommand = { - execute: async (context: Context, address: CustomerAddress) => { + execute: async (context: UseContextReturn, address: CustomerAddress) => { const { data } = await context.app.$vsf.$magento.api.deleteCustomerAddress(address.id); return data?.deleteCustomerAddress ?? {}; diff --git a/packages/theme/modules/customer/composables/useUserAddress/commands/updateCustomerAddressCommand.ts b/packages/theme/modules/customer/composables/useUserAddress/commands/updateCustomerAddressCommand.ts index f8b52f02c..4bf6fe42e 100644 --- a/packages/theme/modules/customer/composables/useUserAddress/commands/updateCustomerAddressCommand.ts +++ b/packages/theme/modules/customer/composables/useUserAddress/commands/updateCustomerAddressCommand.ts @@ -1,10 +1,8 @@ -import type { useContext } from '@nuxtjs/composition-api'; +import { UseContextReturn } from '~/composables/types'; import { CustomerAddressInput } from '~/modules/GraphQL/types'; -type Context = ReturnType; - export const updateCustomerAddressCommand = { - execute: async (context: Context, params: { + execute: async (context: UseContextReturn, params: { addressId: number; input: CustomerAddressInput; }) => { From 706cd60c230668c144ba2e3deed7c2b9ff3fe69c Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Thu, 26 May 2022 12:51:48 +0200 Subject: [PATCH 33/33] fix: types after merge --- .../theme/modules/wishlist/components/WishlistSidebar.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/theme/modules/wishlist/components/WishlistSidebar.vue b/packages/theme/modules/wishlist/components/WishlistSidebar.vue index 070613b29..6e355e707 100644 --- a/packages/theme/modules/wishlist/components/WishlistSidebar.vue +++ b/packages/theme/modules/wishlist/components/WishlistSidebar.vue @@ -217,8 +217,8 @@ export default defineComponent({ () => wishlistStore.wishlist?.items_count ?? 0, ); - const getAttributes = (product: ConfigurableProduct) => product?.product?.configurable_options || []; - const getBundles = (product: BundleProduct) => product?.product?.items?.map((b) => b.title).flat() || []; + const getAttributes = (product: WishlistItemInterface) => (product?.product as ConfigurableProduct)?.configurable_options || []; + const getBundles = (product: WishlistItemInterface) => (product?.product as BundleProduct)?.items?.map((b) => b.title).flat() || []; const getItemLink = (item: WishlistItemInterface) => localeRoute({ path: `/p/${item.product.sku}${productGetters.getSlug( item.product,