axiam-sdk 1.0.0-alpha39 → 1.0.0-alpha41

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/README.md CHANGED
@@ -742,8 +742,19 @@ try {
742
742
  ```
743
743
 
744
744
  The `if` is the important line. **Any other error is a failed login**, and
745
- retrying it over `login()` would hand the plaintext to a server that just
746
- failed to prove it holds the record.
745
+ retrying it over `login()` yourself would hand the plaintext to a server that
746
+ just failed to prove it holds the record.
747
+
748
+ One case is handled for you. `login/start` returns the tenant's `mode`, and when
749
+ it is `"optional"` — the mid-migration state, where accounts acquire a
750
+ registration record only as their passwords are next set — a failed exchange is
751
+ not yet a verdict on the credentials, so `loginOpaque` retries over
752
+ `POST /api/v1/auth/login` itself and returns that call's outcome (CONTRACT.md
753
+ §23.4 rule 7). Under `"required"`, and against a server too old to send `mode`
754
+ at all, it fails closed exactly as before. `mode` is **not** downgrade
755
+ protection: a hostile server that wanted the plaintext could answer `404` and
756
+ get the fallback above regardless. `required` is what closes that, server-side,
757
+ by refusing `/auth/login` for every principal in the tenant.
747
758
 
748
759
  ### What this buys, and what it does not
749
760
 
@@ -1016,6 +1016,7 @@ async function login(client, email, password) {
1016
1016
  } catch (err) {
1017
1017
  const setup = mfaSetupRequired(err);
1018
1018
  if (setup) return setup;
1019
+ if (err instanceof AxiamError) throw err;
1019
1020
  const status = extractAxiosStatus(err);
1020
1021
  if (status !== void 0) {
1021
1022
  throw mapHttpStatusToError(status, extractErrorMessage(extractAxiosData(err)) ?? "login failed", {
@@ -1035,6 +1036,7 @@ async function verifyMfa(client, mfaToken, code) {
1035
1036
  await client.session.onAuthenticated?.();
1036
1037
  return loginSuccessToResult(response.data);
1037
1038
  } catch (err) {
1039
+ if (err instanceof AxiamError) throw err;
1038
1040
  const status = extractAxiosStatus(err);
1039
1041
  if (status !== void 0) {
1040
1042
  throw mapHttpStatusToError(status, extractErrorMessage(extractAxiosData(err)) ?? "verifyMfa failed", {
@@ -1051,6 +1053,7 @@ async function refresh(client) {
1051
1053
  await client.session.axios.post(REFRESH_PATH, client.session.buildRefreshBody());
1052
1054
  await client.session.onAuthenticated?.();
1053
1055
  } catch (err) {
1056
+ if (err instanceof AxiamError) throw err;
1054
1057
  const status = extractAxiosStatus(err);
1055
1058
  if (status !== void 0) {
1056
1059
  throw mapHttpStatusToError(status, extractErrorMessage(extractAxiosData(err)) ?? "refresh failed", {
@@ -1066,6 +1069,7 @@ async function logout(client) {
1066
1069
  try {
1067
1070
  await client.session.axios.post(LOGOUT_PATH, {});
1068
1071
  } catch (err) {
1072
+ if (err instanceof AxiamError) throw err;
1069
1073
  const status = extractAxiosStatus(err);
1070
1074
  if (status !== void 0) {
1071
1075
  throw mapHttpStatusToError(status, extractErrorMessage(extractAxiosData(err)) ?? "logout failed", {
@@ -1231,6 +1235,9 @@ async function loginOpaque(client, usernameOrEmail, password) {
1231
1235
  ke3 = exchange.finish(started.ke2, started);
1232
1236
  } catch (err) {
1233
1237
  if (err instanceof NetworkError) throw err;
1238
+ if (started.mode === "optional") {
1239
+ return await login(client, usernameOrEmail, password);
1240
+ }
1234
1241
  throw mapHttpStatusToError(401, "invalid credentials", { cause: err });
1235
1242
  }
1236
1243
  let response;