@scayle/storefront-core 8.8.0 → 8.10.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 +85 -0
- package/dist/helpers/advancedAttributeHelpers.d.ts +27 -0
- package/dist/helpers/arrayHelpers.d.ts +7 -0
- package/dist/helpers/attributeHelpers.d.ts +32 -0
- package/dist/helpers/basketHelpers.d.ts +7 -0
- package/dist/helpers/categoryHelper.d.ts +38 -0
- package/dist/helpers/filterHelper.d.ts +96 -10
- package/dist/helpers/formHelpers.d.ts +57 -24
- package/dist/helpers/imageHelpers.d.ts +18 -0
- package/dist/helpers/localization.d.ts +6 -4
- package/dist/helpers/objectHelpers.d.ts +7 -0
- package/dist/helpers/orderHelpers.d.ts +31 -16
- package/dist/helpers/productDisruptorHelper.d.ts +43 -0
- package/dist/helpers/productHelpers.d.ts +169 -0
- package/dist/helpers/sanitizationHelpers.d.ts +61 -0
- package/dist/helpers/sortingHelper.d.ts +16 -0
- package/dist/helpers/stringHelpers.d.ts +14 -0
- package/dist/index.d.ts +3 -1
- package/dist/rpc/methods/basket/basket.d.ts +95 -10
- package/dist/rpc/methods/basket/basket.mjs +4 -5
- package/dist/rpc/methods/brands.d.ts +26 -0
- package/dist/rpc/methods/campaign.d.ts +8 -4
- package/dist/rpc/methods/categories.d.ts +65 -5
- package/dist/rpc/methods/categories.mjs +2 -1
- package/dist/rpc/methods/cbd.d.ts +10 -0
- package/dist/rpc/methods/checkout/checkout.d.ts +42 -3
- package/dist/rpc/methods/checkout/checkout.mjs +2 -3
- package/dist/rpc/methods/checkout/order.d.ts +12 -0
- package/dist/rpc/methods/checkout/shopUser.d.ts +20 -0
- package/dist/rpc/methods/checkout/shopUserAddresses.d.ts +7 -0
- package/dist/rpc/methods/navigationTrees.d.ts +27 -0
- package/dist/rpc/methods/oauth/idp.d.ts +24 -0
- package/dist/rpc/methods/products.d.ts +160 -36
- package/dist/rpc/methods/products.mjs +8 -11
- package/dist/rpc/methods/promotion.d.ts +46 -4
- package/dist/rpc/methods/search.d.ts +17 -12
- package/dist/rpc/methods/search.mjs +4 -2
- package/dist/rpc/methods/session.d.ts +71 -0
- package/dist/rpc/methods/session.mjs +13 -13
- package/dist/rpc/methods/shopConfiguration.d.ts +12 -1
- package/dist/rpc/methods/shopConfiguration.mjs +2 -1
- package/dist/rpc/methods/user.d.ts +34 -4
- package/dist/rpc/methods/variants.d.ts +30 -2
- package/dist/rpc/methods/variants.mjs +1 -2
- package/dist/rpc/methods/wishlist.d.ts +42 -7
- package/dist/rpc/methods/wishlist.mjs +3 -4
- package/dist/test/factories/user.d.ts +10 -0
- package/dist/types/api/auth.d.ts +67 -0
- package/dist/types/api/context.d.ts +82 -1
- package/dist/types/api/rpc.d.ts +19 -0
- package/dist/types/breadcrumb.d.ts +9 -0
- package/dist/types/promises.d.ts +10 -0
- package/dist/types/sapi/basket.d.ts +26 -1
- package/dist/types/sapi/filter.d.ts +37 -0
- package/dist/types/sapi/navigation.d.ts +16 -4
- package/dist/types/sapi/order.d.ts +137 -242
- package/dist/types/sapi/product.d.ts +85 -0
- package/dist/types/sapi/productFilter.d.ts +14 -0
- package/dist/types/sapi/router.d.ts +3 -0
- package/dist/types/sapi/search.d.ts +19 -0
- package/dist/types/sapi/sorting.d.ts +7 -0
- package/dist/types/sapi/wishlist.d.ts +6 -0
- package/dist/types/user.d.ts +102 -0
- package/dist/utils/campaign.d.ts +25 -10
- package/package.json +4 -4
|
@@ -1,4 +1,46 @@
|
|
|
1
|
-
import type { PromotionsParams, PromotionsResponseData } from '../../types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { PromotionsParams, PromotionsResponseData, RpcContext } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves promotions based on provided parameters.
|
|
4
|
+
*
|
|
5
|
+
* This function uses the Storefront cache (`cached()`) with a `getPromotions` key prefix to improve performance.
|
|
6
|
+
* Cached entries are returned if found; otherwise, data is fetched and cached.
|
|
7
|
+
*
|
|
8
|
+
* @param params The parameters for retrieving promotions.
|
|
9
|
+
* @param params.pagination Pagination settings.
|
|
10
|
+
* @param params.pagination.page Page number.
|
|
11
|
+
* @param params.pagination.perPage Number of items per page.
|
|
12
|
+
* @param context The RPC context.
|
|
13
|
+
*
|
|
14
|
+
* @returns A Promise that resolves with the promotion data.
|
|
15
|
+
* It will return an `ErrorResponse` if the The Storefront API request fails.
|
|
16
|
+
*/
|
|
17
|
+
export declare const getPromotions: (params: Omit<PromotionsParams, "ids"> | undefined, context: RpcContext) => Promise<Response | PromotionsResponseData>;
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves currently active promotions.
|
|
20
|
+
*
|
|
21
|
+
* This function uses the Storefront cache (`cached()`) with a `getPromotions` key prefix to improve performance.
|
|
22
|
+
* Cached entries are returned if found; otherwise, data is fetched and cached.
|
|
23
|
+
*
|
|
24
|
+
* @param params The parameters for retrieving promotions.
|
|
25
|
+
* @param params.pagination Pagination settings.
|
|
26
|
+
* @param params.pagination.page Page number.
|
|
27
|
+
* @param params.pagination.perPage Number of items per page.
|
|
28
|
+
* @param context The RPC context.
|
|
29
|
+
*
|
|
30
|
+
* @returns A Promise that resolves with the current promotion data.
|
|
31
|
+
* It will return an `ErrorResponse` if the The Storefront API request fails.
|
|
32
|
+
*/
|
|
33
|
+
export declare const getCurrentPromotions: (params: Omit<PromotionsParams, "ids" | "activeAt"> | undefined, context: RpcContext) => Promise<Response | PromotionsResponseData>;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves promotions by their IDs.
|
|
36
|
+
*
|
|
37
|
+
* This function uses the Storefront cache (`cached()`) with a `getByIds-promotions` key prefix to improve performance.
|
|
38
|
+
* Cached entries are returned if found; otherwise, data is fetched and cached.
|
|
39
|
+
*
|
|
40
|
+
* @param ids An array of promotion IDs.
|
|
41
|
+
* @param context The RPC context.
|
|
42
|
+
*
|
|
43
|
+
* @returns A Promise that resolves with the promotion data.
|
|
44
|
+
* It will return an `ErrorResponse` if the The Storefront API request fails.
|
|
45
|
+
*/
|
|
46
|
+
export declare const getPromotionsByIds: (ids: string[], context: RpcContext) => Promise<Response | PromotionsResponseData>;
|
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
import type { SearchEntity, SearchV2ResolveEndpointParameters, SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData } from '../../types/sapi/search';
|
|
2
|
+
import type { RpcContext } from '../../types';
|
|
2
3
|
/**
|
|
3
4
|
* Fetches search suggestions for a given term.
|
|
4
5
|
*
|
|
5
|
-
* @param option
|
|
6
|
-
* @param option.term
|
|
7
|
-
* @param option.with
|
|
8
|
-
* @param option.categoryId
|
|
9
|
-
* @param context
|
|
6
|
+
* @param option The parameters for the request.
|
|
7
|
+
* @param option.term The term to search for.
|
|
8
|
+
* @param option.with An object describing which data the returned suggestions should contain.
|
|
9
|
+
* @param option.categoryId The category ID to search within.
|
|
10
|
+
* @param context The RPC context.
|
|
10
11
|
*
|
|
11
12
|
* @returns A promise that resolves to a list of search suggestions.
|
|
13
|
+
* It will return an `ErrorResponse` if the request fails.
|
|
12
14
|
*/
|
|
13
|
-
export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: SearchV2SuggestionsEndpointParameters,
|
|
15
|
+
export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: SearchV2SuggestionsEndpointParameters, context: RpcContext) => Promise<Response | SearchV2SuggestionsEndpointResponseData>;
|
|
14
16
|
/**
|
|
15
17
|
* Resolves a search query and returns the resolved entity.
|
|
16
18
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @param option
|
|
21
|
-
* @param
|
|
19
|
+
* This function uses the Storefront cache (`cached()`) with a `resolve-${term}` key prefix to improve performance.
|
|
20
|
+
* Cached entries are returned if found; otherwise, data is fetched and cached.
|
|
21
|
+
*
|
|
22
|
+
* @param option The parameters for the search query.
|
|
23
|
+
* @param option.term The search query to resolve.
|
|
24
|
+
* @param option.with An object describing which data the returned result should contain.
|
|
25
|
+
* @param option.categoryId The category ID for which the search should be performed.
|
|
26
|
+
* @param context The RPC context.
|
|
22
27
|
*
|
|
23
28
|
* @returns A promise that resolves to the resolved entity or null if no entity is found.
|
|
24
29
|
*/
|
|
25
|
-
export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters,
|
|
30
|
+
export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters, context: RpcContext) => Promise<SearchEntity | null>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
2
|
-
export const getSearchSuggestions = async function getSearchSuggestions2({ term, with: _with, categoryId },
|
|
2
|
+
export const getSearchSuggestions = async function getSearchSuggestions2({ term, with: _with, categoryId }, context) {
|
|
3
|
+
const { sapiClient, withParams } = context;
|
|
3
4
|
return await mapSAPIFetchErrorToResponse(sapiClient.searchv2.suggestions)(
|
|
4
5
|
term,
|
|
5
6
|
{
|
|
@@ -8,7 +9,8 @@ export const getSearchSuggestions = async function getSearchSuggestions2({ term,
|
|
|
8
9
|
}
|
|
9
10
|
);
|
|
10
11
|
};
|
|
11
|
-
export const resolveSearch = async function resolveSearch2({ term, with: _with, categoryId },
|
|
12
|
+
export const resolveSearch = async function resolveSearch2({ term, with: _with, categoryId }, context) {
|
|
13
|
+
const { cached, sapiClient, withParams } = context;
|
|
12
14
|
const resolvedEntity = await cached(sapiClient.searchv2.resolve, {
|
|
13
15
|
cacheKeyPrefix: `resolve-${term}`
|
|
14
16
|
})(term, {
|
|
@@ -1,20 +1,82 @@
|
|
|
1
1
|
import type { Optional } from 'utility-types';
|
|
2
2
|
import type { GuestRequest, LoginRequest, Oauth, RegisterRequest, RpcContext, RpcContextWithSession, ShopUser, UpdatePasswordByHashRequest } from '../../types';
|
|
3
3
|
import { ErrorResponse } from '../../errors';
|
|
4
|
+
/**
|
|
5
|
+
* Handles the post-login logic, including fetching user data, updating tokens,
|
|
6
|
+
* merging baskets and wishlists, and creating a user-bound session.
|
|
7
|
+
*
|
|
8
|
+
* @param context The RPC context with session information.
|
|
9
|
+
* @param tokens The OAuth tokens.
|
|
10
|
+
*
|
|
11
|
+
* @returns The result of the post login operation. It will return
|
|
12
|
+
* an `ErrorResponse` if fetching the user or merging baskets/wishlists fails.
|
|
13
|
+
*/
|
|
4
14
|
export declare function postLogin(context: RpcContextWithSession, tokens: Oauth): Promise<(ShopUser & ErrorResponse) | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Handles OAuth login requests.
|
|
17
|
+
*
|
|
18
|
+
* @param login The login request data. Includes `email` and `password` keys.
|
|
19
|
+
* @param context The RPC context.
|
|
20
|
+
*
|
|
21
|
+
* @returns A Response object indicating the login status. It will return
|
|
22
|
+
* an `ErrorResponse` if login fails.
|
|
23
|
+
*/
|
|
5
24
|
export declare const oauthLogin: (login: Optional<LoginRequest, "shop_id">, context: RpcContext) => Promise<Response>;
|
|
25
|
+
/**
|
|
26
|
+
* Handles OAuth user registration requests.
|
|
27
|
+
*
|
|
28
|
+
* @param register The registration request data.
|
|
29
|
+
* @param context The RPC context.
|
|
30
|
+
*
|
|
31
|
+
* @returns A Response object indicating the registration status. It will return
|
|
32
|
+
* an `ErrorResponse` if registration fails.
|
|
33
|
+
*/
|
|
6
34
|
export declare const oauthRegister: (register: Optional<RegisterRequest, "shop_id">, context: RpcContext) => Promise<Response>;
|
|
35
|
+
/**
|
|
36
|
+
* Handles OAuth guest login requests.
|
|
37
|
+
*
|
|
38
|
+
* @param guest The guest login request data.
|
|
39
|
+
* @param context The RPC context.
|
|
40
|
+
*
|
|
41
|
+
* @returns A Response object indicating the login status. It will return
|
|
42
|
+
* an `ErrorResponse` if guest login fails.
|
|
43
|
+
*/
|
|
7
44
|
export declare const oauthGuestLogin: (guest: Optional<GuestRequest, "shop_id">, context: RpcContext) => Promise<Response>;
|
|
45
|
+
/**
|
|
46
|
+
* Refreshes the access token using the refresh token.
|
|
47
|
+
*
|
|
48
|
+
* @param context The RPC context.
|
|
49
|
+
*
|
|
50
|
+
* @returns An object indicating the success status of the refresh operation.
|
|
51
|
+
* It will return an `ErrorResponse` if refreshing the token fails.
|
|
52
|
+
*/
|
|
8
53
|
export declare const refreshAccessToken: (context: RpcContext) => Promise<Response | {
|
|
9
54
|
success: true;
|
|
10
55
|
} | {
|
|
11
56
|
success: false;
|
|
12
57
|
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Revokes the current access token and destroys the session.
|
|
60
|
+
*
|
|
61
|
+
* @param context The RPC context.
|
|
62
|
+
*
|
|
63
|
+
* @returns An object indicating the result of the revocation.
|
|
64
|
+
* It will return an `ErrorResponse` if revoking the token fails.
|
|
65
|
+
*/
|
|
13
66
|
export declare const oauthRevokeToken: (context: RpcContext) => Promise<Response | {
|
|
14
67
|
result: true;
|
|
15
68
|
} | {
|
|
16
69
|
result: false;
|
|
17
70
|
}>;
|
|
71
|
+
/**
|
|
72
|
+
* Sends a password reset email to the specified email address.
|
|
73
|
+
*
|
|
74
|
+
* @param email The email address for password reset. Includes email key.
|
|
75
|
+
* @param context The RPC context.
|
|
76
|
+
*
|
|
77
|
+
* @returns An object indicating the success status of the operation.
|
|
78
|
+
* It will return an `ErrorResponse` if sending the password reset email fails.
|
|
79
|
+
*/
|
|
18
80
|
export declare const oauthForgetPassword: ({ email }: {
|
|
19
81
|
email: string;
|
|
20
82
|
}, context: RpcContext) => Promise<Response | {
|
|
@@ -22,4 +84,13 @@ export declare const oauthForgetPassword: ({ email }: {
|
|
|
22
84
|
} | {
|
|
23
85
|
success: false;
|
|
24
86
|
}>;
|
|
87
|
+
/**
|
|
88
|
+
* Updates the password using a password hash.
|
|
89
|
+
*
|
|
90
|
+
* @param passwordHash The password hash data.
|
|
91
|
+
* @param context The RPC context.
|
|
92
|
+
*
|
|
93
|
+
* @returns A Response object indicating the status of the password update.
|
|
94
|
+
* It will return an `ErrorResponse` if updating the password fails.
|
|
95
|
+
*/
|
|
25
96
|
export declare const updatePasswordByHash: (passwordHash: Optional<UpdatePasswordByHashRequest, "shop_id">, context: RpcContext) => Promise<Response>;
|
|
@@ -186,11 +186,11 @@ export const refreshAccessToken = async (context) => {
|
|
|
186
186
|
});
|
|
187
187
|
return { success: !!tokens };
|
|
188
188
|
} catch (error) {
|
|
189
|
-
const
|
|
189
|
+
const response = convertErrorForRpcCall(error, [
|
|
190
190
|
HttpStatusCode.BAD_REQUEST,
|
|
191
191
|
HttpStatusCode.UNAUTHORIZED
|
|
192
192
|
]);
|
|
193
|
-
if (
|
|
193
|
+
if (response && response.status === HttpStatusCode.UNAUTHORIZED) {
|
|
194
194
|
context.log.debug(
|
|
195
195
|
"Failed to refresh Checkout Token due to invalid refresh token. Deleting session"
|
|
196
196
|
);
|
|
@@ -200,8 +200,8 @@ export const refreshAccessToken = async (context) => {
|
|
|
200
200
|
"Failed to refresh Checkout Token for unknown reason."
|
|
201
201
|
);
|
|
202
202
|
}
|
|
203
|
-
if (
|
|
204
|
-
return
|
|
203
|
+
if (response) {
|
|
204
|
+
return response;
|
|
205
205
|
}
|
|
206
206
|
return { success: false };
|
|
207
207
|
}
|
|
@@ -234,13 +234,13 @@ export const oauthRevokeToken = async (context) => {
|
|
|
234
234
|
}, context);
|
|
235
235
|
return { result: true };
|
|
236
236
|
} catch (error) {
|
|
237
|
-
const
|
|
237
|
+
const response = convertErrorForRpcCall(error, [
|
|
238
238
|
HttpStatusCode.BAD_REQUEST,
|
|
239
239
|
HttpStatusCode.UNAUTHORIZED,
|
|
240
240
|
HttpStatusCode.NOT_FOUND
|
|
241
241
|
]);
|
|
242
|
-
if (
|
|
243
|
-
return
|
|
242
|
+
if (response) {
|
|
243
|
+
return response;
|
|
244
244
|
}
|
|
245
245
|
return { result: false };
|
|
246
246
|
}
|
|
@@ -276,14 +276,14 @@ export const oauthForgetPassword = async ({ email }, context) => {
|
|
|
276
276
|
});
|
|
277
277
|
return { success: true };
|
|
278
278
|
} catch (error) {
|
|
279
|
-
const
|
|
279
|
+
const response = convertErrorForRpcCall(error, [
|
|
280
280
|
HttpStatusCode.BAD_REQUEST,
|
|
281
281
|
HttpStatusCode.NOT_FOUND,
|
|
282
282
|
HttpStatusCode.UNAUTHORIZED,
|
|
283
283
|
HttpStatusCode.FORBIDDEN
|
|
284
284
|
]);
|
|
285
|
-
if (
|
|
286
|
-
return
|
|
285
|
+
if (response) {
|
|
286
|
+
return response;
|
|
287
287
|
}
|
|
288
288
|
return { success: false };
|
|
289
289
|
}
|
|
@@ -309,13 +309,13 @@ export const updatePasswordByHash = async (passwordHash, context) => {
|
|
|
309
309
|
});
|
|
310
310
|
await context.createUserBoundSession();
|
|
311
311
|
} catch (error) {
|
|
312
|
-
const
|
|
312
|
+
const response = convertErrorForRpcCall(error, [
|
|
313
313
|
HttpStatusCode.BAD_REQUEST,
|
|
314
314
|
HttpStatusCode.UNAUTHORIZED,
|
|
315
315
|
HttpStatusCode.NOT_ACCEPTABLE
|
|
316
316
|
]);
|
|
317
|
-
if (
|
|
318
|
-
return
|
|
317
|
+
if (response) {
|
|
318
|
+
return response;
|
|
319
319
|
}
|
|
320
320
|
return new ErrorResponse(
|
|
321
321
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import type { ShopConfiguration } from '@scayle/storefront-api';
|
|
2
2
|
import type { RpcContext } from '../../types';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves the shop configuration.
|
|
5
|
+
*
|
|
6
|
+
* This function uses the Storefront cache (`cached()`) with a `get-shopConfigurations` key prefix to improve performance.
|
|
7
|
+
* Cached entries are returned if found; otherwise, data is fetched and cached.
|
|
8
|
+
*
|
|
9
|
+
* @param context The RPC context.
|
|
10
|
+
*
|
|
11
|
+
* @returns The shop configuration. It will return an `ErrorResponse` alternatively
|
|
12
|
+
* if the Storefront API request fails.
|
|
13
|
+
*/
|
|
14
|
+
declare const getShopConfiguration: (context: RpcContext) => Promise<Response | ShopConfiguration>;
|
|
4
15
|
export { getShopConfiguration };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
2
|
-
const getShopConfiguration = async function getShopConfiguration2(
|
|
2
|
+
const getShopConfiguration = async function getShopConfiguration2(context) {
|
|
3
|
+
const { cached, sapiClient } = context;
|
|
3
4
|
return await cached(
|
|
4
5
|
mapSAPIFetchErrorToResponse(sapiClient.shopConfiguration.get),
|
|
5
6
|
{
|
|
@@ -1,22 +1,52 @@
|
|
|
1
1
|
import type { RpcContext, ShopUser } from '../../types';
|
|
2
2
|
import { ErrorResponse } from '../../errors';
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves the user from the context.
|
|
5
|
+
*
|
|
6
|
+
* @param context The RPC context.
|
|
7
|
+
*
|
|
8
|
+
* @returns An object containing the user object, or undefined if not logged in.
|
|
9
|
+
*/
|
|
3
10
|
declare const getUser: (context: RpcContext) => {
|
|
4
11
|
user: ShopUser | undefined;
|
|
5
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Fetches user data using the provided access token.
|
|
15
|
+
*
|
|
16
|
+
* @param param An object containing the access token.
|
|
17
|
+
* @param param.accessToken The access token for authentication.
|
|
18
|
+
* @param context The RPC context.
|
|
19
|
+
*
|
|
20
|
+
* @returns The fetched user data. It will return an `ErrorResponse` alternatively
|
|
21
|
+
* if an error occurs during the API call.
|
|
22
|
+
*/
|
|
6
23
|
declare const fetchUser: ({ accessToken }: {
|
|
7
24
|
accessToken?: string;
|
|
8
25
|
}, context: RpcContext) => Promise<ShopUser>;
|
|
9
26
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
27
|
+
* Refreshes the user session and data.
|
|
28
|
+
* If the user is no longer logged in, the session is destroyed.
|
|
29
|
+
*
|
|
30
|
+
* @param context The RPC context.
|
|
31
|
+
*
|
|
32
|
+
* @returns An object containing the user object, or undefined if session is destroyed.
|
|
33
|
+
* It will return an `ErrorResponse` if no session is found or other errors occur.
|
|
14
34
|
*/
|
|
15
35
|
declare const refreshUser: (context: RpcContext) => Promise<ErrorResponse | {
|
|
16
36
|
user: undefined;
|
|
17
37
|
} | {
|
|
18
38
|
user: ShopUser;
|
|
19
39
|
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves or refreshes the access token.
|
|
42
|
+
*
|
|
43
|
+
* @param param The parameter containing the flag for forced token refresh.
|
|
44
|
+
* @param param.forceTokenRefresh Whether to force a token refresh. Defaults to false.
|
|
45
|
+
* @param context The RPC context.
|
|
46
|
+
*
|
|
47
|
+
* @returns The access token. It will return an `ErrorResponse` alternatively
|
|
48
|
+
* if no session, access token, or refresh token is found.
|
|
49
|
+
*/
|
|
20
50
|
declare const getAccessToken: ({ forceTokenRefresh }: {
|
|
21
51
|
forceTokenRefresh?: boolean;
|
|
22
52
|
} | undefined, context: RpcContext) => Promise<string | ErrorResponse>;
|
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
import type { ProductWith, VariantDetail } from '@scayle/storefront-api';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RpcHandler } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Parameters for fetching variants.
|
|
5
|
+
*/
|
|
3
6
|
export interface FetchVariantsParams {
|
|
7
|
+
/**
|
|
8
|
+
* Array of variant IDs.
|
|
9
|
+
*/
|
|
4
10
|
ids: number[];
|
|
11
|
+
/**
|
|
12
|
+
* Include related data for the variant.
|
|
13
|
+
*/
|
|
5
14
|
include?: ProductWith;
|
|
15
|
+
/**
|
|
16
|
+
* Price promotion key.
|
|
17
|
+
*/
|
|
6
18
|
pricePromotionKey?: string;
|
|
7
19
|
}
|
|
8
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves variant details by their IDs.
|
|
22
|
+
*
|
|
23
|
+
* This function uses the Storefront cache (`cached()`) with a `getByIds-variants` key prefix to improve performance.
|
|
24
|
+
* Cached entries are returned if found; otherwise, data is fetched and cached.
|
|
25
|
+
*
|
|
26
|
+
* @param params Parameters for fetching the variants.
|
|
27
|
+
* @param params.ids Array of variant IDs.
|
|
28
|
+
* @param params.include Include related data for the variant. Defaults to `defaultWith`.
|
|
29
|
+
* @param params.pricePromotionKey Price promotion key. Defaults to 'default'.
|
|
30
|
+
* @param context The RPC context.
|
|
31
|
+
*
|
|
32
|
+
* @returns A Promise that resolves to an array of `VariantDetail` objects.
|
|
33
|
+
*
|
|
34
|
+
* @throws Will throw an error if the SAPI request fails.
|
|
35
|
+
*/
|
|
36
|
+
export declare const getVariantById: RpcHandler<FetchVariantsParams, VariantDetail[]>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
2
|
-
import { getCampaignKey } from "./campaign.mjs";
|
|
3
2
|
const defaultWith = {
|
|
4
3
|
attributes: "all"
|
|
5
4
|
};
|
|
6
5
|
export const getVariantById = async function getVariantById2({ ids, include = defaultWith, pricePromotionKey = "default" }, context) {
|
|
7
6
|
const { sapiClient, cached, withParams } = context;
|
|
8
|
-
const campaignKey = await getCampaignKey
|
|
7
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
9
8
|
const resolvedWith = include ?? withParams?.variant ?? defaultWith;
|
|
10
9
|
return await cached(
|
|
11
10
|
mapSAPIFetchErrorToResponse(sapiClient.variants.getByIds),
|
|
@@ -1,13 +1,48 @@
|
|
|
1
1
|
import type { Wishlist } from '@scayle/storefront-api';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type { ParamRpcHandler, RpcHandler, WishlistWithOptions } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves the wishlist.
|
|
5
|
+
*
|
|
6
|
+
* @param options The options for retrieving the wishlist, including optional `with` parameter.
|
|
7
|
+
* @param options.with Optional parameter for specifying additional data to include in the wishlist response.
|
|
8
|
+
* @param context The RPC context.
|
|
9
|
+
*
|
|
10
|
+
* @returns The wishlist data or an `ErrorResponse` if an error occurs.
|
|
11
|
+
* It will return an `ErrorResponse` if no session is found or if fetching the wishlist fails.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getWishlist: RpcHandler<WishlistWithOptions | undefined, Wishlist>;
|
|
14
|
+
/**
|
|
15
|
+
* Adds an item to the wishlist.
|
|
16
|
+
*
|
|
17
|
+
* @param options The options for adding an item, including product/variant ID and additional data.
|
|
18
|
+
* @param options.variantId The ID of the variant to add.
|
|
19
|
+
* @param options.productId The ID of the product to add.
|
|
20
|
+
* @param options.with Optional parameter for specifying additional data to include in the wishlist response.
|
|
21
|
+
* @param context The RPC context.
|
|
22
|
+
*
|
|
23
|
+
* @returns The updated wishlist or a `Response` object indicating the error if adding fails.
|
|
24
|
+
* It will return an `ErrorResponse` if no session is found,
|
|
25
|
+
* if neither productId nor variantId are provided, or if adding to the wishlist fails.
|
|
26
|
+
*/
|
|
27
|
+
export declare const addItemToWishlist: ParamRpcHandler<{
|
|
5
28
|
variantId?: number;
|
|
6
29
|
productId?: number;
|
|
7
30
|
with?: WishlistWithOptions;
|
|
8
|
-
},
|
|
9
|
-
|
|
31
|
+
}, Wishlist | Response>;
|
|
32
|
+
/**
|
|
33
|
+
* Removes an item from the wishlist.
|
|
34
|
+
*
|
|
35
|
+
* @param options Options for removing the item.
|
|
36
|
+
* @param options.itemKey The key of the item to remove.
|
|
37
|
+
* @param options.with Optional parameter for specifying additional data to include in the wishlist response.
|
|
38
|
+
*
|
|
39
|
+
* @param context The RPC context.
|
|
40
|
+
*
|
|
41
|
+
* @returns The updated wishlist data. It will return an `ErrorResponse`
|
|
42
|
+
* if no session is found or if removing the item fails.
|
|
43
|
+
*/
|
|
44
|
+
export declare const removeItemFromWishlist: RpcHandler<{
|
|
10
45
|
itemKey: string;
|
|
11
46
|
with?: WishlistWithOptions;
|
|
12
|
-
},
|
|
13
|
-
export declare const clearWishlist:
|
|
47
|
+
}, Wishlist>;
|
|
48
|
+
export declare const clearWishlist: RpcHandler<Wishlist>;
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
import { unwrap } from "../../utils/response.mjs";
|
|
8
8
|
import { ErrorResponse } from "../../errors/index.mjs";
|
|
9
9
|
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
10
|
-
import { getCampaignKey } from "./campaign.mjs";
|
|
11
10
|
function getWithParams(params, context) {
|
|
12
11
|
return params.with ?? context.withParams?.wishlist ?? MIN_WITH_PARAMS_WISHLIST;
|
|
13
12
|
}
|
|
@@ -20,7 +19,7 @@ export const getWishlist = async function getWishlist2(options, context) {
|
|
|
20
19
|
);
|
|
21
20
|
}
|
|
22
21
|
const { sapiClient, wishlistKey } = context;
|
|
23
|
-
const campaignKey = await getCampaignKey
|
|
22
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
24
23
|
const resolvedWith = getWithParams({ with: options }, context);
|
|
25
24
|
return await mapSAPIFetchErrorToResponse(sapiClient.wishlist.get)(
|
|
26
25
|
wishlistKey,
|
|
@@ -40,7 +39,7 @@ export const addItemToWishlist = async function addItemToWishlist2(options, cont
|
|
|
40
39
|
);
|
|
41
40
|
}
|
|
42
41
|
const { sapiClient, wishlistKey } = context;
|
|
43
|
-
const campaignKey = await getCampaignKey
|
|
42
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
44
43
|
const { productId, variantId } = options;
|
|
45
44
|
const resolvedWith = getWithParams(options, context);
|
|
46
45
|
const pricePromotionKey = resolvedWith?.pricePromotionKey ?? "";
|
|
@@ -77,7 +76,7 @@ export const removeItemFromWishlist = async function removeItemFromWishlist2(opt
|
|
|
77
76
|
);
|
|
78
77
|
}
|
|
79
78
|
const { sapiClient, wishlistKey } = context;
|
|
80
|
-
const campaignKey = await getCampaignKey
|
|
79
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
81
80
|
const resolvedWith = getWithParams(options, context);
|
|
82
81
|
return await mapSAPIFetchErrorToResponse(sapiClient.wishlist.deleteItem)(
|
|
83
82
|
wishlistKey,
|
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import { Factory } from 'fishery';
|
|
2
2
|
import type { ShopUser } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Factory for creating mock `ShopUser` objects for testing.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const user = userFactory.build() // Generates a default ShopUser object
|
|
9
|
+
* const guestUser = userFactory.build({ isGuest: true }) // Generates a guest ShopUser
|
|
10
|
+
* const multipleUsers = userFactory.buildList(5) // Generates an array of 5 ShopUser objects.
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
3
13
|
export declare const userFactory: Factory<ShopUser, any, ShopUser>;
|
package/dist/types/api/auth.d.ts
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import type { Gender } from '../user';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a pair of OAuth 2.0 access and refresh tokens. These tokens are used for authentication and authorization within an OAuth 2.0 flow.
|
|
4
|
+
*
|
|
5
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-1.4
|
|
6
|
+
* @see https://scayle.dev/en/checkout-guide/authentication-accounts/token-based-authentication
|
|
7
|
+
*/
|
|
2
8
|
export interface OAuthTokens {
|
|
3
9
|
accessToken: string;
|
|
4
10
|
refreshToken: string;
|
|
5
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Represents a base error object providing a structured format for error responses.
|
|
14
|
+
*/
|
|
6
15
|
interface BaseError {
|
|
7
16
|
error: string;
|
|
8
17
|
message: string;
|
|
9
18
|
context: Record<any, any> | null;
|
|
10
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Represents a Bad Request (400) error indicating a validation failure, often caused by incorrect client input.
|
|
22
|
+
*
|
|
23
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6750#section-3.1
|
|
24
|
+
* @see https://scayle.dev/en/api-guides/checkout-authentication-api/getting-started/errors#_400s-status-codes
|
|
25
|
+
*/
|
|
11
26
|
export interface BadRequestError extends BaseError {
|
|
12
27
|
error: 'validation_error';
|
|
13
28
|
message: 'The property ID must be an integer.';
|
|
@@ -16,16 +31,32 @@ export interface BadRequestError extends BaseError {
|
|
|
16
31
|
context: Record<any, any>;
|
|
17
32
|
};
|
|
18
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents an Unauthorized (401) error indicating client authentication failure, typically due to invalid credentials.
|
|
36
|
+
*
|
|
37
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6750#section-3.1
|
|
38
|
+
* @see https://scayle.dev/en/api-guides/checkout-authentication-api/getting-started/errors#unauthorized-client
|
|
39
|
+
*/
|
|
19
40
|
export interface UnauthorizedError extends BaseError {
|
|
20
41
|
error: 'INVALID_CLIENT';
|
|
21
42
|
message: 'Client authentication failed.';
|
|
22
43
|
context: null;
|
|
23
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Represents the request body for login.
|
|
47
|
+
*
|
|
48
|
+
* @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/log-in-users
|
|
49
|
+
*/
|
|
24
50
|
export interface LoginRequest {
|
|
25
51
|
email: string;
|
|
26
52
|
password: string;
|
|
27
53
|
shop_id: number;
|
|
28
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Represents the request body for registration.
|
|
57
|
+
*
|
|
58
|
+
* @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/create-new-user
|
|
59
|
+
*/
|
|
29
60
|
export interface RegisterRequest {
|
|
30
61
|
first_name: string;
|
|
31
62
|
last_name: string;
|
|
@@ -34,6 +65,11 @@ export interface RegisterRequest {
|
|
|
34
65
|
gender: Gender;
|
|
35
66
|
shop_id: number;
|
|
36
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Represents the request body for guest checkout.
|
|
70
|
+
*
|
|
71
|
+
* @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/log-in-users-as-guest
|
|
72
|
+
*/
|
|
37
73
|
export interface GuestRequest {
|
|
38
74
|
first_name: string;
|
|
39
75
|
last_name: string;
|
|
@@ -41,31 +77,62 @@ export interface GuestRequest {
|
|
|
41
77
|
gender: Gender;
|
|
42
78
|
shop_id: number;
|
|
43
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Represents the request body for sending a password reset email.
|
|
82
|
+
*
|
|
83
|
+
* @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/send-password-reset-email
|
|
84
|
+
*/
|
|
44
85
|
export interface SendResetPasswordEmailRequest {
|
|
45
86
|
email: string;
|
|
46
87
|
reset_url: string;
|
|
47
88
|
shop_id: number;
|
|
48
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Represents the request body for updating a password using a hash.
|
|
92
|
+
*
|
|
93
|
+
* @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/update-password-by-hash
|
|
94
|
+
*/
|
|
49
95
|
export interface UpdatePasswordByHashRequest {
|
|
50
96
|
password: string;
|
|
51
97
|
hash: string;
|
|
52
98
|
shop_id: number;
|
|
53
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Represents the request body for updating a password.
|
|
102
|
+
*
|
|
103
|
+
* @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/bearer-auth/update-customers-password
|
|
104
|
+
*/
|
|
54
105
|
export interface UpdatePasswordRequest {
|
|
55
106
|
password: string;
|
|
56
107
|
new_password: string;
|
|
57
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Represents the request body for refreshing an OAuth 2.0 access token using a refresh token.
|
|
111
|
+
*
|
|
112
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-6
|
|
113
|
+
*/
|
|
58
114
|
export interface RefreshTokenRequest {
|
|
59
115
|
grant_type: 'refresh_token';
|
|
60
116
|
refresh_token: string;
|
|
61
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Represents a standard OAuth 2.0 access token response as defined in RFC 6750.
|
|
120
|
+
*
|
|
121
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6750
|
|
122
|
+
* @see https://scayle.dev/en/api-guides/checkout-authentication-api/getting-started/authentication#auth-response
|
|
123
|
+
*/
|
|
62
124
|
export interface Oauth {
|
|
125
|
+
/** The type of token. A `Bearer` token indicates that anyone who possesses the token can use it to access the protected resources, without further authentication. */
|
|
63
126
|
token_type: 'Bearer';
|
|
127
|
+
/** The lifetime of the access token in seconds. */
|
|
64
128
|
expires_in: number;
|
|
129
|
+
/** The access token string issued by the authorization server. */
|
|
65
130
|
access_token: string;
|
|
131
|
+
/** A refresh token that can be used to obtain a new access token. */
|
|
66
132
|
refresh_token: string;
|
|
67
133
|
}
|
|
68
134
|
/**
|
|
135
|
+
* Represents an IDP configuration.
|
|
69
136
|
* This adds `string` so it's flexible enough to support
|
|
70
137
|
* multiple IDPs since we don't know what they are.
|
|
71
138
|
* More narrow type can be defined in the nuxt modules.
|