squarefi-bff-api-module 1.36.27 → 1.36.28

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.
@@ -7,7 +7,14 @@ import { isExternalAuthMode, resolveAccessToken, triggerReverification, triggerU
7
7
  import { deleteTokens, getTokens, refreshTokens } from './tokensFactory';
8
8
  // eslint-disable-next-line no-constant-condition
9
9
  // Backend signals that a sensitive request needs a fresh second-factor verification with this code.
10
- const TWO_FACTOR_REVERIFICATION_CODE = 'two_factor_reverification_required';
10
+ // Backend error codes are UPPER_SNAKE_CASE, and the code can sit at either `data.code` or
11
+ // `data.error.code`. Normalize to upper case and check both locations so the match stays robust.
12
+ const TWO_FACTOR_REVERIFICATION_CODE = 'TWO_FACTOR_REVERIFICATION_REQUIRED';
13
+ const isReverificationRequired = (data) => {
14
+ const code = data?.code ??
15
+ data?.error?.code;
16
+ return typeof code === 'string' && code.toUpperCase() === TWO_FACTOR_REVERIFICATION_CODE;
17
+ };
11
18
  const apiV1BaseURL = process.env.API_URL ?? 'ENV variable API_URL is not defined';
12
19
  const apiV2BaseURL = process.env.API_V2_URL ?? 'ENV variable API_V2_URL is not defined';
13
20
  const apiTOTPBaseURL = process.env.API_TOTP_URL ?? 'ENV variable API_TOTP_URL is not defined';
@@ -46,7 +53,7 @@ export const createApiClient = ({ baseURL, isBearerToken, tenantId }) => {
46
53
  // Step-up 2FA: the backend rejects a sensitive request until the user re-verifies their
47
54
  // second factor. Hand off to the consumer's reverification handler and retry once on success.
48
55
  if (error?.response?.status === ResponseStatus.FORBIDDEN &&
49
- error?.response?.data?.code === TWO_FACTOR_REVERIFICATION_CODE &&
56
+ isReverificationRequired(error?.response?.data) &&
50
57
  !error?.response?.config.context?.isRetryRequest) {
51
58
  const { response, config: failedRequestConfig } = error;
52
59
  return triggerReverification(response.data).then((didReverify) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squarefi-bff-api-module",
3
- "version": "1.36.27",
3
+ "version": "1.36.28",
4
4
  "description": "Squarefi BFF API client module",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",