@faststore/api 1.3.1 → 1.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
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": "f960dad9561b64f519e9cdeb0560af422b11022f"
45
+ "gitHead": "bf541af67cee88f3489d37f6855b7310fc37eb60"
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: (
@@ -0,0 +1,8 @@
1
+ export interface PortalPagetype {
2
+ id: number
3
+ name: string
4
+ url: string
5
+ title: string
6
+ metaTagDescription: string
7
+ pageType: 'Brand' | 'Category' | 'Department' | 'Subcategory' | 'FullText'
8
+ }
@@ -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) ? 'Brand' : root.level === 0 ? 'Department' : 'Category',
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(root.url).pathname
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 = ""