@scayle/storefront-core 8.7.0 → 8.8.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/api/customer.d.ts +73 -0
  3. package/dist/api/customer.mjs +59 -0
  4. package/dist/api/oauth.d.ts +62 -12
  5. package/dist/api/oauth.mjs +51 -15
  6. package/dist/cache/cache.d.ts +47 -0
  7. package/dist/cache/cached.d.ts +93 -0
  8. package/dist/cache/cached.mjs +62 -0
  9. package/dist/cache/providers/unstorage.d.ts +64 -0
  10. package/dist/cache/providers/unstorage.mjs +64 -0
  11. package/dist/constants/cache.d.ts +4 -0
  12. package/dist/constants/hash.d.ts +4 -0
  13. package/dist/constants/hash.mjs +1 -0
  14. package/dist/constants/httpStatus.d.ts +12 -2
  15. package/dist/constants/httpStatus.mjs +2 -2
  16. package/dist/constants/product.d.ts +3 -0
  17. package/dist/constants/promotion.d.ts +6 -0
  18. package/dist/constants/sorting.d.ts +6 -0
  19. package/dist/constants/withParameters.d.ts +28 -0
  20. package/dist/errors/errorResponse.d.ts +37 -0
  21. package/dist/errors/errorResponse.mjs +14 -0
  22. package/dist/helpers/filterHelper.mjs +1 -1
  23. package/dist/index.d.ts +48 -0
  24. package/dist/rpc/methods/basket/basket.mjs +9 -4
  25. package/dist/rpc/methods/campaign.d.ts +13 -0
  26. package/dist/rpc/methods/campaign.mjs +23 -0
  27. package/dist/rpc/methods/checkout/checkout.mjs +4 -2
  28. package/dist/rpc/methods/index.d.ts +1 -0
  29. package/dist/rpc/methods/index.mjs +1 -0
  30. package/dist/rpc/methods/products.d.ts +4 -4
  31. package/dist/rpc/methods/products.mjs +19 -7
  32. package/dist/rpc/methods/variants.d.ts +1 -1
  33. package/dist/rpc/methods/variants.mjs +4 -1
  34. package/dist/rpc/methods/wishlist.mjs +7 -3
  35. package/dist/types/api/context.d.ts +3 -0
  36. package/dist/utils/basket.d.ts +23 -0
  37. package/dist/utils/campaign.d.ts +23 -0
  38. package/dist/utils/campaign.mjs +17 -0
  39. package/dist/utils/fetch.d.ts +21 -2
  40. package/dist/utils/hash.d.ts +67 -0
  41. package/dist/utils/hash.mjs +3 -3
  42. package/dist/utils/index.d.ts +1 -0
  43. package/dist/utils/index.mjs +1 -0
  44. package/dist/utils/keys.d.ts +38 -0
  45. package/dist/utils/log.d.ts +77 -8
  46. package/dist/utils/log.mjs +61 -6
  47. package/dist/utils/response.d.ts +8 -3
  48. package/dist/utils/sapi.d.ts +10 -2
  49. package/dist/utils/timeout.d.ts +18 -0
  50. package/dist/utils/user.d.ts +22 -0
  51. package/dist/utils/user.mjs +5 -2
  52. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 8.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Deprecate `RpcContext.campaignKey`. The `getCampaignKey` RPC should be used instead.
8
+
9
+ ## 8.7.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Introduced JSDoc comments to provide additional contextual descriptions and hints.
14
+
3
15
  ## 8.7.0
4
16
 
5
17
  ### Minor Changes
@@ -1,4 +1,9 @@
1
1
  import type { Gender, Order, RpcContext, ShopUser, ShopUserAddress } from '../types';
2
+ /**
3
+ * Represents a paginated API response.
4
+ *
5
+ * @template EntityType The type of entities in the response.
6
+ */
2
7
  interface PaginatedResponse<EntityType> {
3
8
  entities: EntityType[];
4
9
  pagination: {
@@ -12,10 +17,16 @@ interface PaginatedResponse<EntityType> {
12
17
  total: number;
13
18
  };
14
19
  }
20
+ /**
21
+ * Represents contact data for a customer.
22
+ */
15
23
  interface ContactData {
16
24
  email: string;
17
25
  phone: string;
18
26
  }
27
+ /**
28
+ * Represents personal data for a customer.
29
+ */
19
30
  interface PersonalData {
20
31
  firstName: string;
21
32
  lastName: string;
@@ -23,6 +34,9 @@ interface PersonalData {
23
34
  gender?: Gender;
24
35
  title?: string;
25
36
  }
37
+ /**
38
+ * Data required for updating a password.
39
+ */
26
40
  interface PasswordUpdate {
27
41
  password: string;
28
42
  newPassword: string;
@@ -35,15 +49,46 @@ interface PasswordUpdate {
35
49
  * @see https://scayle.dev/en/api-guides/customer-account-api
36
50
  */
37
51
  export declare class CustomerAPIClient {
52
+ /**
53
+ * Base URL for the Checkout API.
54
+ */
38
55
  baseURL: string;
56
+ /**
57
+ * RPC context containing authentication and other information.
58
+ */
39
59
  context: RpcContext;
60
+ /**
61
+ * Additional headers to include in requests.
62
+ */
40
63
  additionalHeaders: HeadersInit | undefined;
64
+ /**
65
+ * Creates a new instance of the CustomerAPIClient.
66
+ *
67
+ * @param context The RPC context.
68
+ */
41
69
  constructor(context: RpcContext);
70
+ /**
71
+ * Gets the headers for API requests, including authorization.
72
+ */
42
73
  get headers(): HeadersInit;
74
+ /**
75
+ * Sends an API request and handles potential token refresh.
76
+ *
77
+ * @param request The request function to execute.
78
+ * @param retry Whether to retry the request after a token refresh.
79
+ *
80
+ * @returns The parsed JSON response.
81
+ *
82
+ * @template BodyType The expected type of the response body.
83
+ */
43
84
  sendRequest<BodyType>(request: () => Promise<Response>, retry?: boolean): Promise<BodyType>;
44
85
  /**
45
86
  * Get the addresses for the current customer.
46
87
  *
88
+ * @param shopId The ID of the shop.
89
+ *
90
+ * @returns A paginated response containing the customer's addresses.
91
+ *
47
92
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/address/list-addresses
48
93
  */
49
94
  getAddresses(shopId: number): Promise<PaginatedResponse<ShopUserAddress>>;
@@ -51,30 +96,58 @@ export declare class CustomerAPIClient {
51
96
  * Returns customer data and latest orders.
52
97
  * When not logged in, it will return `undefined`.
53
98
  *
99
+ * @param shopId The ID of the shop.
100
+ * @param accessToken Optional access token to use for the request.
101
+ * @returns The customer data.
102
+ *
54
103
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/get-customer
55
104
  */
56
105
  getMe(shopId: number, accessToken?: string): Promise<ShopUser>;
57
106
  /**
58
107
  * Retrieve a customer's order.
59
108
  *
109
+ * @param shopId The ID of the shop.
110
+ * @param orderId The ID of the order.
111
+ *
112
+ * @returns The customer's order.
113
+ *
60
114
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/order/get-order
61
115
  */
62
116
  getOrder(shopId: number, orderId: number): Promise<Order>;
63
117
  /**
64
118
  * Update contact details of a customer.
65
119
  *
120
+ * @param shopId The ID of the shop.
121
+ * @param data Contact data to update.
122
+ * @param data.email Customer's email address.
123
+ * @param data.phone Customer's phone number.
124
+ *
125
+ * @returns The updated customer data.
126
+ *
66
127
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-contact-details
67
128
  */
68
129
  updateContactInfo(shopId: number, { email, phone }: Partial<ContactData>): Promise<ShopUser>;
69
130
  /**
70
131
  * Update customer personal data.
71
132
  *
133
+ * @param shopId The ID of the shop.
134
+ * @param payload Personal data to update.
135
+ *
136
+ * @returns The updated customer data.
137
+ *
72
138
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-personal-data
73
139
  */
74
140
  updatePersonalInfo(shopId: number, payload: Partial<PersonalData>): Promise<ShopUser>;
75
141
  /**
76
142
  * Update customer password.
77
143
  *
144
+ * @param shopId The ID of the shop.
145
+ * @param data Data for updating the password.
146
+ * @param data.password Current password.
147
+ * @param data.newPassword New password.
148
+ *
149
+ * @returns The updated customer data.
150
+ *
78
151
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-password
79
152
  */
80
153
  updatePassword(shopId: number, { password, newPassword }: PasswordUpdate): Promise<ShopUser>;
@@ -2,14 +2,31 @@ import { FetchError } from "../utils/fetch.mjs";
2
2
  import { HttpStatusCode } from "../constants/httpStatus.mjs";
3
3
  import { getOAuthClient } from "./oauth.mjs";
4
4
  export class CustomerAPIClient {
5
+ /**
6
+ * Base URL for the Checkout API.
7
+ */
5
8
  baseURL;
9
+ /**
10
+ * RPC context containing authentication and other information.
11
+ */
6
12
  context;
13
+ /**
14
+ * Additional headers to include in requests.
15
+ */
7
16
  additionalHeaders;
17
+ /**
18
+ * Creates a new instance of the CustomerAPIClient.
19
+ *
20
+ * @param context The RPC context.
21
+ */
8
22
  constructor(context) {
9
23
  this.baseURL = context.checkout.url;
10
24
  this.context = context;
11
25
  this.additionalHeaders = context.internalAccessHeader ? { "x-internal-access": context.internalAccessHeader } : {};
12
26
  }
27
+ /**
28
+ * Gets the headers for API requests, including authorization.
29
+ */
13
30
  get headers() {
14
31
  return {
15
32
  Authorization: `Bearer ${this.context.accessToken}`,
@@ -18,6 +35,16 @@ export class CustomerAPIClient {
18
35
  ...this.additionalHeaders
19
36
  };
20
37
  }
38
+ /**
39
+ * Sends an API request and handles potential token refresh.
40
+ *
41
+ * @param request The request function to execute.
42
+ * @param retry Whether to retry the request after a token refresh.
43
+ *
44
+ * @returns The parsed JSON response.
45
+ *
46
+ * @template BodyType The expected type of the response body.
47
+ */
21
48
  async sendRequest(request, retry = true) {
22
49
  const response = await request();
23
50
  if (response.ok) {
@@ -61,6 +88,10 @@ export class CustomerAPIClient {
61
88
  /**
62
89
  * Get the addresses for the current customer.
63
90
  *
91
+ * @param shopId The ID of the shop.
92
+ *
93
+ * @returns A paginated response containing the customer's addresses.
94
+ *
64
95
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/address/list-addresses
65
96
  */
66
97
  async getAddresses(shopId) {
@@ -77,6 +108,10 @@ export class CustomerAPIClient {
77
108
  * Returns customer data and latest orders.
78
109
  * When not logged in, it will return `undefined`.
79
110
  *
111
+ * @param shopId The ID of the shop.
112
+ * @param accessToken Optional access token to use for the request.
113
+ * @returns The customer data.
114
+ *
80
115
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/get-customer
81
116
  */
82
117
  async getMe(shopId, accessToken) {
@@ -93,6 +128,11 @@ export class CustomerAPIClient {
93
128
  /**
94
129
  * Retrieve a customer's order.
95
130
  *
131
+ * @param shopId The ID of the shop.
132
+ * @param orderId The ID of the order.
133
+ *
134
+ * @returns The customer's order.
135
+ *
96
136
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/order/get-order
97
137
  */
98
138
  async getOrder(shopId, orderId) {
@@ -108,6 +148,13 @@ export class CustomerAPIClient {
108
148
  /**
109
149
  * Update contact details of a customer.
110
150
  *
151
+ * @param shopId The ID of the shop.
152
+ * @param data Contact data to update.
153
+ * @param data.email Customer's email address.
154
+ * @param data.phone Customer's phone number.
155
+ *
156
+ * @returns The updated customer data.
157
+ *
111
158
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-contact-details
112
159
  */
113
160
  async updateContactInfo(shopId, { email, phone }) {
@@ -128,6 +175,11 @@ export class CustomerAPIClient {
128
175
  /**
129
176
  * Update customer personal data.
130
177
  *
178
+ * @param shopId The ID of the shop.
179
+ * @param payload Personal data to update.
180
+ *
181
+ * @returns The updated customer data.
182
+ *
131
183
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-personal-data
132
184
  */
133
185
  async updatePersonalInfo(shopId, payload) {
@@ -145,6 +197,13 @@ export class CustomerAPIClient {
145
197
  /**
146
198
  * Update customer password.
147
199
  *
200
+ * @param shopId The ID of the shop.
201
+ * @param data Data for updating the password.
202
+ * @param data.password Current password.
203
+ * @param data.newPassword New password.
204
+ *
205
+ * @returns The updated customer data.
206
+ *
148
207
  * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-password
149
208
  */
150
209
  async updatePassword(shopId, { password, newPassword }) {
@@ -1,12 +1,24 @@
1
1
  import type { GuestRequest, LoginRequest, Oauth, RefreshTokenRequest, RegisterRequest, SendResetPasswordEmailRequest, UpdatePasswordByHashRequest, UpdatePasswordRequest } from '../types/api/auth';
2
2
  import type { RpcContext } from '../types/api/context';
3
3
  import type { Log } from '../utils/log';
4
+ /**
5
+ * Options for configuring the OAuth client.
6
+ */
4
7
  export interface OAuthOptions {
5
8
  clientId: string;
6
9
  clientSecret: string;
7
10
  apiHost: string;
8
11
  additionalHeaders?: HeadersInit;
9
12
  }
13
+ /**
14
+ * Creates and returns an OAuthClient instance using the provided RPC context.
15
+ *
16
+ * @param context The RPC context containing OAuth configuration.
17
+ *
18
+ * @returns An instance of the OAuthClient.
19
+ *
20
+ * @throws {Error} If OAuth configuration is missing in the context.
21
+ */
10
22
  export declare function getOAuthClient(context: RpcContext): OAuthClient;
11
23
  /**
12
24
  * A client for interacting with the Checkout Authentication API
@@ -14,15 +26,37 @@ export declare function getOAuthClient(context: RpcContext): OAuthClient;
14
26
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api
15
27
  */
16
28
  export declare class OAuthClient {
29
+ /**
30
+ * Headers for API requests.
31
+ */
17
32
  headers: HeadersInit;
33
+ /**
34
+ * Base URL for the API.
35
+ */
18
36
  baseURL: string;
37
+ /**
38
+ * Logger instance.
39
+ */
19
40
  logger?: Log;
41
+ /**
42
+ * OAuth client ID.
43
+ */
20
44
  clientId: string;
45
+ /**
46
+ * Creates a new instance of the OAuthClient.
47
+ *
48
+ * @param options OAuth client options.
49
+ * @param logger Optional logger instance.
50
+ *
51
+ * @throws {MissingCredentialsError} If client ID or client secret are missing.
52
+ */
21
53
  constructor(options: OAuthOptions, logger?: Log);
22
54
  /**
23
55
  * Register a new User and receive an access token.
24
56
  *
25
- * @param payload
57
+ * @param payload The registration data.
58
+ *
59
+ * @returns The OAuth response containing access and refresh tokens.
26
60
  *
27
61
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/create-new-user
28
62
  */
@@ -30,7 +64,9 @@ export declare class OAuthClient {
30
64
  /**
31
65
  * Login a User and receive an access token.
32
66
  *
33
- * @param payload
67
+ * @param payload The login credentials, including the `shopId`.
68
+ *
69
+ * @returns The OAuth response containing access and refresh tokens.
34
70
  *
35
71
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/log-in-users
36
72
  */
@@ -38,7 +74,9 @@ export declare class OAuthClient {
38
74
  /**
39
75
  * Login a User as a guest and receive an access token.
40
76
  *
41
- * @param payload
77
+ * @param payload The guest login data.
78
+ *
79
+ * @returns The OAuth response containing access and refresh tokens.
42
80
  *
43
81
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/log-in-users-as-guest
44
82
  */
@@ -46,7 +84,9 @@ export declare class OAuthClient {
46
84
  /**
47
85
  * Send a reset password email to a User.
48
86
  *
49
- * @param payload
87
+ * @param payload The data for sending the reset password email.
88
+ *
89
+ * @returns Nothing (resolves when the request completes successfully).
50
90
  *
51
91
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/send-password-reset-email
52
92
  */
@@ -55,7 +95,9 @@ export declare class OAuthClient {
55
95
  * Update password by using hash.
56
96
  * All older tokens of the User are also invalidated.
57
97
  *
58
- * @param payload
98
+ * @param payload The data for updating the password by hash.
99
+ *
100
+ * @returns The new OAuth response with updated tokens.
59
101
  *
60
102
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/update-password-by-hash
61
103
  */
@@ -63,20 +105,25 @@ export declare class OAuthClient {
63
105
  /**
64
106
  * Update password via plain string.
65
107
  *
66
- * @param payload
67
- * @param accessToken
108
+ * @param payload The data for updating the password (current and new password).
109
+ * @param accessToken The current access token.
110
+ *
111
+ * @returns Nothing (resolves when the request completes successfully).
68
112
  */
69
113
  updatePassword(payload: UpdatePasswordRequest, accessToken: string): Promise<void>;
70
114
  /**
71
115
  * Generate a new access token via a refresh token.
72
116
  *
73
- * @param payload
117
+ * @param payload The refresh token request data.
118
+ * @returns The new OAuth response with updated access token.
74
119
  */
75
120
  refreshToken(payload: RefreshTokenRequest): Promise<Oauth>;
76
121
  /**
77
122
  * Validate a token.
78
123
  *
79
- * @param accessToken
124
+ * @param accessToken The access token to validate.
125
+ *
126
+ * @returns Nothing (resolves if the token is valid, rejects otherwise).
80
127
  *
81
128
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/bearer-auth/validate-present-token
82
129
  */
@@ -92,8 +139,9 @@ export declare class OAuthClient {
92
139
  * (_because a frontend redirect is required_) this step will be skipped and the IDP-Tokens
93
140
  * will remain valid until they expire or are revoked from IDP side.
94
141
  *
95
- * @param shopId
96
- * @param accessToken
142
+ * @param shopId The ID of the shop.
143
+ * @param accessToken The access token to use for authorization.
144
+ * @returns Nothing (resolves when the token is successfully revoked).
97
145
  *
98
146
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/bearer-auth/delete-access-token-with-id
99
147
  */
@@ -101,7 +149,9 @@ export declare class OAuthClient {
101
149
  /**
102
150
  * Generate a new token based on authorization code.
103
151
  *
104
- * @param code
152
+ * @param code The authorization code.
153
+ *
154
+ * @returns The new OAuth response.
105
155
  */
106
156
  generateToken(code: string): Promise<Oauth>;
107
157
  }
@@ -23,9 +23,7 @@ export function getOAuthClient(context) {
23
23
  if (!context.oauth) {
24
24
  throw new Error("OAuth configuration is missing");
25
25
  }
26
- const clientId = context.oauth.clientId;
27
- const clientSecret = context.oauth.clientSecret;
28
- const apiHost = context.oauth.apiHost;
26
+ const { clientId, clientSecret, apiHost } = context.oauth;
29
27
  const accessHeader = context.internalAccessHeader;
30
28
  return new OAuthClient({
31
29
  clientId,
@@ -35,10 +33,30 @@ export function getOAuthClient(context) {
35
33
  }, context.log);
36
34
  }
37
35
  export class OAuthClient {
36
+ /**
37
+ * Headers for API requests.
38
+ */
38
39
  headers;
40
+ /**
41
+ * Base URL for the API.
42
+ */
39
43
  baseURL;
44
+ /**
45
+ * Logger instance.
46
+ */
40
47
  logger;
48
+ /**
49
+ * OAuth client ID.
50
+ */
41
51
  clientId;
52
+ /**
53
+ * Creates a new instance of the OAuthClient.
54
+ *
55
+ * @param options OAuth client options.
56
+ * @param logger Optional logger instance.
57
+ *
58
+ * @throws {MissingCredentialsError} If client ID or client secret are missing.
59
+ */
42
60
  constructor(options, logger) {
43
61
  const { clientId, clientSecret, apiHost, additionalHeaders } = options;
44
62
  if (!clientId || !clientSecret) {
@@ -58,7 +76,9 @@ export class OAuthClient {
58
76
  /**
59
77
  * Register a new User and receive an access token.
60
78
  *
61
- * @param payload
79
+ * @param payload The registration data.
80
+ *
81
+ * @returns The OAuth response containing access and refresh tokens.
62
82
  *
63
83
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/create-new-user
64
84
  */
@@ -73,7 +93,9 @@ export class OAuthClient {
73
93
  /**
74
94
  * Login a User and receive an access token.
75
95
  *
76
- * @param payload
96
+ * @param payload The login credentials, including the `shopId`.
97
+ *
98
+ * @returns The OAuth response containing access and refresh tokens.
77
99
  *
78
100
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/log-in-users
79
101
  */
@@ -88,7 +110,9 @@ export class OAuthClient {
88
110
  /**
89
111
  * Login a User as a guest and receive an access token.
90
112
  *
91
- * @param payload
113
+ * @param payload The guest login data.
114
+ *
115
+ * @returns The OAuth response containing access and refresh tokens.
92
116
  *
93
117
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/log-in-users-as-guest
94
118
  */
@@ -103,7 +127,9 @@ export class OAuthClient {
103
127
  /**
104
128
  * Send a reset password email to a User.
105
129
  *
106
- * @param payload
130
+ * @param payload The data for sending the reset password email.
131
+ *
132
+ * @returns Nothing (resolves when the request completes successfully).
107
133
  *
108
134
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/send-password-reset-email
109
135
  */
@@ -119,7 +145,9 @@ export class OAuthClient {
119
145
  * Update password by using hash.
120
146
  * All older tokens of the User are also invalidated.
121
147
  *
122
- * @param payload
148
+ * @param payload The data for updating the password by hash.
149
+ *
150
+ * @returns The new OAuth response with updated tokens.
123
151
  *
124
152
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/update-password-by-hash
125
153
  */
@@ -134,8 +162,10 @@ export class OAuthClient {
134
162
  /**
135
163
  * Update password via plain string.
136
164
  *
137
- * @param payload
138
- * @param accessToken
165
+ * @param payload The data for updating the password (current and new password).
166
+ * @param accessToken The current access token.
167
+ *
168
+ * @returns Nothing (resolves when the request completes successfully).
139
169
  */
140
170
  async updatePassword(payload, accessToken) {
141
171
  this.logger?.debug("Updating password");
@@ -151,7 +181,8 @@ export class OAuthClient {
151
181
  /**
152
182
  * Generate a new access token via a refresh token.
153
183
  *
154
- * @param payload
184
+ * @param payload The refresh token request data.
185
+ * @returns The new OAuth response with updated access token.
155
186
  */
156
187
  async refreshToken(payload) {
157
188
  this.logger?.debug("Refreshing access token");
@@ -164,7 +195,9 @@ export class OAuthClient {
164
195
  /**
165
196
  * Validate a token.
166
197
  *
167
- * @param accessToken
198
+ * @param accessToken The access token to validate.
199
+ *
200
+ * @returns Nothing (resolves if the token is valid, rejects otherwise).
168
201
  *
169
202
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/bearer-auth/validate-present-token
170
203
  */
@@ -188,8 +221,9 @@ export class OAuthClient {
188
221
  * (_because a frontend redirect is required_) this step will be skipped and the IDP-Tokens
189
222
  * will remain valid until they expire or are revoked from IDP side.
190
223
  *
191
- * @param shopId
192
- * @param accessToken
224
+ * @param shopId The ID of the shop.
225
+ * @param accessToken The access token to use for authorization.
226
+ * @returns Nothing (resolves when the token is successfully revoked).
193
227
  *
194
228
  * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/bearer-auth/delete-access-token-with-id
195
229
  */
@@ -208,7 +242,9 @@ export class OAuthClient {
208
242
  /**
209
243
  * Generate a new token based on authorization code.
210
244
  *
211
- * @param code
245
+ * @param code The authorization code.
246
+ *
247
+ * @returns The new OAuth response.
212
248
  */
213
249
  async generateToken(code) {
214
250
  return await fetch(`${this.baseURL}/oauth/token`, {
@@ -1,8 +1,55 @@
1
+ /**
2
+ * Interface for Storefront-internal caching mechanism.
3
+ * Used for the `UnstorageCache` with `cached()`.
4
+ */
1
5
  export interface Cache {
6
+ /**
7
+ * Sets a value in the cache.
8
+ *
9
+ * @param key The key to store the value under.
10
+ * @param value The value to store in the cache.
11
+ * @param ttl Time-to-live in milliseconds.
12
+ * @param tags Optional array of tags to associate with the cached value.
13
+ *
14
+ * @returns A promise that resolves when the value is set.
15
+ */
2
16
  set: (key: string, value: any, ttl: number, tags?: string[]) => Promise<void>;
17
+ /**
18
+ * Retrieves a value from the cache.
19
+ *
20
+ * @param key The key of the cached value.
21
+ *
22
+ * @returns A promise that resolves with the cached value or rejects if not found.
23
+ */
3
24
  get: (key: string) => Promise<any>;
25
+ /**
26
+ * Checks if a key exists in the cache.
27
+ *
28
+ * @param key The key to check.
29
+ *
30
+ * @returns A promise that resolves with `true` if the key exists, `false` otherwise.
31
+ */
4
32
  has: (key: string) => Promise<boolean>;
33
+ /**
34
+ * Purges cached values associated with specific tags.
35
+ *
36
+ * @param tags An array of tags to purge.
37
+ *
38
+ * @returns A promise that resolves when the tags are purged.
39
+ */
5
40
  purgeTags: (tags: string[]) => Promise<void>;
41
+ /**
42
+ * Purges cached values by their keys.
43
+ *
44
+ * @param keys An array of keys to purge.
45
+ *
46
+ * @returns A promise that resolves when the keys are purged.
47
+ */
6
48
  purgeKeys: (keys: string[]) => Promise<void>;
49
+ /**
50
+ * Purges all cached values.
51
+ *
52
+ * @returns A promise that resolves when the cache is cleared.
53
+ */
7
54
  purgeAll: () => Promise<void>;
8
55
  }