@faststore/api 2.0.37-alpha.0 → 2.0.46-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.
@@ -44,11 +44,12 @@ export declare const VtexCommerce: ({ account, environment }: Options, ctx: Cont
44
44
  refreshOutdatedData?: boolean | undefined;
45
45
  channel?: Required<Channel> | undefined;
46
46
  }) => Promise<OrderForm>;
47
- updateOrderFormItems: ({ id, orderItems, allowOutdatedData, salesChannel, }: {
47
+ updateOrderFormItems: ({ id, orderItems, allowOutdatedData, salesChannel, shouldSplitItem, }: {
48
48
  id: string;
49
49
  orderItems: OrderFormInputItem[];
50
50
  allowOutdatedData?: "paymentData" | undefined;
51
51
  salesChannel?: string | undefined;
52
+ shouldSplitItem?: boolean | null | undefined;
52
53
  }) => Promise<OrderForm>;
53
54
  setCustomData: ({ id, appId, key, value, }: {
54
55
  id: string;
@@ -56,7 +57,7 @@ export declare const VtexCommerce: ({ account, environment }: Options, ctx: Cont
56
57
  key: string;
57
58
  value: string;
58
59
  }) => Promise<OrderForm>;
59
- region: ({ postalCode, country, salesChannel, }: RegionInput) => Promise<Region>;
60
+ region: ({ postalCode, country, salesChannel, }: RegionInput) => Promise<Region[]>;
60
61
  address: ({ postalCode, country, }: AddressInput) => Promise<Address>;
61
62
  };
62
63
  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
+ }
@@ -38,11 +38,12 @@ export declare const getClients: (options: Options, ctx: Context) => {
38
38
  refreshOutdatedData?: boolean | undefined;
39
39
  channel?: Required<import("../utils/channel").Channel> | undefined;
40
40
  }) => Promise<import("./commerce/types/OrderForm").OrderForm>;
41
- updateOrderFormItems: ({ id, orderItems, allowOutdatedData, salesChannel, }: {
41
+ updateOrderFormItems: ({ id, orderItems, allowOutdatedData, salesChannel, shouldSplitItem, }: {
42
42
  id: string;
43
43
  orderItems: import("./commerce/types/OrderForm").OrderFormInputItem[];
44
44
  allowOutdatedData?: "paymentData" | undefined;
45
45
  salesChannel?: string | undefined;
46
+ shouldSplitItem?: boolean | null | undefined;
46
47
  }) => Promise<import("./commerce/types/OrderForm").OrderForm>;
47
48
  setCustomData: ({ id, appId, key, value, }: {
48
49
  id: string;
@@ -50,7 +51,7 @@ export declare const getClients: (options: Options, ctx: Context) => {
50
51
  key: string;
51
52
  value: string;
52
53
  }) => Promise<import("./commerce/types/OrderForm").OrderForm>;
53
- region: ({ postalCode, country, salesChannel, }: import("./commerce/types/Region").RegionInput) => Promise<import("./commerce/types/Region").Region>;
54
+ region: ({ postalCode, country, salesChannel, }: import("./commerce/types/Region").RegionInput) => Promise<import("./commerce/types/Region").Region[]>;
54
55
  address: ({ postalCode, country, }: import("./commerce/types/Address").AddressInput) => Promise<import("./commerce/types/Address").Address>;
55
56
  };
56
57
  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.46-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": "1b6dc3fde03d00e6c0c0214e0118835763bfaa49"
52
52
  }
@@ -133,7 +133,7 @@ export type IShippingItem = {
133
133
 
134
134
  /** Shopping cart input. */
135
135
  export type IStoreCart = {
136
- /** Order information, including `orderNumber` and `acceptedOffer`. */
136
+ /** Order information, including `orderNumber`, `acceptedOffer` and `shouldSplitItem`. */
137
137
  order: IStoreOrder;
138
138
  };
139
139
 
@@ -172,6 +172,8 @@ export type IStoreOrder = {
172
172
  acceptedOffer: Array<IStoreOffer>;
173
173
  /** ID of the order in [VTEX order management](https://help.vtex.com/en/tutorial/license-manager-resources-oms--60QcBsvWeum02cFi3GjBzg#). */
174
174
  orderNumber: Scalars['String'];
175
+ /** Indicates whether or not items with attachments should be split. */
176
+ shouldSplitItem?: Maybe<Scalars['Boolean']>;
175
177
  };
176
178
 
177
179
  /** Organization input. */
@@ -122,11 +122,13 @@ export const VtexCommerce = (
122
122
  orderItems,
123
123
  allowOutdatedData = 'paymentData',
124
124
  salesChannel = ctx.storage.channel.salesChannel,
125
+ shouldSplitItem = true,
125
126
  }: {
126
127
  id: string
127
128
  orderItems: OrderFormInputItem[]
128
129
  allowOutdatedData?: 'paymentData'
129
130
  salesChannel?: string
131
+ shouldSplitItem?: boolean | null
130
132
  }): Promise<OrderForm> => {
131
133
  const params = new URLSearchParams({
132
134
  allowOutdatedData,
@@ -137,7 +139,10 @@ export const VtexCommerce = (
137
139
  `${base}/api/checkout/pub/orderForm/${id}/items?${params}`,
138
140
  {
139
141
  ...BASE_INIT,
140
- body: JSON.stringify({ orderItems }),
142
+ body: JSON.stringify({
143
+ orderItems,
144
+ noSplitItem: !shouldSplitItem,
145
+ }),
141
146
  method: 'PATCH',
142
147
  }
143
148
  )
@@ -166,7 +171,7 @@ export const VtexCommerce = (
166
171
  postalCode,
167
172
  country,
168
173
  salesChannel,
169
- }: RegionInput): Promise<Region> => {
174
+ }: RegionInput): Promise<Region[]> => {
170
175
  return fetchAPI(
171
176
  `${base}/api/checkout/pub/regions/?postalCode=${postalCode}&country=${country}&sc=${
172
177
  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
 
@@ -249,7 +249,7 @@ export const validateCart = async (
249
249
  ctx: Context,
250
250
  ) => {
251
251
  const { enableOrderFormSync } = ctx.storage.flags
252
- const { orderNumber, acceptedOffer } = order
252
+ const { orderNumber, acceptedOffer, shouldSplitItem } = order
253
253
  const {
254
254
  clients: { commerce },
255
255
  loaders: { skuLoader },
@@ -336,6 +336,7 @@ export const validateCart = async (
336
336
  .updateOrderFormItems({
337
337
  id: orderForm.orderFormId,
338
338
  orderItems: changes,
339
+ shouldSplitItem,
339
340
  })
340
341
  // update orderForm etag so we know last time we touched this orderForm
341
342
  .then((form) =>
@@ -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":
@@ -31,7 +31,7 @@ Shopping cart input.
31
31
  """
32
32
  input IStoreCart {
33
33
  """
34
- Order information, including `orderNumber` and `acceptedOffer`.
34
+ Order information, including `orderNumber`, `acceptedOffer` and `shouldSplitItem`.
35
35
  """
36
36
  order: IStoreOrder!
37
37
  }
@@ -24,4 +24,8 @@ input IStoreOrder {
24
24
  Array with information on each accepted offer.
25
25
  """
26
26
  acceptedOffer: [IStoreOffer!]!
27
+ """
28
+ Indicates whether or not items with attachments should be split.
29
+ """
30
+ shouldSplitItem: Boolean
27
31
  }