@truenas/api-client 3.0.4 → 3.0.5

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/dist/index.d.cts CHANGED
@@ -12798,6 +12798,49 @@ declare class TrueNasApi<D extends ApiDirectoryShape = BaseApiDirectory> {
12798
12798
  private initializeJobEventsSubscription;
12799
12799
  }
12800
12800
 
12801
+ /**
12802
+ * Response from the /api/versions endpoint
12803
+ * Returns an array of version strings directly
12804
+ * Example: ["v25.10.0", "v25.10.1", "v26.0.0"]
12805
+ */
12806
+ type ApiVersionResponse = string[];
12807
+ /**
12808
+ * Parsed API version information
12809
+ *
12810
+ * Version format:
12811
+ * - Legacy (v25.x): vYY.MM.PATCH (e.g., v25.10.0 = October 2025, patch 0)
12812
+ * - New (v26+): vYY.MINOR.PATCH (e.g., v26.0.0 = 2026, minor 0, patch 0)
12813
+ *
12814
+ * Note: The second segment has different semantics based on the year:
12815
+ * - Year 25: month (1-12)
12816
+ * - Year 26+: minor version (0-99)
12817
+ */
12818
+ interface ApiVersion {
12819
+ /** Full version string (e.g., "v26.0.0") */
12820
+ version: string;
12821
+ /** Two-digit year (e.g., 26 = 2026) */
12822
+ year: number;
12823
+ /**
12824
+ * Second version segment (semantics depend on year):
12825
+ * - For v25.x: month (1-12, e.g., 10 = October)
12826
+ * - For v26+: minor version (0-99)
12827
+ */
12828
+ minor: number;
12829
+ /** Patch version number (e.g., 0, 1, 2) */
12830
+ patch: number;
12831
+ /** WebSocket path for this version (e.g., "/api/v26.0.0") */
12832
+ websocketPath: string;
12833
+ }
12834
+ /**
12835
+ * Version compatibility status
12836
+ */
12837
+ declare enum VersionCompatibility {
12838
+ Compatible = "compatible",
12839
+ TooOld = "too-old",
12840
+ TooNew = "too-new",
12841
+ Invalid = "invalid"
12842
+ }
12843
+
12801
12844
  interface ApiKeyCreate {
12802
12845
  id: number;
12803
12846
  key: string;
@@ -12824,6 +12867,24 @@ interface AuthResponse {
12824
12867
  response_type: AuthResponseType;
12825
12868
  username?: string;
12826
12869
  authenticator?: 'LEVEL_1' | 'LEVEL_2' | 'LEVEL_3';
12870
+ /**
12871
+ * A token for re-authenticating without credentials.
12872
+ *
12873
+ * Absent below v26: `AuthRespSuccess` there declares only `response_type`,
12874
+ * `user_info` and `authenticator`. From v26 it is always present and is
12875
+ * `null` when no token was minted — because none was asked for, or because
12876
+ * the session cannot have one. Middleware refuses for a session authenticated
12877
+ * by a one-time *password* (`auth.generate_onetime_password`), which is not
12878
+ * the same thing as 2FA despite this codebase spelling 2FA "OTP" throughout.
12879
+ *
12880
+ * A 2FA account gets `null` for a different reason, and it is this client's
12881
+ * doing rather than the server's: the password request carrying the option is
12882
+ * answered `OTP_REQUIRED` before anything is minted, and `loginWithOtp` does
12883
+ * not send `login_options` on the second step. Middleware would honour it
12884
+ * there — `auth.login_ex_continue` re-enters `login_ex`, and a 2FA session
12885
+ * may hold a token — so this is a gap to close, not a limit to work around.
12886
+ */
12887
+ reconnect_token?: string | null;
12827
12888
  max_session_age?: number;
12828
12889
  max_inactivity?: number;
12829
12890
  urls?: string[];
@@ -12877,6 +12938,7 @@ interface AuthResponse {
12877
12938
  */
12878
12939
  declare class TrueNasAuthenticator {
12879
12940
  private connection;
12941
+ private readonly version?;
12880
12942
  static readonly DefaultSessionLifetime = 300;
12881
12943
  /**
12882
12944
  * whether or not the system is currently authenticated and accessible.
@@ -12896,9 +12958,54 @@ declare class TrueNasAuthenticator {
12896
12958
  key: string;
12897
12959
  };
12898
12960
  sessionLifetime: number;
12899
- constructor(connection: TrueNasConnection);
12961
+ constructor(connection: TrueNasConnection, version?: ApiVersion | undefined);
12962
+ /**
12963
+ * `login_options` asking for a reconnect token, when the server understands it.
12964
+ *
12965
+ * Omitted below v26. `AuthCommonOptions` is `additionalProperties: false`
12966
+ * there and has only `user_info`, so sending the member is a validation
12967
+ * error, not an ignored field — it would fail login outright on the oldest
12968
+ * version this client supports.
12969
+ */
12970
+ /**
12971
+ * Two things this does not do, both deliberate and both worth knowing.
12972
+ *
12973
+ * There is no way for a consumer to decline: every v26+ password login now
12974
+ * mints a single-use credential carrying that session's roles, whether or not
12975
+ * the caller wants one. And the auto-relogin in the constructor subscribes
12976
+ * with no observer, so the token it mints is dropped — a caller reconnecting
12977
+ * repeatedly holds an ageing token while the appliance mints fresh ones
12978
+ * nobody reads. Tokens are single-use with a 600s TTL, so that is the
12979
+ * reconnect case the feature is named for.
12980
+ */
12981
+ private reconnectTokenOption;
12900
12982
  loginWithUserPass(username: string, password: string): rxjs.Observable<AuthResponse>;
12901
12983
  loginWithOtp(code: string): rxjs.Observable<AuthResponse>;
12984
+ /**
12985
+ * Re-authenticate with a token from a previous login's `reconnect_token`.
12986
+ *
12987
+ * This is what lets a second connection to the same appliance authenticate
12988
+ * without asking the user for a password again — middleware sessions are
12989
+ * per-connection, so a second socket has its own to establish.
12990
+ *
12991
+ * The token is single-use and short-lived. On v26+ a successful login mints
12992
+ * another on the response, so a caller keeping a session alive across
12993
+ * reconnects stores the newest each time; below v26 nothing is minted and
12994
+ * there is no chain to keep.
12995
+ *
12996
+ * Re-login is the caller's to drive. A token session is not covered by the
12997
+ * automatic reconnect this class does for password and api-key sessions,
12998
+ * which is deliberate — the token is single-use — but it means a dropped
12999
+ * socket needs the stored token spending explicitly. Middleware holds tokens
13000
+ * in memory, so a `middlewared` restart voids them, and that is a common
13001
+ * reason the socket dropped in the first place.
13002
+ */
13003
+ loginWithToken(token: string): rxjs.Observable<AuthResponse>;
13004
+ /**
13005
+ * No reconnect token is requested here, though v26+ would mint one: an
13006
+ * api-key session already reconnects without a prompt, since the key is held
13007
+ * and replayed. The token exists for the credential that cannot be.
13008
+ */
12902
13009
  loginWithApiKey(credentials: {
12903
13010
  username: string;
12904
13011
  key: string;
@@ -12907,49 +13014,6 @@ declare class TrueNasAuthenticator {
12907
13014
  logout(): rxjs.Observable<boolean>;
12908
13015
  }
12909
13016
 
12910
- /**
12911
- * Response from the /api/versions endpoint
12912
- * Returns an array of version strings directly
12913
- * Example: ["v25.10.0", "v25.10.1", "v26.0.0"]
12914
- */
12915
- type ApiVersionResponse = string[];
12916
- /**
12917
- * Parsed API version information
12918
- *
12919
- * Version format:
12920
- * - Legacy (v25.x): vYY.MM.PATCH (e.g., v25.10.0 = October 2025, patch 0)
12921
- * - New (v26+): vYY.MINOR.PATCH (e.g., v26.0.0 = 2026, minor 0, patch 0)
12922
- *
12923
- * Note: The second segment has different semantics based on the year:
12924
- * - Year 25: month (1-12)
12925
- * - Year 26+: minor version (0-99)
12926
- */
12927
- interface ApiVersion {
12928
- /** Full version string (e.g., "v26.0.0") */
12929
- version: string;
12930
- /** Two-digit year (e.g., 26 = 2026) */
12931
- year: number;
12932
- /**
12933
- * Second version segment (semantics depend on year):
12934
- * - For v25.x: month (1-12, e.g., 10 = October)
12935
- * - For v26+: minor version (0-99)
12936
- */
12937
- minor: number;
12938
- /** Patch version number (e.g., 0, 1, 2) */
12939
- patch: number;
12940
- /** WebSocket path for this version (e.g., "/api/v26.0.0") */
12941
- websocketPath: string;
12942
- }
12943
- /**
12944
- * Version compatibility status
12945
- */
12946
- declare enum VersionCompatibility {
12947
- Compatible = "compatible",
12948
- TooOld = "too-old",
12949
- TooNew = "too-new",
12950
- Invalid = "invalid"
12951
- }
12952
-
12953
13017
  /**
12954
13018
  * The state `Container.status` is narrowed to.
12955
13019
  *
@@ -28043,6 +28107,7 @@ declare enum AuthErrorCode {
28043
28107
  PasswordAuthFailed = "PASSWORD_AUTH_FAILED",
28044
28108
  OtpAuthFailed = "OTP_AUTH_FAILED",
28045
28109
  ApiKeyAuthFailed = "API_KEY_AUTH_FAILED",
28110
+ TokenAuthFailed = "TOKEN_AUTH_FAILED",
28046
28111
  FullAdminRequired = "FULL_ADMIN_REQUIRED"
28047
28112
  }
28048
28113
  declare class AuthError extends Error {
package/dist/index.d.ts CHANGED
@@ -12798,6 +12798,49 @@ declare class TrueNasApi<D extends ApiDirectoryShape = BaseApiDirectory> {
12798
12798
  private initializeJobEventsSubscription;
12799
12799
  }
12800
12800
 
12801
+ /**
12802
+ * Response from the /api/versions endpoint
12803
+ * Returns an array of version strings directly
12804
+ * Example: ["v25.10.0", "v25.10.1", "v26.0.0"]
12805
+ */
12806
+ type ApiVersionResponse = string[];
12807
+ /**
12808
+ * Parsed API version information
12809
+ *
12810
+ * Version format:
12811
+ * - Legacy (v25.x): vYY.MM.PATCH (e.g., v25.10.0 = October 2025, patch 0)
12812
+ * - New (v26+): vYY.MINOR.PATCH (e.g., v26.0.0 = 2026, minor 0, patch 0)
12813
+ *
12814
+ * Note: The second segment has different semantics based on the year:
12815
+ * - Year 25: month (1-12)
12816
+ * - Year 26+: minor version (0-99)
12817
+ */
12818
+ interface ApiVersion {
12819
+ /** Full version string (e.g., "v26.0.0") */
12820
+ version: string;
12821
+ /** Two-digit year (e.g., 26 = 2026) */
12822
+ year: number;
12823
+ /**
12824
+ * Second version segment (semantics depend on year):
12825
+ * - For v25.x: month (1-12, e.g., 10 = October)
12826
+ * - For v26+: minor version (0-99)
12827
+ */
12828
+ minor: number;
12829
+ /** Patch version number (e.g., 0, 1, 2) */
12830
+ patch: number;
12831
+ /** WebSocket path for this version (e.g., "/api/v26.0.0") */
12832
+ websocketPath: string;
12833
+ }
12834
+ /**
12835
+ * Version compatibility status
12836
+ */
12837
+ declare enum VersionCompatibility {
12838
+ Compatible = "compatible",
12839
+ TooOld = "too-old",
12840
+ TooNew = "too-new",
12841
+ Invalid = "invalid"
12842
+ }
12843
+
12801
12844
  interface ApiKeyCreate {
12802
12845
  id: number;
12803
12846
  key: string;
@@ -12824,6 +12867,24 @@ interface AuthResponse {
12824
12867
  response_type: AuthResponseType;
12825
12868
  username?: string;
12826
12869
  authenticator?: 'LEVEL_1' | 'LEVEL_2' | 'LEVEL_3';
12870
+ /**
12871
+ * A token for re-authenticating without credentials.
12872
+ *
12873
+ * Absent below v26: `AuthRespSuccess` there declares only `response_type`,
12874
+ * `user_info` and `authenticator`. From v26 it is always present and is
12875
+ * `null` when no token was minted — because none was asked for, or because
12876
+ * the session cannot have one. Middleware refuses for a session authenticated
12877
+ * by a one-time *password* (`auth.generate_onetime_password`), which is not
12878
+ * the same thing as 2FA despite this codebase spelling 2FA "OTP" throughout.
12879
+ *
12880
+ * A 2FA account gets `null` for a different reason, and it is this client's
12881
+ * doing rather than the server's: the password request carrying the option is
12882
+ * answered `OTP_REQUIRED` before anything is minted, and `loginWithOtp` does
12883
+ * not send `login_options` on the second step. Middleware would honour it
12884
+ * there — `auth.login_ex_continue` re-enters `login_ex`, and a 2FA session
12885
+ * may hold a token — so this is a gap to close, not a limit to work around.
12886
+ */
12887
+ reconnect_token?: string | null;
12827
12888
  max_session_age?: number;
12828
12889
  max_inactivity?: number;
12829
12890
  urls?: string[];
@@ -12877,6 +12938,7 @@ interface AuthResponse {
12877
12938
  */
12878
12939
  declare class TrueNasAuthenticator {
12879
12940
  private connection;
12941
+ private readonly version?;
12880
12942
  static readonly DefaultSessionLifetime = 300;
12881
12943
  /**
12882
12944
  * whether or not the system is currently authenticated and accessible.
@@ -12896,9 +12958,54 @@ declare class TrueNasAuthenticator {
12896
12958
  key: string;
12897
12959
  };
12898
12960
  sessionLifetime: number;
12899
- constructor(connection: TrueNasConnection);
12961
+ constructor(connection: TrueNasConnection, version?: ApiVersion | undefined);
12962
+ /**
12963
+ * `login_options` asking for a reconnect token, when the server understands it.
12964
+ *
12965
+ * Omitted below v26. `AuthCommonOptions` is `additionalProperties: false`
12966
+ * there and has only `user_info`, so sending the member is a validation
12967
+ * error, not an ignored field — it would fail login outright on the oldest
12968
+ * version this client supports.
12969
+ */
12970
+ /**
12971
+ * Two things this does not do, both deliberate and both worth knowing.
12972
+ *
12973
+ * There is no way for a consumer to decline: every v26+ password login now
12974
+ * mints a single-use credential carrying that session's roles, whether or not
12975
+ * the caller wants one. And the auto-relogin in the constructor subscribes
12976
+ * with no observer, so the token it mints is dropped — a caller reconnecting
12977
+ * repeatedly holds an ageing token while the appliance mints fresh ones
12978
+ * nobody reads. Tokens are single-use with a 600s TTL, so that is the
12979
+ * reconnect case the feature is named for.
12980
+ */
12981
+ private reconnectTokenOption;
12900
12982
  loginWithUserPass(username: string, password: string): rxjs.Observable<AuthResponse>;
12901
12983
  loginWithOtp(code: string): rxjs.Observable<AuthResponse>;
12984
+ /**
12985
+ * Re-authenticate with a token from a previous login's `reconnect_token`.
12986
+ *
12987
+ * This is what lets a second connection to the same appliance authenticate
12988
+ * without asking the user for a password again — middleware sessions are
12989
+ * per-connection, so a second socket has its own to establish.
12990
+ *
12991
+ * The token is single-use and short-lived. On v26+ a successful login mints
12992
+ * another on the response, so a caller keeping a session alive across
12993
+ * reconnects stores the newest each time; below v26 nothing is minted and
12994
+ * there is no chain to keep.
12995
+ *
12996
+ * Re-login is the caller's to drive. A token session is not covered by the
12997
+ * automatic reconnect this class does for password and api-key sessions,
12998
+ * which is deliberate — the token is single-use — but it means a dropped
12999
+ * socket needs the stored token spending explicitly. Middleware holds tokens
13000
+ * in memory, so a `middlewared` restart voids them, and that is a common
13001
+ * reason the socket dropped in the first place.
13002
+ */
13003
+ loginWithToken(token: string): rxjs.Observable<AuthResponse>;
13004
+ /**
13005
+ * No reconnect token is requested here, though v26+ would mint one: an
13006
+ * api-key session already reconnects without a prompt, since the key is held
13007
+ * and replayed. The token exists for the credential that cannot be.
13008
+ */
12902
13009
  loginWithApiKey(credentials: {
12903
13010
  username: string;
12904
13011
  key: string;
@@ -12907,49 +13014,6 @@ declare class TrueNasAuthenticator {
12907
13014
  logout(): rxjs.Observable<boolean>;
12908
13015
  }
12909
13016
 
12910
- /**
12911
- * Response from the /api/versions endpoint
12912
- * Returns an array of version strings directly
12913
- * Example: ["v25.10.0", "v25.10.1", "v26.0.0"]
12914
- */
12915
- type ApiVersionResponse = string[];
12916
- /**
12917
- * Parsed API version information
12918
- *
12919
- * Version format:
12920
- * - Legacy (v25.x): vYY.MM.PATCH (e.g., v25.10.0 = October 2025, patch 0)
12921
- * - New (v26+): vYY.MINOR.PATCH (e.g., v26.0.0 = 2026, minor 0, patch 0)
12922
- *
12923
- * Note: The second segment has different semantics based on the year:
12924
- * - Year 25: month (1-12)
12925
- * - Year 26+: minor version (0-99)
12926
- */
12927
- interface ApiVersion {
12928
- /** Full version string (e.g., "v26.0.0") */
12929
- version: string;
12930
- /** Two-digit year (e.g., 26 = 2026) */
12931
- year: number;
12932
- /**
12933
- * Second version segment (semantics depend on year):
12934
- * - For v25.x: month (1-12, e.g., 10 = October)
12935
- * - For v26+: minor version (0-99)
12936
- */
12937
- minor: number;
12938
- /** Patch version number (e.g., 0, 1, 2) */
12939
- patch: number;
12940
- /** WebSocket path for this version (e.g., "/api/v26.0.0") */
12941
- websocketPath: string;
12942
- }
12943
- /**
12944
- * Version compatibility status
12945
- */
12946
- declare enum VersionCompatibility {
12947
- Compatible = "compatible",
12948
- TooOld = "too-old",
12949
- TooNew = "too-new",
12950
- Invalid = "invalid"
12951
- }
12952
-
12953
13017
  /**
12954
13018
  * The state `Container.status` is narrowed to.
12955
13019
  *
@@ -28043,6 +28107,7 @@ declare enum AuthErrorCode {
28043
28107
  PasswordAuthFailed = "PASSWORD_AUTH_FAILED",
28044
28108
  OtpAuthFailed = "OTP_AUTH_FAILED",
28045
28109
  ApiKeyAuthFailed = "API_KEY_AUTH_FAILED",
28110
+ TokenAuthFailed = "TOKEN_AUTH_FAILED",
28046
28111
  FullAdminRequired = "FULL_ADMIN_REQUIRED"
28047
28112
  }
28048
28113
  declare class AuthError extends Error {