From 628fbf50bb2080a25b74d357cc0375f9bee3c5b8 Mon Sep 17 00:00:00 2001 From: l198881 <82917144+l198881@users.noreply.github.com> Date: Tue, 1 Jun 2021 07:55:04 -0300 Subject: [PATCH] Shopify i18n (#9) --- .env.template | 12 +- .gitignore | 1 + .prettierrc | 6 + .vscode/extensions.json | 3 + CHANGELOG.md | 4 - README.md | 120 +- .../config.json => commerce.config.json | 0 components/cart/CartItem/CartItem.tsx | 23 +- .../cart/CartSidebarView/CartSidebarView.tsx | 30 +- .../common/FeatureBar/FeatureBar.module.css | 4 +- components/common/Footer/Footer.tsx | 14 - .../HomeAllProductsGrid.tsx | 4 - .../common/I18nWidget/I18nWidget.module.css | 8 +- components/common/Layout/Layout.tsx | 5 +- components/common/Navbar/Navbar.tsx | 7 +- .../common/UserNav/DropdownMenu.module.css | 4 +- components/common/UserNav/UserNav.tsx | 7 +- components/icons/CreditCard.tsx | 20 + components/icons/MapPin.tsx | 20 + components/icons/index.ts | 2 + .../product/ProductCard/ProductCard.tsx | 6 +- .../ProductView/ProductView.module.css | 2 +- .../product/ProductView/ProductView.tsx | 37 +- components/product/Swatch/Swatch.module.css | 54 +- components/product/Swatch/Swatch.tsx | 25 +- components/product/helpers.ts | 6 +- components/ui/Grid/Grid.module.css | 15 +- components/ui/Hero/Hero.module.css | 5 +- components/ui/Hero/Hero.tsx | 2 +- components/ui/context.tsx | 9 +- .../WishlistButton/WishlistButton.tsx | 15 +- .../wishlist/WishlistCard/WishlistCard.tsx | 3 +- config/seo.json | 14 +- docs/ROADMAP.md | 1 - framework/bigcommerce/.env.template | 8 + framework/bigcommerce/README.md | 398 +- framework/bigcommerce/api/utils/parse-item.ts | 13 +- framework/bigcommerce/auth/use-login.tsx | 62 +- framework/bigcommerce/auth/use-logout.tsx | 39 +- framework/bigcommerce/auth/use-signup.tsx | 66 +- framework/bigcommerce/cart/index.ts | 3 +- framework/bigcommerce/cart/use-add-item.tsx | 35 +- framework/bigcommerce/cart/use-cart.tsx | 11 +- .../bigcommerce/cart/use-remove-item.tsx | 74 +- .../bigcommerce/cart/use-update-item.tsx | 113 +- framework/bigcommerce/commerce.config.json | 6 + .../customer/get-customer-wishlist.ts | 5 +- .../bigcommerce/customer/use-customer.tsx | 11 +- framework/bigcommerce/next.config.js | 8 + framework/bigcommerce/product/get-product.ts | 2 +- framework/bigcommerce/product/use-price.tsx | 4 +- framework/bigcommerce/product/use-search.tsx | 9 +- framework/bigcommerce/provider.ts | 20 +- framework/bigcommerce/types.ts | 3 - framework/bigcommerce/wishlist/index.ts | 1 - .../bigcommerce/wishlist/use-add-item.tsx | 54 +- .../bigcommerce/wishlist/use-remove-item.tsx | 65 +- .../wishlist/use-wishlist-actions.tsx | 11 - .../bigcommerce/wishlist/use-wishlist.tsx | 23 +- framework/commerce/README.md | 334 + framework/commerce/api/index.ts | 1 + framework/commerce/auth/use-login.tsx | 19 + framework/commerce/auth/use-logout.tsx | 19 + framework/commerce/auth/use-signup.tsx | 19 + framework/commerce/cart/use-add-item.tsx | 76 +- framework/commerce/cart/use-cart-actions.tsx | 17 - framework/commerce/cart/use-cart.tsx | 64 +- framework/commerce/cart/use-remove-item.tsx | 33 +- framework/commerce/cart/use-update-item.tsx | 35 +- framework/commerce/config.js | 68 + framework/commerce/customer/use-customer.tsx | 64 +- framework/commerce/index.tsx | 25 +- framework/commerce/new-provider.md | 239 + .../commerce/{ => product}/use-price.tsx | 2 +- framework/commerce/product/use-search.tsx | 65 +- framework/commerce/types.ts | 11 +- framework/commerce/use-login.tsx | 5 - framework/commerce/use-logout.tsx | 5 - framework/commerce/use-signup.tsx | 5 - framework/commerce/utils/default-fetcher.ts | 10 +- framework/commerce/utils/features.ts | 37 - framework/commerce/utils/types.ts | 103 +- framework/commerce/utils/use-action.tsx | 15 - framework/commerce/utils/use-data.tsx | 19 +- framework/commerce/utils/use-hook.ts | 50 + framework/commerce/utils/use-response.tsx | 40 - framework/commerce/wishlist/use-add-item.tsx | 23 +- .../commerce/wishlist/use-remove-item.tsx | 27 +- framework/commerce/wishlist/use-wishlist.tsx | 69 +- framework/shopify/.env.template | 4 + framework/shopify/README.md | 123 + framework/shopify/api/cart/index.ts | 1 + framework/shopify/api/catalog/index.ts | 1 + framework/shopify/api/catalog/products.ts | 1 + framework/shopify/api/checkout/index.ts | 46 + framework/shopify/api/customer.ts | 1 + framework/shopify/api/customers/index.ts | 1 + framework/shopify/api/customers/login.ts | 1 + framework/shopify/api/customers/logout.ts | 1 + framework/shopify/api/customers/signup.ts | 1 + framework/shopify/api/index.ts | 60 + .../shopify/api/utils/create-api-handler.ts | 58 + .../shopify/api/utils/fetch-all-products.ts | 54 + .../shopify/api/utils/fetch-graphql-api.ts | 34 + framework/shopify/api/utils/fetch.ts | 2 + .../shopify/api/utils/is-allowed-method.ts | 28 + framework/shopify/api/wishlist/index.tsx | 2 + framework/shopify/auth/use-login.tsx | 71 + framework/shopify/auth/use-logout.tsx | 36 + framework/shopify/auth/use-signup.tsx | 70 + framework/shopify/cart/index.ts | 4 + framework/shopify/cart/use-add-item.tsx | 60 + framework/shopify/cart/use-cart.tsx | 59 + framework/shopify/cart/use-remove-item.tsx | 71 + framework/shopify/cart/use-update-item.tsx | 107 + framework/shopify/commerce.config.json | 6 + framework/shopify/common/get-all-pages.ts | 49 + framework/shopify/common/get-page.ts | 41 + framework/shopify/common/get-site-info.ts | 31 + framework/shopify/const.ts | 13 + framework/shopify/customer/get-customer-id.ts | 24 + framework/shopify/customer/index.ts | 1 + framework/shopify/customer/use-customer.tsx | 31 + framework/shopify/fetcher.ts | 25 + framework/shopify/index.tsx | 38 + framework/shopify/next.config.js | 8 + .../shopify/product/get-all-collections.ts | 29 + .../shopify/product/get-all-product-paths.ts | 41 + framework/shopify/product/get-all-products.ts | 43 + framework/shopify/product/get-product.ts | 43 + framework/shopify/product/use-price.tsx | 2 + framework/shopify/product/use-search.tsx | 79 + framework/shopify/provider.ts | 27 + framework/shopify/schema.d.ts | 4985 +++++++++ framework/shopify/schema.graphql | 9631 +++++++++++++++++ framework/shopify/types.ts | 43 + framework/shopify/utils/checkout-create.ts | 33 + framework/shopify/utils/checkout-to-cart.ts | 48 + framework/shopify/utils/customer-token.ts | 21 + framework/shopify/utils/get-categories.ts | 40 + framework/shopify/utils/get-checkout-id.ts | 8 + .../shopify/utils/get-search-variables.ts | 29 + framework/shopify/utils/get-sort-variables.ts | 32 + framework/shopify/utils/get-vendors.ts | 37 + .../utils/handle-account-activation.ts | 30 + .../shopify/utils/handle-fetch-response.ts | 27 + framework/shopify/utils/handle-login.ts | 36 + framework/shopify/utils/index.ts | 15 + .../associate-customer-with-checkout.ts | 18 + .../utils/mutations/checkout-create.ts | 17 + .../utils/mutations/checkout-line-item-add.ts | 17 + .../mutations/checkout-line-item-remove.ts | 20 + .../mutations/checkout-line-item-update.ts | 17 + .../mutations/customer-access-token-create.ts | 16 + .../mutations/customer-access-token-delete.ts | 14 + .../mutations/customer-activate-by-url.ts | 19 + .../utils/mutations/customer-activate.ts | 19 + .../utils/mutations/customer-create.ts | 15 + framework/shopify/utils/mutations/index.ts | 9 + framework/shopify/utils/normalize.ts | 186 + .../queries/get-all-collections-query.ts | 14 + .../utils/queries/get-all-pages-query.ts | 14 + .../queries/get-all-product-vendors-query.ts | 17 + .../queries/get-all-products-paths-query.ts | 17 + .../utils/queries/get-all-products-query.ts | 56 + .../utils/queries/get-checkout-query.ts | 65 + .../queries/get-collection-products-query.ts | 24 + .../utils/queries/get-customer-id-query.ts | 8 + .../utils/queries/get-customer-query.ts | 16 + .../shopify/utils/queries/get-page-query.ts | 14 + .../utils/queries/get-product-query.ts | 69 + framework/shopify/utils/queries/index.ts | 10 + framework/shopify/utils/throw-user-errors.ts | 38 + framework/shopify/wishlist/use-add-item.tsx | 13 + .../shopify/wishlist/use-remove-item.tsx | 17 + framework/shopify/wishlist/use-wishlist.tsx | 46 + framework/swell/.env.template | 5 + framework/swell/api/cart/index.ts | 1 + framework/swell/api/catalog/index.ts | 1 + framework/swell/api/catalog/products.ts | 1 + framework/swell/api/checkout/index.ts | 20 + framework/swell/api/customer.ts | 1 + framework/swell/api/customers/index.ts | 1 + framework/swell/api/customers/login.ts | 1 + framework/swell/api/customers/logout.ts | 1 + framework/swell/api/customers/signup.ts | 1 + framework/swell/api/index.ts | 50 + framework/swell/api/operations/get-page.ts | 25 + .../swell/api/utils/create-api-handler.ts | 58 + framework/swell/api/utils/fetch-swell-api.ts | 7 + framework/swell/api/utils/fetch.ts | 2 + .../swell/api/utils/is-allowed-method.ts | 28 + framework/swell/api/wishlist/index.tsx | 2 + framework/swell/auth/use-login.tsx | 74 + framework/swell/auth/use-logout.tsx | 36 + framework/swell/auth/use-signup.tsx | 65 + framework/swell/cart/index.ts | 3 + framework/swell/cart/use-add-item.tsx | 59 + framework/swell/cart/use-cart.tsx | 37 + framework/swell/cart/use-remove-item.tsx | 71 + framework/swell/cart/use-update-item.tsx | 96 + framework/swell/cart/utils/checkout-create.ts | 28 + .../swell/cart/utils/checkout-to-cart.ts | 26 + framework/swell/cart/utils/fetcher.ts | 33 + framework/swell/cart/utils/index.ts | 2 + .../commerce.config.json} | 1 + framework/swell/common/get-all-pages.ts | 37 + framework/swell/common/get-page.ts | 33 + framework/swell/common/get-site-info.ts | 31 + framework/swell/const.ts | 13 + framework/swell/customer/index.ts | 1 + framework/swell/customer/use-customer.tsx | 50 + framework/swell/fetcher.ts | 28 + framework/swell/index.tsx | 47 + framework/swell/next.config.js | 8 + .../swell/product/get-all-collections.ts | 28 + .../swell/product/get-all-product-paths.ts | 39 + framework/swell/product/get-all-products.ts | 36 + framework/swell/product/get-product.ts | 32 + framework/swell/product/use-price.tsx | 2 + framework/swell/product/use-search.tsx | 71 + framework/swell/provider.ts | 31 + framework/swell/schema.d.ts | 5002 +++++++++ framework/swell/schema.graphql | 9631 +++++++++++++++++ framework/swell/swell-js.d.ts | 1 + framework/swell/types.ts | 122 + framework/swell/utils/customer-token.ts | 21 + framework/swell/utils/get-categories.ts | 20 + framework/swell/utils/get-checkout-id.ts | 8 + framework/swell/utils/get-search-variables.ts | 27 + framework/swell/utils/get-sort-variables.ts | 32 + framework/swell/utils/get-vendors.ts | 27 + .../swell/utils/handle-fetch-response.ts | 19 + framework/swell/utils/handle-login.ts | 39 + framework/swell/utils/index.ts | 9 + framework/swell/utils/normalize.ts | 219 + framework/swell/utils/storage.ts | 13 + framework/swell/wishlist/use-add-item.tsx | 13 + framework/swell/wishlist/use-remove-item.tsx | 17 + framework/swell/wishlist/use-wishlist.tsx | 46 + framework/vendure/.env.template | 1 + framework/vendure/README.md | 33 + framework/vendure/api/cart/index.ts | 1 + framework/vendure/api/catalog/index.ts | 1 + framework/vendure/api/catalog/products.ts | 1 + framework/vendure/api/checkout/index.ts | 63 + framework/vendure/api/customers/index.ts | 1 + framework/vendure/api/customers/login.ts | 1 + framework/vendure/api/customers/logout.ts | 1 + framework/vendure/api/customers/signup.ts | 1 + framework/vendure/api/index.ts | 51 + .../vendure/api/utils/fetch-graphql-api.ts | 37 + framework/vendure/api/utils/fetch.ts | 3 + framework/vendure/api/wishlist/index.tsx | 2 + framework/vendure/auth/use-login.tsx | 50 + framework/vendure/auth/use-logout.tsx | 32 + framework/vendure/auth/use-signup.tsx | 68 + framework/vendure/cart/index.ts | 5 + framework/vendure/cart/use-add-item.tsx | 52 + .../cart/use-cart-actions.tsx | 0 framework/vendure/cart/use-cart.tsx | 49 + framework/vendure/cart/use-remove-item.tsx | 48 + framework/vendure/cart/use-update-item.tsx | 78 + framework/vendure/codegen.json | 28 + framework/vendure/commerce.config.json | 6 + framework/vendure/common/get-all-pages.ts | 35 + framework/vendure/common/get-page.ts | 40 + framework/vendure/common/get-site-info.ts | 49 + .../vendure/customer/get-customer-wishlist.ts | 18 + framework/vendure/customer/index.ts | 1 + framework/vendure/customer/use-customer.tsx | 33 + framework/vendure/fetcher.ts | 51 + framework/vendure/index.tsx | 33 + framework/vendure/lib/array-to-tree.ts | 67 + .../vendure/lib/fragments/cart-fragment.ts | 42 + .../lib/fragments/search-result-fragment.ts | 24 + .../mutations/add-item-to-order-mutation.ts | 15 + .../mutations/adjust-order-line-mutation.ts | 15 + .../vendure/lib/mutations/log-in-mutation.ts | 14 + .../vendure/lib/mutations/log-out-mutation.ts | 7 + .../mutations/remove-order-line-mutation.ts | 15 + .../vendure/lib/mutations/sign-up-mutation.ts | 14 + framework/vendure/lib/normalize.ts | 55 + .../lib/queries/active-customer-query.ts | 10 + .../queries/get-all-product-paths-query.ts | 9 + .../lib/queries/get-all-products-query.ts | 12 + .../vendure/lib/queries/get-cart-query.ts | 10 + .../lib/queries/get-collections-query.ts | 21 + .../vendure/lib/queries/get-product-query.ts | 41 + framework/vendure/lib/queries/search-query.ts | 13 + framework/vendure/next.config.js | 8 + .../vendure/product/get-all-product-paths.ts | 48 + framework/vendure/product/get-all-products.ts | 39 + framework/vendure/product/get-product.ts | 64 + framework/vendure/product/index.ts | 4 + framework/vendure/product/use-price.tsx | 2 + framework/vendure/product/use-search.tsx | 65 + framework/vendure/provider.ts | 21 + framework/vendure/schema.d.ts | 3122 ++++++ framework/vendure/schema.graphql | 3860 +++++++ framework/vendure/types.ts | 5 + framework/vendure/wishlist/use-add-item.tsx | 13 + .../vendure/wishlist/use-remove-item.tsx | 17 + framework/vendure/wishlist/use-wishlist.tsx | 46 + lib/colors.ts | 158 +- next.config.js | 36 +- package.json | 27 +- pages/[...pages].tsx | 12 +- pages/blog.tsx | 97 - pages/cart.tsx | 36 +- pages/index.tsx | 19 +- pages/orders.tsx | 3 +- pages/product/[slug].tsx | 15 +- pages/profile.tsx | 3 +- pages/search.tsx | 20 +- pages/wishlist.tsx | 16 +- public/card.png | Bin 0 -> 6286 bytes tsconfig.json | 12 +- yarn.lock | 913 +- 319 files changed, 44504 insertions(+), 2202 deletions(-) create mode 100644 .prettierrc create mode 100644 .vscode/extensions.json delete mode 100644 CHANGELOG.md rename framework/commerce/config.json => commerce.config.json (100%) create mode 100644 components/icons/CreditCard.tsx create mode 100644 components/icons/MapPin.tsx delete mode 100644 docs/ROADMAP.md create mode 100644 framework/bigcommerce/.env.template create mode 100644 framework/bigcommerce/commerce.config.json create mode 100644 framework/bigcommerce/next.config.js delete mode 100644 framework/bigcommerce/wishlist/use-wishlist-actions.tsx create mode 100644 framework/commerce/README.md create mode 100644 framework/commerce/auth/use-login.tsx create mode 100644 framework/commerce/auth/use-logout.tsx create mode 100644 framework/commerce/auth/use-signup.tsx delete mode 100644 framework/commerce/cart/use-cart-actions.tsx create mode 100644 framework/commerce/config.js create mode 100644 framework/commerce/new-provider.md rename framework/commerce/{ => product}/use-price.tsx (97%) delete mode 100644 framework/commerce/use-login.tsx delete mode 100644 framework/commerce/use-logout.tsx delete mode 100644 framework/commerce/use-signup.tsx delete mode 100644 framework/commerce/utils/features.ts delete mode 100644 framework/commerce/utils/use-action.tsx create mode 100644 framework/commerce/utils/use-hook.ts delete mode 100644 framework/commerce/utils/use-response.tsx create mode 100644 framework/shopify/.env.template create mode 100644 framework/shopify/README.md create mode 100644 framework/shopify/api/cart/index.ts create mode 100644 framework/shopify/api/catalog/index.ts create mode 100644 framework/shopify/api/catalog/products.ts create mode 100644 framework/shopify/api/checkout/index.ts create mode 100644 framework/shopify/api/customer.ts create mode 100644 framework/shopify/api/customers/index.ts create mode 100644 framework/shopify/api/customers/login.ts create mode 100644 framework/shopify/api/customers/logout.ts create mode 100644 framework/shopify/api/customers/signup.ts create mode 100644 framework/shopify/api/index.ts create mode 100644 framework/shopify/api/utils/create-api-handler.ts create mode 100644 framework/shopify/api/utils/fetch-all-products.ts create mode 100644 framework/shopify/api/utils/fetch-graphql-api.ts create mode 100644 framework/shopify/api/utils/fetch.ts create mode 100644 framework/shopify/api/utils/is-allowed-method.ts create mode 100644 framework/shopify/api/wishlist/index.tsx create mode 100644 framework/shopify/auth/use-login.tsx create mode 100644 framework/shopify/auth/use-logout.tsx create mode 100644 framework/shopify/auth/use-signup.tsx create mode 100644 framework/shopify/cart/index.ts create mode 100644 framework/shopify/cart/use-add-item.tsx create mode 100644 framework/shopify/cart/use-cart.tsx create mode 100644 framework/shopify/cart/use-remove-item.tsx create mode 100644 framework/shopify/cart/use-update-item.tsx create mode 100644 framework/shopify/commerce.config.json create mode 100644 framework/shopify/common/get-all-pages.ts create mode 100644 framework/shopify/common/get-page.ts create mode 100644 framework/shopify/common/get-site-info.ts create mode 100644 framework/shopify/const.ts create mode 100644 framework/shopify/customer/get-customer-id.ts create mode 100644 framework/shopify/customer/index.ts create mode 100644 framework/shopify/customer/use-customer.tsx create mode 100644 framework/shopify/fetcher.ts create mode 100644 framework/shopify/index.tsx create mode 100644 framework/shopify/next.config.js create mode 100644 framework/shopify/product/get-all-collections.ts create mode 100644 framework/shopify/product/get-all-product-paths.ts create mode 100644 framework/shopify/product/get-all-products.ts create mode 100644 framework/shopify/product/get-product.ts create mode 100644 framework/shopify/product/use-price.tsx create mode 100644 framework/shopify/product/use-search.tsx create mode 100644 framework/shopify/provider.ts create mode 100644 framework/shopify/schema.d.ts create mode 100644 framework/shopify/schema.graphql create mode 100644 framework/shopify/types.ts create mode 100644 framework/shopify/utils/checkout-create.ts create mode 100644 framework/shopify/utils/checkout-to-cart.ts create mode 100644 framework/shopify/utils/customer-token.ts create mode 100644 framework/shopify/utils/get-categories.ts create mode 100644 framework/shopify/utils/get-checkout-id.ts create mode 100644 framework/shopify/utils/get-search-variables.ts create mode 100644 framework/shopify/utils/get-sort-variables.ts create mode 100644 framework/shopify/utils/get-vendors.ts create mode 100644 framework/shopify/utils/handle-account-activation.ts create mode 100644 framework/shopify/utils/handle-fetch-response.ts create mode 100644 framework/shopify/utils/handle-login.ts create mode 100644 framework/shopify/utils/index.ts create mode 100644 framework/shopify/utils/mutations/associate-customer-with-checkout.ts create mode 100644 framework/shopify/utils/mutations/checkout-create.ts create mode 100644 framework/shopify/utils/mutations/checkout-line-item-add.ts create mode 100644 framework/shopify/utils/mutations/checkout-line-item-remove.ts create mode 100644 framework/shopify/utils/mutations/checkout-line-item-update.ts create mode 100644 framework/shopify/utils/mutations/customer-access-token-create.ts create mode 100644 framework/shopify/utils/mutations/customer-access-token-delete.ts create mode 100644 framework/shopify/utils/mutations/customer-activate-by-url.ts create mode 100644 framework/shopify/utils/mutations/customer-activate.ts create mode 100644 framework/shopify/utils/mutations/customer-create.ts create mode 100644 framework/shopify/utils/mutations/index.ts create mode 100644 framework/shopify/utils/normalize.ts create mode 100644 framework/shopify/utils/queries/get-all-collections-query.ts create mode 100644 framework/shopify/utils/queries/get-all-pages-query.ts create mode 100644 framework/shopify/utils/queries/get-all-product-vendors-query.ts create mode 100644 framework/shopify/utils/queries/get-all-products-paths-query.ts create mode 100644 framework/shopify/utils/queries/get-all-products-query.ts create mode 100644 framework/shopify/utils/queries/get-checkout-query.ts create mode 100644 framework/shopify/utils/queries/get-collection-products-query.ts create mode 100644 framework/shopify/utils/queries/get-customer-id-query.ts create mode 100644 framework/shopify/utils/queries/get-customer-query.ts create mode 100644 framework/shopify/utils/queries/get-page-query.ts create mode 100644 framework/shopify/utils/queries/get-product-query.ts create mode 100644 framework/shopify/utils/queries/index.ts create mode 100644 framework/shopify/utils/throw-user-errors.ts create mode 100644 framework/shopify/wishlist/use-add-item.tsx create mode 100644 framework/shopify/wishlist/use-remove-item.tsx create mode 100644 framework/shopify/wishlist/use-wishlist.tsx create mode 100644 framework/swell/.env.template create mode 100644 framework/swell/api/cart/index.ts create mode 100644 framework/swell/api/catalog/index.ts create mode 100644 framework/swell/api/catalog/products.ts create mode 100644 framework/swell/api/checkout/index.ts create mode 100644 framework/swell/api/customer.ts create mode 100644 framework/swell/api/customers/index.ts create mode 100644 framework/swell/api/customers/login.ts create mode 100644 framework/swell/api/customers/logout.ts create mode 100644 framework/swell/api/customers/signup.ts create mode 100644 framework/swell/api/index.ts create mode 100644 framework/swell/api/operations/get-page.ts create mode 100644 framework/swell/api/utils/create-api-handler.ts create mode 100644 framework/swell/api/utils/fetch-swell-api.ts create mode 100644 framework/swell/api/utils/fetch.ts create mode 100644 framework/swell/api/utils/is-allowed-method.ts create mode 100644 framework/swell/api/wishlist/index.tsx create mode 100644 framework/swell/auth/use-login.tsx create mode 100644 framework/swell/auth/use-logout.tsx create mode 100644 framework/swell/auth/use-signup.tsx create mode 100644 framework/swell/cart/index.ts create mode 100644 framework/swell/cart/use-add-item.tsx create mode 100644 framework/swell/cart/use-cart.tsx create mode 100644 framework/swell/cart/use-remove-item.tsx create mode 100644 framework/swell/cart/use-update-item.tsx create mode 100644 framework/swell/cart/utils/checkout-create.ts create mode 100644 framework/swell/cart/utils/checkout-to-cart.ts create mode 100644 framework/swell/cart/utils/fetcher.ts create mode 100644 framework/swell/cart/utils/index.ts rename framework/{bigcommerce/config.json => swell/commerce.config.json} (66%) create mode 100644 framework/swell/common/get-all-pages.ts create mode 100644 framework/swell/common/get-page.ts create mode 100644 framework/swell/common/get-site-info.ts create mode 100644 framework/swell/const.ts create mode 100644 framework/swell/customer/index.ts create mode 100644 framework/swell/customer/use-customer.tsx create mode 100644 framework/swell/fetcher.ts create mode 100644 framework/swell/index.tsx create mode 100644 framework/swell/next.config.js create mode 100644 framework/swell/product/get-all-collections.ts create mode 100644 framework/swell/product/get-all-product-paths.ts create mode 100644 framework/swell/product/get-all-products.ts create mode 100644 framework/swell/product/get-product.ts create mode 100644 framework/swell/product/use-price.tsx create mode 100644 framework/swell/product/use-search.tsx create mode 100644 framework/swell/provider.ts create mode 100644 framework/swell/schema.d.ts create mode 100644 framework/swell/schema.graphql create mode 100644 framework/swell/swell-js.d.ts create mode 100644 framework/swell/types.ts create mode 100644 framework/swell/utils/customer-token.ts create mode 100644 framework/swell/utils/get-categories.ts create mode 100644 framework/swell/utils/get-checkout-id.ts create mode 100644 framework/swell/utils/get-search-variables.ts create mode 100644 framework/swell/utils/get-sort-variables.ts create mode 100644 framework/swell/utils/get-vendors.ts create mode 100644 framework/swell/utils/handle-fetch-response.ts create mode 100644 framework/swell/utils/handle-login.ts create mode 100644 framework/swell/utils/index.ts create mode 100644 framework/swell/utils/normalize.ts create mode 100644 framework/swell/utils/storage.ts create mode 100644 framework/swell/wishlist/use-add-item.tsx create mode 100644 framework/swell/wishlist/use-remove-item.tsx create mode 100644 framework/swell/wishlist/use-wishlist.tsx create mode 100644 framework/vendure/.env.template create mode 100644 framework/vendure/README.md create mode 100644 framework/vendure/api/cart/index.ts create mode 100644 framework/vendure/api/catalog/index.ts create mode 100644 framework/vendure/api/catalog/products.ts create mode 100644 framework/vendure/api/checkout/index.ts create mode 100644 framework/vendure/api/customers/index.ts create mode 100644 framework/vendure/api/customers/login.ts create mode 100644 framework/vendure/api/customers/logout.ts create mode 100644 framework/vendure/api/customers/signup.ts create mode 100644 framework/vendure/api/index.ts create mode 100644 framework/vendure/api/utils/fetch-graphql-api.ts create mode 100644 framework/vendure/api/utils/fetch.ts create mode 100644 framework/vendure/api/wishlist/index.tsx create mode 100644 framework/vendure/auth/use-login.tsx create mode 100644 framework/vendure/auth/use-logout.tsx create mode 100644 framework/vendure/auth/use-signup.tsx create mode 100644 framework/vendure/cart/index.ts create mode 100644 framework/vendure/cart/use-add-item.tsx rename framework/{bigcommerce => vendure}/cart/use-cart-actions.tsx (100%) create mode 100644 framework/vendure/cart/use-cart.tsx create mode 100644 framework/vendure/cart/use-remove-item.tsx create mode 100644 framework/vendure/cart/use-update-item.tsx create mode 100644 framework/vendure/codegen.json create mode 100644 framework/vendure/commerce.config.json create mode 100644 framework/vendure/common/get-all-pages.ts create mode 100644 framework/vendure/common/get-page.ts create mode 100644 framework/vendure/common/get-site-info.ts create mode 100644 framework/vendure/customer/get-customer-wishlist.ts create mode 100644 framework/vendure/customer/index.ts create mode 100644 framework/vendure/customer/use-customer.tsx create mode 100644 framework/vendure/fetcher.ts create mode 100644 framework/vendure/index.tsx create mode 100644 framework/vendure/lib/array-to-tree.ts create mode 100644 framework/vendure/lib/fragments/cart-fragment.ts create mode 100644 framework/vendure/lib/fragments/search-result-fragment.ts create mode 100644 framework/vendure/lib/mutations/add-item-to-order-mutation.ts create mode 100644 framework/vendure/lib/mutations/adjust-order-line-mutation.ts create mode 100644 framework/vendure/lib/mutations/log-in-mutation.ts create mode 100644 framework/vendure/lib/mutations/log-out-mutation.ts create mode 100644 framework/vendure/lib/mutations/remove-order-line-mutation.ts create mode 100644 framework/vendure/lib/mutations/sign-up-mutation.ts create mode 100644 framework/vendure/lib/normalize.ts create mode 100644 framework/vendure/lib/queries/active-customer-query.ts create mode 100644 framework/vendure/lib/queries/get-all-product-paths-query.ts create mode 100644 framework/vendure/lib/queries/get-all-products-query.ts create mode 100644 framework/vendure/lib/queries/get-cart-query.ts create mode 100644 framework/vendure/lib/queries/get-collections-query.ts create mode 100644 framework/vendure/lib/queries/get-product-query.ts create mode 100644 framework/vendure/lib/queries/search-query.ts create mode 100644 framework/vendure/next.config.js create mode 100644 framework/vendure/product/get-all-product-paths.ts create mode 100644 framework/vendure/product/get-all-products.ts create mode 100644 framework/vendure/product/get-product.ts create mode 100644 framework/vendure/product/index.ts create mode 100644 framework/vendure/product/use-price.tsx create mode 100644 framework/vendure/product/use-search.tsx create mode 100644 framework/vendure/provider.ts create mode 100644 framework/vendure/schema.d.ts create mode 100644 framework/vendure/schema.graphql create mode 100644 framework/vendure/types.ts create mode 100644 framework/vendure/wishlist/use-add-item.tsx create mode 100644 framework/vendure/wishlist/use-remove-item.tsx create mode 100644 framework/vendure/wishlist/use-wishlist.tsx delete mode 100644 pages/blog.tsx create mode 100644 public/card.png diff --git a/.env.template b/.env.template index 73a8a6e3b..b68daaffe 100644 --- a/.env.template +++ b/.env.template @@ -1,5 +1,15 @@ +# Available providers: bigcommerce, shopify, swell +COMMERCE_PROVIDER= + BIGCOMMERCE_STOREFRONT_API_URL= BIGCOMMERCE_STOREFRONT_API_TOKEN= BIGCOMMERCE_STORE_API_URL= BIGCOMMERCE_STORE_API_TOKEN= -BIGCOMMERCE_STORE_API_CLIENT_ID= \ No newline at end of file +BIGCOMMERCE_STORE_API_CLIENT_ID= +BIGCOMMERCE_CHANNEL_ID= + +NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN= +NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN= + +NEXT_PUBLIC_SWELL_STORE_ID= +NEXT_PUBLIC_SWELL_PUBLIC_KEY= diff --git a/.gitignore b/.gitignore index 50d4285ba..22f1bf4f3 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ out/ # misc .DS_Store *.pem +.idea # debug npm-debug.log* diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..e1076edfa --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "useTabs": false +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..c83e26348 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["esbenp.prettier-vscode"] +} diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 7d1d95638..000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,4 +0,0 @@ -## Changelog - -- Select Variants Working -- Click on cart item title, closes the sidebar diff --git a/README.md b/README.md index ea6248c51..8f29734e5 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,10 @@ Start right now at [nextjs.org/commerce](https://nextjs.org/commerce) Demo live at: [demo.vercel.store](https://demo.vercel.store/) -This project is currently under development. +- Shopify Demo: https://shopify.vercel.store/ +- Swell Demo: https://swell.vercel.store/ +- BigCommerce Demo: https://bigcommerce.vercel.store/ +- Vendure Demo: https://vendure.vercel.store ## Features @@ -21,82 +24,66 @@ This project is currently under development. - Integrations - Integrate seamlessly with the most common ecommerce platforms. - Dark Mode Support -## Work in progress - -We're using Github Projects to keep track of issues in progress and todo's. Here is our [Board](https://github.com/vercel/commerce/projects/1) - ## Integrations -Next.js Commerce integrates out-of-the-box with BigCommerce. We plan to support all major ecommerce backends. +Next.js Commerce integrates out-of-the-box with BigCommerce and Shopify. We plan to support all major ecommerce backends. -## Goals +## Considerations -- **Next.js Commerce** should have a completely data **agnostic** UI -- **Aware of schema**: should ship with the right data schemas and types. -- All providers should return the right data types and schemas to blend correctly with Next.js Commerce. -- `@framework` will be the alias utilized in commerce and it will map to the ecommerce provider of preference- e.g BigCommerce, Shopify, Swell. All providers should expose the same standardized functions. _Note that the same applies for recipes using a CMS + an ecommerce provider._ +- `framework/commerce` contains all types, helpers and functions to be used as base to build a new **provider**. +- **Providers** live under `framework`'s root folder and they will extend Next.js Commerce types and functionality (`framework/commerce`). +- We have a **Features API** to ensure feature parity between the UI and the Provider. The UI should update accordingly and no extra code should be bundled. All extra configuration for features will live under `features` in `commerce.config.json` and if needed it can also be accessed programatically. +- Each **provider** should add its corresponding `next.config.js` and `commerce.config.json` adding specific data related to the provider. For example in case of BigCommerce, the images CDN and additional API routes. +- **Providers don't depend on anything that's specific to the application they're used in**. They only depend on `framework/commerce`, on their own framework folder and on some dependencies included in `package.json` -There is a `framework` folder in the root folder that will contain multiple ecommerce providers. +## Configuration -Additionally, we need to ensure feature parity (not all providers have e.g. wishlist) we will also have to build a feature API to disable/enable features in the UI. +### How to change providers -People actively working on this project: @okbel & @lfades. +Open `.env.local` and change the value of `COMMERCE_PROVIDER` to the provider you would like to use, then set the environment variables for that provider (use `.env.template` as the base). -## Framework +The setup for Shopify would look like this for example: -Framework is where the data comes from. It contains mostly hooks and functions. - -## Structure - -Main folder and its exposed functions - -- `product` - - usePrice - - useSearch - - getProduct - - getAllProducts -- `wishlist` - - useWishlist - - addWishlistItem - - removeWishlistItem -- `auth` - - useLogin - - useLogout - - useSignup -- `cart` - - - useCart - - useAddItem - - useRemoveItem - - useCartActions - - useUpdateItem - -- `config.json` -- README.md - -#### Example of correct usage of Commece Framework - -```js -import { useUI } from '@components/ui' -import { useCustomer } from '@framework/customer' -import { useAddItem, useWishlist, useRemoveItem } from '@framework/wishlist' +``` +COMMERCE_PROVIDER=shopify +NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxx +NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN=xxxxxxx.myshopify.com ``` -## Config +And check that the `tsconfig.json` resolves to the chosen provider: + +``` + "@framework": ["framework/shopify"], + "@framework/*": ["framework/shopify/*"] +``` + +That's it! ### Features -In order to make the UI entirely functional, we need to specify which features certain providers do not **provide**. +Every provider defines the features that it supports under `framework/{provider}/commerce.config.json` -**Disabling wishlist:** +#### How to turn Features on and off -``` -{ - "features": { - "wishlist": false +> NOTE: The selected provider should support the feature that you are toggling. (This means that you can't turn wishlist on if the provider doesn't support this functionality out the box) + +- Open `commerce.config.json` +- You'll see a config file like this: + ```json + { + "features": { + "wishlist": false + } } -} -``` + ``` +- Turn wishlist on by setting wishlist to true. +- Run the app and the wishlist functionality should be back on. + +### How to create a new provider + +Follow our docs for [Adding a new Commerce Provider](framework/commerce/new-provider.md). + +If you succeeded building a provider, submit a PR with a valid demo and we'll review it asap. ## Contribute @@ -106,11 +93,15 @@ Our commitment to Open Source can be found [here](https://vercel.com/oss). 2. Create a new branch `git checkout -b MY_BRANCH_NAME` 3. Install yarn: `npm install -g yarn` 4. Install the dependencies: `yarn` -5. Duplicate `.env.template` and rename it to `.env.local`. -6. Add proper store values to `.env.local`. +5. Duplicate `.env.template` and rename it to `.env.local` +6. Add proper store values to `.env.local` 7. Run `yarn dev` to build and watch for code changes -8. The development branch is `canary` (this is the branch pull requests should be made against). - On a release, `canary` branch is rebased into `master`. + +## Work in progress + +We're using Github Projects to keep track of issues in progress and todo's. Here is our [Board](https://github.com/vercel/commerce/projects/1) + +People actively working on this project: @okbel & @lfades. ## Troubleshoot @@ -128,6 +119,7 @@ BIGCOMMERCE_STOREFRONT_API_TOKEN=<> BIGCOMMERCE_STORE_API_URL=<> BIGCOMMERCE_STORE_API_TOKEN=<> BIGCOMMERCE_STORE_API_CLIENT_ID=<> +BIGCOMMERCE_CHANNEL_ID=<> ``` If your project was started with a "Deploy with Vercel" button, you can use Vercel's CLI to retrieve these credentials. diff --git a/framework/commerce/config.json b/commerce.config.json similarity index 100% rename from framework/commerce/config.json rename to commerce.config.json diff --git a/components/cart/CartItem/CartItem.tsx b/components/cart/CartItem/CartItem.tsx index bb57c3f25..e6820d32c 100644 --- a/components/cart/CartItem/CartItem.tsx +++ b/components/cart/CartItem/CartItem.tsx @@ -33,7 +33,7 @@ const CartItem = ({ currencyCode, }) - const updateItem = useUpdateItem(item) + const updateItem = useUpdateItem({ item }) const removeItem = useRemoveItem() const [quantity, setQuantity] = useState(item.quantity) const [removing, setRemoving] = useState(false) @@ -92,15 +92,18 @@ const CartItem = ({ })} {...rest} > -
{description}
- + Read it hereLoading...
+ if (error) return{error.message}
+ if (!data) return null + + returnLoading...
+ if (error) return{error.message}
+ if (isEmpty) returnThe cart is empty
+ + returnThe cart total is {data.totalPrice}
+} +``` + +### useAddItem + +Returns a function that adds a new item to the cart when called, if this is the first item it will create the cart: + +```jsx +import { useAddItem } from '@framework/cart' + +const AddToCartButton = ({ productId, variantId }) => { + const addItem = useAddItem() + + const addToCart = async () => { + await addItem({ + productId, + variantId, + }) + } + + return +} +``` + +### useUpdateItem + +Returns a function that updates a current item in the cart when called, usually the quantity. + +```jsx +import { useUpdateItem } from '@framework/cart' + +const CartItemQuantity = ({ item }) => { + const [quantity, setQuantity] = useState(item.quantity) + const updateItem = useUpdateItem({ item }) + + const updateQuantity = async (e) => { + const val = e.target.value + + setQuantity(val) + await updateItem({ quantity: val }) + } + + return ( + + ) +} +``` + +If the `quantity` is lower than 1 the item will be removed from the cart. + +### useRemoveItem + +Returns a function that removes an item in the cart when called: + +```jsx +import { useRemoveItem } from '@framework/cart' + +const RemoveButton = ({ item }) => { + const removeItem = useRemoveItem() + const handleRemove = async () => { + await removeItem(item) + } + + return +} +``` + +## Wishlist Hooks + +Wishlist hooks work just like [cart hooks](#cart-hooks). Feel free to check how those work first. + +The example below shows how to use the `useWishlist`, `useAddItem` and `useRemoveItem` hooks: + +```jsx +import { useWishlist, useAddItem, useRemoveItem } from '@framework/wishlist' + +const WishlistButton = ({ productId, variant }) => { + const addItem = useAddItem() + const removeItem = useRemoveItem() + const { data, isLoading, isEmpty, error } = useWishlist() + + if (isLoading) returnLoading...
+ if (error) return{error.message}
+ if (isEmpty) returnThe wihslist is empty
+ + const { data: customer } = useCustomer() + const itemInWishlist = data?.items?.find( + (item) => item.product_id === productId && item.variant_id === variant.id + ) + + const handleWishlistChange = async (e) => { + e.preventDefault() + if (!customer) return + + if (itemInWishlist) { + await removeItem({ id: itemInWishlist.id }) + } else { + await addItem({ + productId, + variantId: variant.id, + }) + } + } + + return ( + + ) +} +``` + +## Commerce API + +While commerce hooks focus on client side data fetching and interactions, the commerce API focuses on static content generation for pages and API endpoints in a Node.js context. + +> The commerce API is currently going through a refactor in https://github.com/vercel/commerce/pull/252 - We'll update the docs once the API is released. + +## More + +Feel free to read through the source for more usage, and check the commerce vercel demo and commerce repo for usage examples: ([demo.vercel.store](https://demo.vercel.store/)) ([repo](https://github.com/vercel/commerce)) diff --git a/framework/commerce/api/index.ts b/framework/commerce/api/index.ts index 77b2eeb7e..c15ca7a79 100644 --- a/framework/commerce/api/index.ts +++ b/framework/commerce/api/index.ts @@ -2,6 +2,7 @@ import type { RequestInit, Response } from '@vercel/fetch' export interface CommerceAPIConfig { locale?: string + locales?: string[] commerceUrl: string apiToken: string cartCookie: string diff --git a/framework/commerce/auth/use-login.tsx b/framework/commerce/auth/use-login.tsx new file mode 100644 index 000000000..cc4cf6a73 --- /dev/null +++ b/framework/commerce/auth/use-login.tsx @@ -0,0 +1,19 @@ +import { useHook, useMutationHook } from '../utils/use-hook' +import { mutationFetcher } from '../utils/default-fetcher' +import type { MutationHook, HookFetcherFn } from '../utils/types' +import type { Provider } from '..' + +export type UseLogin< + H extends MutationHook= Prop< - Prop
, - 'useAddItem' -> - -// Input expected by the action returned by the `useAddItem` hook -export type UseAddItemInput
= UseHookInput< - UseAddItemHandler
-> - -export type UseAddItemResult
= ReturnType<
- UseHookResponse = Partial<
- UseAddItemInput
-> extends UseAddItemInput
- ? (input?: UseAddItemInput ) => (input: Input) => UseAddItemResult
- : (input: UseAddItemInput ) => (input: Input) => UseAddItemResult
+export type UseAddItem<
+ H extends MutationHook (
- input: UseAddItemInput
-) {
- const { providerRef, fetcherRef } = useCommerce ()
-
- const provider = providerRef.current
- const opts = provider.cart?.useAddItem
-
- const fetcherFn = opts?.fetcher ?? fetcher
- const useHook = opts?.useHook ?? (() => () => {})
- const fetchFn = provider.fetcher ?? fetcherRef.current
- const action = useHook({ input })
-
- return useCallback(
- function addItem(input: Input) {
- return action({
- input,
- fetch({ input }) {
- return fetcherFn({
- input,
- options: opts!.fetchOptions,
- fetch: fetchFn,
- })
- },
- })
- },
- [input, fetchFn, opts?.fetchOptions]
- )
-}
+export default useAddItem
diff --git a/framework/commerce/cart/use-cart-actions.tsx b/framework/commerce/cart/use-cart-actions.tsx
deleted file mode 100644
index 3ba4b2e1a..000000000
--- a/framework/commerce/cart/use-cart-actions.tsx
+++ /dev/null
@@ -1,17 +0,0 @@
-import type { HookFetcher, HookFetcherOptions } from '../utils/types'
-import useAddItem from './use-add-item'
-import useRemoveItem from './use-remove-item'
-import useUpdateItem from './use-update-item'
-
-// This hook is probably not going to be used, but it's here
-// to show how a commerce should be structuring it
-export default function useCartActions = Prop<
- Prop ,
- 'useCart'
->
-
-export type UseCartInput = UseHookInput = UseHookResponse<
- UseCartHandler
->
-
-export type UseCart = Partial<
- UseCartInput
-> extends UseCartInput
- ? (input?: UseCartInput ) => CartResponse
- : (input: UseCartInput ) => CartResponse
+export type UseCart<
+ H extends SWRHook (
- input: UseCartInput = {}
-) {
- const { providerRef, fetcherRef, cartCookie } = useCommerce ()
-
- const provider = providerRef.current
- const opts = provider.cart?.useCart
-
- const fetcherFn = opts?.fetcher ?? fetcher
- const useHook = opts?.useHook ?? ((ctx) => ctx.useData())
+const fn = (provider: Provider) => provider.cart?.useCart!
+const useCart: UseCart = (input) => {
+ const hook = useHook(fn)
+ const { cartCookie } = useCommerce()
+ const fetcherFn = hook.fetcher ?? fetcher
const wrapper: typeof fetcher = (context) => {
context.input.cartId = Cookies.get(cartCookie)
return fetcherFn(context)
}
-
- return useHook({
- input,
- useData(ctx) {
- const response = useData(
- { ...opts!, fetcher: wrapper },
- ctx?.input ?? [],
- provider.fetcher ?? fetcherRef.current,
- ctx?.swrOptions ?? input.swrOptions
- )
- return response
- },
- })
+ return useSWRHook({ ...hook, fetcher: wrapper })(input)
}
+
+export default useCart
diff --git a/framework/commerce/cart/use-remove-item.tsx b/framework/commerce/cart/use-remove-item.tsx
index 8a63b1b73..a9d1b37d2 100644
--- a/framework/commerce/cart/use-remove-item.tsx
+++ b/framework/commerce/cart/use-remove-item.tsx
@@ -1,10 +1,35 @@
-import useAction from '../utils/use-action'
+import { useHook, useMutationHook } from '../utils/use-hook'
+import { mutationFetcher } from '../utils/default-fetcher'
+import type { HookFetcherFn, MutationHook } from '../utils/types'
+import type { Cart, LineItem, RemoveCartItemBody } from '../types'
+import type { Provider } from '..'
-// Input expected by the action returned by the `useRemoveItem` hook
-export interface RemoveItemInput {
+/**
+ * Input expected by the action returned by the `useRemoveItem` hook
+ */
+export type RemoveItemInput = {
id: string
}
-const useRemoveItem = useAction
+export type UseRemoveItem<
+ H extends MutationHook = Prop<
- Prop ,
- 'useCustomer'
->
+export type UseCustomer<
+ H extends SWRHook = UseHookInput<
- UseCustomerHandler
->
+export const fetcher: HookFetcherFn = UseHookResponse<
- UseCustomerHandler
->
+const fn = (provider: Provider) => provider.customer?.useCustomer!
-export type UseCustomer = Partial<
- UseCustomerInput
-> extends UseCustomerInput
- ? (input?: UseCustomerInput ) => CustomerResponse
- : (input: UseCustomerInput ) => CustomerResponse
-
-export const fetcher = defaultFetcher as HookFetcherFn (
- input: UseCustomerInput = {}
-) {
- const { providerRef, fetcherRef } = useCommerce ()
-
- const provider = providerRef.current
- const opts = provider.customer?.useCustomer
-
- const fetcherFn = opts?.fetcher ?? fetcher
- const useHook = opts?.useHook ?? ((ctx) => ctx.useData())
-
- return useHook({
- input,
- useData(ctx) {
- const response = useData(
- { ...opts!, fetcher: fetcherFn },
- ctx?.input ?? [],
- provider.fetcher ?? fetcherRef.current,
- ctx?.swrOptions ?? input.swrOptions
- )
- return response
- },
- })
+const useCustomer: UseCustomer = (input) => {
+ const hook = useHook(fn)
+ return useSWRHook({ fetcher, ...hook })(input)
}
+
+export default useCustomer
diff --git a/framework/commerce/index.tsx b/framework/commerce/index.tsx
index 243fba2db..07bf74a22 100644
--- a/framework/commerce/index.tsx
+++ b/framework/commerce/index.tsx
@@ -6,7 +6,7 @@ import {
useMemo,
useRef,
} from 'react'
-import { Fetcher, HookHandler, MutationHandler } from './utils/types'
+import { Fetcher, SWRHook, MutationHook } from './utils/types'
import type { FetchCartInput } from './cart/use-cart'
import type { Cart, Wishlist, Customer, SearchProductsData } from './types'
@@ -15,17 +15,26 @@ const Commerce = createContext = Prop<
- Prop ,
- 'useSearch'
->
+export type UseSearch<
+ H extends SWRHook = UseHookInput<
- UseSearchHandler
->
+export const fetcher: HookFetcherFn = UseHookResponse<
- UseSearchHandler
->
+const fn = (provider: Provider) => provider.products?.useSearch!
-export type UseSearch = Partial<
- UseSeachInput
-> extends UseSeachInput
- ? (input?: UseSeachInput ) => SearchResponse
- : (input: UseSeachInput ) => SearchResponse
-
-export const fetcher = defaultFetcher as HookFetcherFn (
- input: UseSeachInput = {}
-) {
- const { providerRef, fetcherRef } = useCommerce ()
-
- const provider = providerRef.current
- const opts = provider.products?.useSearch
-
- const fetcherFn = opts?.fetcher ?? fetcher
- const useHook = opts?.useHook ?? ((ctx) => ctx.useData())
-
- return useHook({
- input,
- useData(ctx) {
- const response = useData(
- { ...opts!, fetcher: fetcherFn },
- ctx?.input ?? [],
- provider.fetcher ?? fetcherRef.current,
- ctx?.swrOptions ?? input.swrOptions
- )
- return response
- },
- })
+const useSearch: UseSearch = (input) => {
+ const hook = useHook(fn)
+ return useSWRHook({ fetcher, ...hook })(input)
}
+
+export default useSearch
diff --git a/framework/commerce/types.ts b/framework/commerce/types.ts
index 0ae766095..86361fd9f 100644
--- a/framework/commerce/types.ts
+++ b/framework/commerce/types.ts
@@ -1,10 +1,6 @@
-import type { Wishlist as BCWishlist } from '@framework/api/wishlist'
-import type { Customer as BCCustomer } from '@framework/api/customers'
-import type { SearchProductsData as BCSearchProductsData } from '@framework/api/catalog/products'
-
-export type CommerceProviderConfig = {
- features: Record ()
+ const provider = providerRef.current
+ return fn(provider)
+}
+
+export function useSWRHook = Prop<
- Prop ,
- 'useWishlist'
->
+export type UseWishlist<
+ H extends SWRHook = UseHookInput<
- UseWishlistHandler
->
+export const fetcher: HookFetcherFn = UseHookResponse<
- UseWishlistHandler
->
+const fn = (provider: Provider) => provider.wishlist?.useWishlist!
-export type UseWishlist = Partial<
- UseWishlistInput
-> extends UseWishlistInput
- ? (input?: UseWishlistInput ) => WishlistResponse
- : (input: UseWishlistInput ) => WishlistResponse
-
-export const fetcher = defaultFetcher as HookFetcherFn (
- input: UseWishlistInput = {}
-) {
- const { providerRef, fetcherRef } = useCommerce ()
-
- const provider = providerRef.current
- const opts = provider.wishlist?.useWishlist
-
- const fetcherFn = opts?.fetcher ?? fetcher
- const useHook = opts?.useHook ?? ((ctx) => ctx.useData())
-
- return useHook({
- input,
- useData(ctx) {
- const response = useData(
- { ...opts!, fetcher: fetcherFn },
- ctx?.input ?? [],
- provider.fetcher ?? fetcherRef.current,
- ctx?.swrOptions ?? input.swrOptions
- )
- return response
- },
- })
+const useWishlist: UseWishlist = (input) => {
+ const hook = useHook(fn)
+ return useSWRHook({ fetcher, ...hook })(input)
}
+
+export default useWishlist
diff --git a/framework/shopify/.env.template b/framework/shopify/.env.template
new file mode 100644
index 000000000..74f446835
--- /dev/null
+++ b/framework/shopify/.env.template
@@ -0,0 +1,4 @@
+COMMERCE_PROVIDER=shopify
+
+NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN=
+NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN=
diff --git a/framework/shopify/README.md b/framework/shopify/README.md
new file mode 100644
index 000000000..d67111a41
--- /dev/null
+++ b/framework/shopify/README.md
@@ -0,0 +1,123 @@
+## Shopify Provider
+
+**Demo:** https://shopify.demo.vercel.store/
+
+Before getting starter, a [Shopify](https://www.shopify.com/) account and store is required before using the provider.
+
+Next, copy the `.env.template` file in this directory to `.env.local` in the main directory (which will be ignored by Git):
+
+```bash
+cp framework/shopify/.env.template .env.local
+```
+
+Then, set the environment variables in `.env.local` to match the ones from your store.
+
+## Contribute
+
+Our commitment to Open Source can be found [here](https://vercel.com/oss).
+
+If you find an issue with the provider or want a new feature, feel free to open a PR or [create a new issue](https://github.com/vercel/commerce/issues).
+
+## Modifications
+
+These modifications are temporarily until contributions are made to remove them.
+
+### Adding item to Cart
+
+```js
+// components/product/ProductView/ProductView.tsx
+const ProductView: FC