@faststore/api 1.2.36 → 1.3.3
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/CHANGELOG.md +35 -0
- package/dist/__generated__/schema.d.ts +4 -0
- package/dist/api.cjs.development.js +33 -16
- package/dist/api.cjs.development.js.map +1 -1
- package/dist/api.cjs.production.min.js +1 -1
- package/dist/api.cjs.production.min.js.map +1 -1
- package/dist/api.esm.js +33 -16
- package/dist/api.esm.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/platforms/vtex/clients/commerce/index.d.ts +6 -2
- package/dist/platforms/vtex/clients/commerce/types/Portal.d.ts +8 -0
- package/dist/platforms/vtex/clients/index.d.ts +3 -0
- package/dist/platforms/vtex/index.d.ts +8 -1
- package/dist/platforms/vtex/resolvers/collection.d.ts +2 -1
- package/dist/platforms/vtex/resolvers/query.d.ts +2 -1
- package/package.json +2 -2
- package/src/__generated__/schema.ts +6 -0
- package/src/platforms/vtex/clients/commerce/index.ts +8 -3
- package/src/platforms/vtex/clients/commerce/types/Portal.ts +8 -0
- package/src/platforms/vtex/clients/search/index.ts +7 -7
- package/src/platforms/vtex/resolvers/collection.ts +17 -5
- package/src/platforms/vtex/resolvers/query.ts +12 -0
- package/src/typeDefs/query.graphql +2 -3
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Resolver } from '..';
|
|
2
2
|
import type { Brand } from '../clients/commerce/types/Brand';
|
|
3
3
|
import type { CategoryTree } from '../clients/commerce/types/CategoryTree';
|
|
4
|
+
import type { PortalPagetype } from '../clients/commerce/types/Portal';
|
|
4
5
|
declare type Root = Brand | (CategoryTree & {
|
|
5
6
|
level: number;
|
|
6
|
-
});
|
|
7
|
+
}) | PortalPagetype;
|
|
7
8
|
export declare const StoreCollection: Record<string, Resolver<Root>>;
|
|
8
9
|
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { QueryProductArgs, QueryAllCollectionsArgs, QueryAllProductsArgs, QuerySearchArgs } from '../../../__generated__/schema';
|
|
1
|
+
import type { QueryProductArgs, QueryAllCollectionsArgs, QueryAllProductsArgs, QuerySearchArgs, QueryCollectionArgs } from '../../../__generated__/schema';
|
|
2
2
|
import type { CategoryTree } from '../clients/commerce/types/CategoryTree';
|
|
3
3
|
import type { Context } from '../index';
|
|
4
4
|
export declare const Query: {
|
|
5
5
|
product: (_: unknown, { locator }: QueryProductArgs, ctx: Context) => Promise<import("../utils/enhanceSku").EnhancedSku>;
|
|
6
|
+
collection: (_: unknown, { slug }: QueryCollectionArgs, ctx: Context) => Promise<import("../clients/commerce/types/Portal").PortalPagetype>;
|
|
6
7
|
search: (_: unknown, { first, after: maybeAfter, sort, term, selectedFacets }: QuerySearchArgs, ctx: Context) => Promise<{
|
|
7
8
|
page: number;
|
|
8
9
|
count: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"graphql": "^15.6.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "e9edffcfa59763f2312062b636613166fbca739c"
|
|
46
46
|
}
|
|
@@ -62,6 +62,7 @@ export type Query = {
|
|
|
62
62
|
__typename?: 'Query';
|
|
63
63
|
allCollections: StoreCollectionConnection;
|
|
64
64
|
allProducts: StoreProductConnection;
|
|
65
|
+
collection: StoreCollection;
|
|
65
66
|
product: StoreProduct;
|
|
66
67
|
search: StoreSearchResult;
|
|
67
68
|
};
|
|
@@ -79,6 +80,11 @@ export type QueryAllProductsArgs = {
|
|
|
79
80
|
};
|
|
80
81
|
|
|
81
82
|
|
|
83
|
+
export type QueryCollectionArgs = {
|
|
84
|
+
slug: Scalars['String'];
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
|
|
82
88
|
export type QueryProductArgs = {
|
|
83
89
|
locator: Array<IStoreSelectedFacet>;
|
|
84
90
|
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { Context, Options } from '../../index'
|
|
2
2
|
import { fetchAPI } from '../fetch'
|
|
3
|
+
import type { Brand } from './types/Brand'
|
|
4
|
+
import type { CategoryTree } from './types/CategoryTree'
|
|
5
|
+
import type { OrderForm, OrderFormInputItem } from './types/OrderForm'
|
|
6
|
+
import type { PortalPagetype } from './types/Portal'
|
|
3
7
|
import type {
|
|
4
8
|
Simulation,
|
|
5
9
|
SimulationArgs,
|
|
6
10
|
SimulationOptions,
|
|
7
11
|
} from './types/Simulation'
|
|
8
|
-
import type { CategoryTree } from './types/CategoryTree'
|
|
9
|
-
import type { Brand } from './types/Brand'
|
|
10
|
-
import type { OrderForm, OrderFormInputItem } from './types/OrderForm'
|
|
11
12
|
|
|
12
13
|
const BASE_INIT = {
|
|
13
14
|
method: 'POST',
|
|
@@ -32,6 +33,10 @@ export const VtexCommerce = (
|
|
|
32
33
|
tree: (depth = 3): Promise<CategoryTree[]> =>
|
|
33
34
|
fetchAPI(`${base}/api/catalog_system/pub/category/tree/${depth}`),
|
|
34
35
|
},
|
|
36
|
+
portal: {
|
|
37
|
+
pagetype: (slug: string): Promise<PortalPagetype> =>
|
|
38
|
+
fetchAPI(`${base}/api/catalog_system/pub/portal/pagetype/${slug}`),
|
|
39
|
+
},
|
|
35
40
|
},
|
|
36
41
|
checkout: {
|
|
37
42
|
simulation: (
|
|
@@ -34,16 +34,16 @@ export const IntelligentSearch = (
|
|
|
34
34
|
ctx: Context
|
|
35
35
|
) => {
|
|
36
36
|
const base = `http://portal.${environment}.com.br/search-api/v1/${account}`
|
|
37
|
+
const policyFacet = { key: 'trade-policy', value: ctx.storage.channel }
|
|
37
38
|
|
|
38
39
|
const addDefaultFacets = (facets: SelectedFacet[]) => {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
)
|
|
40
|
+
const facet = facets.find(({ key }) => key === policyFacet.key)
|
|
41
|
+
|
|
42
|
+
if (facet === undefined) {
|
|
43
|
+
return [...facets, policyFacet]
|
|
44
|
+
}
|
|
42
45
|
|
|
43
|
-
return
|
|
44
|
-
'trade-policy': ctx.storage.channel,
|
|
45
|
-
...facetsObj,
|
|
46
|
-
}).map(([key, value]) => ({ key, value }))
|
|
46
|
+
return facets
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
const search = <T>({
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { slugify } from '../utils/slugify'
|
|
2
1
|
import type { Resolver } from '..'
|
|
3
2
|
import type { Brand } from '../clients/commerce/types/Brand'
|
|
4
3
|
import type { CategoryTree } from '../clients/commerce/types/CategoryTree'
|
|
4
|
+
import type { PortalPagetype } from '../clients/commerce/types/Portal'
|
|
5
|
+
import { slugify } from '../utils/slugify'
|
|
5
6
|
|
|
6
|
-
type Root = Brand | (CategoryTree & { level: number })
|
|
7
|
+
type Root = Brand | (CategoryTree & { level: number }) | PortalPagetype
|
|
7
8
|
|
|
8
9
|
const isBrand = (x: any): x is Brand => x.type === 'brand'
|
|
9
10
|
|
|
11
|
+
const isPortalPageType = (x: any): x is PortalPagetype =>
|
|
12
|
+
typeof x.pageType === 'string'
|
|
13
|
+
|
|
10
14
|
export const StoreCollection: Record<string, Resolver<Root>> = {
|
|
11
15
|
id: ({ id }) => id.toString(),
|
|
12
16
|
slug: ({ name }) => slugify(name),
|
|
13
17
|
seo: (root) =>
|
|
14
|
-
isBrand(root)
|
|
18
|
+
isBrand(root) || isPortalPageType(root)
|
|
15
19
|
? {
|
|
16
20
|
title: root.title,
|
|
17
21
|
description: root.metaTagDescription,
|
|
@@ -21,14 +25,22 @@ export const StoreCollection: Record<string, Resolver<Root>> = {
|
|
|
21
25
|
description: root.MetaTagDescription,
|
|
22
26
|
},
|
|
23
27
|
type: (root) =>
|
|
24
|
-
isBrand(root)
|
|
28
|
+
isBrand(root)
|
|
29
|
+
? 'Brand'
|
|
30
|
+
: isPortalPageType(root)
|
|
31
|
+
? root.pageType
|
|
32
|
+
: root.level === 0
|
|
33
|
+
? 'Department'
|
|
34
|
+
: 'Category',
|
|
25
35
|
meta: (root) =>
|
|
26
36
|
isBrand(root)
|
|
27
37
|
? {
|
|
28
38
|
selectedFacets: [{ key: 'brand', value: slugify(root.name) }],
|
|
29
39
|
}
|
|
30
40
|
: {
|
|
31
|
-
selectedFacets: new URL(
|
|
41
|
+
selectedFacets: new URL(
|
|
42
|
+
isPortalPageType(root) ? `https://${root.url}` : root.url
|
|
43
|
+
).pathname
|
|
32
44
|
.slice(1)
|
|
33
45
|
.split('/')
|
|
34
46
|
.map((segment, index) => ({
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
QueryAllCollectionsArgs,
|
|
8
8
|
QueryAllProductsArgs,
|
|
9
9
|
QuerySearchArgs,
|
|
10
|
+
QueryCollectionArgs,
|
|
10
11
|
} from '../../../__generated__/schema'
|
|
11
12
|
import type { CategoryTree } from '../clients/commerce/types/CategoryTree'
|
|
12
13
|
import type { Context } from '../index'
|
|
@@ -27,6 +28,17 @@ export const Query = {
|
|
|
27
28
|
|
|
28
29
|
return skuLoader.load(locator.map(transformSelectedFacet))
|
|
29
30
|
},
|
|
31
|
+
collection: async (
|
|
32
|
+
_: unknown,
|
|
33
|
+
{ slug }: QueryCollectionArgs,
|
|
34
|
+
ctx: Context
|
|
35
|
+
) => {
|
|
36
|
+
const {
|
|
37
|
+
clients: { commerce },
|
|
38
|
+
} = ctx
|
|
39
|
+
|
|
40
|
+
return commerce.catalog.portal.pagetype(slug)
|
|
41
|
+
},
|
|
30
42
|
search: async (
|
|
31
43
|
_: unknown,
|
|
32
44
|
{ first, after: maybeAfter, sort, term, selectedFacets }: QuerySearchArgs,
|
|
@@ -8,7 +8,6 @@ type StoreProductConnection {
|
|
|
8
8
|
edges: [StoreProductEdge!]!
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
type StoreCollectionEdge {
|
|
13
12
|
node: StoreCollection!
|
|
14
13
|
cursor: String!
|
|
@@ -48,10 +47,10 @@ type StoreSearchResult {
|
|
|
48
47
|
type Query {
|
|
49
48
|
product(locator: [IStoreSelectedFacet!]!): StoreProduct!
|
|
50
49
|
|
|
50
|
+
collection(slug: String!): StoreCollection!
|
|
51
|
+
|
|
51
52
|
search(
|
|
52
|
-
# Relay style pagination args. To know more: https://relay.dev/graphql/connections.htm
|
|
53
53
|
first: Int!
|
|
54
|
-
# Relay style pagination args. To know more: https://relay.dev/graphql/connections.htm
|
|
55
54
|
after: String
|
|
56
55
|
sort: StoreSort = score_desc
|
|
57
56
|
term: String = ""
|