@scayle/storefront-core 8.59.3 → 8.59.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 8.59.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed error handling in `oauthRegister` and other OAuth-related RPC methods to properly propagate HTTP status codes like 409 Conflict instead of converting them to 500 Internal Server Error.
8
+
9
+ The `convertErrorForRpcCall` function now correctly handles `OAuthRequestError` instances that wrap `FetchError` objects. Previously, when OAuth API errors occurred (such as attempting to register with an existing email), the error handling only checked for direct `FetchError` instances, causing wrapped errors to fall through to a generic 500 error response. Now the function extracts the underlying `FetchError` from `OAuthRequestError` instances, ensuring that the correct HTTP status codes are returned to the frontend.
10
+
3
11
  ## 8.59.3
4
12
 
5
13
  ## 8.59.2
@@ -40,7 +40,7 @@ export const getCheckoutToken = defineRpcHandler(async (jwtPayload = {}, context
40
40
  ...customData,
41
41
  ...orderCustomData
42
42
  }
43
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.59.3"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
43
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.59.4"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
44
44
  return {
45
45
  accessToken: refreshedAccessToken,
46
46
  checkoutJwt
@@ -1,6 +1,18 @@
1
1
  import type { Optional } from 'utility-types';
2
2
  import type { GuestRequest, LoginRequest, Oauth, ParamRpcHandler, RegisterRequest, RpcContextWithSession, RpcHandler, UpdatePasswordByHashRequest } from '../../types';
3
3
  import { ErrorResponse } from '../../errors';
4
+ /**
5
+ * Ensure error is a fetch error with one of the status codes
6
+ *
7
+ * @param error Any error object.
8
+ * @param httpStatuses Array of HTTP status codes to check against.
9
+ *
10
+ * @returns A Response object if the error matches the criteria, undefined otherwise.
11
+ * It will return an `ErrorResponse` if the provided Error is a `FetchError`
12
+ * or an `OAuthRequestError` with a `FetchError` cause, and its status is included in httpStatuses.
13
+ * Otherwise, it returns undefined.
14
+ */
15
+ export declare const convertErrorForRpcCall: (error: any, httpStatuses: Array<number>) => Response | undefined;
4
16
  /**
5
17
  * Handles the post-login logic, including fetching user data, updating tokens,
6
18
  * merging baskets and wishlists, and creating a user-bound session.
@@ -9,15 +9,21 @@ import { FetchError } from "../../utils/fetch.mjs";
9
9
  import { mergeBaskets, mergeWishlists } from "../../utils/user.mjs";
10
10
  import { fetchUser } from "../../rpc/methods/user.mjs";
11
11
  import { unwrap } from "../../utils/response.mjs";
12
- import { getOAuthClient } from "../../api/oauth.mjs";
12
+ import { getOAuthClient, OAuthRequestError } from "../../api/oauth.mjs";
13
13
  import { ErrorResponse } from "../../errors/index.mjs";
14
14
  import { defineRpcHandler } from "../../utils/index.mjs";
15
- const convertErrorForRpcCall = (error, httpStatuses) => {
16
- if (error instanceof FetchError && httpStatuses.includes(error.response.status)) {
15
+ export const convertErrorForRpcCall = (error, httpStatuses) => {
16
+ let fetchError;
17
+ if (error instanceof FetchError) {
18
+ fetchError = error;
19
+ } else if (error instanceof OAuthRequestError && error.cause instanceof FetchError) {
20
+ fetchError = error.cause;
21
+ }
22
+ if (fetchError && httpStatuses.includes(fetchError.response.status)) {
17
23
  return new ErrorResponse(
18
- error.response.status,
19
- error.response.statusText,
20
- error.name
24
+ fetchError.response.status,
25
+ fetchError.response.statusText,
26
+ fetchError.name
21
27
  );
22
28
  }
23
29
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "8.59.3",
3
+ "version": "8.59.4",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",