@scayle/storefront-core 8.9.0 → 8.11.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 +67 -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 +1 -1
- package/dist/rpc/methods/basket/basket.d.ts +95 -10
- 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 +40 -0
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/rpc/methods/checkout/order.d.ts +12 -0
- package/dist/rpc/methods/checkout/order.mjs +0 -10
- 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 +150 -7
- package/dist/rpc/methods/products.mjs +1 -3
- 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 +28 -0
- package/dist/rpc/methods/wishlist.d.ts +35 -0
- 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 +61 -0
- 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/package.json +1 -1
|
@@ -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
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
|
}
|
|
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
|
+
*/
|
|
8
36
|
export declare const getVariantById: RpcHandler<FetchVariantsParams, VariantDetail[]>;
|
|
@@ -1,11 +1,46 @@
|
|
|
1
1
|
import type { Wishlist } from '@scayle/storefront-api';
|
|
2
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
|
+
*/
|
|
3
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
|
+
*/
|
|
4
27
|
export declare const addItemToWishlist: ParamRpcHandler<{
|
|
5
28
|
variantId?: number;
|
|
6
29
|
productId?: number;
|
|
7
30
|
with?: WishlistWithOptions;
|
|
8
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
|
+
*/
|
|
9
44
|
export declare const removeItemFromWishlist: RpcHandler<{
|
|
10
45
|
itemKey: string;
|
|
11
46
|
with?: WishlistWithOptions;
|
|
@@ -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.
|
|
@@ -6,6 +6,9 @@ import type { AuthenticationType, ShopUser } from '../user';
|
|
|
6
6
|
import type { BasketWithOptions, CategoryWith, ProductCategoryWith, ProductWith, SearchV2With, SearchWith, VariantWith, WishlistWithOptions } from '../';
|
|
7
7
|
import type { IDPConfig, OAuthTokens } from './auth';
|
|
8
8
|
import type { RpcMethodCall } from '../..';
|
|
9
|
+
/**
|
|
10
|
+
* Parameters that can be included in the request context.
|
|
11
|
+
*/
|
|
9
12
|
export type WithParams = Partial<{
|
|
10
13
|
basket: BasketWithOptions;
|
|
11
14
|
wishlist: WishlistWithOptions;
|
|
@@ -16,11 +19,32 @@ export type WithParams = Partial<{
|
|
|
16
19
|
searchV2: SearchV2With;
|
|
17
20
|
variant: VariantWith;
|
|
18
21
|
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Represents runtime configuration options.
|
|
24
|
+
*/
|
|
19
25
|
export interface RuntimeConfiguration {
|
|
20
26
|
[key: string]: any;
|
|
21
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Additional context information for RPC calls.
|
|
30
|
+
* AThis interface can be augmented to extend the `RpcContext` type and
|
|
31
|
+
* allows to adding custom properties to the RPC context.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Augment AdditionalRpcContext type
|
|
36
|
+
* declare module '@scayle/storefront-core' {
|
|
37
|
+
* interface AdditionalRpcContext {
|
|
38
|
+
* myNewProp: string
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
22
43
|
export interface AdditionalRpcContext {
|
|
23
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Context interface with session information.
|
|
47
|
+
*/
|
|
24
48
|
export interface ContextWithSession {
|
|
25
49
|
wishlistKey: string;
|
|
26
50
|
basketKey: string;
|
|
@@ -33,6 +57,9 @@ export interface ContextWithSession {
|
|
|
33
57
|
updateUser: (user: ShopUser) => void;
|
|
34
58
|
updateTokens: (tokens: OAuthTokens) => void;
|
|
35
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Context interface without session information.
|
|
62
|
+
*/
|
|
36
63
|
export interface ContextWithoutSession {
|
|
37
64
|
wishlistKey: undefined;
|
|
38
65
|
basketKey: undefined;
|
|
@@ -45,21 +72,39 @@ export interface ContextWithoutSession {
|
|
|
45
72
|
updateUser: undefined;
|
|
46
73
|
updateTokens: undefined;
|
|
47
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Information provided after a successful login.
|
|
77
|
+
*/
|
|
48
78
|
interface LoginInformation {
|
|
49
79
|
shopId: number;
|
|
50
80
|
user: ShopUser;
|
|
51
81
|
authenticationType?: AuthenticationType;
|
|
52
82
|
accessToken: string;
|
|
53
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Information provided after a successful logout.
|
|
86
|
+
*/
|
|
54
87
|
interface LogoutInformation {
|
|
55
88
|
shopId: number;
|
|
56
89
|
user: ShopUser;
|
|
57
90
|
authenticationType?: AuthenticationType;
|
|
58
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Hooks for storefront events.
|
|
94
|
+
*/
|
|
59
95
|
export interface StorefrontHooks {
|
|
96
|
+
/**
|
|
97
|
+
* Hook called after a successful login.
|
|
98
|
+
*/
|
|
60
99
|
'storefront:afterLogin': (loginInfo: LoginInformation, context: RpcContext) => Promise<void> | void;
|
|
100
|
+
/**
|
|
101
|
+
* Hook called after a successful logout.
|
|
102
|
+
*/
|
|
61
103
|
'storefront:afterLogout': (logoutInfo: LogoutInformation, context: RpcContext) => Promise<void> | void;
|
|
62
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* The main RPC context interface, combining various properties.
|
|
107
|
+
*/
|
|
63
108
|
export type RpcContext = {
|
|
64
109
|
locale: string;
|
|
65
110
|
checkout: {
|
|
@@ -123,7 +168,23 @@ export type RpcContext = {
|
|
|
123
168
|
callHookWith?: Hookable<StorefrontHooks>['callHookWith'];
|
|
124
169
|
callRpc?: RpcMethodCall;
|
|
125
170
|
} & AdditionalRpcContext & (ContextWithoutSession | ContextWithSession);
|
|
171
|
+
/**
|
|
172
|
+
* RPC context type with guaranteed session information.
|
|
173
|
+
*/
|
|
126
174
|
export type RpcContextWithSession = RpcContext & ContextWithSession;
|
|
175
|
+
/**
|
|
176
|
+
* Assertion function to narrow the type of `RpcContext` to `RpcContextWithSession`.
|
|
177
|
+
*
|
|
178
|
+
* @param context - The RPC context object.
|
|
179
|
+
*
|
|
180
|
+
* @throws {Error} If `context.sessionId` is not defined.
|
|
181
|
+
*/
|
|
127
182
|
export declare function assertSession(context: RpcContext): asserts context is RpcContextWithSession;
|
|
183
|
+
/**
|
|
184
|
+
* Type guard function to check if the provided `RpcContext` has session information.
|
|
185
|
+
* @param context The RPC context object.
|
|
186
|
+
*
|
|
187
|
+
* @returns True if `context.sessionId` is defined, false otherwise.
|
|
188
|
+
*/
|
|
128
189
|
export declare function hasSession(context: RpcContext): context is RpcContextWithSession;
|
|
129
190
|
export {};
|
package/dist/types/api/rpc.d.ts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import type { RpcContext } from './context';
|
|
2
|
+
/**
|
|
3
|
+
* Type for an RPC handler that accepts parameters.
|
|
4
|
+
*
|
|
5
|
+
* @template Params The type of the parameters object.
|
|
6
|
+
* @template ResponseType The type of the response.
|
|
7
|
+
*/
|
|
2
8
|
export type ParamRpcHandler<Params extends Record<string, any>, ResponseType> = (params: Params, context: RpcContext) => Promise<(ResponseType extends undefined ? void : ResponseType) | Response> | ResponseType | Response;
|
|
9
|
+
/**
|
|
10
|
+
* Type for an RPC handler that does not accept parameters.
|
|
11
|
+
*
|
|
12
|
+
* @template ResponseType The type of the response.
|
|
13
|
+
*/
|
|
3
14
|
export type NoParamRpcHandler<ResponseType> = (context: RpcContext) => Promise<ResponseType | Response> | ResponseType | Response;
|
|
15
|
+
/**
|
|
16
|
+
* Generic RPC handler type. Handles both cases with and without parameters.
|
|
17
|
+
*
|
|
18
|
+
* @template A The response type if no parameters are used, or the parameters type if parameters are used.
|
|
19
|
+
* @template B The response type if parameters are used.
|
|
20
|
+
* If `void`, no parameters are expected.
|
|
21
|
+
* This allows for defining RPC handlers that either accept parameters or not.
|
|
22
|
+
*/
|
|
4
23
|
export type RpcHandler<A, B = void> = B extends void ? NoParamRpcHandler<A> : ParamRpcHandler<A, B>;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an item in a breadcrumb navigation.
|
|
3
|
+
*/
|
|
1
4
|
export interface BreadcrumbItem {
|
|
5
|
+
/**
|
|
6
|
+
* The displayed text for the breadcrumb item.
|
|
7
|
+
*/
|
|
2
8
|
value: string;
|
|
9
|
+
/**
|
|
10
|
+
* The navigation target (URL or route) for the breadcrumb item.
|
|
11
|
+
*/
|
|
3
12
|
to: string;
|
|
4
13
|
}
|
package/dist/types/promises.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the type resolved by a promise or promise-like value.
|
|
3
|
+
*
|
|
4
|
+
* @template T The input type, which can be a promise-like value.
|
|
5
|
+
*/
|
|
1
6
|
export type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T;
|
|
7
|
+
/**
|
|
8
|
+
* Extracts the return type of a promise-returning function, after the promise resolves.
|
|
9
|
+
*
|
|
10
|
+
* @template T The promise-returning function type.
|
|
11
|
+
*/
|
|
2
12
|
export type PromiseReturnType<T extends (...args: any) => Promise<any>> = Awaited<ReturnType<T>>;
|
|
@@ -1,23 +1,48 @@
|
|
|
1
1
|
import type { BasketItemDisplayData, BasketItemDisplayDataKey, BasketResponse, BasketResponseData, BasketWith, BasketItemDisplayDataItem, CreateBasketItemParameters, ItemGroup } from '@scayle/storefront-api';
|
|
2
|
+
/**
|
|
3
|
+
* Represents custom data for a basket item. Corresponds to the `customData` property
|
|
4
|
+
* of `CreateBasketItemParameters`.
|
|
5
|
+
*/
|
|
2
6
|
export type BasketCustomData = Pick<CreateBasketItemParameters, 'customData'>;
|
|
7
|
+
/**
|
|
8
|
+
* Represents display data for a basket item. Uses a partial record to allow flexibility in
|
|
9
|
+
* which display data keys are present.
|
|
10
|
+
*/
|
|
3
11
|
export type BasketDisplayData = Partial<Record<BasketItemDisplayDataKey, BasketItemDisplayDataItem>>;
|
|
4
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Parameters for adding or updating an item in the basket.
|
|
14
|
+
*/
|
|
5
15
|
export interface AddOrUpdateItemType {
|
|
6
16
|
variantId: number;
|
|
7
17
|
quantity: number;
|
|
18
|
+
/** Display data for the item. */
|
|
8
19
|
displayData?: BasketItemDisplayData;
|
|
20
|
+
/** Custom data for the item. */
|
|
9
21
|
customData?: {
|
|
10
22
|
[key: string | number]: any;
|
|
11
23
|
};
|
|
24
|
+
/** Item group for the item. */
|
|
12
25
|
itemGroup?: ItemGroup;
|
|
26
|
+
/** If the product is not in the "catalog" anymore, keep it in the basket */
|
|
13
27
|
includeItemsWithoutProductData?: boolean;
|
|
14
28
|
promotionId?: string | null;
|
|
15
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Options for fetching a basket, extending the base `BasketWith` type.
|
|
32
|
+
*/
|
|
16
33
|
export interface BasketWithOptions extends BasketWith {
|
|
34
|
+
/** Key for filtering the price promotions */
|
|
17
35
|
pricePromotionKey?: string;
|
|
36
|
+
/** if the product is not in the "catalog" anymore, keep it in the basket */
|
|
18
37
|
includeItemsWithoutProductData?: boolean;
|
|
19
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Parameters for the `useBasket` composable.
|
|
41
|
+
*/
|
|
20
42
|
export interface UseBasketParams {
|
|
43
|
+
/** Key for caching. */
|
|
21
44
|
key?: string;
|
|
45
|
+
/** Data to include with the basket. */
|
|
22
46
|
with: BasketWithOptions;
|
|
23
47
|
}
|
|
48
|
+
export type { BasketItemDisplayData, BasketItemDisplayDataItem, BasketResponseData, BasketWith, BasketResponse, ItemGroup, };
|