@graphcommerce/magento-store 5.1.0 → 5.1.1-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 5.1.1-canary.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1762](https://github.com/graphcommerce-org/graphcommerce/pull/1762) [`0dcbc432a`](https://github.com/graphcommerce-org/graphcommerce/commit/0dcbc432a4595d8758b58e9f5871eb0614ec3d7e) - Requested URLs to product pages incorrectly return a notFound error ([@paales](https://github.com/paales))
8
+
9
+ - [#1762](https://github.com/graphcommerce-org/graphcommerce/pull/1762) [`1d03b8b1e`](https://github.com/graphcommerce-org/graphcommerce/commit/1d03b8b1effbe45215e16add45e82f4632584bc9) - Addtional implementations of the RoutableInterface caused redirects to fail ([@paales](https://github.com/paales))
10
+
3
11
  ## 5.1.0
4
12
 
5
13
  ### Minor Changes
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-store",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "5.1.0",
5
+ "version": "5.1.1-canary.0",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,15 +12,15 @@
12
12
  }
13
13
  },
14
14
  "devDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "5.1.0",
16
- "@graphcommerce/prettier-config-pwa": "5.1.0",
17
- "@graphcommerce/typescript-config-pwa": "5.1.0"
15
+ "@graphcommerce/eslint-config-pwa": "5.1.1-canary.0",
16
+ "@graphcommerce/prettier-config-pwa": "5.1.1-canary.0",
17
+ "@graphcommerce/typescript-config-pwa": "5.1.1-canary.0"
18
18
  },
19
19
  "dependencies": {
20
- "@graphcommerce/graphql": "5.1.0",
21
- "@graphcommerce/graphql-mesh": "5.1.0",
22
- "@graphcommerce/image": "5.1.0",
23
- "@graphcommerce/next-ui": "5.1.0"
20
+ "@graphcommerce/graphql": "5.1.1-canary.0",
21
+ "@graphcommerce/graphql-mesh": "5.1.1-canary.0",
22
+ "@graphcommerce/image": "5.1.1-canary.0",
23
+ "@graphcommerce/next-ui": "5.1.1-canary.0"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@lingui/react": "^3.13.2",
@@ -1,6 +1,6 @@
1
1
  import { ParsedUrlQuery } from 'querystring'
2
2
  import { ApolloClient, flushMeasurePerf, NormalizedCacheObject } from '@graphcommerce/graphql'
3
- import { nonNullable } from '@graphcommerce/next-ui'
3
+ import { nonNullable, isTypename } from '@graphcommerce/next-ui'
4
4
  import { Redirect } from 'next'
5
5
  import { StoreConfigDocument } from '../StoreConfig.gql'
6
6
  import { defaultLocale } from '../localeToStore'
@@ -66,23 +66,43 @@ export async function redirectOrNotFound(
66
66
 
67
67
  const routeData = await Promise.any(routePromises)
68
68
 
69
+ const relativeUrl =
70
+ routeData.route?.relative_url && routeData.route?.relative_url !== urlKey
71
+ ? routeData.route.relative_url
72
+ : undefined
73
+
69
74
  // There is a URL, so we need to check if it can be found in the database.
70
75
  const permanent = routeData.route?.redirect_code === 301
71
76
 
72
- // Add special handling for the homepage.
73
- if (routeData.route?.url_key && routeData.route?.__typename.endsWith('Product')) {
77
+ if (!routeData.route) return notFound()
78
+
79
+ if (
80
+ isTypename(routeData.route, [
81
+ 'ConfigurableProduct',
82
+ 'BundleProduct',
83
+ 'SimpleProduct',
84
+ 'VirtualProduct',
85
+ 'DownloadableProduct',
86
+ ])
87
+ ) {
74
88
  if (process.env.NEXT_PUBLIC_SINGLE_PRODUCT_PAGE !== '1') {
75
89
  console.warn('Redirects are only supported for NEXT_PUBLIC_SINGLE_PRODUCT_PAGE')
76
90
  }
77
91
 
92
+ if (relativeUrl) {
93
+ return redirect(`/p/${relativeUrl}`, permanent, locale)
94
+ }
95
+
78
96
  if (routeData.products?.items?.find((i) => i?.url_key === routeData.route?.url_key)) {
79
97
  return redirect(`/p/${routeData.route?.url_key}`, permanent, locale)
80
98
  }
99
+
81
100
  return notFound()
82
101
  }
83
102
 
84
- // The default URL for categories or CMS pages is handled by the pages/[...url].tsx file.
85
- if (routeData.route?.url_key) return redirect(`/${routeData.route?.url_key}`, permanent, locale)
103
+ if (relativeUrl) {
104
+ return redirect(`/${relativeUrl}`, permanent, locale)
105
+ }
86
106
  } catch (e) {
87
107
  // We're done
88
108
  }