Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/utm fs #2557

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/site/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "site",
"version": "2.2.78",
"version": "2.2.79",
"author": "Emerson Laurentino @emersonlaurentino",
"license": "MIT",
"private": true,
Expand All @@ -10,7 +10,7 @@
"start": "next start"
},
"dependencies": {
"@faststore/api": "^2.2.78",
"@faststore/api": "^2.2.79",
"@faststore/sdk": "^2.2.78",
"@faststore/ui": "^2.2.78",
"next": "13.0.7",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.2.78",
"version": "2.2.79",
"npmClient": "yarn",
"command": {
"publish": {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/mocks/ValidateCartMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export const checkoutOrderFormCustomDataInvalidFetch = {
}

export const productSearchPage1Count1Fetch = {
info: 'https://storeframework.vtexcommercestable.com.br/api/io/_v/api/intelligent-search/product_search/trade-policy/1?page=1&count=1&query=sku%3A2737806&sort=&fuzzy=auto&locale=en-US&hideUnavailableItems=false',
info: 'https://storeframework.vtexcommercestable.com.br/api/io/_v/api/intelligent-search/product_search/trade-policy/1?page=1&count=1&query=sku%3A2737806&sort=&fuzzy=auto&locale=en-US&show-invisible-items=true&hideUnavailableItems=false',
init: undefined,
options: { storeCookies: expect.any(Function) },
result: {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@faststore/api",
"version": "2.2.78",
"version": "2.2.79",
"license": "MIT",
"main": "dist/cjs/src/index.js",
"typings": "dist/esm/src/index.d.ts",
Expand All @@ -26,7 +26,7 @@
"dev": "concurrently \"yarn generate -w\" \"tsc --watch\" \"yarn dev:graphql\"",
"dev:graphql": "nodemon --watch src --ext graphql --exec \"copyfiles \"src/**/*.graphql\" dist/esm\"",
"dev:server": "tsx --no-cache ./local/server.ts",
"build": "graphql-codegen --config codegen.yml && (yarn build:cjs & yarn build:esm)",
"build": "graphql-codegen --config codegen.yml && (yarn build:cjs && yarn build:esm)",
"build:cjs": "tsc --module commonjs --moduleResolution node10 --outDir dist/cjs && copyfiles \"src/**/*.graphql\" dist/cjs",
"build:esm": "tsc && copyfiles \"src/**/*.graphql\" dist/esm",
"lint": "eslint src/**/*.ts",
Expand Down
29 changes: 28 additions & 1 deletion packages/api/src/platforms/vtex/clients/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface SearchArgs {
selectedFacets?: SelectedFacet[]
fuzzy?: '0' | '1' | 'auto'
hideUnavailableItems?: boolean
showInvisibleItems?: boolean
segment?: string
}

export interface ProductLocator {
Expand All @@ -54,6 +56,15 @@ export const IntelligentSearch = (
const base = `https://${account}.${environment}.com.br/api/io`
const storeCookies = getStoreCookie(ctx)

const getVtexSegment = (cookies?: string) => {
if (typeof cookies !== 'string') {
return null;
}

const match = cookies.match(/fs_segment=([^;]*)/);
return match ? match[1] : null;
};

const getPolicyFacet = (): IStoreSelectedFacet | null => {
const { salesChannel } = ctx.storage.channel

Expand Down Expand Up @@ -112,6 +123,8 @@ export const IntelligentSearch = (
selectedFacets = [],
type,
fuzzy = 'auto',
showInvisibleItems,
segment = undefined,
}: SearchArgs): Promise<T> => {
const params = new URLSearchParams({
page: (page + 1).toString(),
Expand All @@ -122,6 +135,10 @@ export const IntelligentSearch = (
locale: ctx.storage.locale,
})

if (showInvisibleItems) {
params.append('show-invisible-items', 'true')
}

if (hideUnavailableItems !== undefined) {
params.append('hideUnavailableItems', hideUnavailableItems.toString())
}
Expand All @@ -130,9 +147,19 @@ export const IntelligentSearch = (
.map(({ key, value }) => `${key}/${value}`)
.join('/')

const segmentCookie = ctx ? getVtexSegment(ctx.headers.cookie) : null;

const headers = segmentCookie || segment
? {
headers: {
'Cookie': `vtex_segment=${segmentCookie || segment}`,
},
}
: undefined;

return fetchAPI(
`${base}/_v/api/intelligent-search/${type}/${pathname}?${params.toString()}`,
undefined,
headers,
{ storeCookies }
)
}
Expand Down
10 changes: 9 additions & 1 deletion packages/api/src/platforms/vtex/loaders/sku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ import type { Options } from '..'
import type { Clients } from '../clients'

export const getSkuLoader = (_: Options, clients: Clients) => {
const loader = async (skuIds: readonly string[]) => {
const loader = async (keys: readonly string[]) => {
const skuIds = keys.map((key) => key.split('-')[0]);
const showInvisibleItems = keys.some((key) => key.split('-')[1] === 'invisibleItems')

const segmentKey = keys.find((key) => key.split('-')[1]?.startsWith('segment:'))
const segment = segmentKey ? segmentKey.split('segment:')[1] : undefined

const { products } = await clients.search.products({
query: `sku:${skuIds.join(';')}`,
page: 0,
count: skuIds.length,
showInvisibleItems,
...(segment && { segment })
})

const skuBySkuId = products.reduce((acc, product) => {
Expand Down
5 changes: 4 additions & 1 deletion packages/api/src/platforms/vtex/resolvers/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
findSkuId,
findSlug,
transformSelectedFacet,
findSegment
} from '../utils/facets'
import { SORT_MAP } from '../utils/sort'
import { StoreCollection } from './collection'
Expand All @@ -34,6 +35,7 @@ export const Query = {
const locale = findLocale(locator)
const id = findSkuId(locator)
const slug = findSlug(locator)
const segment = findSegment(locator)

if (channel) {
mutateChannelContext(ctx, channel)
Expand All @@ -55,7 +57,7 @@ export const Query = {
throw new Error('Invalid SkuId')
}

const sku = await skuLoader.load(skuId)
const sku = await skuLoader.load(segment ? `${skuId}-segment:${segment}` : skuId)

/**
* Here be dragons 🦄🦄🦄
Expand Down Expand Up @@ -92,6 +94,7 @@ export const Query = {
page: 0,
count: 1,
query: `product:${route.id}`,
segment
})

if (!product) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const orderFormToCart = async (
orderNumber: form.orderFormId,
acceptedOffer: form.items.map(async (item) => ({
...item,
product: await skuLoader.load(item.id),
product: await skuLoader.load(`${item.id}-invisibleItems`),
})),
},
messages: form.messages.map(({ text, status }) => ({
Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/platforms/vtex/utils/facets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ export const findLocale = (facets?: Maybe<SelectedFacet[]>) =>

export const findChannel = (facets?: Maybe<SelectedFacet[]>) =>
facets?.find((facet) => facet.key === 'channel')?.value ?? null

export const findSegment = (facets?: Maybe<SelectedFacet[]>) =>
facets?.find((facet) => facet.key === 'segment')?.value ?? undefined
2 changes: 1 addition & 1 deletion packages/api/src/typeDefs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { print } from 'graphql'
import { loadFilesSync } from '@graphql-tools/load-files'

// Empty string ('') is interpreted as the current dir. Referencing it as './' won't work.
export const typeDefs = loadFilesSync('', { extensions: ['.graphql'] })
export const typeDefs = loadFilesSync(__dirname, { extensions: ['.graphql'] })
.map(print)
.join('\n')
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"license": "MIT",
"scripts": {
"dev": "tsc --watch",
"build": "tsc --module commonjs --outDir dist/cjs & tsc --module esnext --outDir dist/esm",
"build": "tsc --module commonjs --outDir dist/cjs && tsc --module esnext --outDir dist/esm",
"lint": "eslint src/**/*.{ts,tsx}"
},
"repository": {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@faststore/core",
"version": "2.2.78",
"version": "2.2.79",
"license": "MIT",
"repository": "vtex/faststore",
"browserslist": "supports es6-module and not dead",
Expand All @@ -11,16 +11,16 @@
"scripts": {
"generate:schema": "tsx src/server/generator/generateGraphQLSchemaFile.ts",
"generate:codegen": "graphql-codegen",
"format:generated": "prettier --write \"@generated/**/*.{ts,js,tsx,jsx,json}\" --loglevel error",
"generate": "faststore generate-graphql -c",
"build": "yarn partytown & yarn generate && next build",
"dev": "yarn partytown & yarn generate && next dev",
"build": "yarn partytown && yarn generate && next build",
"dev": "yarn partytown && yarn generate && next dev",
"clean": "rm -r .next",
"serve": "next start",
"test:e2e": "cypress open",
"test": "jest",
"lhci": "lhci autorun",
"format": "prettier --write \"**/*.{ts,js,tsx,jsx,json}\"",
"format:generated": "prettier --write \"@generated/**/*.{ts,js,tsx,jsx,json}\" --loglevel error",
"lint": "next lint",
"stylelint": "stylelint \"**/*.scss\"",
"stylelint:fix": "stylelint \"**/*.scss\" --fix",
Expand All @@ -37,7 +37,7 @@
"@envelop/graphql-jit": "^1.1.1",
"@envelop/parser-cache": "^2.2.0",
"@envelop/validation-cache": "^2.2.0",
"@faststore/api": "^2.2.78",
"@faststore/api": "^2.2.79",
"@faststore/components": "^2.2.78",
"@faststore/graphql-utils": "^2.2.78",
"@faststore/sdk": "^2.2.78",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"scripts": {
"dev": "tsc --watch",
"build": "tsc --module commonjs --outDir dist/cjs & tsc --module esnext --outDir dist/esm",
"build": "tsc --module commonjs --outDir dist/cjs && tsc --module esnext --outDir dist/esm",
"lint": "eslint src/**/*.{ts,tsx}",
"size": "size-limit",
"analyze": "size-limit --why"
Expand Down
Loading