@scayle/storefront-core 8.17.1 → 8.18.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 8.18.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Update RPC methods to use explicit typing. This is an internal change to enable Typescript's `isolatedDeclarations` option. It will not impact regular usage of RPC methods, however if you are importing one of the functions directly, the explicit rather than inferred type will be used.
8
+
9
+ ### Patch Changes
10
+
11
+ **Dependencies**
12
+
13
+ - Updated dependency to @scayle/storefront-api@18.2.2
14
+
3
15
  ## 8.17.1
4
16
 
5
17
  ### Patch Changes
@@ -1,7 +1,6 @@
1
1
  import { ExistingItemHandling } from '@scayle/storefront-api';
2
- import type { AddManyItemsBasketResponse, AddOrUpdateItemError, BasketResponse, UpdateBasketItemQuantity } from '@scayle/storefront-api';
3
- import { ErrorResponse } from '../../../errors';
4
- import type { AddOrUpdateItemType, BasketResponseData, BasketWithOptions, Product, RpcContext, Variant } from '../../../types';
2
+ import type { AddOrUpdateItemError, UpdateBasketItemQuantity } from '@scayle/storefront-api';
3
+ import type { AddOrUpdateItemType, BasketResponseData, BasketWithOptions, Product, RpcHandler, Variant } from '../../../types';
5
4
  /**
6
5
  * Adds an item to the basket.
7
6
  *
@@ -20,16 +19,13 @@ import type { AddOrUpdateItemType, BasketResponseData, BasketWithOptions, Produc
20
19
  * @returns The updated basket, potentially with errors. It will return
21
20
  * an `ErrorResponse` if no session is found or adding to basket fails.
22
21
  */
23
- export declare const addItemToBasket: ({ variantId, promotionId, quantity, displayData, customData, existingItemHandling, itemGroup, with: _with, orderCustomData, }: AddOrUpdateItemType & {
22
+ export declare const addItemToBasket: RpcHandler<AddOrUpdateItemType & {
24
23
  existingItemHandling?: ExistingItemHandling;
25
24
  with?: BasketWithOptions;
26
25
  orderCustomData?: Record<string, unknown>;
27
- }, context: RpcContext) => Promise<ErrorResponse | {
26
+ }, {
28
27
  basket: BasketResponseData<Product, Variant>;
29
- errors?: undefined;
30
- } | {
31
- basket: BasketResponseData<Product, Variant>;
32
- errors: AddOrUpdateItemError[];
28
+ errors?: AddOrUpdateItemError[];
33
29
  }>;
34
30
  /**
35
31
  * Adds multiple items to the basket.
@@ -44,17 +40,14 @@ export declare const addItemToBasket: ({ variantId, promotionId, quantity, displ
44
40
  * @returns The updated basket, potentially with errors. It will return
45
41
  * an `ErrorResponse` if no session is found or adding to basket fails.
46
42
  */
47
- export declare const addItemsToBasket: (params: {
43
+ export declare const addItemsToBasket: RpcHandler<{
48
44
  items: AddOrUpdateItemType[];
49
45
  existingItemHandling: ExistingItemHandling;
50
46
  with?: BasketWithOptions;
51
47
  orderCustomData?: Record<string, unknown>;
52
- }, context: RpcContext) => Promise<ErrorResponse | {
53
- basket: BasketResponseData<Product, Variant>;
54
- errors?: undefined;
55
- } | {
48
+ }, {
56
49
  basket: BasketResponseData<Product, Variant>;
57
- errors: AddOrUpdateItemError[];
50
+ errors?: AddOrUpdateItemError[];
58
51
  }>;
59
52
  /**
60
53
  * Retrieves the current basket.
@@ -66,9 +59,9 @@ export declare const addItemsToBasket: (params: {
66
59
  * @returns The basket data. It will return an `ErrorResponse` alternatively
67
60
  * if no session is found or retrieving the basket fails.
68
61
  */
69
- export declare const getBasket: (options: (BasketWithOptions & {
62
+ export declare const getBasket: RpcHandler<BasketWithOptions & {
70
63
  orderCustomData?: Record<string, unknown>;
71
- }) | undefined, context: RpcContext) => Promise<ErrorResponse | {
64
+ } | undefined, {
72
65
  basket: BasketResponseData<Product, Variant>;
73
66
  }>;
74
67
  /**
@@ -83,11 +76,11 @@ export declare const getBasket: (options: (BasketWithOptions & {
83
76
  * @returns The updated basket. It will return an `ErrorResponse` alternatively
84
77
  * if no session is found or removing the item fails.
85
78
  */
86
- export declare const removeItemFromBasket: (options: {
79
+ export declare const removeItemFromBasket: RpcHandler<{
87
80
  itemKey: string;
88
81
  with?: BasketWithOptions;
89
82
  orderCustomData?: Record<string, unknown>;
90
- }, context: RpcContext) => Promise<ErrorResponse | {
83
+ }, {
91
84
  basket: BasketResponseData<Product, Variant>;
92
85
  }>;
93
86
  /**
@@ -98,7 +91,7 @@ export declare const removeItemFromBasket: (options: {
98
91
  * @returns True if the basket was cleared successfully. It will return
99
92
  * an `ErrorResponse` alternatively iIf an error occurs during basket clearing.
100
93
  */
101
- export declare const clearBasket: (context: RpcContext) => Promise<true | ErrorResponse>;
94
+ export declare const clearBasket: RpcHandler<boolean>;
102
95
  /**
103
96
  * Merges two baskets.
104
97
  *
@@ -111,12 +104,12 @@ export declare const clearBasket: (context: RpcContext) => Promise<true | ErrorR
111
104
  *
112
105
  * @returns The new merged basket as result of the merge operation.
113
106
  */
114
- export declare const mergeBaskets: ({ fromBasketKey, toBasketKey, with: _with, orderCustomData }: {
107
+ export declare const mergeBaskets: RpcHandler<{
115
108
  fromBasketKey: string;
116
109
  toBasketKey: string;
117
110
  with?: BasketWithOptions;
118
111
  orderCustomData?: Record<string, unknown>;
119
- }, context: RpcContext) => Promise<BasketResponse<Product, Variant> | AddManyItemsBasketResponse<Product, Variant> | undefined>;
112
+ }, any>;
120
113
  /**
121
114
  * Type defining an object containing properties of a basket item than should be
122
115
  * applied to the basket item during the update.
@@ -154,6 +147,6 @@ export interface UpdateBasketItemRequestParameter {
154
147
  * In case of an error the, the failure kind will be resolved.
155
148
  * It will return an `ErrorResponse` if no session is found or update operation fails.
156
149
  */
157
- export declare const updateBasketItem: ({ basketItemKey, update, with: _with }: UpdateBasketItemRequestParameter, context: RpcContext) => Promise<ErrorResponse | {
150
+ export declare const updateBasketItem: RpcHandler<UpdateBasketItemRequestParameter, {
158
151
  basket: BasketResponseData<Product, Variant>;
159
152
  }>;
@@ -1,4 +1,4 @@
1
- import type { Brand, BrandsEndpointRequestParameters, BrandsEndpointResponseData } from '../../types';
1
+ import type { Brand, BrandsEndpointRequestParameters, BrandsEndpointResponseData, RpcHandler } from '../../types';
2
2
  /**
3
3
  * Retrieves a list of brands.
4
4
  *
@@ -13,7 +13,7 @@ import type { Brand, BrandsEndpointRequestParameters, BrandsEndpointResponseData
13
13
  *
14
14
  * @returns The list of brands. It will return an `ErrorResponse` if the request fails.
15
15
  */
16
- export declare const getBrands: ({ pagination }: BrandsEndpointRequestParameters, { sapiClient, cached }: import("../../types").RpcContext) => Promise<Response | BrandsEndpointResponseData>;
16
+ export declare const getBrands: RpcHandler<BrandsEndpointRequestParameters, BrandsEndpointResponseData>;
17
17
  /**
18
18
  * Retrieves a brand by its ID.
19
19
  *
@@ -26,6 +26,6 @@ export declare const getBrands: ({ pagination }: BrandsEndpointRequestParameters
26
26
  *
27
27
  * @returns The brand. It will return an `ErrorResponse` alternatively If the request fails.
28
28
  */
29
- export declare const getBrandById: ({ brandId }: {
29
+ export declare const getBrandById: RpcHandler<{
30
30
  brandId: number;
31
- }, { sapiClient, cached }: import("../../types").RpcContext) => Promise<Response | Brand>;
31
+ }, Brand>;
@@ -11,7 +11,10 @@ export const getBrands = async function getBrands2({ pagination }, { sapiClient,
11
11
  });
12
12
  };
13
13
  export const getBrandById = async function getBrandById2({ brandId }, { sapiClient, cached }) {
14
- return await cached(mapSAPIFetchErrorToResponse(sapiClient.brands.getById), {
15
- cacheKeyPrefix: `getBrandById-${brandId}`
16
- })(brandId);
14
+ return await cached(
15
+ mapSAPIFetchErrorToResponse(sapiClient.brands.getById),
16
+ {
17
+ cacheKeyPrefix: `getBrandById-${brandId}`
18
+ }
19
+ )(brandId);
17
20
  };
@@ -3,7 +3,7 @@ import {
3
3
  sortCampaignsByDateAscending,
4
4
  isCampaignActive
5
5
  } from "../../utils/campaign.mjs";
6
- export const getCampaignKey = async (context) => {
6
+ export const getCampaignKey = async function getCampaignKey2(context) {
7
7
  if (context.campaignKey) {
8
8
  return context.campaignKey;
9
9
  }
@@ -1,4 +1,4 @@
1
- import type { Category, ProductCategoryPropertyWith, RpcContext } from '../../types';
1
+ import type { Category, ProductCategoryPropertyWith, RpcHandler } from '../../types';
2
2
  /**
3
3
  * Retrieves the root categories.
4
4
  *
@@ -13,11 +13,11 @@ import type { Category, ProductCategoryPropertyWith, RpcContext } from '../../ty
13
13
  *
14
14
  * @returns The root categories and the active node (undefined).
15
15
  */
16
- export declare const getRootCategories: ({ children, includeHidden, properties }: {
16
+ export declare const getRootCategories: RpcHandler<{
17
17
  children?: number;
18
18
  includeHidden?: true;
19
19
  properties?: ProductCategoryPropertyWith;
20
- }, context: RpcContext) => Promise<{
20
+ }, {
21
21
  categories: Category[];
22
22
  activeNode: undefined;
23
23
  }>;
@@ -37,12 +37,12 @@ export declare const getRootCategories: ({ children, includeHidden, properties }
37
37
  * @returns The category or undefined if not found.
38
38
  * It will return an `ErrorResponse` if an error occurs during the API call.
39
39
  */
40
- export declare const getCategoryByPath: ({ path, children, includeHidden, properties }: {
40
+ export declare const getCategoryByPath: RpcHandler<{
41
41
  path: string;
42
42
  children?: number;
43
43
  includeHidden?: true;
44
44
  properties?: ProductCategoryPropertyWith;
45
- }, context: RpcContext) => Promise<Response | Category>;
45
+ }, Category | undefined>;
46
46
  /**
47
47
  * Retrieves categories by path.
48
48
  *
@@ -58,17 +58,14 @@ export declare const getCategoryByPath: ({ path, children, includeHidden, proper
58
58
  *
59
59
  * @returns The categories data.
60
60
  */
61
- export declare const getCategoriesByPath: ({ path, children, includeHidden, properties }: {
61
+ export declare const getCategoriesByPath: RpcHandler<{
62
62
  path: string;
63
63
  children?: number;
64
64
  includeHidden?: true;
65
65
  properties?: ProductCategoryPropertyWith;
66
- }, context: RpcContext) => Promise<{
67
- categories: Category[];
68
- activeNode: undefined;
69
- } | {
70
- categories: Category;
71
- activeNode: Category;
66
+ }, {
67
+ categories: Category[] | Category;
68
+ activeNode?: Category;
72
69
  }>;
73
70
  /**
74
71
  * Retrieves a category by ID.
@@ -85,9 +82,9 @@ export declare const getCategoriesByPath: ({ path, children, includeHidden, prop
85
82
  *
86
83
  * @returns The category. It will return an `ErrorResponse` if category retrieval fails.
87
84
  */
88
- export declare const getCategoryById: ({ id, children, includeHidden, properties }: {
85
+ export declare const getCategoryById: RpcHandler<{
89
86
  id: number;
90
87
  children?: number;
91
88
  includeHidden?: true;
92
89
  properties?: ProductCategoryPropertyWith;
93
- }, context: RpcContext) => Promise<Response | Category>;
90
+ }, Category>;
@@ -1,5 +1,4 @@
1
- import { ErrorResponse } from '../../errors';
2
- import type { Order, RpcContext } from '../../types';
1
+ import type { Order, RpcHandler } from '../../types';
3
2
  /**
4
3
  * Retrieves order data using a CBD token.
5
4
  *
@@ -10,6 +9,6 @@ import type { Order, RpcContext } from '../../types';
10
9
  * @returns The order data. It will return an `ErrorResponse` alternatively if
11
10
  * the CBD token is invalid, expired, or if an error occurs during the order retrieval.
12
11
  */
13
- export declare const getOrderDataByCbd: ({ cbdToken }: {
12
+ export declare const getOrderDataByCbd: RpcHandler<{
14
13
  cbdToken: string;
15
- }, context: RpcContext) => Promise<ErrorResponse | Order<Record<string, unknown>, Record<string, unknown>>>;
14
+ }, Order>;
@@ -36,7 +36,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
36
36
  carrier,
37
37
  basketId: context.basketKey,
38
38
  campaignKey
39
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.17.1"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
39
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.18.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
40
40
  return {
41
41
  accessToken: refreshedAccessToken,
42
42
  checkoutJwt
@@ -1,5 +1,4 @@
1
- import { ErrorResponse } from '../../../errors';
2
- import type { Order } from '../../../types';
1
+ import type { Order, RpcHandler } from '../../../types';
3
2
  /**
4
3
  * Retrieves an order by its ID.
5
4
  *
@@ -12,6 +11,6 @@ import type { Order } from '../../../types';
12
11
  * the order does not belong to the current user, the order is not found,
13
12
  * or an unknown error occurs.
14
13
  */
15
- export declare const getOrderById: ({ orderId }: {
14
+ export declare const getOrderById: RpcHandler<{
16
15
  orderId: number;
17
- }, context: import("../../../types").RpcContext) => Promise<ErrorResponse | Order<Record<string, unknown>, Record<string, unknown>>>;
16
+ }, Order>;
@@ -1,5 +1,4 @@
1
- import { ErrorResponse } from '../../../errors';
2
- import type { ShopUser, UpdatePasswordParams } from '../../../types';
1
+ import type { RpcHandler, ShopUser, UpdatePasswordParams } from '../../../types';
3
2
  /**
4
3
  * Updates the shop user.
5
4
  *
@@ -9,7 +8,7 @@ import type { ShopUser, UpdatePasswordParams } from '../../../types';
9
8
  * @returns The updated user. It will return an `ErrorResponse` alternatively
10
9
  * if updating user information fails.
11
10
  */
12
- export declare const updateShopUser: (payload: Partial<ShopUser>, context: import("../../../types").RpcContext) => Promise<ErrorResponse | {
11
+ export declare const updateShopUser: RpcHandler<Partial<ShopUser>, {
13
12
  user: ShopUser;
14
13
  }>;
15
14
  /**
@@ -23,6 +22,6 @@ export declare const updateShopUser: (payload: Partial<ShopUser>, context: impor
23
22
  * @returns The user object (or undefined if an error occurs and shopUser is undefined).
24
23
  * It will return an `ErrorResponse` if updating the password fails.
25
24
  */
26
- export declare const updatePassword: ({ oldPassword, newPassword }: UpdatePasswordParams, context: import("../../../types").RpcContext) => Promise<ErrorResponse | {
27
- user: ShopUser | undefined;
25
+ export declare const updatePassword: RpcHandler<UpdatePasswordParams, {
26
+ user?: ShopUser;
28
27
  }>;
@@ -1,4 +1,4 @@
1
- import type { ShopUserAddress } from '../../../types';
1
+ import type { RpcHandler, ShopUserAddress } from '../../../types';
2
2
  /**
3
3
  * Retrieves the shop user addresses.
4
4
  *
@@ -6,5 +6,5 @@ import type { ShopUserAddress } from '../../../types';
6
6
  *
7
7
  * @returns The shop user addresses.
8
8
  */
9
- declare const getShopUserAddresses: (context: import("../../../types").RpcContext) => Promise<ShopUserAddress[]>;
9
+ declare const getShopUserAddresses: RpcHandler<ShopUserAddress[]>;
10
10
  export { getShopUserAddresses };
@@ -1,6 +1,5 @@
1
1
  import type { NavigationAllEndpointResponseData, NavigationTree } from '@scayle/storefront-api';
2
- import type { FetchNavigationTreeByIdParams, FetchNavigationTreeByNameParams, FetchNavigationTreesParams } from '../../types';
3
- import { ErrorResponse } from '../../errors';
2
+ import type { FetchNavigationTreeByIdParams, FetchNavigationTreeByNameParams, FetchNavigationTreesParams, RpcHandler } from '../../types';
4
3
  /**
5
4
  * Fetches all navigation trees.
6
5
  *
@@ -14,7 +13,7 @@ import { ErrorResponse } from '../../errors';
14
13
  * @returns The navigation trees data. It will return an `ErrorResponse`
15
14
  * if an error occurs during fetching.
16
15
  */
17
- export declare const fetchAllNavigationTrees: ({ params }: FetchNavigationTreesParams, { sapiClient: { navigation }, cached }: import("../../types").RpcContext) => Promise<NavigationAllEndpointResponseData>;
16
+ export declare const fetchAllNavigationTrees: RpcHandler<FetchNavigationTreesParams, NavigationAllEndpointResponseData>;
18
17
  /**
19
18
  * Fetches a navigation tree by its ID.
20
19
  *
@@ -29,5 +28,5 @@ export declare const fetchAllNavigationTrees: ({ params }: FetchNavigationTreesP
29
28
  * @returns The navigation tree data. It will return an `ErrorResponse`
30
29
  * if an error occurs during fetching.
31
30
  */
32
- export declare const fetchNavigationTreeById: ({ treeId, params }: FetchNavigationTreeByIdParams, { sapiClient: { navigation }, cached }: import("../../types").RpcContext) => Promise<NavigationTree>;
33
- export declare const fetchNavigationTreeByName: ({ treeName, params }: FetchNavigationTreeByNameParams, { sapiClient: { navigation }, cached }: import("../../types").RpcContext) => Promise<ErrorResponse | NavigationTree>;
31
+ export declare const fetchNavigationTreeById: RpcHandler<FetchNavigationTreeByIdParams, NavigationTree>;
32
+ export declare const fetchNavigationTreeByName: RpcHandler<FetchNavigationTreeByNameParams, NavigationTree>;
@@ -1,5 +1,4 @@
1
- import { ErrorResponse } from '../../../errors';
2
- import type { RpcContext } from '../../../types';
1
+ import type { RpcHandler } from '../../../types';
3
2
  /**
4
3
  * Retrieves external IDP redirect URLs.
5
4
  *
@@ -13,11 +12,9 @@ import type { RpcContext } from '../../../types';
13
12
  * or an ErrorResponse if an error occurs. It will return an `ErrorResponse`
14
13
  * if JWT signing fails or another unexpected error occurs.
15
14
  */
16
- export declare const getExternalIdpRedirect: ({ queryParams }: {
15
+ export declare const getExternalIdpRedirect: RpcHandler<{
17
16
  queryParams?: Record<string, string>;
18
- }, context: RpcContext) => Promise<ErrorResponse | {
19
- [k: string]: string;
20
- }>;
17
+ }, Record<string, string>>;
21
18
  /**
22
19
  * Handles the IDP login callback.
23
20
  *
@@ -29,8 +26,8 @@ export declare const getExternalIdpRedirect: ({ queryParams }: {
29
26
  *
30
27
  * @returns A success message, or an `ErrorResponse` an error during login occurs.
31
28
  */
32
- export declare const handleIDPLoginCallback: (payload: {
29
+ export declare const handleIDPLoginCallback: RpcHandler<{
33
30
  code: string;
34
- }, context: RpcContext) => Promise<ErrorResponse | {
31
+ }, {
35
32
  message: string;
36
33
  }>;
@@ -20,8 +20,8 @@ export declare function resolveCategoryIdFromParams(context: RpcContext, params:
20
20
  categoryId: number;
21
21
  category?: undefined;
22
22
  }): Promise<{
23
- category: string | undefined;
24
- categoryId: number | undefined;
23
+ category?: string;
24
+ categoryId?: number;
25
25
  }>;
26
26
  /**
27
27
  * Retrieves a product by its ID.
@@ -1,4 +1,4 @@
1
- import type { PromotionsParams, RpcContext } from '../../types';
1
+ import type { PromotionsParams, PromotionsResponseData, RpcHandler } from '../../types';
2
2
  /**
3
3
  * Retrieves promotions based on provided parameters.
4
4
  *
@@ -14,7 +14,7 @@ import type { PromotionsParams, RpcContext } from '../../types';
14
14
  * @returns A Promise that resolves with the promotion data.
15
15
  * It will return an `ErrorResponse` if the The Storefront API request fails.
16
16
  */
17
- export declare const getPromotions: (params: Omit<PromotionsParams, "ids"> | undefined, context: RpcContext) => Promise<any>;
17
+ export declare const getPromotions: RpcHandler<Omit<PromotionsParams, 'ids'>, PromotionsResponseData>;
18
18
  /**
19
19
  * Retrieves currently active promotions.
20
20
  *
@@ -30,7 +30,7 @@ export declare const getPromotions: (params: Omit<PromotionsParams, "ids"> | und
30
30
  * @returns A Promise that resolves with the current promotion data.
31
31
  * It will return an `ErrorResponse` if the The Storefront API request fails.
32
32
  */
33
- export declare const getCurrentPromotions: (params: Omit<PromotionsParams, "ids" | "activeAt"> | undefined, context: RpcContext) => Promise<any>;
33
+ export declare const getCurrentPromotions: RpcHandler<Omit<PromotionsParams, 'ids' | 'activeAt'>, PromotionsResponseData>;
34
34
  /**
35
35
  * Retrieves promotions by their IDs.
36
36
  *
@@ -43,4 +43,4 @@ export declare const getCurrentPromotions: (params: Omit<PromotionsParams, "ids"
43
43
  * @returns A Promise that resolves with the promotion data.
44
44
  * It will return an `ErrorResponse` if the The Storefront API request fails.
45
45
  */
46
- export declare const getPromotionsByIds: (ids: string[], context: RpcContext) => Promise<any>;
46
+ export declare const getPromotionsByIds: RpcHandler<string[], PromotionsResponseData>;
@@ -1,5 +1,5 @@
1
- import type { SearchEntity, SearchV2ResolveEndpointParameters, SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData } from '../../types/sapi/search';
2
- import type { RpcContext } from '../../types';
1
+ import type { SearchV2ResolveEndpointParameters, SearchV2ResolveEndpointResponseData, SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData } from '../../types/sapi/search';
2
+ import type { RpcHandler } from '../../types';
3
3
  /**
4
4
  * Fetches search suggestions for a given term.
5
5
  *
@@ -12,7 +12,7 @@ import type { RpcContext } from '../../types';
12
12
  * @returns A promise that resolves to a list of search suggestions.
13
13
  * It will return an `ErrorResponse` if the request fails.
14
14
  */
15
- export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: SearchV2SuggestionsEndpointParameters, context: RpcContext) => Promise<Response | SearchV2SuggestionsEndpointResponseData>;
15
+ export declare const getSearchSuggestions: RpcHandler<SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData>;
16
16
  /**
17
17
  * Resolves a search query and returns the resolved entity.
18
18
  *
@@ -27,4 +27,4 @@ export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: S
27
27
  *
28
28
  * @returns A promise that resolves to the resolved entity or null if no entity is found.
29
29
  */
30
- export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters, context: RpcContext) => Promise<SearchEntity | null>;
30
+ export declare const resolveSearch: RpcHandler<SearchV2ResolveEndpointParameters, Promise<SearchV2ResolveEndpointResponseData | null>>;
@@ -1,5 +1,5 @@
1
1
  import type { Optional } from 'utility-types';
2
- import type { GuestRequest, LoginRequest, Oauth, RegisterRequest, RpcContext, RpcContextWithSession, ShopUser, UpdatePasswordByHashRequest } from '../../types';
2
+ import type { GuestRequest, LoginRequest, Oauth, ParamRpcHandler, RegisterRequest, RpcContextWithSession, RpcHandler, UpdatePasswordByHashRequest } from '../../types';
3
3
  import { ErrorResponse } from '../../errors';
4
4
  /**
5
5
  * Handles the post-login logic, including fetching user data, updating tokens,
@@ -11,7 +11,7 @@ import { ErrorResponse } from '../../errors';
11
11
  * @returns The result of the post login operation. It will return
12
12
  * an `ErrorResponse` if fetching the user or merging baskets/wishlists fails.
13
13
  */
14
- export declare function postLogin(context: RpcContextWithSession, tokens: Oauth): Promise<(ShopUser & ErrorResponse) | undefined>;
14
+ export declare function postLogin(context: RpcContextWithSession, tokens: Oauth): Promise<ErrorResponse | undefined>;
15
15
  /**
16
16
  * Handles OAuth login requests.
17
17
  *
@@ -21,7 +21,7 @@ export declare function postLogin(context: RpcContextWithSession, tokens: Oauth)
21
21
  * @returns A Response object indicating the login status. It will return
22
22
  * an `ErrorResponse` if login fails.
23
23
  */
24
- export declare const oauthLogin: (login: Optional<LoginRequest, "shop_id">, context: RpcContext) => Promise<Response>;
24
+ export declare const oauthLogin: ParamRpcHandler<Optional<LoginRequest, 'shop_id'>, undefined>;
25
25
  /**
26
26
  * Handles OAuth user registration requests.
27
27
  *
@@ -31,7 +31,7 @@ export declare const oauthLogin: (login: Optional<LoginRequest, "shop_id">, cont
31
31
  * @returns A Response object indicating the registration status. It will return
32
32
  * an `ErrorResponse` if registration fails.
33
33
  */
34
- export declare const oauthRegister: (register: Optional<RegisterRequest, "shop_id">, context: RpcContext) => Promise<Response>;
34
+ export declare const oauthRegister: ParamRpcHandler<Optional<RegisterRequest, 'shop_id'>, undefined>;
35
35
  /**
36
36
  * Handles OAuth guest login requests.
37
37
  *
@@ -41,7 +41,7 @@ export declare const oauthRegister: (register: Optional<RegisterRequest, "shop_i
41
41
  * @returns A Response object indicating the login status. It will return
42
42
  * an `ErrorResponse` if guest login fails.
43
43
  */
44
- export declare const oauthGuestLogin: (guest: Optional<GuestRequest, "shop_id">, context: RpcContext) => Promise<Response>;
44
+ export declare const oauthGuestLogin: ParamRpcHandler<Optional<GuestRequest, 'shop_id'>, undefined>;
45
45
  /**
46
46
  * Refreshes the access token using the refresh token.
47
47
  *
@@ -50,10 +50,8 @@ export declare const oauthGuestLogin: (guest: Optional<GuestRequest, "shop_id">,
50
50
  * @returns An object indicating the success status of the refresh operation.
51
51
  * It will return an `ErrorResponse` if refreshing the token fails.
52
52
  */
53
- export declare const refreshAccessToken: (context: RpcContext) => Promise<Response | {
54
- success: true;
55
- } | {
56
- success: false;
53
+ export declare const refreshAccessToken: RpcHandler<{
54
+ success: boolean;
57
55
  }>;
58
56
  /**
59
57
  * Revokes the current access token and destroys the session.
@@ -63,10 +61,8 @@ export declare const refreshAccessToken: (context: RpcContext) => Promise<Respon
63
61
  * @returns An object indicating the result of the revocation.
64
62
  * It will return an `ErrorResponse` if revoking the token fails.
65
63
  */
66
- export declare const oauthRevokeToken: (context: RpcContext) => Promise<Response | {
67
- result: true;
68
- } | {
69
- result: false;
64
+ export declare const oauthRevokeToken: RpcHandler<{
65
+ result: boolean;
70
66
  }>;
71
67
  /**
72
68
  * Sends a password reset email to the specified email address.
@@ -77,12 +73,10 @@ export declare const oauthRevokeToken: (context: RpcContext) => Promise<Response
77
73
  * @returns An object indicating the success status of the operation.
78
74
  * It will return an `ErrorResponse` if sending the password reset email fails.
79
75
  */
80
- export declare const oauthForgetPassword: ({ email }: {
76
+ export declare const oauthForgetPassword: RpcHandler<{
81
77
  email: string;
82
- }, context: RpcContext) => Promise<Response | {
83
- success: true;
84
- } | {
85
- success: false;
78
+ }, {
79
+ success: boolean;
86
80
  }>;
87
81
  /**
88
82
  * Updates the password using a password hash.
@@ -93,4 +87,4 @@ export declare const oauthForgetPassword: ({ email }: {
93
87
  * @returns A Response object indicating the status of the password update.
94
88
  * It will return an `ErrorResponse` if updating the password fails.
95
89
  */
96
- export declare const updatePasswordByHash: (passwordHash: Optional<UpdatePasswordByHashRequest, "shop_id">, context: RpcContext) => Promise<Response>;
90
+ export declare const updatePasswordByHash: ParamRpcHandler<Optional<UpdatePasswordByHashRequest, 'shop_id'>, undefined>;
@@ -1,5 +1,5 @@
1
1
  import type { ShopConfiguration } from '@scayle/storefront-api';
2
- import type { RpcContext } from '../../types';
2
+ import type { RpcHandler } from '../../types';
3
3
  /**
4
4
  * Retrieves the shop configuration.
5
5
  *
@@ -11,5 +11,5 @@ import type { RpcContext } from '../../types';
11
11
  * @returns The shop configuration. It will return an `ErrorResponse` alternatively
12
12
  * if the Storefront API request fails.
13
13
  */
14
- declare const getShopConfiguration: (context: RpcContext) => Promise<Response | ShopConfiguration>;
14
+ declare const getShopConfiguration: RpcHandler<ShopConfiguration>;
15
15
  export { getShopConfiguration };
@@ -1,5 +1,4 @@
1
- import type { RpcContext, ShopUser } from '../../types';
2
- import { ErrorResponse } from '../../errors';
1
+ import type { RpcContext, RpcHandler, ShopUser } from '../../types';
3
2
  /**
4
3
  * Retrieves the user from the context.
5
4
  *
@@ -7,9 +6,9 @@ import { ErrorResponse } from '../../errors';
7
6
  *
8
7
  * @returns An object containing the user object, or undefined if not logged in.
9
8
  */
10
- declare const getUser: (context: RpcContext) => {
11
- user: ShopUser | undefined;
12
- };
9
+ declare const getUser: RpcHandler<{
10
+ user?: ShopUser;
11
+ }>;
13
12
  /**
14
13
  * Fetches user data using the provided access token.
15
14
  *
@@ -32,10 +31,8 @@ declare const fetchUser: ({ accessToken }: {
32
31
  * @returns An object containing the user object, or undefined if session is destroyed.
33
32
  * It will return an `ErrorResponse` if no session is found or other errors occur.
34
33
  */
35
- declare const refreshUser: (context: RpcContext) => Promise<ErrorResponse | {
36
- user: undefined;
37
- } | {
38
- user: ShopUser;
34
+ declare const refreshUser: RpcHandler<{
35
+ user?: ShopUser;
39
36
  }>;
40
37
  /**
41
38
  * Retrieves or refreshes the access token.
@@ -47,7 +44,7 @@ declare const refreshUser: (context: RpcContext) => Promise<ErrorResponse | {
47
44
  * @returns The access token. It will return an `ErrorResponse` alternatively
48
45
  * if no session, access token, or refresh token is found.
49
46
  */
50
- declare const getAccessToken: ({ forceTokenRefresh }: {
47
+ declare const getAccessToken: RpcHandler<{
51
48
  forceTokenRefresh?: boolean;
52
- } | undefined, context: RpcContext) => Promise<string | ErrorResponse>;
49
+ }, string>;
53
50
  export { getUser, fetchUser, refreshUser, getAccessToken };
@@ -42,7 +42,10 @@ const refreshUser = async function refreshUser2(context) {
42
42
  return { user: void 0 };
43
43
  }
44
44
  try {
45
- const user = await fetchUser({ accessToken }, context);
45
+ const user = await context.callRpc?.("fetchUser", { accessToken });
46
+ if (!user) {
47
+ return { user: void 0 };
48
+ }
46
49
  context.updateUser(user);
47
50
  return { user };
48
51
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "8.17.1",
3
+ "version": "8.18.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -63,7 +63,7 @@
63
63
  "fishery": "^2.2.3"
64
64
  },
65
65
  "dependencies": {
66
- "@scayle/storefront-api": "18.2.1",
66
+ "@scayle/storefront-api": "18.2.2",
67
67
  "@scayle/unstorage-scayle-kv-driver": "0.1.1",
68
68
  "crypto-js": "^4.2.0",
69
69
  "hookable": "^5.5.3",
@@ -89,5 +89,8 @@
89
89
  "unbuild": "3.5.0",
90
90
  "unstorage": "1.15.0",
91
91
  "vitest": "2.1.9"
92
+ },
93
+ "volta": {
94
+ "node": "22.14.0"
92
95
  }
93
96
  }