@faststore/api 2.0.37-alpha.0 → 2.0.44-alpha.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.
@@ -56,7 +56,7 @@ export declare const VtexCommerce: ({ account, environment }: Options, ctx: Cont
56
56
  key: string;
57
57
  value: string;
58
58
  }) => Promise<OrderForm>;
59
- region: ({ postalCode, country, salesChannel, }: RegionInput) => Promise<Region>;
59
+ region: ({ postalCode, country, salesChannel, }: RegionInput) => Promise<Region[]>;
60
60
  address: ({ postalCode, country, }: AddressInput) => Promise<Address>;
61
61
  };
62
62
  session: (search: string) => Promise<Session>;
@@ -3,6 +3,12 @@ export interface RegionInput {
3
3
  country: string;
4
4
  salesChannel?: string | null;
5
5
  }
6
- export declare type Region = Array<{
6
+ export interface Seller {
7
7
  id: string;
8
- }>;
8
+ name: string;
9
+ logo: string;
10
+ }
11
+ export interface Region {
12
+ id: string;
13
+ sellers: Seller[];
14
+ }
@@ -50,7 +50,7 @@ export declare const getClients: (options: Options, ctx: Context) => {
50
50
  key: string;
51
51
  value: string;
52
52
  }) => Promise<import("./commerce/types/OrderForm").OrderForm>;
53
- region: ({ postalCode, country, salesChannel, }: import("./commerce/types/Region").RegionInput) => Promise<import("./commerce/types/Region").Region>;
53
+ region: ({ postalCode, country, salesChannel, }: import("./commerce/types/Region").RegionInput) => Promise<import("./commerce/types/Region").Region[]>;
54
54
  address: ({ postalCode, country, }: import("./commerce/types/Address").AddressInput) => Promise<import("./commerce/types/Address").Address>;
55
55
  };
56
56
  session: (search: string) => Promise<import("./commerce/types/Session").Session>;
@@ -1,4 +1,5 @@
1
1
  export interface Channel {
2
+ seller?: string;
2
3
  regionId?: string;
3
4
  salesChannel?: string;
4
5
  }
@@ -18,10 +18,7 @@ export declare const FACET_CROSS_SELLING_MAP: {
18
18
  * Transform facets from the store to VTEX platform facets.
19
19
  * For instance, the channel in Store becomes trade-policy and regionId in VTEX's realm
20
20
  * */
21
- export declare const transformSelectedFacet: ({ key, value }: SelectedFacet) => {
22
- key: string;
23
- value: string;
24
- }[] | {
21
+ export declare const transformSelectedFacet: ({ key, value }: SelectedFacet) => never[] | {
25
22
  key: string;
26
23
  value: string;
27
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "2.0.37-alpha.0",
3
+ "version": "2.0.44-alpha.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "devDependencies": {
33
33
  "@faststore/eslint-config": "^2.0.37-alpha.0",
34
- "@faststore/shared": "^2.0.37-alpha.0",
34
+ "@faststore/shared": "^2.0.44-alpha.0",
35
35
  "@graphql-codegen/cli": "2.2.0",
36
36
  "@graphql-codegen/typescript": "2.2.2",
37
37
  "concurrently": "^6.2.1",
@@ -48,5 +48,5 @@
48
48
  "peerDependencies": {
49
49
  "graphql": "^15.6.0"
50
50
  },
51
- "gitHead": "dac60f1c06a9df8faf33752ec8f8c9737fed677d"
51
+ "gitHead": "acf23500bf3f608eaff4debbf42c75e6e5a4c654"
52
52
  }
@@ -166,7 +166,7 @@ export const VtexCommerce = (
166
166
  postalCode,
167
167
  country,
168
168
  salesChannel,
169
- }: RegionInput): Promise<Region> => {
169
+ }: RegionInput): Promise<Region[]> => {
170
170
  return fetchAPI(
171
171
  `${base}/api/checkout/pub/regions/?postalCode=${postalCode}&country=${country}&sc=${
172
172
  salesChannel ?? ''
@@ -1,7 +1,16 @@
1
1
  export interface RegionInput {
2
- postalCode: string
3
- country: string
4
- salesChannel?: string | null
2
+ postalCode: string;
3
+ country: string;
4
+ salesChannel?: string | null;
5
5
  }
6
6
 
7
- export type Region = Array<{ id: string }>
7
+ export interface Seller {
8
+ id: string; // storeframework01
9
+ name: string; // My Awsome Seller
10
+ logo: string;
11
+ }
12
+
13
+ export interface Region {
14
+ id: string;
15
+ sellers: Seller[];
16
+ }
@@ -66,15 +66,17 @@ export const IntelligentSearch = (
66
66
  }
67
67
 
68
68
  const getRegionFacet = (): IStoreSelectedFacet | null => {
69
- const { regionId } = ctx.storage.channel
69
+ const { regionId, seller } = ctx.storage.channel
70
+ const sellerRegionId = seller ? Buffer.from(`SW#${seller}`).toString('base64') : null
71
+ const facet = sellerRegionId ?? regionId
70
72
 
71
- if (!regionId) {
73
+ if (!facet) {
72
74
  return null
73
75
  }
74
76
 
75
77
  return {
76
78
  key: REGION_KEY,
77
- value: regionId,
79
+ value: facet,
78
80
  }
79
81
  }
80
82
 
@@ -57,10 +57,10 @@ export const StoreOffer: Record<string, Resolver<Root>> = {
57
57
 
58
58
  return null
59
59
  },
60
- seller: (root) => {
60
+ seller: (root, _, ctx) => {
61
61
  if (isSearchItem(root)) {
62
62
  return {
63
- identifier: root.seller.sellerId ?? '',
63
+ identifier: ctx.storage.channel?.seller || root.seller.sellerId || '',
64
64
  }
65
65
  }
66
66
 
@@ -30,6 +30,9 @@ export const validateSession = async (
30
30
 
31
31
  const profile = sessionData?.namespaces.profile ?? null
32
32
  const store = sessionData?.namespaces.store ?? null
33
+ const region = regionData?.[0]
34
+ // Set seller only if it's inside a region
35
+ const seller = region?.sellers.find(seller => channel.seller === seller.id)
33
36
 
34
37
  const newSession = {
35
38
  ...oldSession,
@@ -40,7 +43,8 @@ export const validateSession = async (
40
43
  country: store?.countryCode.value ?? oldSession.country,
41
44
  channel: ChannelMarshal.stringify({
42
45
  salesChannel: store?.channel?.value ?? channel.salesChannel,
43
- regionId: regionData?.[0]?.id ?? channel.regionId,
46
+ regionId: region?.id ?? channel.regionId,
47
+ seller: seller?.id
44
48
  }),
45
49
  person: profile?.id
46
50
  ? {
@@ -1,4 +1,5 @@
1
1
  export interface Channel {
2
+ seller?: string
2
3
  regionId?: string
3
4
  salesChannel?: string
4
5
  }
@@ -9,6 +10,7 @@ export default class ChannelMarshal {
9
10
  const parsedChannel = JSON.parse(channelString) as Channel
10
11
 
11
12
  return {
13
+ seller: parsedChannel.seller ?? '',
12
14
  regionId: parsedChannel.regionId ?? '',
13
15
  salesChannel: parsedChannel.salesChannel ?? '',
14
16
  }
@@ -1,4 +1,3 @@
1
- import ChannelMarshal from './channel'
2
1
  import type { Maybe } from '../../../__generated__/schema'
3
2
  import { BadRequestError } from '../../errors'
4
3
 
@@ -27,27 +26,12 @@ export const FACET_CROSS_SELLING_MAP = {
27
26
  * */
28
27
  export const transformSelectedFacet = ({ key, value }: SelectedFacet) => {
29
28
  switch (key) {
30
- case 'channel': {
31
- const channel = ChannelMarshal.parse(value)
32
- const channelFacets = [
33
- { key: 'trade-policy', value: channel.salesChannel },
34
- ]
35
-
36
- if (channel.regionId) {
37
- channelFacets.push({ key: 'region-id', value: channel.regionId })
38
- }
39
-
40
- return channelFacets
41
- }
42
-
43
- case 'locale': {
44
- return [] // remove this facet from search
45
- }
46
-
47
29
  case 'price': {
48
30
  return { key, value: value.replace('-to-', ':') }
49
31
  }
50
-
32
+
33
+ case 'channel':
34
+ case 'locale':
51
35
  case "buy":
52
36
  case "view":
53
37
  case "similars":