@scayle/storefront-core 8.3.2 → 8.5.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 (101) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/api/customer.d.ts +19 -13
  3. package/dist/api/customer.mjs +16 -10
  4. package/dist/api/oauth.d.ts +45 -11
  5. package/dist/api/oauth.mjs +43 -10
  6. package/dist/rpc/methods/checkout/checkout.mjs +1 -1
  7. package/dist/rpc/methods/search.d.ts +22 -0
  8. package/dist/types/user.d.ts +1 -1
  9. package/package.json +9 -19
  10. package/dist/api/customer.cjs +0 -158
  11. package/dist/api/oauth.cjs +0 -205
  12. package/dist/cache/cache.cjs +0 -1
  13. package/dist/cache/cached.cjs +0 -90
  14. package/dist/cache/index.cjs +0 -27
  15. package/dist/cache/providers/unstorage.cjs +0 -55
  16. package/dist/constants/basket.cjs +0 -26
  17. package/dist/constants/cache.cjs +0 -7
  18. package/dist/constants/hash.cjs +0 -11
  19. package/dist/constants/httpStatus.cjs +0 -634
  20. package/dist/constants/index.cjs +0 -93
  21. package/dist/constants/product.cjs +0 -10
  22. package/dist/constants/promotion.cjs +0 -12
  23. package/dist/constants/sorting.cjs +0 -22
  24. package/dist/constants/withParameters.cjs +0 -132
  25. package/dist/errors/errorResponse.cjs +0 -27
  26. package/dist/errors/index.cjs +0 -16
  27. package/dist/helpers/advancedAttributeHelpers.cjs +0 -30
  28. package/dist/helpers/arrayHelpers.cjs +0 -10
  29. package/dist/helpers/attributeHelpers.cjs +0 -24
  30. package/dist/helpers/basketHelpers.cjs +0 -12
  31. package/dist/helpers/categoryHelper.cjs +0 -61
  32. package/dist/helpers/filterHelper.cjs +0 -185
  33. package/dist/helpers/formHelpers.cjs +0 -114
  34. package/dist/helpers/imageHelpers.cjs +0 -20
  35. package/dist/helpers/index.cjs +0 -181
  36. package/dist/helpers/localization.cjs +0 -13
  37. package/dist/helpers/objectHelpers.cjs +0 -19
  38. package/dist/helpers/orderHelpers.cjs +0 -10
  39. package/dist/helpers/product.fixture.cjs +0 -766
  40. package/dist/helpers/productDisruptorHelper.cjs +0 -37
  41. package/dist/helpers/productHelpers.cjs +0 -156
  42. package/dist/helpers/sanitizationHelpers.cjs +0 -35
  43. package/dist/helpers/sortingHelper.cjs +0 -68
  44. package/dist/helpers/stringHelpers.cjs +0 -8
  45. package/dist/index.cjs +0 -100
  46. package/dist/rpc/methods/basket/basket.cjs +0 -270
  47. package/dist/rpc/methods/brands.cjs +0 -33
  48. package/dist/rpc/methods/categories.cjs +0 -129
  49. package/dist/rpc/methods/cbd.cjs +0 -38
  50. package/dist/rpc/methods/checkout/checkout.cjs +0 -48
  51. package/dist/rpc/methods/checkout/index.cjs +0 -49
  52. package/dist/rpc/methods/checkout/order.cjs +0 -42
  53. package/dist/rpc/methods/checkout/shopUser.cjs +0 -110
  54. package/dist/rpc/methods/checkout/shopUserAddresses.cjs +0 -12
  55. package/dist/rpc/methods/index.cjs +0 -225
  56. package/dist/rpc/methods/navigationTrees.cjs +0 -54
  57. package/dist/rpc/methods/oauth/idp.cjs +0 -59
  58. package/dist/rpc/methods/products.cjs +0 -309
  59. package/dist/rpc/methods/promotion.cjs +0 -51
  60. package/dist/rpc/methods/search.cjs +0 -40
  61. package/dist/rpc/methods/session.cjs +0 -257
  62. package/dist/rpc/methods/shopConfiguration.cjs +0 -15
  63. package/dist/rpc/methods/user.cjs +0 -103
  64. package/dist/rpc/methods/variants.cjs +0 -29
  65. package/dist/rpc/methods/wishlist.cjs +0 -104
  66. package/dist/server.cjs +0 -47
  67. package/dist/test/factories/index.cjs +0 -16
  68. package/dist/types/api/auth.cjs +0 -1
  69. package/dist/types/api/context.cjs +0 -15
  70. package/dist/types/api/rpc.cjs +0 -1
  71. package/dist/types/breadcrumb.cjs +0 -1
  72. package/dist/types/index.cjs +0 -267
  73. package/dist/types/promises.cjs +0 -1
  74. package/dist/types/sapi/basket.cjs +0 -1
  75. package/dist/types/sapi/brand.cjs +0 -1
  76. package/dist/types/sapi/campaign.cjs +0 -1
  77. package/dist/types/sapi/category.cjs +0 -1
  78. package/dist/types/sapi/filter.cjs +0 -1
  79. package/dist/types/sapi/navigation.cjs +0 -1
  80. package/dist/types/sapi/order.cjs +0 -1
  81. package/dist/types/sapi/product.cjs +0 -1
  82. package/dist/types/sapi/productFilter.cjs +0 -1
  83. package/dist/types/sapi/promotion.cjs +0 -1
  84. package/dist/types/sapi/redirects.cjs +0 -1
  85. package/dist/types/sapi/router.cjs +0 -1
  86. package/dist/types/sapi/search.cjs +0 -1
  87. package/dist/types/sapi/sorting.cjs +0 -1
  88. package/dist/types/sapi/variant.cjs +0 -1
  89. package/dist/types/sapi/wishlist.cjs +0 -1
  90. package/dist/types/user.cjs +0 -1
  91. package/dist/utils/basket.cjs +0 -14
  92. package/dist/utils/fetch.cjs +0 -19
  93. package/dist/utils/hash.cjs +0 -72
  94. package/dist/utils/index.cjs +0 -49
  95. package/dist/utils/keys.cjs +0 -67
  96. package/dist/utils/log.cjs +0 -93
  97. package/dist/utils/response.cjs +0 -13
  98. package/dist/utils/sapi.cjs +0 -26
  99. package/dist/utils/timeout.cjs +0 -18
  100. package/dist/utils/user.cjs +0 -90
  101. /package/dist/api/{README.md → INFO.md} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 8.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - The CommonJS export format will be removed in this version. All exports are provided through ES Modules (`import`/`export`) exclusively
8
+
9
+ This change will primarily affect users who are currently using the CommonJS format of this package. To update your code, you should replace `require` statements with `import` statements and update your build tooling if necessary.
10
+
11
+ ```TypeScript
12
+ const { ... } = require('@scayle/storefront-core');
13
+
14
+ // will become
15
+
16
+ import { ... } from '@scayle/storefront-core';
17
+ ```
18
+
19
+ ## 8.4.0
20
+
21
+ ### Minor Changes
22
+
23
+ - [Types] - Extend `Gender` type with `n` option
24
+
3
25
  ## 8.3.2
4
26
 
5
27
  ### Patch Changes
@@ -28,11 +28,11 @@ interface PasswordUpdate {
28
28
  newPassword: string;
29
29
  }
30
30
  /**
31
- * An API client for interacting with the Checkout Customer API
31
+ * An API client for interacting with the Checkout Customer API.
32
32
  *
33
- * Should be initialized with the token set acquired from the Auth API
33
+ * Should be initialized with the token set acquired from the Auth API.
34
34
  *
35
- * @see https://scayle.dev/api/oauth/latest
35
+ * @see https://scayle.dev/en/api-guides/customer-account-api
36
36
  */
37
37
  export declare class CustomerAPIClient {
38
38
  baseURL: string;
@@ -42,34 +42,40 @@ export declare class CustomerAPIClient {
42
42
  get headers(): HeadersInit;
43
43
  sendRequest<BodyType>(request: () => Promise<Response>, retry?: boolean): Promise<BodyType>;
44
44
  /**
45
- * Get the addresses for the current customer
45
+ * Get the addresses for the current customer.
46
+ *
47
+ * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/address/list-addresses
46
48
  */
47
49
  getAddresses(shopId: number): Promise<PaginatedResponse<ShopUserAddress>>;
48
50
  /**
49
51
  * Returns customer data and latest orders.
50
- * When not logged in will return undefined.
51
- * @see https://scayle.dev/api/oauth/latest/fetch-authorized-payload
52
+ * When not logged in, it will return `undefined`.
53
+ *
54
+ * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/get-customer
52
55
  */
53
56
  getMe(shopId: number, accessToken?: string): Promise<ShopUser>;
54
57
  /**
55
- * Fetch a customer's order
56
- * @see https://scayle.dev/api/oauth/latest/fetch-order-by-id
58
+ * Retrieve a customer's order.
59
+ *
60
+ * @see https://scayle.dev/en/api-guides/customer-account-api/resources/order/get-order
57
61
  */
58
62
  getOrder(shopId: number, orderId: number): Promise<Order>;
59
63
  /**
60
- * Update the customer's contact details
64
+ * Update contact details of a customer.
61
65
  *
62
- * @see https://scayle.dev/api/oauth/latest/put-customer-contact
66
+ * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-contact-details
63
67
  */
64
68
  updateContactInfo(shopId: number, { email, phone }: Partial<ContactData>): Promise<ShopUser>;
65
69
  /**
66
- * Update the customer's personal details
70
+ * Update customer personal data.
71
+ *
72
+ * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-personal-data
67
73
  */
68
74
  updatePersonalInfo(shopId: number, payload: Partial<PersonalData>): Promise<ShopUser>;
69
75
  /**
70
- * Update the customer's password
76
+ * Update customer password.
71
77
  *
72
- * @see https://scayle.dev/api/oauth/latest/put-customer-password
78
+ * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-password
73
79
  */
74
80
  updatePassword(shopId: number, { password, newPassword }: PasswordUpdate): Promise<ShopUser>;
75
81
  }
@@ -59,7 +59,9 @@ export class CustomerAPIClient {
59
59
  throw new FetchError(response);
60
60
  }
61
61
  /**
62
- * Get the addresses for the current customer
62
+ * Get the addresses for the current customer.
63
+ *
64
+ * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/address/list-addresses
63
65
  */
64
66
  async getAddresses(shopId) {
65
67
  return await this.sendRequest(
@@ -73,8 +75,9 @@ export class CustomerAPIClient {
73
75
  }
74
76
  /**
75
77
  * Returns customer data and latest orders.
76
- * When not logged in will return undefined.
77
- * @see https://scayle.dev/api/oauth/latest/fetch-authorized-payload
78
+ * When not logged in, it will return `undefined`.
79
+ *
80
+ * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/get-customer
78
81
  */
79
82
  async getMe(shopId, accessToken) {
80
83
  return await this.sendRequest(
@@ -88,8 +91,9 @@ export class CustomerAPIClient {
88
91
  );
89
92
  }
90
93
  /**
91
- * Fetch a customer's order
92
- * @see https://scayle.dev/api/oauth/latest/fetch-order-by-id
94
+ * Retrieve a customer's order.
95
+ *
96
+ * @see https://scayle.dev/en/api-guides/customer-account-api/resources/order/get-order
93
97
  */
94
98
  async getOrder(shopId, orderId) {
95
99
  return this.sendRequest(
@@ -102,9 +106,9 @@ export class CustomerAPIClient {
102
106
  );
103
107
  }
104
108
  /**
105
- * Update the customer's contact details
109
+ * Update contact details of a customer.
106
110
  *
107
- * @see https://scayle.dev/api/oauth/latest/put-customer-contact
111
+ * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-contact-details
108
112
  */
109
113
  async updateContactInfo(shopId, { email, phone }) {
110
114
  return await this.sendRequest(
@@ -122,7 +126,9 @@ export class CustomerAPIClient {
122
126
  );
123
127
  }
124
128
  /**
125
- * Update the customer's personal details
129
+ * Update customer personal data.
130
+ *
131
+ * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-personal-data
126
132
  */
127
133
  async updatePersonalInfo(shopId, payload) {
128
134
  return await this.sendRequest(
@@ -137,9 +143,9 @@ export class CustomerAPIClient {
137
143
  );
138
144
  }
139
145
  /**
140
- * Update the customer's password
146
+ * Update customer password.
141
147
  *
142
- * @see https://scayle.dev/api/oauth/latest/put-customer-password
148
+ * @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-password
143
149
  */
144
150
  async updatePassword(shopId, { password, newPassword }) {
145
151
  return await this.sendRequest(
@@ -10,7 +10,8 @@ export interface OAuthOptions {
10
10
  export declare function getOAuthClient(context: RpcContext): OAuthClient;
11
11
  /**
12
12
  * A client for interacting with the Checkout Authentication API
13
- * Docs for all the routes: https://gitlab.com/aboutyou/checkout/schemas/checkout-auth-api/-/blob/main/build/openapi.yaml
13
+ *
14
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api
14
15
  */
15
16
  export declare class OAuthClient {
16
17
  headers: HeadersInit;
@@ -19,54 +20,87 @@ export declare class OAuthClient {
19
20
  clientId: string;
20
21
  constructor(options: OAuthOptions, logger?: Log);
21
22
  /**
22
- * Register a user and retrieve a token set
23
+ * Register a new User and receive an access token.
24
+ *
23
25
  * @param payload
26
+ *
27
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/create-new-user
24
28
  */
25
29
  register(payload: RegisterRequest): Promise<Oauth>;
26
30
  /**
27
- * Execute a user login on the OAuth API and receive a token set
31
+ * Login a User and receive an access token.
32
+ *
28
33
  * @param payload
34
+ *
35
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/log-in-users
29
36
  */
30
37
  login(payload: LoginRequest): Promise<Oauth>;
31
38
  /**
32
- * Execute a guest user login on the OAuth API and receive a token set
39
+ * Login a User as a guest and receive an access token.
40
+ *
33
41
  * @param payload
42
+ *
43
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/log-in-users-as-guest
34
44
  */
35
45
  guestLogin(payload: GuestRequest): Promise<Oauth>;
36
46
  /**
37
- * Send a password reset email
47
+ * Send a reset password email to a User.
48
+ *
38
49
  * @param payload
50
+ *
51
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/send-password-reset-email
39
52
  */
40
53
  sendPasswordResetEmail(payload: SendResetPasswordEmailRequest): Promise<void>;
41
54
  /**
42
- * Update password by hash
55
+ * Update password by using hash.
56
+ * All older tokens of the User are also invalidated.
57
+ *
43
58
  * @param payload
59
+ *
60
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/update-password-by-hash
44
61
  */
45
62
  updatePasswordByHash(payload: UpdatePasswordByHashRequest): Promise<Oauth>;
46
63
  /**
47
- * Update a user's password
64
+ * Update password via plain string.
65
+ *
48
66
  * @param payload
49
67
  * @param accessToken
50
68
  */
51
69
  updatePassword(payload: UpdatePasswordRequest, accessToken: string): Promise<void>;
52
70
  /**
53
- * Generate a new access token via a refresh token
71
+ * Generate a new access token via a refresh token.
72
+ *
54
73
  * @param payload
55
74
  */
56
75
  refreshToken(payload: RefreshTokenRequest): Promise<Oauth>;
57
76
  /**
58
- * Validate an access token
77
+ * Validate a token.
78
+ *
59
79
  * @param accessToken
80
+ *
81
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/bearer-auth/validate-present-token
60
82
  */
61
83
  validateToken(accessToken: string): Promise<void>;
62
84
  /**
63
- * Revoke an access token
85
+ * Revoke an Access Token and all related Refresh Tokens.
86
+ *
87
+ * Uses a valid Bearer Access Token in the Authorization header and will
88
+ * revoke the token with the given ID (_which could be a different token_).
89
+ * If a external identity provider was used for the target token,
90
+ * the corresponding IDP-AccessToken and IDP-RefreshToken will be revoked as well.
91
+ * In case the identity provider does not support revoking tokens over api calls
92
+ * (_because a frontend redirect is required_) this step will be skipped and the IDP-Tokens
93
+ * will remain valid until they expire or are revoked from IDP side.
94
+ *
64
95
  * @param shopId
65
96
  * @param accessToken
97
+ *
98
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/bearer-auth/delete-access-token-with-id
66
99
  */
67
100
  revokeToken(shopId: number, accessToken: string): Promise<void>;
68
101
  /**
69
- * Generate a new token based on authorization code
102
+ * Generate a new token based on authorization code.
103
+ *
70
104
  * @param code
71
105
  */
72
106
  generateToken(code: string): Promise<Oauth>;
@@ -56,8 +56,11 @@ export class OAuthClient {
56
56
  };
57
57
  }
58
58
  /**
59
- * Register a user and retrieve a token set
59
+ * Register a new User and receive an access token.
60
+ *
60
61
  * @param payload
62
+ *
63
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/create-new-user
61
64
  */
62
65
  async register(payload) {
63
66
  this.logger?.debug("Registering user");
@@ -68,8 +71,11 @@ export class OAuthClient {
68
71
  }).then(oauthResponseHandler);
69
72
  }
70
73
  /**
71
- * Execute a user login on the OAuth API and receive a token set
74
+ * Login a User and receive an access token.
75
+ *
72
76
  * @param payload
77
+ *
78
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/log-in-users
73
79
  */
74
80
  async login(payload) {
75
81
  this.logger?.debug("Logging in");
@@ -80,8 +86,11 @@ export class OAuthClient {
80
86
  }).then(oauthResponseHandler);
81
87
  }
82
88
  /**
83
- * Execute a guest user login on the OAuth API and receive a token set
89
+ * Login a User as a guest and receive an access token.
90
+ *
84
91
  * @param payload
92
+ *
93
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/log-in-users-as-guest
85
94
  */
86
95
  async guestLogin(payload) {
87
96
  this.logger?.debug("Logging in as guest");
@@ -92,8 +101,11 @@ export class OAuthClient {
92
101
  }).then(oauthResponseHandler);
93
102
  }
94
103
  /**
95
- * Send a password reset email
104
+ * Send a reset password email to a User.
105
+ *
96
106
  * @param payload
107
+ *
108
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/send-password-reset-email
97
109
  */
98
110
  async sendPasswordResetEmail(payload) {
99
111
  this.logger?.debug("Sending password reset email");
@@ -104,8 +116,12 @@ export class OAuthClient {
104
116
  }).then(emptyOAuthResponseHandler);
105
117
  }
106
118
  /**
107
- * Update password by hash
119
+ * Update password by using hash.
120
+ * All older tokens of the User are also invalidated.
121
+ *
108
122
  * @param payload
123
+ *
124
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/oauth-client/update-password-by-hash
109
125
  */
110
126
  async updatePasswordByHash(payload) {
111
127
  this.logger?.debug("Updating password by hash");
@@ -116,7 +132,8 @@ export class OAuthClient {
116
132
  }).then(oauthResponseHandler);
117
133
  }
118
134
  /**
119
- * Update a user's password
135
+ * Update password via plain string.
136
+ *
120
137
  * @param payload
121
138
  * @param accessToken
122
139
  */
@@ -132,7 +149,8 @@ export class OAuthClient {
132
149
  }).then(emptyOAuthResponseHandler);
133
150
  }
134
151
  /**
135
- * Generate a new access token via a refresh token
152
+ * Generate a new access token via a refresh token.
153
+ *
136
154
  * @param payload
137
155
  */
138
156
  async refreshToken(payload) {
@@ -144,8 +162,11 @@ export class OAuthClient {
144
162
  }).then(oauthResponseHandler);
145
163
  }
146
164
  /**
147
- * Validate an access token
165
+ * Validate a token.
166
+ *
148
167
  * @param accessToken
168
+ *
169
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/bearer-auth/validate-present-token
149
170
  */
150
171
  async validateToken(accessToken) {
151
172
  this.logger?.debug("Validating access token");
@@ -157,9 +178,20 @@ export class OAuthClient {
157
178
  }).then(emptyOAuthResponseHandler);
158
179
  }
159
180
  /**
160
- * Revoke an access token
181
+ * Revoke an Access Token and all related Refresh Tokens.
182
+ *
183
+ * Uses a valid Bearer Access Token in the Authorization header and will
184
+ * revoke the token with the given ID (_which could be a different token_).
185
+ * If a external identity provider was used for the target token,
186
+ * the corresponding IDP-AccessToken and IDP-RefreshToken will be revoked as well.
187
+ * In case the identity provider does not support revoking tokens over api calls
188
+ * (_because a frontend redirect is required_) this step will be skipped and the IDP-Tokens
189
+ * will remain valid until they expire or are revoked from IDP side.
190
+ *
161
191
  * @param shopId
162
192
  * @param accessToken
193
+ *
194
+ * @see https://scayle.dev/en/api-guides/checkout-authentication-api/resources/bearer-auth/delete-access-token-with-id
163
195
  */
164
196
  async revokeToken(shopId, accessToken) {
165
197
  this.logger?.debug("Revoking access token");
@@ -174,7 +206,8 @@ export class OAuthClient {
174
206
  }).then(emptyOAuthResponseHandler);
175
207
  }
176
208
  /**
177
- * Generate a new token based on authorization code
209
+ * Generate a new token based on authorization code.
210
+ *
178
211
  * @param code
179
212
  */
180
213
  async generateToken(code) {
@@ -35,7 +35,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
35
35
  carrier,
36
36
  basketId: context.basketKey,
37
37
  campaignKey: context.campaignKey
38
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.3.2"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
38
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.5.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
39
39
  return {
40
40
  accessToken: refreshedAccessToken,
41
41
  checkoutJwt
@@ -1,3 +1,25 @@
1
1
  import type { SearchEntity, SearchV2ResolveEndpointParameters, SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData } from '../../types/sapi/search';
2
+ /**
3
+ * Fetches search suggestions for a given term.
4
+ *
5
+ * @param option - The parameters for the request.
6
+ * @param option.term - The term to search for.
7
+ * @param option.with - An object describing which data the returned suggestions should contain.
8
+ * @param option.categoryId - The category ID to search within.
9
+ * @param context - The rpc context associated with the request.
10
+ *
11
+ * @returns A promise that resolves to a list of search suggestions.
12
+ */
2
13
  export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: SearchV2SuggestionsEndpointParameters, { sapiClient, withParams }: import("../../types").RpcContext) => Promise<Response | SearchV2SuggestionsEndpointResponseData>;
14
+ /**
15
+ * Resolves a search query and returns the resolved entity.
16
+ *
17
+ * @param option - The parameters for the search query.
18
+ * @param option.term - The search query to resolve.
19
+ * @param option.with - An object describing which data the returned result should contain.
20
+ * @param option.categoryId - The category ID for which the search should be performed.
21
+ * @param context - The rpc context associated with the request.
22
+ *
23
+ * @returns A promise that resolves to the resolved entity or null if no entity is found.
24
+ */
3
25
  export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters, { cached, sapiClient, withParams }: import("../../types").RpcContext) => Promise<SearchEntity | null>;
@@ -1,6 +1,6 @@
1
1
  import type { UseBasketParams } from './sapi/basket';
2
2
  import type { UseWishlistParams } from './sapi/wishlist';
3
- export type Gender = 'm' | 'f' | 'd';
3
+ export type Gender = 'm' | 'f' | 'd' | 'n';
4
4
  export interface UpdatePasswordParams {
5
5
  oldPassword: string;
6
6
  newPassword: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "8.3.2",
3
+ "version": "8.5.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -14,36 +14,26 @@
14
14
  "./package.json": "./package.json",
15
15
  ".": {
16
16
  "types": "./dist/index.d.ts",
17
- "import": "./dist/index.mjs",
18
- "require": "./dist/index.cjs",
19
- "default": "./dist/index.cjs"
17
+ "default": "./dist/index.mjs"
20
18
  },
21
19
  "./server": {
22
20
  "types": "./dist/server.d.ts",
23
- "import": "./dist/server.mjs",
24
- "require": "./dist/server.cjs",
25
- "default": "./dist/server.cjs"
21
+ "default": "./dist/server.mjs"
26
22
  },
27
23
  "./dist/test/factories": {
28
24
  "types": "./dist/test/factories/index.d.ts",
29
- "import": "./dist/test/factories/index.mjs",
30
- "require": "./dist/test/factories/index.cjs",
31
- "default": "./dist/test/factories/index.cjs"
25
+ "default": "./dist/test/factories/index.mjs"
32
26
  },
33
27
  "./test/factories": {
34
28
  "types": "./dist/test/factories/index.d.ts",
35
- "import": "./dist/test/factories/index.mjs",
36
- "require": "./dist/test/factories/index.cjs",
37
- "default": "./dist/test/factories/index.cjs"
29
+ "default": "./dist/test/factories/index.mjs"
38
30
  },
39
31
  "./dist/*": {
40
32
  "types": "./dist/*.d.ts",
41
- "import": "./dist/*.mjs",
42
- "require": "./dist/*.cjs",
43
- "default": "./dist/*.cjs"
33
+ "default": "./dist/*.mjs"
44
34
  }
45
35
  },
46
- "main": "./dist/index.cjs",
36
+ "main": "./dist/index.mjs",
47
37
  "module": "./dist/index.mjs",
48
38
  "types": "./dist/index.d.ts",
49
39
  "files": [
@@ -83,11 +73,11 @@
83
73
  "devDependencies": {
84
74
  "@scayle/eslint-config-storefront": "4.4.1",
85
75
  "@types/crypto-js": "4.2.2",
86
- "@types/node": "22.13.1",
76
+ "@types/node": "22.13.2",
87
77
  "@types/webpack-env": "1.18.8",
88
78
  "@vitest/coverage-v8": "2.1.9",
89
79
  "dprint": "0.49.0",
90
- "eslint": "9.19.0",
80
+ "eslint": "9.20.1",
91
81
  "eslint-formatter-gitlab": "5.1.0",
92
82
  "publint": "0.2.12",
93
83
  "rimraf": "6.0.1",
@@ -1,158 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CustomerAPIClient = void 0;
7
- var _fetch = require("../utils/fetch.cjs");
8
- var _httpStatus = require("../constants/httpStatus.cjs");
9
- var _oauth = require("./oauth.cjs");
10
- class CustomerAPIClient {
11
- baseURL;
12
- context;
13
- additionalHeaders;
14
- constructor(context) {
15
- this.baseURL = context.checkout.url;
16
- this.context = context;
17
- this.additionalHeaders = context.internalAccessHeader ? {
18
- "x-internal-access": context.internalAccessHeader
19
- } : {};
20
- }
21
- get headers() {
22
- return {
23
- Authorization: `Bearer ${this.context.accessToken}`,
24
- Accept: "application/json",
25
- "Content-Type": "application/json",
26
- ...this.additionalHeaders
27
- };
28
- }
29
- async sendRequest(request, retry = true) {
30
- const response = await request();
31
- if (response.ok) {
32
- return await response.json();
33
- }
34
- if ((response.status === _httpStatus.HttpStatusCode.UNAUTHORIZED && response.headers.get("WWW-Authenticate")?.includes("invalid_token") || response.status === _httpStatus.HttpStatusCode.FORBIDDEN) && this.context.accessToken && this.context.refreshToken) {
35
- if (retry) {
36
- const client = (0, _oauth.getOAuthClient)(this.context);
37
- try {
38
- const tokens = await client.refreshToken({
39
- grant_type: "refresh_token",
40
- refresh_token: this.context.refreshToken
41
- });
42
- this.context.updateTokens({
43
- accessToken: tokens?.access_token,
44
- refreshToken: tokens?.refresh_token
45
- });
46
- } catch (e) {
47
- if (e instanceof _fetch.FetchError && e.response.status === _httpStatus.HttpStatusCode.UNAUTHORIZED) {
48
- this.context.log.debug("Failed to refresh Checkout Token due to invalid refresh token. Deleting session");
49
- await this.context.destroySession();
50
- } else {
51
- this.context.log.debug("Failed to refresh Checkout Token for unknown reason.");
52
- }
53
- throw new _fetch.FetchError(response);
54
- }
55
- return await this.sendRequest(request, false);
56
- } else {
57
- this.context.log.debug("Invalid Checkout Token. Deleting session");
58
- await this.context.destroySession();
59
- }
60
- }
61
- throw new _fetch.FetchError(response);
62
- }
63
- /**
64
- * Get the addresses for the current customer
65
- */
66
- async getAddresses(shopId) {
67
- return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/addresses`, {
68
- headers: {
69
- ...this.headers,
70
- "X-Shop-Id": shopId.toString()
71
- }
72
- }));
73
- }
74
- /**
75
- * Returns customer data and latest orders.
76
- * When not logged in will return undefined.
77
- * @see https://scayle.dev/api/oauth/latest/fetch-authorized-payload
78
- */
79
- async getMe(shopId, accessToken) {
80
- return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/me`, {
81
- headers: {
82
- ...this.headers,
83
- ...(accessToken ? {
84
- Authorization: `Bearer ${accessToken}`
85
- } : {}),
86
- "X-Shop-Id": shopId.toString()
87
- }
88
- }));
89
- }
90
- /**
91
- * Fetch a customer's order
92
- * @see https://scayle.dev/api/oauth/latest/fetch-order-by-id
93
- */
94
- async getOrder(shopId, orderId) {
95
- return this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/order/${orderId}`, {
96
- headers: {
97
- ...this.headers,
98
- "X-Shop-Id": shopId.toString()
99
- }
100
- }));
101
- }
102
- /**
103
- * Update the customer's contact details
104
- *
105
- * @see https://scayle.dev/api/oauth/latest/put-customer-contact
106
- */
107
- async updateContactInfo(shopId, {
108
- email,
109
- phone
110
- }) {
111
- return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/contact`, {
112
- method: "PUT",
113
- headers: {
114
- ...this.headers,
115
- "X-Shop-Id": shopId.toString()
116
- },
117
- body: JSON.stringify({
118
- email,
119
- phone
120
- })
121
- }));
122
- }
123
- /**
124
- * Update the customer's personal details
125
- */
126
- async updatePersonalInfo(shopId, payload) {
127
- return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/personal`, {
128
- method: "PUT",
129
- headers: {
130
- ...this.headers,
131
- "X-Shop-Id": shopId.toString()
132
- },
133
- body: JSON.stringify(payload)
134
- }));
135
- }
136
- /**
137
- * Update the customer's password
138
- *
139
- * @see https://scayle.dev/api/oauth/latest/put-customer-password
140
- */
141
- async updatePassword(shopId, {
142
- password,
143
- newPassword
144
- }) {
145
- return await this.sendRequest(() => fetch(`${this.baseURL}/api/oauth/customer/password`, {
146
- method: "PUT",
147
- headers: {
148
- ...this.headers,
149
- "X-Shop-Id": shopId.toString()
150
- },
151
- body: JSON.stringify({
152
- password,
153
- newPassword
154
- })
155
- }));
156
- }
157
- }
158
- exports.CustomerAPIClient = CustomerAPIClient;