@faststore/api 1.9.3 → 1.9.6

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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Options as OptionsVTEX } from './platforms/vtex';
2
2
  export * from './__generated__/schema';
3
+ export * from './platforms/errors';
3
4
  export declare type Options = OptionsVTEX;
4
5
  export declare const getTypeDefs: () => string;
5
6
  export declare const getResolvers: (options: Options) => {
@@ -0,0 +1,19 @@
1
+ declare type ErrorType = 'BadRequestError' | 'NotFoundError' | 'RedirectError';
2
+ interface Extension {
3
+ type: ErrorType;
4
+ status: number;
5
+ }
6
+ declare class FastStoreError<T extends Extension = Extension> extends Error {
7
+ extensions: T;
8
+ constructor(extensions: T, message?: string);
9
+ }
10
+ export declare class BadRequestError extends FastStoreError {
11
+ constructor(message?: string);
12
+ }
13
+ export declare class NotFoundError extends FastStoreError {
14
+ constructor(message?: string);
15
+ }
16
+ export declare const isFastStoreError: (error: any) => error is FastStoreError<Extension>;
17
+ export declare const isNotFoundError: (error: any) => error is NotFoundError;
18
+ export declare const isBadRequestError: (error: any) => error is BadRequestError;
19
+ export {};
@@ -10,7 +10,7 @@ export interface SearchArgs {
10
10
  type: 'product_search' | 'facets';
11
11
  sort?: Sort;
12
12
  selectedFacets?: SelectedFacet[];
13
- fuzzy?: '0' | '1';
13
+ fuzzy?: '0' | '1' | 'auto';
14
14
  hideUnavailableItems?: boolean;
15
15
  }
16
16
  export interface ProductLocator {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "1.9.3",
3
+ "version": "1.9.6",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -44,5 +44,5 @@
44
44
  "peerDependencies": {
45
45
  "graphql": "^15.6.0"
46
46
  },
47
- "gitHead": "a7c7d1f5e20bfa6c157e0b50c6679336a67a8b4a"
47
+ "gitHead": "69e237e43d8fc3940fffdd2a9fa8d5ed43f40181"
48
48
  }
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ import { typeDefs } from './typeDefs'
8
8
  import type { Options as OptionsVTEX } from './platforms/vtex'
9
9
 
10
10
  export * from './__generated__/schema'
11
+ export * from './platforms/errors'
11
12
 
12
13
  export type Options = OptionsVTEX
13
14
 
@@ -0,0 +1,34 @@
1
+ type ErrorType = 'BadRequestError' | 'NotFoundError' | 'RedirectError'
2
+
3
+ interface Extension {
4
+ type: ErrorType
5
+ status: number
6
+ }
7
+
8
+ class FastStoreError<T extends Extension = Extension> extends Error {
9
+ constructor(public extensions: T, message?: string) {
10
+ super(message)
11
+ this.name = 'FastStoreError'
12
+ }
13
+ }
14
+
15
+ export class BadRequestError extends FastStoreError {
16
+ constructor(message?: string) {
17
+ super({ status: 400, type: 'BadRequestError' }, message)
18
+ }
19
+ }
20
+
21
+ export class NotFoundError extends FastStoreError {
22
+ constructor(message?: string) {
23
+ super({ status: 404, type: 'NotFoundError' }, message)
24
+ }
25
+ }
26
+
27
+ export const isFastStoreError = (error: any): error is FastStoreError =>
28
+ error?.name === 'FastStoreError'
29
+
30
+ export const isNotFoundError = (error: any): error is NotFoundError =>
31
+ error?.extensions?.type === 'NotFoundError'
32
+
33
+ export const isBadRequestError = (error: any): error is BadRequestError =>
34
+ error?.extensions?.type === 'BadRequestError'
@@ -25,7 +25,7 @@ export interface SearchArgs {
25
25
  type: 'product_search' | 'facets'
26
26
  sort?: Sort
27
27
  selectedFacets?: SelectedFacet[]
28
- fuzzy?: '0' | '1'
28
+ fuzzy?: '0' | '1' | 'auto'
29
29
  hideUnavailableItems?: boolean
30
30
  }
31
31
 
@@ -97,7 +97,7 @@ export const IntelligentSearch = (
97
97
  sort = '',
98
98
  selectedFacets = [],
99
99
  type,
100
- fuzzy = '0',
100
+ fuzzy = 'auto',
101
101
  }: SearchArgs): Promise<T> => {
102
102
  const params = new URLSearchParams({
103
103
  page: (page + 1).toString(),
@@ -1,7 +1,7 @@
1
1
  import DataLoader from 'dataloader'
2
2
  import pLimit from 'p-limit'
3
3
 
4
- import { NotFoundError } from '../utils/errors'
4
+ import { NotFoundError } from '../../errors'
5
5
  import type { CollectionPageType } from '../clients/commerce/types/Portal'
6
6
  import type { Options } from '..'
7
7
  import type { Clients } from '../clients'
@@ -1,7 +1,7 @@
1
1
  import DataLoader from 'dataloader'
2
2
 
3
- import { BadRequestError } from '../utils/errors'
4
3
  import { enhanceSku } from '../utils/enhanceSku'
4
+ import { BadRequestError, NotFoundError } from '../../errors'
5
5
  import type { EnhancedSku } from '../utils/enhanceSku'
6
6
  import type { Options } from '..'
7
7
  import type { Clients } from '../clients'
@@ -36,11 +36,11 @@ export const getSkuLoader = (_: Options, clients: Clients) => {
36
36
  }, {} as Record<string, EnhancedSku>)
37
37
 
38
38
  const skus = skuIds.map((skuId) => skuBySkuId[skuId])
39
- const missingSkus = skus.filter((sku) => !sku)
39
+ const missingSkus = skuIds.filter((skuId) => !skuBySkuId[skuId])
40
40
 
41
41
  if (missingSkus.length > 0) {
42
- throw new Error(
43
- `Search API did not return the following skus: ${missingSkus.join(',')}`
42
+ throw new NotFoundError(
43
+ `Search API did not found the following skus: ${missingSkus.join(',')}`
44
44
  )
45
45
  }
46
46
 
@@ -1,6 +0,0 @@
1
- export declare class BadRequestError extends Error {
2
- constructor(message: string);
3
- }
4
- export declare class NotFoundError extends Error {
5
- constructor(message: string);
6
- }
@@ -1,13 +0,0 @@
1
- export class BadRequestError extends Error {
2
- constructor(message: string) {
3
- super(message)
4
- this.name = 'BadRequestError'
5
- }
6
- }
7
-
8
- export class NotFoundError extends Error {
9
- constructor(message: string) {
10
- super(message)
11
- this.name = 'NotFoundError'
12
- }
13
- }