@faststore/api 3.29.0 → 3.30.1
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/dist/cjs/package.json +1 -1
- package/dist/cjs/src/__generated__/schema.d.ts +39 -0
- package/dist/cjs/src/__generated__/schema.js.map +1 -1
- package/dist/cjs/src/index.d.ts +3 -0
- package/dist/cjs/src/platforms/vtex/clients/commerce/index.d.ts +10 -7
- package/dist/cjs/src/platforms/vtex/clients/commerce/index.js +13 -0
- package/dist/cjs/src/platforms/vtex/clients/commerce/index.js.map +1 -1
- package/dist/cjs/src/platforms/vtex/clients/commerce/types/Profile.d.ts +18 -0
- package/dist/cjs/src/platforms/vtex/clients/commerce/types/Profile.js +3 -0
- package/dist/cjs/src/platforms/vtex/clients/commerce/types/Profile.js.map +1 -0
- package/dist/cjs/src/platforms/vtex/clients/index.d.ts +3 -0
- package/dist/cjs/src/platforms/vtex/clients/index.js.map +1 -1
- package/dist/cjs/src/platforms/vtex/clients/search/index.d.ts +1 -1
- package/dist/cjs/src/platforms/vtex/clients/search/index.js +16 -4
- package/dist/cjs/src/platforms/vtex/clients/search/index.js.map +1 -1
- package/dist/cjs/src/platforms/vtex/index.d.ts +3 -0
- package/dist/cjs/src/platforms/vtex/resolvers/query.d.ts +6 -2
- package/dist/cjs/src/platforms/vtex/resolvers/query.js +25 -13
- package/dist/cjs/src/platforms/vtex/resolvers/query.js.map +1 -1
- package/dist/cjs/src/typeDefs/profile.graphql +61 -0
- package/dist/cjs/src/typeDefs/query.graphql +11 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/src/__generated__/schema.d.ts +39 -0
- package/dist/esm/src/__generated__/schema.js.map +1 -1
- package/dist/esm/src/index.d.ts +3 -0
- package/dist/esm/src/platforms/vtex/clients/commerce/index.d.ts +10 -7
- package/dist/esm/src/platforms/vtex/clients/commerce/index.js +13 -0
- package/dist/esm/src/platforms/vtex/clients/commerce/index.js.map +1 -1
- package/dist/esm/src/platforms/vtex/clients/commerce/types/Profile.d.ts +18 -0
- package/dist/esm/src/platforms/vtex/clients/commerce/types/Profile.js +2 -0
- package/dist/esm/src/platforms/vtex/clients/commerce/types/Profile.js.map +1 -0
- package/dist/esm/src/platforms/vtex/clients/index.d.ts +3 -0
- package/dist/esm/src/platforms/vtex/clients/index.js.map +1 -1
- package/dist/esm/src/platforms/vtex/clients/search/index.d.ts +1 -1
- package/dist/esm/src/platforms/vtex/clients/search/index.js +17 -5
- package/dist/esm/src/platforms/vtex/clients/search/index.js.map +1 -1
- package/dist/esm/src/platforms/vtex/index.d.ts +3 -0
- package/dist/esm/src/platforms/vtex/resolvers/query.d.ts +6 -2
- package/dist/esm/src/platforms/vtex/resolvers/query.js +14 -2
- package/dist/esm/src/platforms/vtex/resolvers/query.js.map +1 -1
- package/dist/esm/src/typeDefs/profile.graphql +61 -0
- package/dist/esm/src/typeDefs/query.graphql +11 -0
- package/package.json +2 -2
- package/src/__generated__/schema.ts +43 -0
- package/src/platforms/vtex/clients/commerce/index.ts +29 -9
- package/src/platforms/vtex/clients/commerce/types/Profile.ts +19 -0
- package/src/platforms/vtex/clients/index.ts +1 -1
- package/src/platforms/vtex/clients/search/index.ts +22 -4
- package/src/platforms/vtex/resolvers/query.ts +40 -17
- package/src/typeDefs/profile.graphql +61 -0
- package/src/typeDefs/query.graphql +11 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Context, Options } from '../../'
|
|
2
2
|
import type { IStoreSelectedFacet } from '../../../../__generated__/schema'
|
|
3
|
-
import { getStoreCookie } from '../../utils/cookies'
|
|
3
|
+
import { getStoreCookie, getWithCookie } from '../../utils/cookies'
|
|
4
4
|
import type {
|
|
5
5
|
FuzzyFacet,
|
|
6
6
|
OperatorFacet,
|
|
@@ -82,11 +82,29 @@ export const IntelligentSearch = (
|
|
|
82
82
|
hideUnavailableItems,
|
|
83
83
|
simulationBehavior,
|
|
84
84
|
showSponsored,
|
|
85
|
+
subDomainPrefix,
|
|
85
86
|
}: Options,
|
|
86
87
|
ctx: Context
|
|
87
88
|
) => {
|
|
88
89
|
const base = `https://${account}.${environment}.com.br/api/io`
|
|
89
90
|
const storeCookies = getStoreCookie(ctx)
|
|
91
|
+
const withCookie = getWithCookie(ctx)
|
|
92
|
+
|
|
93
|
+
const host =
|
|
94
|
+
new Headers(ctx.headers).get('x-forwarded-host') ?? ctx.headers?.host ?? ''
|
|
95
|
+
|
|
96
|
+
const selectedPrefix = subDomainPrefix
|
|
97
|
+
? subDomainPrefix
|
|
98
|
+
.map((prefix) => prefix + '.')
|
|
99
|
+
.find((prefix) => host.includes(prefix)) || ''
|
|
100
|
+
: ''
|
|
101
|
+
|
|
102
|
+
const forwardedHost = host.replace(selectedPrefix, '')
|
|
103
|
+
|
|
104
|
+
const headers: HeadersInit = withCookie({
|
|
105
|
+
'content-type': 'application/json',
|
|
106
|
+
'X-FORWARDED-HOST': forwardedHost,
|
|
107
|
+
})
|
|
90
108
|
|
|
91
109
|
const getPolicyFacet = (): IStoreSelectedFacet | null => {
|
|
92
110
|
const { salesChannel } = ctx.storage.channel
|
|
@@ -202,7 +220,7 @@ export const IntelligentSearch = (
|
|
|
202
220
|
|
|
203
221
|
return fetchAPI(
|
|
204
222
|
`${base}/_v/api/intelligent-search/${type}/${pathname}?${params.toString()}`,
|
|
205
|
-
|
|
223
|
+
{ headers },
|
|
206
224
|
{ storeCookies }
|
|
207
225
|
)
|
|
208
226
|
}
|
|
@@ -220,7 +238,7 @@ export const IntelligentSearch = (
|
|
|
220
238
|
|
|
221
239
|
return fetchAPI(
|
|
222
240
|
`${base}/_v/api/intelligent-search/search_suggestions?${params.toString()}`,
|
|
223
|
-
|
|
241
|
+
{ headers },
|
|
224
242
|
{ storeCookies }
|
|
225
243
|
)
|
|
226
244
|
}
|
|
@@ -232,7 +250,7 @@ export const IntelligentSearch = (
|
|
|
232
250
|
|
|
233
251
|
return fetchAPI(
|
|
234
252
|
`${base}/_v/api/intelligent-search/top_searches?${params.toString()}`,
|
|
235
|
-
|
|
253
|
+
{ headers },
|
|
236
254
|
{ storeCookies }
|
|
237
255
|
)
|
|
238
256
|
}
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
QueryAllCollectionsArgs,
|
|
3
|
+
QueryAllProductsArgs,
|
|
4
|
+
QueryCollectionArgs,
|
|
5
|
+
QueryProductArgs,
|
|
6
|
+
QueryProfileArgs,
|
|
7
|
+
QueryRedirectArgs,
|
|
8
|
+
QuerySearchArgs,
|
|
9
|
+
QuerySellersArgs,
|
|
10
|
+
QueryShippingArgs,
|
|
11
|
+
} from '../../../__generated__/schema'
|
|
2
12
|
import { BadRequestError, NotFoundError } from '../../errors'
|
|
13
|
+
import type { CategoryTree } from '../clients/commerce/types/CategoryTree'
|
|
14
|
+
import type { ProfileAddress } from '../clients/commerce/types/Profile'
|
|
15
|
+
import type { SearchArgs } from '../clients/search'
|
|
16
|
+
import type { Context } from '../index'
|
|
3
17
|
import { mutateChannelContext, mutateLocaleContext } from '../utils/contex'
|
|
4
18
|
import { enhanceSku } from '../utils/enhanceSku'
|
|
5
19
|
import {
|
|
@@ -10,22 +24,10 @@ import {
|
|
|
10
24
|
findSlug,
|
|
11
25
|
transformSelectedFacet,
|
|
12
26
|
} from '../utils/facets'
|
|
27
|
+
import { isValidSkuId, pickBestSku } from '../utils/sku'
|
|
13
28
|
import { SORT_MAP } from '../utils/sort'
|
|
29
|
+
import { FACET_CROSS_SELLING_MAP } from './../utils/facets'
|
|
14
30
|
import { StoreCollection } from './collection'
|
|
15
|
-
import type {
|
|
16
|
-
QueryAllCollectionsArgs,
|
|
17
|
-
QueryAllProductsArgs,
|
|
18
|
-
QueryCollectionArgs,
|
|
19
|
-
QueryProductArgs,
|
|
20
|
-
QuerySearchArgs,
|
|
21
|
-
QuerySellersArgs,
|
|
22
|
-
QueryShippingArgs,
|
|
23
|
-
QueryRedirectArgs,
|
|
24
|
-
} from '../../../__generated__/schema'
|
|
25
|
-
import type { CategoryTree } from '../clients/commerce/types/CategoryTree'
|
|
26
|
-
import type { Context } from '../index'
|
|
27
|
-
import { isValidSkuId, pickBestSku } from '../utils/sku'
|
|
28
|
-
import type { SearchArgs } from '../clients/search'
|
|
29
31
|
|
|
30
32
|
export const Query = {
|
|
31
33
|
product: async (_: unknown, { locator }: QueryProductArgs, ctx: Context) => {
|
|
@@ -288,7 +290,6 @@ export const Query = {
|
|
|
288
290
|
address,
|
|
289
291
|
}
|
|
290
292
|
},
|
|
291
|
-
|
|
292
293
|
redirect: async (
|
|
293
294
|
_: unknown,
|
|
294
295
|
{ term, selectedFacets }: QueryRedirectArgs,
|
|
@@ -311,7 +312,6 @@ export const Query = {
|
|
|
311
312
|
url: redirect,
|
|
312
313
|
}
|
|
313
314
|
},
|
|
314
|
-
|
|
315
315
|
sellers: async (
|
|
316
316
|
_: unknown,
|
|
317
317
|
{ postalCode, geoCoordinates, country, salesChannel }: QuerySellersArgs,
|
|
@@ -335,4 +335,27 @@ export const Query = {
|
|
|
335
335
|
sellers,
|
|
336
336
|
}
|
|
337
337
|
},
|
|
338
|
+
profile: async (_: unknown, { id }: QueryProfileArgs, ctx: Context) => {
|
|
339
|
+
const {
|
|
340
|
+
clients: { commerce },
|
|
341
|
+
} = ctx
|
|
342
|
+
|
|
343
|
+
const addresses = await commerce.profile.addresses(id)
|
|
344
|
+
|
|
345
|
+
function mapAddressesToList(
|
|
346
|
+
addressesObj: Record<string, string>
|
|
347
|
+
): ProfileAddress[] {
|
|
348
|
+
if (!addressesObj || Object.keys(addressesObj).length === 0) {
|
|
349
|
+
return []
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return Object.values(addressesObj).map(
|
|
353
|
+
(stringifiedObj) => JSON.parse(stringifiedObj) as ProfileAddress
|
|
354
|
+
)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const parsedAddresses = mapAddressesToList(addresses)
|
|
358
|
+
|
|
359
|
+
return { addresses: parsedAddresses }
|
|
360
|
+
},
|
|
338
361
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
type Profile {
|
|
2
|
+
"""
|
|
3
|
+
Collection of user's address
|
|
4
|
+
"""
|
|
5
|
+
addresses: [ProfileAddress]
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type ProfileAddress {
|
|
9
|
+
"""
|
|
10
|
+
ProfileAddress address name/id.
|
|
11
|
+
"""
|
|
12
|
+
addressName: String
|
|
13
|
+
"""
|
|
14
|
+
ProfileAddress address type.
|
|
15
|
+
"""
|
|
16
|
+
addressType: String
|
|
17
|
+
"""
|
|
18
|
+
ProfileAddress postal code.
|
|
19
|
+
"""
|
|
20
|
+
postalCode: String
|
|
21
|
+
"""
|
|
22
|
+
ProfileAddress city.
|
|
23
|
+
"""
|
|
24
|
+
city: String
|
|
25
|
+
"""
|
|
26
|
+
ProfileAddress state.
|
|
27
|
+
"""
|
|
28
|
+
state: String
|
|
29
|
+
"""
|
|
30
|
+
ProfileAddress country.
|
|
31
|
+
"""
|
|
32
|
+
country: String
|
|
33
|
+
"""
|
|
34
|
+
ProfileAddress street.
|
|
35
|
+
"""
|
|
36
|
+
street: String
|
|
37
|
+
"""
|
|
38
|
+
ProfileAddress number.
|
|
39
|
+
"""
|
|
40
|
+
number: String
|
|
41
|
+
"""
|
|
42
|
+
ProfileAddress neighborhood.
|
|
43
|
+
"""
|
|
44
|
+
neighborhood: String
|
|
45
|
+
"""
|
|
46
|
+
ProfileAddress complement.
|
|
47
|
+
"""
|
|
48
|
+
complement: String
|
|
49
|
+
"""
|
|
50
|
+
ProfileAddress reference.
|
|
51
|
+
"""
|
|
52
|
+
reference: String
|
|
53
|
+
"""
|
|
54
|
+
ProfileAddress receiver name.
|
|
55
|
+
"""
|
|
56
|
+
receiverName: String
|
|
57
|
+
"""
|
|
58
|
+
ProfileAddress geo coordinate.
|
|
59
|
+
"""
|
|
60
|
+
geoCoordinate: [Float]
|
|
61
|
+
}
|
|
@@ -338,6 +338,17 @@ type Query {
|
|
|
338
338
|
salesChannel: String
|
|
339
339
|
): SellersData
|
|
340
340
|
@cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)
|
|
341
|
+
|
|
342
|
+
"""
|
|
343
|
+
Returns information about the profile.
|
|
344
|
+
"""
|
|
345
|
+
profile(
|
|
346
|
+
"""
|
|
347
|
+
Identifier for user.
|
|
348
|
+
"""
|
|
349
|
+
id: String!
|
|
350
|
+
): Profile
|
|
351
|
+
@cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)
|
|
341
352
|
}
|
|
342
353
|
|
|
343
354
|
"""
|