diff --git a/.eslintignore b/.eslintignore
index 7cbbadfda..38b4aa797 100755
--- a/.eslintignore
+++ b/.eslintignore
@@ -1,4 +1,8 @@
**/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
+.eslintrc.js
diff --git a/.eslintrc.js b/.eslintrc.js
index 092e5d103..5327c1907 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'),
],
@@ -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/.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/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..941083af6 100644
--- a/internals/eslint-import/index.js
+++ b/internals/eslint-import/index.js
@@ -5,5 +5,5 @@ module.exports = {
'./rules/extends',
'./rules/rules',
'./rules/settings',
- ].map(require.resolve),
+ ].map((element) => require.resolve(element)),
};
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/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",
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/__tests__/setup/index.ts b/packages/api-client/__tests__/setup/index.ts
deleted file mode 100644
index e69de29bb..000000000
diff --git a/packages/api-client/babel.config.js b/packages/api-client/babel.config.js
index d3540f51b..6c66aa368 100644
--- a/packages/api-client/babel.config.js
+++ b/packages/api-client/babel.config.js
@@ -1,9 +1,10 @@
+// eslint-disable-next-line unicorn/prefer-module
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/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/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,
diff --git a/packages/api-client/tsconfig.eslint.json b/packages/api-client/tsconfig.eslint.json
new file mode 100644
index 000000000..a47730729
--- /dev/null
+++ b/packages/api-client/tsconfig.eslint.json
@@ -0,0 +1,7 @@
+{
+ "extends": "../../tsconfig.json",
+ "exclude": [
+ "lib",
+ "node_modules"
+ ]
+}
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/__tests__/getters/productHelpers.spec.ts b/packages/composables/__tests__/getters/productHelpers.spec.ts
index b4233c7cd..d09b187f1 100644
--- a/packages/composables/__tests__/getters/productHelpers.spec.ts
+++ b/packages/composables/__tests__/getters/productHelpers.spec.ts
@@ -1,144 +1,131 @@
+import { Product } from '@vue-storefront/magento-api';
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 = {
- "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
\n- Dual top handles.
\n- Adjustable shoulder strap.
\n- Full-length zipper.
\n- L 29\" x W 13\" x H 11\".
\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
\n- Dual top handles.
\n- Adjustable shoulder strap.
\n- Full-length zipper.
\n- L 29" x W 13" x H 11".
\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"
- }]
-} as any;
+ 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 unknown as Product;
describe('[magento-getters] product getters', () => {
it('returns default values', () => {
@@ -165,20 +152,21 @@ 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',
+ },
]);
});
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');
});
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..6c66aa368 100644
--- a/packages/composables/babel.config.js
+++ b/packages/composables/babel.config.js
@@ -1,9 +1,10 @@
+// eslint-disable-next-line unicorn/prefer-module
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/cookie.js b/packages/composables/nuxt/cookie.js
index 203e3ec44..21bcd8ed3 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 = {
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/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/nuxt/plugin.js b/packages/composables/nuxt/plugin.js
index d3b40aa7f..669d6994e 100644
--- a/packages/composables/nuxt/plugin.js
+++ b/packages/composables/nuxt/plugin.js
@@ -1,4 +1,6 @@
-import { integrationPlugin } from '@vue-storefront/magento-theme/helpers/integrationPlugin'
+/* 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';
import cookie from '@vue-storefront/magento/nuxt/cookie';
@@ -6,7 +8,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 +26,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 +69,7 @@ export default integrationPlugin(({ app, res, req, integration }) => {
getCountry,
setCountry,
},
- }
+ },
});
integration.configure('magento', settings);
diff --git a/packages/composables/src/composables/useCart/index.ts b/packages/composables/src/composables/useCart/index.ts
index 34466777f..3409fa882 100644
--- a/packages/composables/src/composables/useCart/index.ts
+++ b/packages/composables/src/composables/useCart/index.ts
@@ -67,6 +67,7 @@ const factoryParams: UseCartFactoryParams = {
return createVirtualCart();
}
+ // eslint-disable-next-line no-param-reassign
cartId = await createRealCart();
apiState.setCartId(cartId);
}
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;
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/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/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,
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
*/
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..c5fa07ece 100644
--- a/packages/composables/src/factories/useStoreFactory.ts
+++ b/packages/composables/src/factories/useStoreFactory.ts
@@ -39,7 +39,7 @@ export function useStoreFactory): Promise => {
+ const change = (store: ComposableFunctionArgs) => {
loading.value = true;
try {
_factoryParams.change(store);
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;
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/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
diff --git a/packages/composables/src/getters/orderGetters.ts b/packages/composables/src/getters/orderGetters.ts
index 6512be9ec..a07c36c0a 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): OrderItemInterface[] => 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);
diff --git a/packages/composables/src/getters/productGetters.ts b/packages/composables/src/getters/productGetters.ts
index 630016e1f..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';
@@ -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?: CategoryTree): AgnosticBreadcrumb[] => {
let breadcrumbs = [];
if (!product) {
@@ -221,7 +221,7 @@ export const getBreadcrumbs = (product: any, category?: Category): AgnosticBread
}
if (category) {
- breadcrumbs = categoryGetters.getBreadcrumbs(category) as AgnosticBreadcrumb[];
+ breadcrumbs = categoryGetters.getBreadcrumbs(category);
}
breadcrumbs.push({
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[] => [];
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;
}[];
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);
diff --git a/packages/composables/tsconfig.eslint.json b/packages/composables/tsconfig.eslint.json
new file mode 100644
index 000000000..a47730729
--- /dev/null
+++ b/packages/composables/tsconfig.eslint.json
@@ -0,0 +1,7 @@
+{
+ "extends": "../../tsconfig.json",
+ "exclude": [
+ "lib",
+ "node_modules"
+ ]
+}
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']);