From 19eb3a1df292d9212805f07b118197e40af36114 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 08:40:00 +0200 Subject: [PATCH 01/24] chore: eslint composables and api-client properly There are now 2 tsconfigs: one (.eslint.json) that tells eslint which files to scan, and tsconfig.json which is related to building the library If you try to lint a file that's not part of any TS project, ESLint will complain that it needs to be part of some TS project - it can't be "exclude"d etc. But at the same time, I don't want to mess with the types distributed by the api-client package (ie. I want to lin .spec.ts files but I don't want them to appear in the library's dist). Hence the .eslint.tsconfig.json file was created --- .eslintignore | 3 +++ .eslintrc.js | 4 ++-- packages/api-client/tsconfig.eslint.json | 13 +++++++++++++ packages/composables/tsconfig.eslint.json | 13 +++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 packages/api-client/tsconfig.eslint.json create mode 100644 packages/composables/tsconfig.eslint.json diff --git a/.eslintignore b/.eslintignore index 7cbbadfda..fc6cc690f 100755 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,7 @@ **/node_modules/**/* **/lib/* packages/api-client/src/types/GraphQL.ts +packages/api-client/server +packages/composables/lib +packages/api-client/lib packages/theme/static/sw.js diff --git a/.eslintrc.js b/.eslintrc.js index 092e5d103..b9abf4456 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,8 +13,8 @@ module.exports = { parser: '@typescript-eslint/parser', project: [ resolve(__dirname, './tsconfig.json'), - resolve(__dirname, './packages/api-client/tsconfig.json'), - resolve(__dirname, './packages/composables/tsconfig.json'), + resolve(__dirname, './packages/api-client/tsconfig.eslint.json'), + resolve(__dirname, './packages/composables/tsconfig.eslint.json'), resolve(__dirname, './packages/theme/tsconfig.json'), resolve(__dirname, './packages/theme/tests/e2e/tsconfig.json'), ], diff --git a/packages/api-client/tsconfig.eslint.json b/packages/api-client/tsconfig.eslint.json new file mode 100644 index 000000000..b3c40a219 --- /dev/null +++ b/packages/api-client/tsconfig.eslint.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./lib", + "rootDir": "./src", + "baseUrl": "./", + "lib": [] + }, + "exclude": [ + "lib", + "node_modules" + ] +} diff --git a/packages/composables/tsconfig.eslint.json b/packages/composables/tsconfig.eslint.json new file mode 100644 index 000000000..b3c40a219 --- /dev/null +++ b/packages/composables/tsconfig.eslint.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./lib", + "rootDir": "./src", + "baseUrl": "./", + "lib": [] + }, + "exclude": [ + "lib", + "node_modules" + ] +} From e4f360e18660f46e8865d89ae238e5ab1d8f8f6f Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 08:49:11 +0200 Subject: [PATCH 02/24] chore: autofix composables and api-client this is after these packages started being linted properly, so new errors appearred --- .../api/storeConfig/storeConfig.spec.ts | 6 +- packages/api-client/babel.config.js | 8 +- packages/api-client/jest.config.js | 2 +- .../__tests__/getters/productHelpers.spec.ts | 197 +++++++++--------- packages/composables/babel.config.js | 8 +- packages/composables/jest.config.js | 2 +- packages/composables/nuxt/plugin.js | 22 +- 7 files changed, 124 insertions(+), 121 deletions(-) diff --git a/packages/api-client/__tests__/api/storeConfig/storeConfig.spec.ts b/packages/api-client/__tests__/api/storeConfig/storeConfig.spec.ts index 1207868f7..0b17a6bc2 100644 --- a/packages/api-client/__tests__/api/storeConfig/storeConfig.spec.ts +++ b/packages/api-client/__tests__/api/storeConfig/storeConfig.spec.ts @@ -1,5 +1,5 @@ import request from '../../setup/request'; -import {STORE_CONFIG_MOCK_RESP} from './../../mockData/api/storeConfig' +import { STORE_CONFIG_MOCK_RESP } from '../../mockData/api/storeConfig'; describe('[Magento-API-Client] storeConfig', () => { it('Fetching the storeConfig', async () => { @@ -60,8 +60,8 @@ describe('[Magento-API-Client] storeConfig', () => { welcome } } - ` - }) + `, + }), }); const { data } = await res.json(); diff --git a/packages/api-client/babel.config.js b/packages/api-client/babel.config.js index d3540f51b..ed8b326b9 100644 --- a/packages/api-client/babel.config.js +++ b/packages/api-client/babel.config.js @@ -2,8 +2,8 @@ module.exports = { presets: [ ['@babel/preset-env', { targets: { - node: 'current' - } - }] - ] + node: 'current', + }, + }], + ], }; diff --git a/packages/api-client/jest.config.js b/packages/api-client/jest.config.js index 180a0a0ec..87c8e4e24 100644 --- a/packages/api-client/jest.config.js +++ b/packages/api-client/jest.config.js @@ -23,7 +23,7 @@ module.exports = { testEnvironment: 'jsdom', transform: { '^.+\\.(m)js$': 'babel-jest', - '^.+\\.ts$': 'ts-jest' + '^.+\\.ts$': 'ts-jest', }, transformIgnorePatterns: [ 'node_modules', diff --git a/packages/composables/__tests__/getters/productHelpers.spec.ts b/packages/composables/__tests__/getters/productHelpers.spec.ts index b4233c7cd..f1abe998c 100644 --- a/packages/composables/__tests__/getters/productHelpers.spec.ts +++ b/packages/composables/__tests__/getters/productHelpers.spec.ts @@ -26,118 +26,119 @@ import { } from '../../src/getters/productGetters'; const product = { - "options_container": null, - "meta_description": null, - "meta_keyword": null, - "meta_title": null, - "description": { - "html": "

The sporty Joust Duffle Bag can't be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places to go.

\n

", - "__typename": "ComplexTextValue" + options_container: null, + meta_description: null, + meta_keyword: null, + meta_title: null, + description: { + html: '

The sporty Joust Duffle Bag can\'t be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it\'s ideal for athletes with places to go.

\n

', + __typename: 'ComplexTextValue', }, - "short_description": { "html": "", "__typename": "ComplexTextValue" }, - "uid": "MQ==", - "__typename": "SimpleProduct", - "sku": "24-MB01", - "name": "Joust Duffle Bag", - "stock_status": "IN_STOCK", - "only_x_left_in_stock": null, - "rating_summary": 50, - "thumbnail": { - "url": "https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg", - "position": null, - "disabled": null, - "label": "Joust Duffle Bag", - "__typename": "ProductImage" + short_description: { html: '', __typename: 'ComplexTextValue' }, + uid: 'MQ==', + __typename: 'SimpleProduct', + sku: '24-MB01', + name: 'Joust Duffle Bag', + stock_status: 'IN_STOCK', + only_x_left_in_stock: null, + rating_summary: 50, + thumbnail: { + url: 'https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg', + position: null, + disabled: null, + label: 'Joust Duffle Bag', + __typename: 'ProductImage', }, - "price_range": { - "maximum_price": { - "final_price": { - "currency": "USD", - "value": 34, - "__typename": "Money" + price_range: { + maximum_price: { + final_price: { + currency: 'USD', + value: 34, + __typename: 'Money', }, - "regular_price": { "currency": "USD", "value": 34, "__typename": "Money" }, - "__typename": "ProductPrice" + regular_price: { currency: 'USD', value: 34, __typename: 'Money' }, + __typename: 'ProductPrice', }, - "minimum_price": { - "final_price": { - "currency": "USD", - "value": 34, - "__typename": "Money" + minimum_price: { + final_price: { + currency: 'USD', + value: 34, + __typename: 'Money', }, - "regular_price": { "currency": "USD", "value": 34, "__typename": "Money" }, - "__typename": "ProductPrice" + regular_price: { currency: 'USD', value: 34, __typename: 'Money' }, + __typename: 'ProductPrice', }, - "__typename": "PriceRange" + __typename: 'PriceRange', }, - "url_key": "joust-duffle-bag", - "url_rewrites": [{ - "url": "joust-duffle-bag.html", - "__typename": "UrlRewrite" + url_key: 'joust-duffle-bag', + url_rewrites: [{ + url: 'joust-duffle-bag.html', + __typename: 'UrlRewrite', }, { - "url": "gear/joust-duffle-bag.html", - "__typename": "UrlRewrite" - }, { "url": "gear/bags/joust-duffle-bag.html", "__typename": "UrlRewrite" }], - "categories": [{ - "uid": "Mw==", - "name": "Gear", - "url_suffix": ".html", - "url_path": "gear", - "breadcrumbs": null, - "__typename": "CategoryTree" + url: 'gear/joust-duffle-bag.html', + __typename: 'UrlRewrite', + }, { url: 'gear/bags/joust-duffle-bag.html', __typename: 'UrlRewrite' }], + categories: [{ + uid: 'Mw==', + name: 'Gear', + url_suffix: '.html', + url_path: 'gear', + breadcrumbs: null, + __typename: 'CategoryTree', }, { - "uid": "NA==", - "name": "Bags", - "url_suffix": ".html", - "url_path": "gear/bags", - "breadcrumbs": [{ - "category_name": "Gear", - "category_url_path": "gear", - "__typename": "Breadcrumb" + uid: 'NA==', + name: 'Bags', + url_suffix: '.html', + url_path: 'gear/bags', + breadcrumbs: [{ + category_name: 'Gear', + category_url_path: 'gear', + __typename: 'Breadcrumb', }], - "__typename": "CategoryTree" + __typename: 'CategoryTree', }], - "review_count": 2, - "reviews": { - "items": [{ - "average_rating": 60, - "ratings_breakdown": [{ - "name": "Rating", - "value": "3", - "__typename": "ProductReviewRating" + review_count: 2, + reviews: { + items: [{ + average_rating: 60, + ratings_breakdown: [{ + name: 'Rating', + value: '3', + __typename: 'ProductReviewRating', }], - "__typename": "ProductReview" + __typename: 'ProductReview', }, { - "average_rating": 40, - "ratings_breakdown": [{ - "name": "Rating", - "value": "2", - "__typename": "ProductReviewRating" + average_rating: 40, + ratings_breakdown: [{ + name: 'Rating', + value: '2', + __typename: 'ProductReviewRating', }], - "__typename": "ProductReview" - }], "__typename": "ProductReviews" + __typename: 'ProductReview', + }], + __typename: 'ProductReviews', }, - "small_image": { - "url": "https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg", - "position": null, - "disabled": null, - "label": "Joust Duffle Bag", - "__typename": "ProductImage" + small_image: { + url: 'https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg', + position: null, + disabled: null, + label: 'Joust Duffle Bag', + __typename: 'ProductImage', }, - "image": { - "url": "https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg", - "position": null, - "disabled": null, - "label": "Joust Duffle Bag", - "__typename": "ProductImage" + image: { + url: 'https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg', + position: null, + disabled: null, + label: 'Joust Duffle Bag', + __typename: 'ProductImage', }, - "media_gallery": [{ - "url": "https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg", - "position": 1, - "disabled": false, - "label": "Image", - "__typename": "ProductImage" - }] + media_gallery: [{ + url: 'https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg', + position: 1, + disabled: false, + label: 'Image', + __typename: 'ProductImage', + }], } as any; describe('[magento-getters] product getters', () => { @@ -165,8 +166,8 @@ describe('[magento-getters] product getters', () => { { small: 'https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg', normal: 'https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg', - big: 'https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg' - } + big: 'https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg', + }, ]); }); @@ -178,7 +179,7 @@ describe('[magento-getters] product getters', () => { it('returns product categories', () => { expect(getCategoryIds(product)).toEqual([ 'Mw==', - 'NA==' + 'NA==', ]); }); diff --git a/packages/composables/babel.config.js b/packages/composables/babel.config.js index d3540f51b..ed8b326b9 100644 --- a/packages/composables/babel.config.js +++ b/packages/composables/babel.config.js @@ -2,8 +2,8 @@ module.exports = { presets: [ ['@babel/preset-env', { targets: { - node: 'current' - } - }] - ] + node: 'current', + }, + }], + ], }; diff --git a/packages/composables/jest.config.js b/packages/composables/jest.config.js index 65abac5c8..3e0bbf46f 100644 --- a/packages/composables/jest.config.js +++ b/packages/composables/jest.config.js @@ -22,7 +22,7 @@ module.exports = { testEnvironment: 'jsdom', transform: { '^.+\\.(m)js$': 'babel-jest', - '^.+\\.ts$': 'ts-jest' + '^.+\\.ts$': 'ts-jest', }, transformIgnorePatterns: [ 'node_modules', diff --git a/packages/composables/nuxt/plugin.js b/packages/composables/nuxt/plugin.js index d3b40aa7f..c9258b253 100644 --- a/packages/composables/nuxt/plugin.js +++ b/packages/composables/nuxt/plugin.js @@ -1,4 +1,4 @@ -import { integrationPlugin } from '@vue-storefront/magento-theme/helpers/integrationPlugin' +import { integrationPlugin } from '@vue-storefront/magento-theme/helpers/integrationPlugin'; import { mapConfigToSetupObject } from '@vue-storefront/magento/nuxt/helpers'; import defaultConfig from '@vue-storefront/magento/nuxt/defaultConfig'; import cookie from '@vue-storefront/magento/nuxt/cookie'; @@ -6,7 +6,9 @@ import cookie from '@vue-storefront/magento/nuxt/cookie'; const moduleOptions = JSON.parse('<%= JSON.stringify(options) %>'); // TODO should be moved to THEME and expose consistent cookie management API -export default integrationPlugin(({ app, res, req, integration }) => { +export default integrationPlugin(({ + app, res, req, integration, +}) => { const cartCookieName = moduleOptions.cookies?.cartCookieName || defaultConfig.cookies.cartCookieName; const customerCookieName = moduleOptions.cookies?.customerCookieName || defaultConfig.cookies.customerCookieName; const storeCookieName = moduleOptions.cookies?.storeCookieName || defaultConfig.cookies.storeCookieName; @@ -22,34 +24,34 @@ export default integrationPlugin(({ app, res, req, integration }) => { const getCartId = () => getCookies(cartCookieName); - const setCartId = (id) => !id ? removeCookie(cartCookieName) : setCookie(cartCookieName, id); + const setCartId = (id) => (!id ? removeCookie(cartCookieName) : setCookie(cartCookieName, id)); const getCustomerToken = () => getCookies(customerCookieName); - const setCustomerToken = (token) => !token ? removeCookie(customerCookieName) : setCookie(customerCookieName, token); + const setCustomerToken = (token) => (!token ? removeCookie(customerCookieName) : setCookie(customerCookieName, token)); const getStore = () => getCookies(storeCookieName); - const setStore = (id) => !id ? removeCookie(storeCookieName) : setCookie(storeCookieName, id); + const setStore = (id) => (!id ? removeCookie(storeCookieName) : setCookie(storeCookieName, id)); const getCurrency = () => getCookies(currencyCookieName); - const setCurrency = (id) => !id ? removeCookie(currencyCookieName) : setCookie(currencyCookieName, id); + const setCurrency = (id) => (!id ? removeCookie(currencyCookieName) : setCookie(currencyCookieName, id)); const getLocale = () => getCookies(localeCookieName); - const setLocale = (id) => !id ? removeCookie(localeCookieName) : setCookie(localeCookieName, id); + const setLocale = (id) => (!id ? removeCookie(localeCookieName) : setCookie(localeCookieName, id)); const getCountry = () => getCookies(countryCookieName); - const setCountry = id => !id ? removeCookie(countryCookieName) : setCookie(countryCookieName, id); + const setCountry = (id) => (!id ? removeCookie(countryCookieName) : setCookie(countryCookieName, id)); const settings = mapConfigToSetupObject({ moduleOptions, app, additionalProperties: { state: { - //Cart + // Cart getCartId, setCartId, // Customer @@ -65,7 +67,7 @@ export default integrationPlugin(({ app, res, req, integration }) => { getCountry, setCountry, }, - } + }, }); integration.configure('magento', settings); From bcf8662b6c9e53015c9076dc554f79b79d0ac638 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 08:50:52 +0200 Subject: [PATCH 03/24] refactor: simplify eslint tsconfig --- packages/api-client/tsconfig.eslint.json | 6 ------ packages/composables/tsconfig.eslint.json | 6 ------ 2 files changed, 12 deletions(-) diff --git a/packages/api-client/tsconfig.eslint.json b/packages/api-client/tsconfig.eslint.json index b3c40a219..a47730729 100644 --- a/packages/api-client/tsconfig.eslint.json +++ b/packages/api-client/tsconfig.eslint.json @@ -1,11 +1,5 @@ { "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "./lib", - "rootDir": "./src", - "baseUrl": "./", - "lib": [] - }, "exclude": [ "lib", "node_modules" diff --git a/packages/composables/tsconfig.eslint.json b/packages/composables/tsconfig.eslint.json index b3c40a219..a47730729 100644 --- a/packages/composables/tsconfig.eslint.json +++ b/packages/composables/tsconfig.eslint.json @@ -1,11 +1,5 @@ { "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "./lib", - "rootDir": "./src", - "baseUrl": "./", - "lib": [] - }, "exclude": [ "lib", "node_modules" From 09a6fda4550c2602db32b4235d47538ab9ae198f Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 08:53:51 +0200 Subject: [PATCH 04/24] chore: remove unused from composables/productHelpers.spec.ts --- .../__tests__/getters/productHelpers.spec.ts | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/packages/composables/__tests__/getters/productHelpers.spec.ts b/packages/composables/__tests__/getters/productHelpers.spec.ts index f1abe998c..2282cf731 100644 --- a/packages/composables/__tests__/getters/productHelpers.spec.ts +++ b/packages/composables/__tests__/getters/productHelpers.spec.ts @@ -1,28 +1,13 @@ import { getAttributes, - getAverageRating, - getBreadcrumbs, - getCategory, getCategoryIds, getCoverImage, - getDescription, getFiltered, - getFormattedPrice, getGallery, getId, getName, getPrice, - getProductRelatedProduct, - getProductSku, - getProductThumbnailImage, - getProductUpsellProduct, - getShortDescription, getSlug, - getTotalReviews, - getTypeId, - getSwatchData, - getGroupedProducts, - getBundleProducts, } from '../../src/getters/productGetters'; const product = { From a546dcd1ab579c8a2622c4a2cb2403d48ebbaac0 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 09:02:50 +0200 Subject: [PATCH 05/24] chore: fake incomplete product --- .../composables/__tests__/getters/productHelpers.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/composables/__tests__/getters/productHelpers.spec.ts b/packages/composables/__tests__/getters/productHelpers.spec.ts index 2282cf731..d09b187f1 100644 --- a/packages/composables/__tests__/getters/productHelpers.spec.ts +++ b/packages/composables/__tests__/getters/productHelpers.spec.ts @@ -1,3 +1,4 @@ +import { Product } from '@vue-storefront/magento-api'; import { getAttributes, getCategoryIds, @@ -124,7 +125,7 @@ const product = { label: 'Image', __typename: 'ProductImage', }], -} as any; +} as unknown as Product; describe('[magento-getters] product getters', () => { it('returns default values', () => { @@ -157,7 +158,8 @@ describe('[magento-getters] product getters', () => { }); it('returns cover image', () => { - expect(getCoverImage({ images: [] } as any)).toEqual(null); + // @ts-expect-error intentional lack of image + expect(getCoverImage({})).toEqual(null); expect(getCoverImage(product)).toEqual('https://m2.caravelx.com/media/catalog/product/cache/746ba992681b73af7e339699b3e0caf7/m/b/mb01-blue-0.jpg'); }); From ab9a0e5b2191c4a5a12c340034aa67a71f47f9b5 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 09:19:11 +0200 Subject: [PATCH 06/24] chore: remove empty index file --- packages/api-client/__tests__/setup/index.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 packages/api-client/__tests__/setup/index.ts diff --git a/packages/api-client/__tests__/setup/index.ts b/packages/api-client/__tests__/setup/index.ts deleted file mode 100644 index e69de29bb..000000000 From ae40e1d6713bb682e36de2782fc4f461fc0c1ef6 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 09:19:50 +0200 Subject: [PATCH 07/24] chore: remove unused gql --- packages/api-client/src/api/wishlist/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/api-client/src/api/wishlist/index.ts b/packages/api-client/src/api/wishlist/index.ts index 86c52a708..31e24c14a 100644 --- a/packages/api-client/src/api/wishlist/index.ts +++ b/packages/api-client/src/api/wishlist/index.ts @@ -1,6 +1,5 @@ import { ApolloQueryResult } from '@apollo/client/core'; import { CustomQuery } from '@vue-storefront/core'; -import gql from 'graphql-tag'; import { WishlistQuery, WishlistQueryVariables, From f64306f6f0bb2e680ae27b5df3c0dbf8762c5fd3 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 09:54:17 +0200 Subject: [PATCH 08/24] chore: fix eslint errors in useWishlist --- .../composables/src/composables/useWishlist/index.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/composables/src/composables/useWishlist/index.ts b/packages/composables/src/composables/useWishlist/index.ts index a238636aa..182be3a56 100644 --- a/packages/composables/src/composables/useWishlist/index.ts +++ b/packages/composables/src/composables/useWishlist/index.ts @@ -121,10 +121,7 @@ const factoryParams: UseWishlistFactoryParams = { } }, removeItem: async (context, params) => { - const { - product, - currentWishlist, - } = params; + const { currentWishlist } = params; Logger.debug('[Magento Storefront]: useWishlist.removeItem params->', params); const itemOnWishlist = findItemOnWishlist(currentWishlist, params.product); @@ -137,8 +134,8 @@ const factoryParams: UseWishlistFactoryParams = { return data?.removeProductsFromWishlist?.wishlist ?? {}; }, - clear: async ({ currentWishlist }) => ({}), - isInWishlist: (context, params) => { + clear: () => (Promise.resolve()), + isInWishlist: (_context, params) => { const { currentWishlist, product, From 7ef94f2b54bdcd2de5f047f85027cb0feae9a881 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 09:56:25 +0200 Subject: [PATCH 09/24] chore: disable max-len eslint warning for cat search (no good formatting available) --- packages/composables/src/composables/useCategorySearch/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/composables/src/composables/useCategorySearch/index.ts b/packages/composables/src/composables/useCategorySearch/index.ts index 29c6eae27..8c24ad440 100644 --- a/packages/composables/src/composables/useCategorySearch/index.ts +++ b/packages/composables/src/composables/useCategorySearch/index.ts @@ -20,6 +20,7 @@ const factoryParams: UseCategorySearchFactory UseCategorySearch = useCategorySearchFactory(factoryParams); export default useCategorySearch; From 5c433a9b9797c6a061df5b94739043ff8722a6aa Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 10:05:02 +0200 Subject: [PATCH 10/24] chore: fix misc eslint errors --- packages/composables/nuxt/index.js | 2 +- packages/composables/src/composables/useCurrency/index.ts | 2 +- .../composables/src/composables/useExternalCheckout/index.ts | 1 + packages/composables/src/composables/useReview/index.ts | 2 +- packages/composables/src/factories/useForgotPasswordFactory.ts | 1 - packages/composables/src/factories/useStoreFactory.ts | 1 + 6 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/composables/nuxt/index.js b/packages/composables/nuxt/index.js index 57c828263..aaed24be7 100644 --- a/packages/composables/nuxt/index.js +++ b/packages/composables/nuxt/index.js @@ -11,7 +11,7 @@ const getMissingFields = (options) => [ 'locales', ].filter((o) => options[o] === undefined); -export default function (moduleOptions) { +export default function composablesModule(moduleOptions) { const options = isNuxtI18nUsed(moduleOptions) ? { ...moduleOptions, diff --git a/packages/composables/src/composables/useCurrency/index.ts b/packages/composables/src/composables/useCurrency/index.ts index 008da2dbd..e736b0e7f 100644 --- a/packages/composables/src/composables/useCurrency/index.ts +++ b/packages/composables/src/composables/useCurrency/index.ts @@ -7,7 +7,7 @@ import { useCurrencyFactory, UseCurrencyFactoryParams } from '../../factories/us import { UseCurrency } from '../../types/composables'; const factoryParams: UseCurrencyFactoryParams = { - load: async (context: Context, params): Promise => { + load: async (context: Context, _params): Promise => { const { data } = await context.$magento.api.currency(); return data.currency || {}; diff --git a/packages/composables/src/composables/useExternalCheckout/index.ts b/packages/composables/src/composables/useExternalCheckout/index.ts index b42f4ca86..e655aa072 100644 --- a/packages/composables/src/composables/useExternalCheckout/index.ts +++ b/packages/composables/src/composables/useExternalCheckout/index.ts @@ -12,6 +12,7 @@ const factoryParams: UseExternalCheckoutFactoryParams = { cart: useCart(), }; }, + // eslint-disable-next-line @typescript-eslint/require-await initializeCheckout: async (context: Context, params) => { Logger.debug('[Magento]: Initialize external checkout', { params }); diff --git a/packages/composables/src/composables/useReview/index.ts b/packages/composables/src/composables/useReview/index.ts index ee2b930c3..a768922ca 100644 --- a/packages/composables/src/composables/useReview/index.ts +++ b/packages/composables/src/composables/useReview/index.ts @@ -46,7 +46,7 @@ ProductReviewRatingMetadata> = { return data?.createProductReview?.review ?? {}; }, - loadReviewMetadata: async (context: Context, params) => { + loadReviewMetadata: async (context: Context, _params) => { Logger.debug('[Magento] load review metadata'); const { data } = await context.$magento.api.productReviewRatingsMetadata(); diff --git a/packages/composables/src/factories/useForgotPasswordFactory.ts b/packages/composables/src/factories/useForgotPasswordFactory.ts index d8414b60f..a0fc0173f 100644 --- a/packages/composables/src/factories/useForgotPasswordFactory.ts +++ b/packages/composables/src/factories/useForgotPasswordFactory.ts @@ -6,7 +6,6 @@ import { ComposableFunctionArgs, configureFactoryParams, Context, - CustomQuery, FactoryParams, Logger, sharedRef, diff --git a/packages/composables/src/factories/useStoreFactory.ts b/packages/composables/src/factories/useStoreFactory.ts index 76f193a22..8a5103d3a 100644 --- a/packages/composables/src/factories/useStoreFactory.ts +++ b/packages/composables/src/factories/useStoreFactory.ts @@ -39,6 +39,7 @@ export function useStoreFactory): Promise => { loading.value = true; try { From 1b741cc695904f976fa445196508fda18b709ad2 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 10:24:10 +0200 Subject: [PATCH 11/24] chore: fix eslint errors in productGetters --- packages/composables/src/getters/productGetters.ts | 4 ++-- packages/composables/src/getters/reviewGetters.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/composables/src/getters/productGetters.ts b/packages/composables/src/getters/productGetters.ts index 630016e1f..69a2d4bca 100644 --- a/packages/composables/src/getters/productGetters.ts +++ b/packages/composables/src/getters/productGetters.ts @@ -105,7 +105,7 @@ export const getProductThumbnailImage = (product: Product): string => { return product.thumbnail.url; }; -export const getFiltered = (products: Product[], filters: ProductVariantFilters | any = {}): Product[] => { +export const getFiltered = (products: Product[], _filters: ProductVariantFilters | any = {}): Product[] => { if (!products) { return []; } @@ -213,7 +213,7 @@ export const getFormattedPrice = (price: number) => { }).format(price); }; -export const getBreadcrumbs = (product: any, category?: Category): AgnosticBreadcrumb[] => { +export const getBreadcrumbs = (product: Product, category?: Category): AgnosticBreadcrumb[] => { let breadcrumbs = []; if (!product) { diff --git a/packages/composables/src/getters/reviewGetters.ts b/packages/composables/src/getters/reviewGetters.ts index 2bf2ca85c..348e3d616 100644 --- a/packages/composables/src/getters/reviewGetters.ts +++ b/packages/composables/src/getters/reviewGetters.ts @@ -27,7 +27,7 @@ export const getReviewDate = (item: ProductReview): string => item.created_at; export const getTotalReviews = (review: ProductReviews): number => review?.review_count || 0; -export const getAverageRating = (review): number => (review?.reviews?.items?.reduce((acc, curr) => Number.parseInt(`${acc}`, 10) + getReviewRating(curr), 0)) / (review?.review_count || 1) || 0; +export const getAverageRating = (review: ProductReviews): number => (review?.reviews?.items?.reduce((acc, curr) => Number.parseInt(`${acc}`, 10) + getReviewRating(curr as ProductReview), 0) ?? 0) / (review?.review_count || 1) || 0; export const getRatesCount = (_review: ProductReviews): AgnosticRateCount[] => []; From 605c8b98b7feff850e15052c1b112a275bc91e93 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 10:56:41 +0200 Subject: [PATCH 12/24] refactor: improve wishlistGetters typing --- .../src/getters/wishlistGetters.ts | 55 ++++++++----------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/packages/composables/src/getters/wishlistGetters.ts b/packages/composables/src/getters/wishlistGetters.ts index 97763ad9a..f08b91371 100644 --- a/packages/composables/src/getters/wishlistGetters.ts +++ b/packages/composables/src/getters/wishlistGetters.ts @@ -7,19 +7,19 @@ import { AgnosticTotals, AgnosticPagination, } from '@vue-storefront/core'; import { - Wishlist, WishlistQuery, + Wishlist, WishlistItemInterface, } from '@vue-storefront/magento-api'; -export type WishlistProduct = WishlistQuery['customer']['wishlists'][0]['items_v2']['items'][0] & { variant: any }; +export type WishlistProduct = WishlistItemInterface; // 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; @@ -38,22 +38,16 @@ 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 -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 total: acc.total + getItemPrice(curr).special, - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands subtotal: acc.subtotal + getItemPrice(curr).regular, }), ({ total: 0, subtotal: 0 })); } @@ -63,14 +57,11 @@ export const getTotals = (wishlist): AgnosticTotals => { }), ({ 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)); -// 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, @@ -81,22 +72,24 @@ const getPagination = (wishlistData: Wishlist): AgnosticPagination => ({ }); const getProducts = (wishlistData: Wishlist[] | Wishlist): { - product: WishlistProduct; + product: WishlistItemInterface; quantity: number; added_at: string; }[] => { if (!wishlistData || (Array.isArray(wishlistData) && wishlistData.length === 0)) { return []; } - - const reducer = (acc, curr) => [...acc, ...curr?.items_v2?.items.map((item) => ({ + const reducer = ( + acc, + curr: Wishlist, + ) => [...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) => ({ product: item.product, quantity: item.quantity, added_at: item.added_at, @@ -104,19 +97,19 @@ const getProducts = (wishlistData: Wishlist[] | Wishlist): { }); return Array.isArray(wishlistData) - ? wishlistData.reduce((acc, curr) => reducer(acc, curr), []) - : wishlistData?.items_v2?.items.map((e) => mapper(e)); + ? wishlistData.reduce((accumulator, element) => reducer(accumulator, element), []) + : wishlistData?.items_v2?.items.map((element) => mapper(element)); }; -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; getProducts(wishlistData): { - product: WishlistProduct; + product: WishlistItemInterface; quantity: number; added_at: string; }[]; From 08f5712945aa850368a1d80c28c948d0f0995c9d Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 11:00:58 +0200 Subject: [PATCH 13/24] refactor: improve categorytree typing --- packages/composables/src/getters/categoryGetters.ts | 8 ++++---- packages/composables/src/getters/productGetters.ts | 6 +++--- packages/composables/src/helpers/buildCategoryTree.ts | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/composables/src/getters/categoryGetters.ts b/packages/composables/src/getters/categoryGetters.ts index 4298c4c6e..8d95164bf 100644 --- a/packages/composables/src/getters/categoryGetters.ts +++ b/packages/composables/src/getters/categoryGetters.ts @@ -2,11 +2,11 @@ * @deprecated since version 1.0.0 */ import { CategoryGetters, AgnosticCategoryTree, AgnosticBreadcrumb } from '@vue-storefront/core'; -import { Category } from '@vue-storefront/magento-api'; +import { CategoryTree } from '@vue-storefront/magento-api'; import { buildCategoryTree } from '../helpers/buildCategoryTree'; // eslint-disable-next-line @typescript-eslint/no-unused-vars -export const getTree = (category: Category): AgnosticCategoryTree | null => { +export const getTree = (category: CategoryTree): AgnosticCategoryTree | null => { if (!category) { return null; } @@ -14,7 +14,7 @@ export const getTree = (category: Category): AgnosticCategoryTree | null => { }; export const getCategoryTree = ( - category: Category, + category: CategoryTree, currentCategory: string = '', withProducts = false, ): AgnosticCategoryTree | null => ( @@ -45,7 +45,7 @@ export const getCategoryBreadcrumbs = (category: any): AgnosticBreadcrumb[] => { return breadcrumbs; }; -const categoryGetters: CategoryGetters = { +const categoryGetters: CategoryGetters = { getTree, getBreadcrumbs: getCategoryBreadcrumbs, getCategoryTree, diff --git a/packages/composables/src/getters/productGetters.ts b/packages/composables/src/getters/productGetters.ts index 69a2d4bca..b158918c1 100644 --- a/packages/composables/src/getters/productGetters.ts +++ b/packages/composables/src/getters/productGetters.ts @@ -10,7 +10,7 @@ import { } from '@vue-storefront/core'; import { BundleProduct, - Category, GroupedProduct, + Category, CategoryTree, GroupedProduct, Product, } from '@vue-storefront/magento-api'; @@ -213,7 +213,7 @@ export const getFormattedPrice = (price: number) => { }).format(price); }; -export const getBreadcrumbs = (product: Product, category?: Category): AgnosticBreadcrumb[] => { +export const getBreadcrumbs = (product: Product, category?: CategoryTree): AgnosticBreadcrumb[] => { let breadcrumbs = []; if (!product) { @@ -221,7 +221,7 @@ export const getBreadcrumbs = (product: Product, category?: Category): AgnosticB } if (category) { - breadcrumbs = categoryGetters.getBreadcrumbs(category) as AgnosticBreadcrumb[]; + breadcrumbs = categoryGetters.getBreadcrumbs(category); } breadcrumbs.push({ diff --git a/packages/composables/src/helpers/buildCategoryTree.ts b/packages/composables/src/helpers/buildCategoryTree.ts index 272b5556a..1c67c8b79 100644 --- a/packages/composables/src/helpers/buildCategoryTree.ts +++ b/packages/composables/src/helpers/buildCategoryTree.ts @@ -2,9 +2,10 @@ * @deprecated since version 1.0.0 */ import { AgnosticCategoryTree } from '@vue-storefront/core'; +import { CategoryTree } from '@vue-storefront/magento-api'; import { htmlDecode } from './htmlDecoder'; -export const buildCategoryTree = (rootCategory: any, currentCategory: string, withProducts = false): AgnosticCategoryTree => { +export const buildCategoryTree = (rootCategory: CategoryTree, currentCategory: string, withProducts = false): AgnosticCategoryTree => { const hasChildren = Array.isArray(rootCategory.children) && rootCategory.children.length > 0; const isCurrent = rootCategory.uid === currentCategory; const label = htmlDecode(rootCategory.name); From b6acd5bb5d55d91af543663baf216ea533344ac9 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 11:06:21 +0200 Subject: [PATCH 14/24] refactor: orderGetters typings --- .../composables/src/getters/orderGetters.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/composables/src/getters/orderGetters.ts b/packages/composables/src/getters/orderGetters.ts index 6512be9ec..7ab983ebb 100644 --- a/packages/composables/src/getters/orderGetters.ts +++ b/packages/composables/src/getters/orderGetters.ts @@ -2,24 +2,25 @@ * @deprecated since version 1.0.0 */ import { AgnosticPagination } from '@vue-storefront/core'; +import { CustomerOrder, OrderItemInterface } from '@vue-storefront/magento-api'; -export const getDate = (order: any): string => new Date(order?.created_at).toLocaleDateString() || ''; +export const getDate = (order: CustomerOrder): string => new Date(order?.created_at).toLocaleDateString() || ''; -export const getId = (order: any): string => String(Number.parseInt(order?.order_number, 10) || Math.floor(Math.random() * 100)); +export const getId = (order: CustomerOrder): string => String(Number.parseInt(order?.order_number, 10) || Math.floor(Math.random() * 100)); -export const getStatus = (order: any): string => order?.status || 'Failed'; +export const getStatus = (order: CustomerOrder): string => order?.status || 'Failed'; -export const getPrice = (order: any): number | null => order?.grand_total || 0; +export const getPrice = (order: CustomerOrder): number | null => order?.grand_total || 0; -export const getItems = (order: any): any[] => order?.items || []; +export const getItems = (order: CustomerOrder): any[] => order?.items || []; -export const getItemSku = (item: any): string => item?.product_sku || 0; +export const getItemSku = (item: OrderItemInterface): string => item?.product_sku || ''; -export const getItemName = (item: any): string => item?.product_name || 0; +export const getItemName = (item: OrderItemInterface): string => item?.product_name || ''; -export const getItemQty = (item: any): number => item?.quantity_ordered || 0; +export const getItemQty = (item: OrderItemInterface): number => item?.quantity_ordered || 0; -export const getItemPrice = (item: any): number => item?.product_sale_price?.value || 0; +export const getItemPrice = (item: OrderItemInterface): number => item?.product_sale_price?.value || 0; export const getFormattedPrice = (price: number) => String(price); From 6533a414f97baa844b17d1ec6270b16a4c55a4d9 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 11:07:31 +0200 Subject: [PATCH 15/24] chore: fix facetGetters type issue --- packages/composables/src/getters/facetGetters.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/composables/src/getters/facetGetters.ts b/packages/composables/src/getters/facetGetters.ts index 59192e0df..7353e45ef 100644 --- a/packages/composables/src/getters/facetGetters.ts +++ b/packages/composables/src/getters/facetGetters.ts @@ -24,7 +24,7 @@ import { // eslint-disable-next-line @typescript-eslint/no-unused-vars const getAll = (searchData: SearchData, criteria?: string[]): AgnosticFacet[] => buildFacets(searchData, reduceForFacets, criteria); -const getGrouped = (searchData, criteria?: string[]): AgnosticGroupedFacet[] => buildFacets(searchData, reduceForGroupedFacets, criteria) +const getGrouped = (searchData: SearchData, criteria?: string[]): AgnosticGroupedFacet[] => buildFacets(searchData, reduceForGroupedFacets, criteria) ?.filter((facet) => facet.options && facet.options.length > 0); // eslint-disable-next-line @typescript-eslint/no-unused-vars From de253a9428f09e2e17278d469bbf5ecd79f5211f Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 11:16:51 +0200 Subject: [PATCH 16/24] refactor: fix usewishlist type issues --- .../composables/src/factories/useWishlistFactory.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/composables/src/factories/useWishlistFactory.ts b/packages/composables/src/factories/useWishlistFactory.ts index 2bf155c17..81f053679 100644 --- a/packages/composables/src/factories/useWishlistFactory.ts +++ b/packages/composables/src/factories/useWishlistFactory.ts @@ -12,6 +12,7 @@ import { ComposableFunctionArgs, PlatformApi, } from '@vue-storefront/core'; +import { Wishlist } from '@vue-storefront/magento-api'; import { UseWishlist, UseWishlistErrors } from '../types/composables'; export interface UseWishlistFactoryParams( factoryParams: UseWishlistFactoryParams, ) => { - const calculateWishlistTotal = (wishlists) => wishlists.reduce((prev, next) => (prev?.items_count ?? 0) + (next?.items_count ?? 0), 0); + const calculateWishlistTotal = (wishlists: Wishlist[]) => wishlists.reduce((prev, next) => prev + (next?.items_count ?? 0), 0); const useWishlist = (ssrKey = 'useWishlistFactory'): UseWishlist => { const loading: Ref = sharedRef(false, `useWishlist-loading-${ssrKey}`); @@ -135,9 +136,9 @@ export const useWishlistFactory = { Logger.debug(`useWishlist/${ssrKey}/loadItemsCount`); try { - const loadedWishlist = await _factoryParams.loadItemsCount(params); - itemsCount.value = calculateWishlistTotal(loadedWishlist); + const loadedWishlist : WISHLIST = await _factoryParams.loadItemsCount(params); + itemsCount.value = calculateWishlistTotal([loadedWishlist]); error.value.loadItemsCount = null; } catch (err) { error.value.loadItemsCount = err; From 6ee4bb8a6144f70887dbe97bd21ef00c02e9e7bc Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 11:37:39 +0200 Subject: [PATCH 17/24] refactor: fix misc eslint errors --- packages/api-client/possible-types.js | 4 ++++ packages/composables/__tests__/_mountComposable.ts | 6 +++--- packages/composables/nuxt/cookie.js | 2 ++ packages/composables/nuxt/plugin.js | 2 ++ packages/composables/src/composables/useCart/index.ts | 4 ++-- .../composables/src/composables/useUserShipping/index.ts | 2 +- packages/composables/src/factories/useStoreFactory.ts | 3 +-- packages/theme/composables/useUiHelpers/index.ts | 2 +- 8 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/api-client/possible-types.js b/packages/api-client/possible-types.js index 53590aae3..05abd9a2d 100644 --- a/packages/api-client/possible-types.js +++ b/packages/api-client/possible-types.js @@ -1,7 +1,9 @@ +/* eslint-disable unicorn/prefer-module */ require('dotenv').config(); const fetch = require('cross-fetch'); const fs = require('fs'); +// eslint-disable-next-line promise/catch-or-return fetch(process.env.VSF_MAGENTO_GRAPHQL_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -22,9 +24,11 @@ fetch(process.env.VSF_MAGENTO_GRAPHQL_URL, { `, }), }).then((result) => result.json()) + // eslint-disable-next-line promise/always-return .then((result) => { const possibleTypes = {}; + // eslint-disable-next-line no-underscore-dangle result.data.__schema.types.forEach((supertype) => { if (supertype.possibleTypes) { possibleTypes[supertype.name] = supertype.possibleTypes.map((subtype) => subtype.name); diff --git a/packages/composables/__tests__/_mountComposable.ts b/packages/composables/__tests__/_mountComposable.ts index b2e35eeca..cfebcb992 100644 --- a/packages/composables/__tests__/_mountComposable.ts +++ b/packages/composables/__tests__/_mountComposable.ts @@ -1,12 +1,12 @@ import { shallowMount } from '@vue/test-utils'; -import { createComponent } from '@vue/composition-api'; +import { defineComponent } from '@vue/composition-api'; const mountComposable = (composableFn) => { - const component = createComponent({ - template: '
my component
', + const component = defineComponent({ setup() { return composableFn(); }, + template: '
my component
', }); return shallowMount(component); diff --git a/packages/composables/nuxt/cookie.js b/packages/composables/nuxt/cookie.js index 203e3ec44..48c86258d 100644 --- a/packages/composables/nuxt/cookie.js +++ b/packages/composables/nuxt/cookie.js @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unsafe-argument */ import CookieUniversal from 'cookie-universal'; const baseSetCookieOptions = { @@ -8,6 +9,7 @@ const baseSetCookieOptions = { const isBrowser = () => typeof window !== 'undefined'; export default (req, res) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument const cookie = isBrowser() ? CookieUniversal() : CookieUniversal(req, res); const setCookie = (id, data, options = {}) => { diff --git a/packages/composables/nuxt/plugin.js b/packages/composables/nuxt/plugin.js index c9258b253..669d6994e 100644 --- a/packages/composables/nuxt/plugin.js +++ b/packages/composables/nuxt/plugin.js @@ -1,3 +1,5 @@ +/* eslint-disable import/no-extraneous-dependencies */ +// for removal of reliance on Vue Storefront Core import { integrationPlugin } from '@vue-storefront/magento-theme/helpers/integrationPlugin'; import { mapConfigToSetupObject } from '@vue-storefront/magento/nuxt/helpers'; import defaultConfig from '@vue-storefront/magento/nuxt/defaultConfig'; diff --git a/packages/composables/src/composables/useCart/index.ts b/packages/composables/src/composables/useCart/index.ts index 34466777f..71739fee8 100644 --- a/packages/composables/src/composables/useCart/index.ts +++ b/packages/composables/src/composables/useCart/index.ts @@ -67,8 +67,8 @@ const factoryParams: UseCartFactoryParams = { return createVirtualCart(); } - cartId = await createRealCart(); - apiState.setCartId(cartId); + const realCart = await createRealCart(); + apiState.setCartId(realCart); } return getCartData(cartId); diff --git a/packages/composables/src/composables/useUserShipping/index.ts b/packages/composables/src/composables/useUserShipping/index.ts index de231d6c1..07859bd94 100644 --- a/packages/composables/src/composables/useUserShipping/index.ts +++ b/packages/composables/src/composables/useUserShipping/index.ts @@ -31,7 +31,7 @@ const factoryParams: UseUserShippingFactoryParams = { deleteAddress: async (context: Context, params) => { Logger.debug('[Magento] delete shipping address', { params }); - const { data } = await context.$magento.api.deleteCustomerAddress(params.address.id); + const { data } = await context.$magento.api.deleteCustomerAddress(params.address.id as number); return data?.deleteCustomerAddress ?? {}; }, diff --git a/packages/composables/src/factories/useStoreFactory.ts b/packages/composables/src/factories/useStoreFactory.ts index 8a5103d3a..c5fa07ece 100644 --- a/packages/composables/src/factories/useStoreFactory.ts +++ b/packages/composables/src/factories/useStoreFactory.ts @@ -39,8 +39,7 @@ export function useStoreFactory): Promise => { + const change = (store: ComposableFunctionArgs) => { loading.value = true; try { _factoryParams.change(store); diff --git a/packages/theme/composables/useUiHelpers/index.ts b/packages/theme/composables/useUiHelpers/index.ts index fa5130d7b..4b3457c17 100644 --- a/packages/theme/composables/useUiHelpers/index.ts +++ b/packages/theme/composables/useUiHelpers/index.ts @@ -1,8 +1,8 @@ import { useRoute, useRouter } from '@nuxtjs/composition-api'; import type { FacetInterface } from '~/composables/types'; import type { CategoryTree } from '~/modules/GraphQL/types'; -import type { Params, QueryParams, FilterParams } from './Params'; import type { UseUiHelpersInterface } from '~/composables'; +import type { Params, QueryParams, FilterParams } from './Params'; const nonFilters = new Set(['page', 'sort', 'term', 'itemsPerPage']); From 93c3b86a7f2e7cf0003cfa1fca876dad324a831f Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 11:53:54 +0200 Subject: [PATCH 18/24] chore: fix misc eslint issues --- .eslintignore | 1 + .eslintrc.js | 6 ++++++ commitlint.config.js | 1 + internals/eslint-import/index.js | 1 + internals/eslint-jest/index.js | 2 +- internals/eslint-typescript/index.js | 2 +- internals/eslint/index.js | 2 +- packages/api-client/babel.config.js | 1 + packages/composables/babel.config.js | 1 + packages/composables/nuxt/helpers/index.js | 1 + packages/composables/src/factories/useCurrencyFactory.ts | 1 + 11 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.eslintignore b/.eslintignore index fc6cc690f..38b4aa797 100755 --- a/.eslintignore +++ b/.eslintignore @@ -5,3 +5,4 @@ packages/api-client/server packages/composables/lib packages/api-client/lib packages/theme/static/sw.js +.eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js index b9abf4456..5327c1907 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -48,6 +48,12 @@ module.exports = { "promise/catch-or-return": "off", // conflicts with Cypress.Chainable "promise/always-return": "off", } + }, + { + "files": ["internals/**/*"], + "rules": { + "unicorn/prefer-module": "off", + } } ] } diff --git a/commitlint.config.js b/commitlint.config.js index 422b19445..047108857 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1 +1,2 @@ +// eslint-disable-next-line unicorn/prefer-module module.exports = { extends: ['@commitlint/config-conventional'] }; diff --git a/internals/eslint-import/index.js b/internals/eslint-import/index.js index de54dd087..5848061a1 100644 --- a/internals/eslint-import/index.js +++ b/internals/eslint-import/index.js @@ -5,5 +5,6 @@ module.exports = { './rules/extends', './rules/rules', './rules/settings', + // eslint-disable-next-line unicorn/no-array-callback-reference ].map(require.resolve), }; diff --git a/internals/eslint-jest/index.js b/internals/eslint-jest/index.js index c02f0dc6c..344edc3eb 100644 --- a/internals/eslint-jest/index.js +++ b/internals/eslint-jest/index.js @@ -3,5 +3,5 @@ module.exports = { './rules/plugins', './rules/extends', './rules/rules', - ].map(require.resolve), + ].map((element) => require.resolve(element)), }; diff --git a/internals/eslint-typescript/index.js b/internals/eslint-typescript/index.js index c02f0dc6c..344edc3eb 100644 --- a/internals/eslint-typescript/index.js +++ b/internals/eslint-typescript/index.js @@ -3,5 +3,5 @@ module.exports = { './rules/plugins', './rules/extends', './rules/rules', - ].map(require.resolve), + ].map((element) => require.resolve(element)), }; diff --git a/internals/eslint/index.js b/internals/eslint/index.js index a478b2696..09abf5da3 100644 --- a/internals/eslint/index.js +++ b/internals/eslint/index.js @@ -6,5 +6,5 @@ module.exports = { './rules/plugins', './rules/extends', './rules/rules', - ].map(require.resolve), + ].map((element) => require.resolve(element)), }; diff --git a/packages/api-client/babel.config.js b/packages/api-client/babel.config.js index ed8b326b9..6c66aa368 100644 --- a/packages/api-client/babel.config.js +++ b/packages/api-client/babel.config.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line unicorn/prefer-module module.exports = { presets: [ ['@babel/preset-env', { diff --git a/packages/composables/babel.config.js b/packages/composables/babel.config.js index ed8b326b9..6c66aa368 100644 --- a/packages/composables/babel.config.js +++ b/packages/composables/babel.config.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line unicorn/prefer-module module.exports = { presets: [ ['@babel/preset-env', { diff --git a/packages/composables/nuxt/helpers/index.js b/packages/composables/nuxt/helpers/index.js index 397921d94..5abbf3f89 100644 --- a/packages/composables/nuxt/helpers/index.js +++ b/packages/composables/nuxt/helpers/index.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line import/no-extraneous-dependencies import defaultConfig from '@vue-storefront/magento/nuxt/defaultConfig'; export const getLocaleSettings = (app, moduleOptions) => { diff --git a/packages/composables/src/factories/useCurrencyFactory.ts b/packages/composables/src/factories/useCurrencyFactory.ts index 294b4ea5b..51f652f6f 100644 --- a/packages/composables/src/factories/useCurrencyFactory.ts +++ b/packages/composables/src/factories/useCurrencyFactory.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-misused-promises */ /** * @deprecated since version 1.0.0 */ From 2466e0f55abb14535b71b59549ee6194256d08a6 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 12:01:33 +0200 Subject: [PATCH 19/24] chore: consistent array-callback --- internals/eslint-import/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internals/eslint-import/index.js b/internals/eslint-import/index.js index 5848061a1..941083af6 100644 --- a/internals/eslint-import/index.js +++ b/internals/eslint-import/index.js @@ -5,6 +5,5 @@ module.exports = { './rules/extends', './rules/rules', './rules/settings', - // eslint-disable-next-line unicorn/no-array-callback-reference - ].map(require.resolve), + ].map((element) => require.resolve(element)), }; From 0dbf8159d7a95483d519eb09a6b1e5bc33e1f6e1 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 12:02:40 +0200 Subject: [PATCH 20/24] chore: remove redundant unsafe-argument eslint comment --- packages/composables/nuxt/cookie.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/composables/nuxt/cookie.js b/packages/composables/nuxt/cookie.js index 48c86258d..21bcd8ed3 100644 --- a/packages/composables/nuxt/cookie.js +++ b/packages/composables/nuxt/cookie.js @@ -9,7 +9,6 @@ const baseSetCookieOptions = { const isBrowser = () => typeof window !== 'undefined'; export default (req, res) => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument const cookie = isBrowser() ? CookieUniversal() : CookieUniversal(req, res); const setCookie = (id, data, options = {}) => { From db7d56411d32ac75aa0e4d2ca285e5fe1b9acff2 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 12:03:37 +0200 Subject: [PATCH 21/24] chore: don't break cartId implementation --- packages/composables/src/composables/useCart/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/composables/src/composables/useCart/index.ts b/packages/composables/src/composables/useCart/index.ts index 71739fee8..3409fa882 100644 --- a/packages/composables/src/composables/useCart/index.ts +++ b/packages/composables/src/composables/useCart/index.ts @@ -67,8 +67,9 @@ const factoryParams: UseCartFactoryParams = { return createVirtualCart(); } - const realCart = await createRealCart(); - apiState.setCartId(realCart); + // eslint-disable-next-line no-param-reassign + cartId = await createRealCart(); + apiState.setCartId(cartId); } return getCartData(cartId); From efcfda71e1a42e32926164b6b13ed044cc64f1ff Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 12:05:28 +0200 Subject: [PATCH 22/24] chore: remove any --- packages/composables/src/getters/orderGetters.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/composables/src/getters/orderGetters.ts b/packages/composables/src/getters/orderGetters.ts index 7ab983ebb..a07c36c0a 100644 --- a/packages/composables/src/getters/orderGetters.ts +++ b/packages/composables/src/getters/orderGetters.ts @@ -12,7 +12,7 @@ export const getStatus = (order: CustomerOrder): string => order?.status || 'Fai export const getPrice = (order: CustomerOrder): number | null => order?.grand_total || 0; -export const getItems = (order: CustomerOrder): any[] => order?.items || []; +export const getItems = (order: CustomerOrder): OrderItemInterface[] => order?.items || []; export const getItemSku = (item: OrderItemInterface): string => item?.product_sku || ''; From 05d914653fdfeae9f624d5c69215aea1fd7cf987 Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 13:17:28 +0200 Subject: [PATCH 23/24] ci: add eslint action --- .github/workflows/eslint.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/eslint.yml diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml new file mode 100644 index 000000000..87c573aa9 --- /dev/null +++ b/.github/workflows/eslint.yml @@ -0,0 +1,25 @@ +name: ESLint +on: + pull_request: + types: ['opened', 'edited', 'reopened', 'synchronize'] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + + - name: Setup node + uses: actions/setup-node@v2 + with: + node-version: "16" + + - name: Install Dependencies + run: yarn + + - name: Run ESLint + run: yarn exec eslint . From 775b026023fcece2c8c6ca4911eb803d0143e90d Mon Sep 17 00:00:00 2001 From: Artur Tagisow Date: Tue, 17 May 2022 13:29:37 +0200 Subject: [PATCH 24/24] ci: run lint in build this is necessary because typescript-eslint requires packages to be built to check for errors --- .github/workflows/eslint.yml | 25 ------------------------- .github/workflows/test.yml | 5 +++++ package.json | 5 +++-- 3 files changed, 8 insertions(+), 27 deletions(-) delete mode 100644 .github/workflows/eslint.yml diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml deleted file mode 100644 index 87c573aa9..000000000 --- a/.github/workflows/eslint.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: ESLint -on: - pull_request: - types: ['opened', 'edited', 'reopened', 'synchronize'] - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - - name: Setup node - uses: actions/setup-node@v2 - with: - node-version: "16" - - - name: Install Dependencies - run: yarn - - - name: Run ESLint - run: yarn exec eslint . diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c81da536b..d1ed60d80 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,5 +36,10 @@ jobs: - name: Build packages run: yarn build + # typescript-eslint needs all packages to be built + # to check type-related linting rules + - name: Check for linting errors + run: yarn lint + - name: Test theme run: yarn test:theme diff --git a/package.json b/package.json index 658a6de16..59e737fc2 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,10 @@ "internals/*" ], "scripts": { - "build": "yarn build:api-client && yarn build:theme", + "build": "yarn build:api-client && yarn build:theme && yarn build:composables", "build:api-client": "cd packages/api-client && yarn build", "build:theme": "cd packages/theme && yarn build", + "build:composables": "cd packages/composables && yarn build", "contributors:add": "all-contributors add", "contributors:generate": "all-contributors generate", "dev:api-client": "cd packages/api-client && yarn dev", @@ -22,7 +23,7 @@ "docs:dev": "cd docs && yarn dev", "docs:build": "cd docs && yarn build", "graphql:codegen": "graphql-codegen --config codegen.yml", - "lint": "eslint . --ext .ts,.vue --fix", + "lint": "eslint .", "prepare": "[ -d '.husky' ] && (husky install && shx rm -rf .git/hooks && shx ln -s ../.husky .git/hooks) || true", "publish:api-client": "node ./scripts/publishApi.js", "start": "cd packages/theme && yarn start",