@truenas/api-client 9.0.6 → 11.0.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.
@@ -1731,6 +1731,7 @@ __export(v27_0_0_exports, {
1731
1731
  IscsiTargetCreateModeInput: () => IscsiTargetCreateModeInput,
1732
1732
  KeychainCredentialEntryType: () => KeychainCredentialEntryType,
1733
1733
  KeychainCredentialEntryTypeInput: () => KeychainCredentialEntryTypeInput,
1734
+ Layout: () => Layout,
1734
1735
  Level: () => Level,
1735
1736
  NFS4ACEType: () => NFS4ACEType,
1736
1737
  NFS4ACETypeInput: () => NFS4ACETypeInput,
@@ -1845,6 +1846,10 @@ var Interval = {
1845
1846
  "30": 30,
1846
1847
  "60": 60
1847
1848
  };
1849
+ var Layout = {
1850
+ Bucket: "BUCKET",
1851
+ Dataset: "DATASET"
1852
+ };
1848
1853
  var Name2 = {
1849
1854
  Cpu: "cpu",
1850
1855
  Cputemp: "cputemp",
@@ -1988,6 +1993,7 @@ __export(v28_0_0_exports, {
1988
1993
  IscsiTargetCreateModeInput: () => IscsiTargetCreateModeInput,
1989
1994
  KeychainCredentialEntryType: () => KeychainCredentialEntryType,
1990
1995
  KeychainCredentialEntryTypeInput: () => KeychainCredentialEntryTypeInput,
1996
+ Layout: () => Layout,
1991
1997
  Level: () => Level,
1992
1998
  NFS4ACEType: () => NFS4ACEType,
1993
1999
  NFS4ACETypeInput: () => NFS4ACETypeInput,
@@ -2063,6 +2069,8 @@ __export(v28_0_0_exports, {
2063
2069
  Versioning: () => Versioning,
2064
2070
  Volblocksize: () => Volblocksize,
2065
2071
  When: () => When,
2072
+ ZFSResourceUserspaceEntryType: () => ZFSResourceUserspaceEntryType,
2073
+ ZFSResourceUserspaceEntryTypeInput: () => ZFSResourceUserspaceEntryTypeInput,
2066
2074
  ZfsTierRewriteJobEntryStatus: () => ZfsTierRewriteJobEntryStatus,
2067
2075
  ZfsTierRewriteJobEntryStatusInput: () => ZfsTierRewriteJobEntryStatusInput,
2068
2076
  ZpoolScrubRunAction: () => ZpoolScrubRunAction
@@ -2148,6 +2156,14 @@ var VMWareMatchDatastoresWithDatasetsResultFilesystemTypeInput = {
2148
2156
  Filesystem: "FILESYSTEM",
2149
2157
  Volume: "VOLUME"
2150
2158
  };
2159
+ var ZFSResourceUserspaceEntryType = {
2160
+ User: "user",
2161
+ Group: "group"
2162
+ };
2163
+ var ZFSResourceUserspaceEntryTypeInput = {
2164
+ User: "user",
2165
+ Group: "group"
2166
+ };
2151
2167
 
2152
2168
  // src/generated/index.ts
2153
2169
  var SUPPORTED_API_VERSIONS = [
@@ -2184,6 +2200,7 @@ var TrueNasAuthMechanism = /* @__PURE__ */ ((TrueNasAuthMechanism2) => {
2184
2200
  var AuthErrorCode = /* @__PURE__ */ ((AuthErrorCode2) => {
2185
2201
  AuthErrorCode2["PasswordAuthFailed"] = "PASSWORD_AUTH_FAILED";
2186
2202
  AuthErrorCode2["OtpAuthFailed"] = "OTP_AUTH_FAILED";
2203
+ AuthErrorCode2["OtpLoginNotPending"] = "OTP_LOGIN_NOT_PENDING";
2187
2204
  AuthErrorCode2["ApiKeyAuthFailed"] = "API_KEY_AUTH_FAILED";
2188
2205
  AuthErrorCode2["TokenAuthFailed"] = "TOKEN_AUTH_FAILED";
2189
2206
  AuthErrorCode2["LoginSuperseded"] = "LOGIN_SUPERSEDED";
@@ -2197,11 +2214,12 @@ var AuthError = class _AuthError extends Error {
2197
2214
  * `AUTH_ERR`; the code alone says only which mechanism failed. Absent when the login
2198
2215
  * never got an answer of that kind (an error frame, or a superseded login).
2199
2216
  */
2200
- constructor(code, message, response) {
2217
+ constructor(code, message, response, options = {}) {
2201
2218
  super(message);
2202
2219
  this.code = code;
2203
2220
  this.response = response;
2204
2221
  this.name = "AuthError";
2222
+ this.loginPending = options.loginPending ?? false;
2205
2223
  Object.setPrototypeOf(this, _AuthError.prototype);
2206
2224
  }
2207
2225
  };
@@ -2742,6 +2760,7 @@ var throwOnAuthenticationFailure = (code, message) => switchMap((response) => {
2742
2760
  }
2743
2761
  return of(response);
2744
2762
  });
2763
+ var isOtpLoginNotPending = (error) => error.data?.errname === "EINVAL" && typeof error.data.reason === "string" && error.data.reason.includes("OTP_TOKEN: no authentication in progress");
2745
2764
  var TrueNasAuthenticator = class _TrueNasAuthenticator {
2746
2765
  constructor(connection, version) {
2747
2766
  this.connection = connection;
@@ -2925,6 +2944,19 @@ var TrueNasAuthenticator = class _TrueNasAuthenticator {
2925
2944
  take(1)
2926
2945
  );
2927
2946
  }
2947
+ /**
2948
+ * The second step of a two-factor login, after `loginWithUserPass` answered
2949
+ * `OTP_REQUIRED`.
2950
+ *
2951
+ * Emits the answer when the code is accepted (`SUCCESS`), or when middleware
2952
+ * refuses the account outright (`EXPIRED`, `DENIED`, `REDIRECT`); never
2953
+ * `OTP_REQUIRED`. A refused code errors with `AuthError`, the same way on
2954
+ * every release:
2955
+ *
2956
+ * - `OtpAuthFailed` with `loginPending: true`: ask for another code.
2957
+ * - `OtpAuthFailed` with `loginPending: false`: start over with the password.
2958
+ * - `OtpLoginNotPending`: no login was waiting for a code; start over.
2959
+ */
2928
2960
  loginWithOtp(code) {
2929
2961
  const { sentDuring, callerInitiated } = this.beginLogin();
2930
2962
  let answered = false;
@@ -2944,6 +2976,12 @@ var TrueNasAuthenticator = class _TrueNasAuthenticator {
2944
2976
  }),
2945
2977
  map((msg) => {
2946
2978
  if (msg.error) {
2979
+ if (isOtpLoginNotPending(msg.error)) {
2980
+ throw new AuthError(
2981
+ "OTP_LOGIN_NOT_PENDING" /* OtpLoginNotPending */,
2982
+ "TrueNAS is no longer waiting for a one-time passcode for this login. Please sign in with your password again."
2983
+ );
2984
+ }
2947
2985
  const errorMessage = getApiErrorMessage(
2948
2986
  msg.error,
2949
2987
  "Authentication failed"
@@ -2952,6 +2990,23 @@ var TrueNasAuthenticator = class _TrueNasAuthenticator {
2952
2990
  }
2953
2991
  return msg.result;
2954
2992
  }),
2993
+ // A wrong code is answered differently by release, and the API version
2994
+ // does not say which: 25.10 answers `OTP_REQUIRED` and keeps the login
2995
+ // for another code, 27+ answers `AUTH_ERR` and drops it. Both are the
2996
+ // same failure to the caller, told apart only by `loginPending`, so no
2997
+ // caller has to read `OTP_REQUIRED` as "wrong code".
2998
+ map((res) => {
2999
+ const loginPending = res?.response_type === "OTP_REQUIRED" /* OtpRequired */;
3000
+ if (loginPending || res?.response_type === "AUTH_ERR" /* AuthErr */) {
3001
+ throw new AuthError(
3002
+ "OTP_AUTH_FAILED" /* OtpAuthFailed */,
3003
+ loginPending ? "TrueNAS rejected the one-time passcode. Please verify it and try again." : "TrueNAS rejected the one-time passcode. Please sign in with your password again.",
3004
+ res,
3005
+ { loginPending }
3006
+ );
3007
+ }
3008
+ return res;
3009
+ }),
2955
3010
  tap((res) => {
2956
3011
  if (res?.response_type === "SUCCESS" /* Success */) {
2957
3012
  this.assertNotSuperseded(sentDuring);
@@ -2959,10 +3014,6 @@ var TrueNasAuthenticator = class _TrueNasAuthenticator {
2959
3014
  this.authenticated$.next(true);
2960
3015
  }
2961
3016
  }),
2962
- throwOnAuthenticationFailure(
2963
- "OTP_AUTH_FAILED" /* OtpAuthFailed */,
2964
- "TrueNAS authentication failed. Please verify your one-time passcode and try again."
2965
- ),
2966
3017
  finalize(() => {
2967
3018
  this.endLogin(sentDuring, callerInitiated, answered);
2968
3019
  }),
@@ -4205,7 +4256,12 @@ function toContainer3(container) {
4205
4256
  return {
4206
4257
  id: container.id.toString(),
4207
4258
  name: container.name,
4208
- status: toAppState(container.status.state),
4259
+ // `status` is nullable from v28. Middleware's own word on when: "`null` if
4260
+ // `query-options.extra.retrieve_status` is `false`" — so a null is status
4261
+ // that was not fetched, not a container in an unreportable state. That is
4262
+ // what `Unknown` is for ("no usable state"), and it keeps `Container.status`
4263
+ // non-optional for every caller.
4264
+ status: container.status ? toAppState(container.status.state) : "UNKNOWN" /* Unknown */,
4209
4265
  // Optional in the generated entry, required by `Container`.
4210
4266
  autostart: container.autostart ?? false,
4211
4267
  description
@@ -4779,5 +4835,5 @@ var UserRole = /* @__PURE__ */ ((UserRole2) => {
4779
4835
  })(UserRole || {});
4780
4836
 
4781
4837
  export { AppState, AuthError, AuthErrorCode, AuthResponseType, InvalidVersionResponseError, JobState, NoCompatibleVersionsError, SUPPORTED_API_VERSIONS, TrueNasApiClient, TrueNasApiClientV2510, TrueNasApiClientV27, TrueNasApiClientV28, TrueNasApiError, TrueNasAuthMechanism, TrueNasAuthenticator, TrueNasConnection, UserRole, VersionCompatibility, VersionDiscovery, VersionDiscoveryError, VersionDiscoveryNetworkError, VersionDiscoveryTimeoutError, VersionEndpointNotFoundError, VersionTooNewError, VersionTooOldError, clientClassFor, consoleLogger, createTrueNasClient, getApiErrorMessage, getCloseMessage, isJobFinished, noopLogger, parseApiVersion, policyViolationCloseCode, subscriptionName, v25_10_0_exports, v25_10_1_exports, v25_10_2_exports, v25_10_3_exports, v25_10_4_exports, v25_10_5_exports, v27_0_0_exports, v28_0_0_exports };
4782
- //# sourceMappingURL=chunk-R4VP3HBB.js.map
4783
- //# sourceMappingURL=chunk-R4VP3HBB.js.map
4838
+ //# sourceMappingURL=chunk-ZH75OPDH.js.map
4839
+ //# sourceMappingURL=chunk-ZH75OPDH.js.map