@graphcommerce/magento-store 9.0.0-canary.99 → 9.0.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 +58 -1027
- package/Money.tsx +10 -8
- package/PageMeta.tsx +3 -5
- package/components/GlobalHead/GlobalHead.tsx +2 -4
- package/components/StoreSwitcherButton/StoreSwitcherButton.tsx +3 -2
- package/components/StoreSwitcherList/StoreSwitcherList.tsx +5 -12
- package/hooks/useFindCountry.ts +2 -1
- package/hooks/useFindRegion.ts +5 -1
- package/package.json +8 -8
- package/test/apolloClientStore.fixture.ts +3 -1
- package/utils/redirectOrNotFound.ts +16 -22
- package/plugins/magentoStoreGraphqlConfig.ts +0 -39
package/Money.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useQuery } from '@graphcommerce/graphql'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { CurrencyFormatProps } from '@graphcommerce/next-ui'
|
|
3
|
+
import { CurrencyFormat } from '@graphcommerce/next-ui'
|
|
4
|
+
import type { MoneyFragment } from './Money.gql'
|
|
4
5
|
import { StoreConfigDocument } from './StoreConfig.gql'
|
|
5
6
|
|
|
6
7
|
type OverridableProps = {
|
|
@@ -12,18 +13,19 @@ export type MoneyProps = MoneyFragment & OverridableProps
|
|
|
12
13
|
|
|
13
14
|
export function Money(props: MoneyProps) {
|
|
14
15
|
const { currency, value, round = false, formatOptions } = props
|
|
15
|
-
const
|
|
16
|
+
const baseCurrencyCode = useQuery(StoreConfigDocument).data?.storeConfig?.base_currency_code
|
|
16
17
|
const digits = (value ?? 0) % 1 !== 0
|
|
18
|
+
const maximumFractionDigits = round && !digits ? 0 : 2
|
|
19
|
+
const currencyCode = currency ?? baseCurrencyCode ?? ''
|
|
17
20
|
|
|
18
21
|
if (typeof value === 'undefined' || value === null) return null
|
|
19
22
|
|
|
20
23
|
return (
|
|
21
24
|
<CurrencyFormat
|
|
22
|
-
currency={
|
|
23
|
-
maximumFractionDigits={
|
|
25
|
+
currency={currencyCode}
|
|
26
|
+
maximumFractionDigits={maximumFractionDigits}
|
|
24
27
|
{...formatOptions}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
</CurrencyFormat>
|
|
28
|
+
value={value}
|
|
29
|
+
/>
|
|
28
30
|
)
|
|
29
31
|
}
|
package/PageMeta.tsx
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { useQuery } from '@graphcommerce/graphql'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
PageMetaProps as NextPageMetaProps,
|
|
5
|
-
} from '@graphcommerce/next-ui'
|
|
2
|
+
import type { PageMetaProps as NextPageMetaProps } from '@graphcommerce/next-ui'
|
|
3
|
+
import { PageMeta as NextPageMeta } from '@graphcommerce/next-ui'
|
|
6
4
|
import { StoreConfigDocument } from './StoreConfig.gql'
|
|
7
5
|
|
|
8
|
-
type PageMetaProps = Omit<NextPageMetaProps, 'canonical'> & {
|
|
6
|
+
export type PageMetaProps = Omit<NextPageMetaProps, 'canonical'> & {
|
|
9
7
|
canonical?: string
|
|
10
8
|
}
|
|
11
9
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { useQuery } from '@graphcommerce/graphql'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
GlobalHeadProps as GlobalHeadPropsBase,
|
|
5
|
-
} from '@graphcommerce/next-ui'
|
|
2
|
+
import type { GlobalHeadProps as GlobalHeadPropsBase } from '@graphcommerce/next-ui'
|
|
3
|
+
import { GlobalHead as GlobalHeadBase } from '@graphcommerce/next-ui'
|
|
6
4
|
import { StoreConfigDocument } from '../../StoreConfig.gql'
|
|
7
5
|
|
|
8
6
|
export type GlobalHeadProps = Omit<GlobalHeadPropsBase, 'name'>
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { useQuery } from '@graphcommerce/graphql'
|
|
2
2
|
import { FlagAvatar, extendableComponent } from '@graphcommerce/next-ui'
|
|
3
|
-
import {
|
|
3
|
+
import type { SxProps, Theme } from '@mui/material'
|
|
4
|
+
import { Button } from '@mui/material'
|
|
4
5
|
import { useRouter } from 'next/router'
|
|
5
6
|
import { StoreConfigDocument } from '../../StoreConfig.gql'
|
|
6
7
|
|
|
7
8
|
export type StoreSwitcherButtonProps = { sx?: SxProps<Theme> }
|
|
8
9
|
|
|
9
|
-
const name = 'StoreSwitcherButton'
|
|
10
|
+
const name = 'StoreSwitcherButton'
|
|
10
11
|
const parts = ['root', 'avatar'] as const
|
|
11
12
|
const { classes } = extendableComponent(name, parts)
|
|
12
13
|
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
/* eslint-disable spaced-comment */
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
ListItemText,
|
|
6
|
-
Collapse,
|
|
7
|
-
ListItemAvatar,
|
|
8
|
-
SxProps,
|
|
9
|
-
Theme,
|
|
10
|
-
ListItemButton,
|
|
11
|
-
} from '@mui/material'
|
|
2
|
+
import { FlagAvatar, NextLink, extendableComponent } from '@graphcommerce/next-ui'
|
|
3
|
+
import type { SxProps, Theme } from '@mui/material'
|
|
4
|
+
import { Collapse, List, ListItemAvatar, ListItemButton, ListItemText } from '@mui/material'
|
|
12
5
|
import React from 'react'
|
|
13
6
|
import { localeToStore, storeToLocale } from '../../localeToStore'
|
|
14
|
-
import { StoreSwitcherListQuery } from './StoreSwitcherList.gql'
|
|
7
|
+
import type { StoreSwitcherListQuery } from './StoreSwitcherList.gql'
|
|
15
8
|
|
|
16
9
|
type Store = NonNullable<NonNullable<StoreSwitcherListQuery['availableStores']>[0]>
|
|
17
10
|
|
|
@@ -20,7 +13,7 @@ export type StoreSwitcherListProps = {
|
|
|
20
13
|
sx?: SxProps<Theme>
|
|
21
14
|
} & StoreSwitcherListQuery
|
|
22
15
|
|
|
23
|
-
const name = 'StoreSwitcherList'
|
|
16
|
+
const name = 'StoreSwitcherList'
|
|
24
17
|
const parts = ['list', 'listItem', 'listItemIndented', 'avatar'] as const
|
|
25
18
|
const { classes } = extendableComponent(name, parts)
|
|
26
19
|
|
package/hooks/useFindCountry.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useQuery } from '@graphcommerce/graphql'
|
|
2
|
-
import {
|
|
2
|
+
import type { CountryRegionsQuery } from '../queries/CountryRegions.gql'
|
|
3
|
+
import { CountryRegionsDocument } from '../queries/CountryRegions.gql'
|
|
3
4
|
|
|
4
5
|
export function useFindCountry(
|
|
5
6
|
countryCode?: string | null,
|
package/hooks/useFindRegion.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { Maybe, Region } from '@graphcommerce/graphql-mesh'
|
|
1
|
+
import type { Maybe, Region } from '@graphcommerce/graphql-mesh'
|
|
2
2
|
import { useFindCountry } from './useFindCountry'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
4
8
|
export function useFindRegion(
|
|
5
9
|
countryCode?: Maybe<string>,
|
|
6
10
|
regionId?: Maybe<number>,
|
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": "9.0.0
|
|
5
|
+
"version": "9.0.0",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@graphcommerce/eslint-config-pwa": "^9.0.0
|
|
16
|
-
"@graphcommerce/graphql": "^9.0.0
|
|
17
|
-
"@graphcommerce/graphql-mesh": "^9.0.0
|
|
18
|
-
"@graphcommerce/image": "^9.0.0
|
|
19
|
-
"@graphcommerce/next-ui": "^9.0.0
|
|
20
|
-
"@graphcommerce/prettier-config-pwa": "^9.0.0
|
|
21
|
-
"@graphcommerce/typescript-config-pwa": "^9.0.0
|
|
15
|
+
"@graphcommerce/eslint-config-pwa": "^9.0.0",
|
|
16
|
+
"@graphcommerce/graphql": "^9.0.0",
|
|
17
|
+
"@graphcommerce/graphql-mesh": "^9.0.0",
|
|
18
|
+
"@graphcommerce/image": "^9.0.0",
|
|
19
|
+
"@graphcommerce/next-ui": "^9.0.0",
|
|
20
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.0",
|
|
21
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.0",
|
|
22
22
|
"@lingui/core": "^4.2.1",
|
|
23
23
|
"@lingui/macro": "^4.2.1",
|
|
24
24
|
"@lingui/react": "^4.2.1",
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
+
|
|
2
3
|
/* eslint-disable no-empty-pattern */
|
|
3
|
-
import {
|
|
4
|
+
import type { NormalizedCacheObject } from '@graphcommerce/graphql'
|
|
5
|
+
import { ApolloClient, InMemoryCache } from '@graphcommerce/graphql'
|
|
4
6
|
import { test as base } from '@playwright/test'
|
|
5
7
|
import { localeToStore } from '../localeToStore'
|
|
6
8
|
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '@graphcommerce/graphql'
|
|
8
|
-
import { nonNullable, isTypename, storefrontConfig } from '@graphcommerce/next-ui'
|
|
9
|
-
import { Redirect } from 'next'
|
|
10
|
-
import { StoreConfigQuery } from '../StoreConfig.gql'
|
|
1
|
+
import type { ApolloClient, ApolloQueryResult, NormalizedCacheObject } from '@graphcommerce/graphql'
|
|
2
|
+
import { flushMeasurePerf } from '@graphcommerce/graphql'
|
|
3
|
+
import { isTypename, nonNullable, storefrontConfig } from '@graphcommerce/next-ui'
|
|
4
|
+
import type { Redirect } from 'next'
|
|
5
|
+
import type { ParsedUrlQuery } from 'querystring'
|
|
6
|
+
import type { StoreConfigQuery } from '../StoreConfig.gql'
|
|
11
7
|
import { defaultLocale } from '../localeToStore'
|
|
12
|
-
import {
|
|
8
|
+
import type { HandleRedirectQuery } from './HandleRedirect.gql'
|
|
9
|
+
import { HandleRedirectDocument } from './HandleRedirect.gql'
|
|
13
10
|
|
|
14
11
|
export type RedirectOr404Return = Promise<
|
|
15
12
|
| { redirect: Redirect; revalidate?: number | boolean }
|
|
@@ -18,8 +15,7 @@ export type RedirectOr404Return = Promise<
|
|
|
18
15
|
|
|
19
16
|
const notFound = (from: string, reason: string) => {
|
|
20
17
|
flushMeasurePerf()
|
|
21
|
-
|
|
22
|
-
console.log(`[redirectOrNotFound: /${from}] ${reason}`)
|
|
18
|
+
console.info(`[redirectOrNotFound: /${from}] ${reason}`)
|
|
23
19
|
return { notFound: true, revalidate: 60 * 20 } as const
|
|
24
20
|
}
|
|
25
21
|
|
|
@@ -33,7 +29,7 @@ export const redirectTo = (
|
|
|
33
29
|
permanent: boolean,
|
|
34
30
|
locale?: string,
|
|
35
31
|
): { redirect: Redirect; revalidate?: number | boolean } => {
|
|
36
|
-
console.
|
|
32
|
+
console.info(
|
|
37
33
|
`[redirectTo]: ${permanent ? 'Permanent' : 'Temporary'} redirect to ${urlPrefix(locale)}${to}`,
|
|
38
34
|
)
|
|
39
35
|
return {
|
|
@@ -49,8 +45,7 @@ const redirect = (from: string, to: string, permanent: boolean, locale?: string)
|
|
|
49
45
|
|
|
50
46
|
flushMeasurePerf()
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
console.log(
|
|
48
|
+
console.info(
|
|
54
49
|
`[redirectOrNotFound: ${prefix ? `/${prefix}` : ''}/${from}] ${
|
|
55
50
|
permanent ? 'Permanent' : 'Temporary'
|
|
56
51
|
} redirect to ${destination}`,
|
|
@@ -89,7 +84,7 @@ export async function redirectOrNotFound(
|
|
|
89
84
|
|
|
90
85
|
// Handle the case where we transition from using the default .html suffix, to not using one
|
|
91
86
|
if (from.endsWith('.html')) {
|
|
92
|
-
candidates.add(from.slice(0, -
|
|
87
|
+
candidates.add(from.slice(0, -'.html'.length))
|
|
93
88
|
}
|
|
94
89
|
|
|
95
90
|
const routePromises = [...candidates].filter(Boolean).map(
|
|
@@ -143,20 +138,19 @@ export async function redirectOrNotFound(
|
|
|
143
138
|
|
|
144
139
|
const url_key = routeData.route?.url_key
|
|
145
140
|
if (!routeData.products?.items?.find((i) => i?.url_key === url_key))
|
|
146
|
-
return notFound(from,
|
|
141
|
+
return notFound(from, "Route found, but product isn't returned from products query")
|
|
147
142
|
|
|
148
143
|
return redirect(from, `${productRoute}${url_key}`, true, locale)
|
|
149
144
|
}
|
|
150
145
|
|
|
151
146
|
if (redirectUrl) return redirect(from, `/${redirectUrl}`, permanent, locale)
|
|
152
147
|
|
|
153
|
-
return notFound(from,
|
|
148
|
+
return notFound(from, 'Route found, but no redirect URL')
|
|
154
149
|
} catch (e) {
|
|
155
150
|
if (e instanceof Error) {
|
|
156
151
|
return notFound(from, `Error while redirecting: ${e.message}`)
|
|
157
152
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return notFound(from, `Error while redirecting`)
|
|
153
|
+
console.info(e)
|
|
154
|
+
return notFound(from, 'Error while redirecting')
|
|
161
155
|
}
|
|
162
156
|
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { setContext, type graphqlConfig as graphqlConfigType } from '@graphcommerce/graphql'
|
|
2
|
-
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
3
|
-
|
|
4
|
-
export const config: PluginConfig = {
|
|
5
|
-
type: 'function',
|
|
6
|
-
module: '@graphcommerce/graphql',
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
declare module '@graphcommerce/graphql/config' {
|
|
10
|
-
interface PreviewData {
|
|
11
|
-
magentoPreviewVersion?: string
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const graphqlConfig: FunctionPlugin<typeof graphqlConfigType> = (prev, conf) => {
|
|
16
|
-
const results = prev(conf)
|
|
17
|
-
|
|
18
|
-
const previewVersion = conf.previewData?.magentoPreviewVersion
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
...results,
|
|
22
|
-
links: [
|
|
23
|
-
...results.links,
|
|
24
|
-
setContext((_, context) => {
|
|
25
|
-
if (!context.headers) context.headers = {}
|
|
26
|
-
context.headers.store = conf.storefront.magentoStoreCode
|
|
27
|
-
if (conf.preview) {
|
|
28
|
-
// To disable caching from the backend, we provide a bogus cache ID.
|
|
29
|
-
context.headers['x-magento-cache-id'] =
|
|
30
|
-
`random-cache-id${Math.random().toString(36).slice(2)}`
|
|
31
|
-
if (previewVersion) {
|
|
32
|
-
context.headers['preview-version'] = previewVersion
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return context
|
|
36
|
-
}),
|
|
37
|
-
],
|
|
38
|
-
}
|
|
39
|
-
}
|