diff --git a/@generated/graphql/index.ts b/@generated/graphql/index.ts index 5466e7cce..5b6f2c60d 100644 --- a/@generated/graphql/index.ts +++ b/@generated/graphql/index.ts @@ -54,9 +54,9 @@ export type Directory = Node & { atime: Scalars['Date'] atimeMs: Scalars['Float'] base: Scalars['String'] + birthTime: Scalars['Date'] /** @deprecated Use `birthTime` instead */ birthtime: Maybe - birthTime: Scalars['Date'] /** @deprecated Use `birthTime` instead */ birthtimeMs: Maybe changeTime: Scalars['Date'] @@ -183,8 +183,8 @@ export type DirectoryFieldsEnum = | 'atime' | 'atimeMs' | 'base' - | 'birthtime' | 'birthTime' + | 'birthtime' | 'birthtimeMs' | 'changeTime' | 'children' @@ -302,8 +302,8 @@ export type DirectoryFilterInput = { atime: InputMaybe atimeMs: InputMaybe base: InputMaybe - birthtime: InputMaybe birthTime: InputMaybe + birthtime: InputMaybe birthtimeMs: InputMaybe changeTime: InputMaybe children: InputMaybe @@ -381,9 +381,9 @@ export type File = Node & { atime: Scalars['Date'] atimeMs: Scalars['Float'] base: Scalars['String'] + birthTime: Scalars['Date'] /** @deprecated Use `birthTime` instead */ birthtime: Maybe - birthTime: Scalars['Date'] /** @deprecated Use `birthTime` instead */ birthtimeMs: Maybe changeTime: Scalars['Date'] @@ -510,8 +510,8 @@ export type FileFieldsEnum = | 'atime' | 'atimeMs' | 'base' - | 'birthtime' | 'birthTime' + | 'birthtime' | 'birthtimeMs' | 'changeTime' | 'children' @@ -629,8 +629,8 @@ export type FileFilterInput = { atime: InputMaybe atimeMs: InputMaybe base: InputMaybe - birthtime: InputMaybe birthTime: InputMaybe + birthtime: InputMaybe birthtimeMs: InputMaybe changeTime: InputMaybe children: InputMaybe @@ -729,39 +729,6 @@ export type GatsbyImagePlaceholder = | 'NONE' | 'TRACED_SVG' -export type Internal = { - content: Maybe - contentDigest: Scalars['String'] - description: Maybe - fieldOwners: Maybe>> - ignoreType: Maybe - mediaType: Maybe - owner: Scalars['String'] - type: Scalars['String'] -} - -export type InternalFilterInput = { - content: InputMaybe - contentDigest: InputMaybe - description: InputMaybe - fieldOwners: InputMaybe - ignoreType: InputMaybe - mediaType: InputMaybe - owner: InputMaybe - type: InputMaybe -} - -export type IntQueryOperatorInput = { - eq: InputMaybe - gt: InputMaybe - gte: InputMaybe - in: InputMaybe>> - lt: InputMaybe - lte: InputMaybe - ne: InputMaybe - nin: InputMaybe>> -} - export type IStoreCart = { order: IStoreOrder } @@ -799,6 +766,45 @@ export type IStoreSelectedFacet = { value: Scalars['String'] } +export type IStoreSession = { + channel: InputMaybe + country: InputMaybe + postalCode: InputMaybe +} + +export type IntQueryOperatorInput = { + eq: InputMaybe + gt: InputMaybe + gte: InputMaybe + in: InputMaybe>> + lt: InputMaybe + lte: InputMaybe + ne: InputMaybe + nin: InputMaybe>> +} + +export type Internal = { + content: Maybe + contentDigest: Scalars['String'] + description: Maybe + fieldOwners: Maybe>> + ignoreType: Maybe + mediaType: Maybe + owner: Scalars['String'] + type: Scalars['String'] +} + +export type InternalFilterInput = { + content: InputMaybe + contentDigest: InputMaybe + description: InputMaybe + fieldOwners: InputMaybe + ignoreType: InputMaybe + mediaType: InputMaybe + owner: InputMaybe + type: InputMaybe +} + export type Mutation = { validateCart: Maybe } @@ -851,9 +857,10 @@ export type Query = { collection: StoreCollection directory: Maybe file: Maybe + person: StorePerson product: StoreProduct - region: Maybe search: StoreSearchResult + session: StoreSession site: Maybe siteBuildMetadata: Maybe siteFunction: Maybe @@ -946,8 +953,8 @@ export type QueryDirectoryArgs = { atime: InputMaybe atimeMs: InputMaybe base: InputMaybe - birthtime: InputMaybe birthTime: InputMaybe + birthtime: InputMaybe birthtimeMs: InputMaybe changeTime: InputMaybe children: InputMaybe @@ -984,8 +991,8 @@ export type QueryFileArgs = { atime: InputMaybe atimeMs: InputMaybe base: InputMaybe - birthtime: InputMaybe birthTime: InputMaybe + birthtime: InputMaybe birthtimeMs: InputMaybe changeTime: InputMaybe children: InputMaybe @@ -1020,10 +1027,6 @@ export type QueryProductArgs = { locator: Array } -export type QueryRegionArgs = { - input: InputMaybe -} - export type QuerySearchArgs = { after: InputMaybe first: Scalars['Int'] @@ -1032,6 +1035,10 @@ export type QuerySearchArgs = { term?: InputMaybe } +export type QuerySessionArgs = { + session: IStoreSession +} + export type QuerySiteArgs = { buildTime: InputMaybe children: InputMaybe @@ -1138,14 +1145,6 @@ export type QueryStoreProductArgs = { slug: InputMaybe } -export type RegionInput = { - /** Three letter country code according to ISO 3166-1 alpha 3. */ - country: Scalars['String'] - postalCode: Scalars['String'] - /** VTEX sales channel ID. */ - salesChannel: InputMaybe -} - export type Site = Node & { buildTime: Maybe children: Array @@ -1832,6 +1831,12 @@ export type SitePageContext = { slug: Maybe } +export type SitePageContextFilterInput = { + _xparams: InputMaybe + id: InputMaybe + slug: InputMaybe +} + export type SitePageContext_Xparams = { slug: Maybe } @@ -1840,12 +1845,6 @@ export type SitePageContext_XparamsFilterInput = { slug: InputMaybe } -export type SitePageContextFilterInput = { - _xparams: InputMaybe - id: InputMaybe - slug: InputMaybe -} - export type SitePageEdge = { next: Maybe node: SitePage @@ -1898,6 +1897,7 @@ export type SitePageFieldsEnum = | 'context___id' | 'context___slug' | 'id' + | 'internalComponentName' | 'internal___content' | 'internal___contentDigest' | 'internal___description' @@ -1906,7 +1906,6 @@ export type SitePageFieldsEnum = | 'internal___mediaType' | 'internal___owner' | 'internal___type' - | 'internalComponentName' | 'isCreatedByStatefulCreatePages' | 'matchPath' | 'parent___children' @@ -1948,6 +1947,7 @@ export type SitePageFieldsEnum = | 'parent___parent___parent___children' | 'parent___parent___parent___id' | 'path' + | 'pluginCreatorId' | 'pluginCreator___browserAPIs' | 'pluginCreator___children' | 'pluginCreator___children___children' @@ -2046,7 +2046,6 @@ export type SitePageFieldsEnum = | 'pluginCreator___resolve' | 'pluginCreator___ssrAPIs' | 'pluginCreator___version' - | 'pluginCreatorId' export type SitePageFilterInput = { children: InputMaybe @@ -3109,6 +3108,13 @@ export type StorePageInfo = { totalCount: Scalars['Int'] } +export type StorePerson = { + email: Scalars['String'] + familyName: Scalars['String'] + givenName: Scalars['String'] + id: Scalars['String'] +} + export type StoreProduct = Node & { additionalProperty: Array aggregateRating: StoreAggregateRating @@ -3526,6 +3532,12 @@ export type StoreSeoFilterInput = { titleTemplate: InputMaybe } +export type StoreSession = { + channel: Maybe + country: Maybe + postalCode: Maybe +} + export type StoreSort = | 'discount_desc' | 'name_asc' @@ -3556,10 +3568,12 @@ export type StoreCollectionQuery = { } export type RegionQueryQueryVariables = Exact<{ - input: InputMaybe + session: IStoreSession }> -export type RegionQueryQuery = { region: string | null } +export type RegionQueryQuery = { + session: { channel: string | null | undefined } +} export type ProductSummary_ProductFragment = { slug: string @@ -3669,13 +3683,19 @@ export type ProductGalleryQueryQuery = { export type HomePageQueryQueryVariables = Exact<{ [key: string]: never }> export type HomePageQueryQuery = { - site: { - siteMetadata: { - title: string | null - description: string | null - titleTemplate: string | null - } | null - } | null + site: + | { + siteMetadata: + | { + title: string | null | undefined + description: string | null | undefined + titleTemplate: string | null | undefined + } + | null + | undefined + } + | null + | undefined allStoreProduct: { nodes: Array<{ slug: string @@ -3703,13 +3723,19 @@ export type HomePageQueryQuery = { export type SearchPageQueryQueryVariables = Exact<{ [key: string]: never }> export type SearchPageQueryQuery = { - site: { - siteMetadata: { - titleTemplate: string | null - title: string | null - description: string | null - } | null - } | null + site: + | { + siteMetadata: + | { + titleTemplate: string | null | undefined + title: string | null | undefined + description: string | null | undefined + } + | null + | undefined + } + | null + | undefined } export type CollectionPageQueryQueryVariables = Exact<{ @@ -3717,20 +3743,33 @@ export type CollectionPageQueryQueryVariables = Exact<{ }> export type CollectionPageQueryQuery = { - site: { - siteMetadata: { - titleTemplate: string | null - title: string | null - description: string | null - } | null - } | null - collection: { - seo: { title: string; description: string } - breadcrumbList: { - itemListElement: Array<{ item: string; name: string; position: number }> - } - meta: { selectedFacets: Array<{ key: string; value: string }> } - } | null + site: + | { + siteMetadata: + | { + titleTemplate: string | null | undefined + title: string | null | undefined + description: string | null | undefined + } + | null + | undefined + } + | null + | undefined + collection: + | { + seo: { title: string; description: string } + breadcrumbList: { + itemListElement: Array<{ + item: string + name: string + position: number + }> + } + meta: { selectedFacets: Array<{ key: string; value: string }> } + } + | null + | undefined allStoreProduct: { nodes: Array<{ slug: string @@ -3760,43 +3799,56 @@ export type ProductPageQueryQueryVariables = Exact<{ }> export type ProductPageQueryQuery = { - site: { - siteMetadata: { - title: string | null - description: string | null - titleTemplate: string | null - siteUrl: string | null - } | null - } | null - product: { - slug: string - sku: string - gtin: string - name: string - description: string - id: string - seo: { title: string; description: string } - brand: { name: string } - breadcrumbList: { - itemListElement: Array<{ item: string; name: string; position: number }> - } - image: Array<{ url: string; alternateName: string }> - offers: { - lowPrice: number - highPrice: number - priceCurrency: string - offers: Array<{ - availability: string - price: number - priceValidUntil: string - priceCurrency: string - itemCondition: string - listPrice: number - seller: { identifier: string } - }> - } - isVariantOf: { productGroupID: string; name: string } - } | null + site: + | { + siteMetadata: + | { + title: string | null | undefined + description: string | null | undefined + titleTemplate: string | null | undefined + siteUrl: string | null | undefined + } + | null + | undefined + } + | null + | undefined + product: + | { + slug: string + sku: string + gtin: string + name: string + description: string + id: string + seo: { title: string; description: string } + brand: { name: string } + breadcrumbList: { + itemListElement: Array<{ + item: string + name: string + position: number + }> + } + image: Array<{ url: string; alternateName: string }> + offers: { + lowPrice: number + highPrice: number + priceCurrency: string + offers: Array<{ + availability: string + price: number + priceValidUntil: string + priceCurrency: string + itemCondition: string + listPrice: number + seller: { identifier: string } + }> + } + isVariantOf: { productGroupID: string; name: string } + } + | null + | undefined allStoreProduct: { nodes: Array<{ slug: string @@ -3826,26 +3878,29 @@ export type ValidateCartMutationMutationVariables = Exact<{ }> export type ValidateCartMutationMutation = { - validateCart: { - order: { - orderNumber: string - acceptedOffer: Array<{ - quantity: number - price: number - listPrice: number - seller: { identifier: string } - itemOffered: { - sku: string - name: string - gtin: string - image: Array<{ url: string; alternateName: string }> - brand: { name: string } - isVariantOf: { productGroupID: string; name: string } + validateCart: + | { + order: { + orderNumber: string + acceptedOffer: Array<{ + quantity: number + price: number + listPrice: number + seller: { identifier: string } + itemOffered: { + sku: string + name: string + gtin: string + image: Array<{ url: string; alternateName: string }> + brand: { name: string } + isVariantOf: { productGroupID: string; name: string } + } + }> } - }> - } - messages: Array<{ text: string; status: StoreStatus }> - } | null + messages: Array<{ text: string; status: StoreStatus }> + } + | null + | undefined } export type CartMessageFragment = { text: string; status: StoreStatus } diff --git a/@generated/graphql/persisted.json b/@generated/graphql/persisted.json index c5a304aa2..356e59523 100644 --- a/@generated/graphql/persisted.json +++ b/@generated/graphql/persisted.json @@ -1,6 +1,6 @@ { "StoreCollection": "query StoreCollection {\n allStoreCollection(filter: {type: {eq: Department}}) {\n edges {\n node {\n slug\n seo {\n title\n }\n }\n }\n }\n}\n", - "RegionQuery": "query RegionQuery($input: RegionInput) {\n region(input: $input)\n}\n", + "RegionQuery": "query RegionQuery($session: IStoreSession!) {\n session(session: $session) {\n channel\n }\n}\n", "ProductGalleryQuery": "query ProductGalleryQuery($first: Int!, $after: String!, $sort: StoreSort!, $term: String!, $selectedFacets: [IStoreSelectedFacet!]!) {\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n ) {\n products {\n pageInfo {\n totalCount\n }\n edges {\n node {\n id: productID\n slug\n sku\n brand {\n brandName: name\n name\n }\n name\n gtin\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n }\n }\n }\n facets {\n key\n label\n type\n values {\n label\n value\n selected\n quantity\n }\n }\n }\n}\n", "HomePageQuery": "query HomePageQuery {\n site {\n siteMetadata {\n title\n description\n titleTemplate\n }\n }\n allStoreProduct(limit: 14) {\n nodes {\n id: productID\n slug\n sku\n brand {\n brandName: name\n name\n }\n name\n gtin\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n }\n }\n}\n", "SearchPageQuery": "query SearchPageQuery {\n site {\n siteMetadata {\n titleTemplate\n title\n description\n }\n }\n}\n", diff --git a/gatsby-browser.js b/gatsby-browser.js index aaebd43f1..8b05a98cc 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -13,6 +13,8 @@ import TestProvider from './src/sdk/tests' import { uiActions, uiEffects, uiInitialState } from './src/sdk/ui' import storeConfig from './store.config' +const channel = JSON.stringify(storeConfig.channel) + export const wrapRootElement = ({ element }) => ( @@ -22,7 +24,7 @@ export const wrapRootElement = ({ element }) => ( actions={uiActions} effects={uiEffects} > - + {element} diff --git a/gatsby-ssr.js b/gatsby-ssr.js index 4875ffcaf..f8dc475a4 100644 --- a/gatsby-ssr.js +++ b/gatsby-ssr.js @@ -11,6 +11,8 @@ import TestProvider from './src/sdk/tests' import { uiActions, uiEffects, uiInitialState } from './src/sdk/ui' import storeConfig from './store.config' +const channel = JSON.stringify(storeConfig.channel) + export const wrapRootElement = ({ element }) => ( @@ -20,7 +22,7 @@ export const wrapRootElement = ({ element }) => ( actions={uiActions} effects={uiEffects} > - + {element} diff --git a/package.json b/package.json index d61149b92..b04d2ae30 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@envelop/graphql-jit": "^1.1.1", "@envelop/parser-cache": "^2.2.0", "@envelop/validation-cache": "^2.2.0", - "@faststore/api": "https://pkg.csb.dev/vtex/faststore/commit/a83409a6/@faststore/api", + "@faststore/api": "https://pkg.csb.dev/vtex/faststore/commit/abef51fc/@faststore/api", "@faststore/sdk": "^1.6.7", "@faststore/ui": "^1.6.7", "@vtex/gatsby-plugin-nginx": "^1.6.7", diff --git a/src/components/common/PostalCode/PostalCodeInput.tsx b/src/components/common/PostalCode/PostalCodeInput.tsx index 845624899..98716c18f 100644 --- a/src/components/common/PostalCode/PostalCodeInput.tsx +++ b/src/components/common/PostalCode/PostalCodeInput.tsx @@ -15,8 +15,10 @@ const POSTAL_CODE_STORAGE_KEY = 'main::store::postalCode' const POSTAL_CODE_INPUT_ID = 'postal-code-input' export const RegionQuery = gql` - query RegionQuery($input: RegionInput) { - region(input: $input) + query RegionQuery($session: IStoreSession!) { + session(session: $session) { + channel + } } ` @@ -27,9 +29,9 @@ export default function PostalCodeInput() { '' ) - const { country } = useSession() + const { country, setSession, ...partialSession } = useSession() - const handleSubmit = (event: KeyboardEvent) => { + const handleSubmit = async (event: KeyboardEvent) => { const value = ref.current?.value if (!(event.key === 'Enter' && typeof value === 'string')) { @@ -37,12 +39,23 @@ export default function PostalCodeInput() { } setPostalCode(value) - request(RegionQuery, { - input: { - postalCode: value, - country: country ?? 'BRA', - salesChannel: null, - }, + const { + session: { channel }, + } = await request( + RegionQuery, + { + session: { + channel: partialSession.channel, + postalCode: value, + country, + }, + } + ) + + setSession({ + ...partialSession, + country, + channel: channel ?? partialSession.channel, }) } diff --git a/src/sdk/product/useProduct.ts b/src/sdk/product/useProduct.ts index 6136813be..f9f98d905 100644 --- a/src/sdk/product/useProduct.ts +++ b/src/sdk/product/useProduct.ts @@ -29,7 +29,7 @@ export const useProduct = ( return { locator: [ { key: 'id', value: productID }, - { key: 'channel', value: channel }, + { key: 'channel', value: JSON.parse(channel).salesChannel }, ], } }, [channel, productID]) diff --git a/src/server/index.js b/src/server/index.js index ca61f37d4..fa4874ea6 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -20,7 +20,8 @@ const apiOptions = { platform: storeConfig.platform, account: storeConfig.api.storeId, environment: storeConfig.api.environment, - channel: storeConfig.channel, + // TODO: the API should handle this sales channel as string + channel: storeConfig.channel.salesChannel, } const apiSchema = getSchema(apiOptions) diff --git a/store.config.js b/store.config.js index 68d246f83..b0743f7ca 100644 --- a/store.config.js +++ b/store.config.js @@ -9,7 +9,9 @@ module.exports = { }, // Default channel - channel: '1', + channel: { + salesChannel: '1', + }, // Production URLs storeUrl: 'https://vtexfaststore.com', diff --git a/yarn.lock b/yarn.lock index 6380fd063..deffac7e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1472,9 +1472,21 @@ minimatch "^3.0.4" strip-json-comments "^3.1.1" -"@faststore/api@https://pkg.csb.dev/vtex/faststore/commit/a83409a6/@faststore/api": +"@faststore/api@https://pkg.csb.dev/vtex/faststore/commit/3614aa32/@faststore/api": version "1.6.10" - resolved "https://pkg.csb.dev/vtex/faststore/commit/a83409a6/@faststore/api#52bef6ef069a7638bfe8ca2ea9499db09406b86e" + resolved "https://pkg.csb.dev/vtex/faststore/commit/3614aa32/@faststore/api#7834e267497c4345382063b847c4844d452508b8" + dependencies: + "@graphql-tools/schema" "^8.2.0" + "@rollup/plugin-graphql" "^1.0.0" + "@sindresorhus/slugify" "^1.1.2" + dataloader "^2.0.0" + fast-deep-equal "^3.1.3" + isomorphic-unfetch "^3.1.0" + p-limit "^3.1.0" + +"@faststore/api@https://pkg.csb.dev/vtex/faststore/commit/abef51fc/@faststore/api": + version "1.6.10" + resolved "https://pkg.csb.dev/vtex/faststore/commit/abef51fc/@faststore/api#a23c611b1032708e9809a1c8f640e3f32225f878" dependencies: "@graphql-tools/schema" "^8.2.0" "@rollup/plugin-graphql" "^1.0.0"