@truenas/api-client 6.0.0 → 6.0.1

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
@@ -13814,6 +13814,94 @@ declare const consoleLogger: Logger;
13814
13814
  /** Logger that discards everything. The default when no logger is provided. */
13815
13815
  declare const noopLogger: Logger;
13816
13816
 
13817
+ /**
13818
+ * API error types for versioned TrueNAS API
13819
+ *
13820
+ * Handles both JSON-RPC 2.0 standard errors and TrueNAS custom error formats.
13821
+ */
13822
+ /**
13823
+ * JSON-RPC 2.0 standard error format
13824
+ * @see https://www.jsonrpc.org/specification#error_object
13825
+ */
13826
+ interface JsonRpcError {
13827
+ /** Error code indicating the error type */
13828
+ code: number;
13829
+ /** Human-readable error message */
13830
+ message: string;
13831
+ /** Optional additional error data */
13832
+ data?: unknown;
13833
+ }
13834
+ /**
13835
+ * TrueNAS custom error format
13836
+ * Used in some API responses alongside JSON-RPC errors
13837
+ */
13838
+ interface TrueNasError {
13839
+ /** Additional error properties */
13840
+ [key: string]: unknown;
13841
+ /** Human-readable error reason (TrueNAS-specific field) */
13842
+ reason: string;
13843
+ }
13844
+ /**
13845
+ * The TrueNAS payload a versioned-API error carries in its `data`.
13846
+ *
13847
+ * `/api/<version>` answers a failed method call with a JSON-RPC error whose
13848
+ * `data` holds this — `rpc.py`'s `format_truenas_error`. The legacy
13849
+ * `/websocket` endpoint sends these fields at the top level instead, which is
13850
+ * a different handler on a route this client never opens.
13851
+ */
13852
+ interface TrueNasErrorData extends TrueNasError {
13853
+ /** The errno middleware raised; `EINVAL` for anything it could not adapt. */
13854
+ error: number;
13855
+ /** `get_errname(errno)`, derived from `error` rather than chosen separately. */
13856
+ errname: string;
13857
+ /** `str(e) or repr(e)` — the repr for an exception that stringifies to nothing. */
13858
+ reason: string;
13859
+ /**
13860
+ * `null` when the appliance has nothing to add.
13861
+ *
13862
+ * `rpc.py`'s generic arm sets `extra = None` for any exception it cannot
13863
+ * adapt — `MatchNotFound` from an empty `get`, for one — and only an adapted
13864
+ * error carries a list. A validation error carries the errors themselves.
13865
+ */
13866
+ extra: unknown[] | null;
13867
+ /** The formatted traceback, or `null`, which is what a client normally sees. */
13868
+ trace: {
13869
+ class: string;
13870
+ formatted: string;
13871
+ repr: string;
13872
+ } | null;
13873
+ }
13874
+ /**
13875
+ * The error a versioned-API frame carries.
13876
+ *
13877
+ * A JSON-RPC error object throughout: `code` and `message` are always present,
13878
+ * and `data` holds the TrueNAS payload for the codes that have one. The
13879
+ * dataless codes are real — `-32601 "Method does not exist"`,
13880
+ * `-32600 "Invalid request"`, `-32000 "too many concurrent calls"` — so `data`
13881
+ * is optional rather than merely defensive.
13882
+ */
13883
+ interface TrueNasErrorFrame extends JsonRpcError {
13884
+ data?: TrueNasErrorData;
13885
+ }
13886
+ /**
13887
+ * Union type for all possible API error formats
13888
+ */
13889
+ type ApiError = JsonRpcError | TrueNasError;
13890
+ /**
13891
+ * Extract a human-readable error message from an API error
13892
+ *
13893
+ * Handles multiple error formats:
13894
+ * - JSON-RPC 2.0 with nested TrueNAS data: uses `data.reason` field
13895
+ * - JSON-RPC 2.0 standard: uses `message` field
13896
+ * - TrueNAS custom: uses `reason` field
13897
+ * - Unknown format: returns fallback message
13898
+ *
13899
+ * @param error - The error object from API response
13900
+ * @param fallback - Fallback message if error format is unrecognized
13901
+ * @returns Human-readable error message
13902
+ */
13903
+ declare function getApiErrorMessage(error: unknown, fallback?: string): string;
13904
+
13817
13905
  interface TrueNasMessage {
13818
13906
  id?: string;
13819
13907
  /** JSON-RPC 2.0 protocol version, e.g. '2.0' (present on versioned-API messages). */
@@ -13828,12 +13916,18 @@ interface TrueNasMessage {
13828
13916
  collection?: string;
13829
13917
  fields?: unknown;
13830
13918
  subs?: string[];
13831
- error?: {
13832
- error: number;
13833
- errname: string;
13834
- extra: (string | number)[];
13835
- reason: string;
13836
- };
13919
+ /**
13920
+ * The JSON-RPC error object, with the TrueNAS payload under `data`.
13921
+ *
13922
+ * This used to declare `data`'s fields at the top level, which is the shape
13923
+ * the legacy `/websocket` endpoint sends. The versioned endpoint this client
13924
+ * connects to wraps them — `main.py` routes every `/api/{version}` to
13925
+ * `RpcWebSocketHandler`, and `rpc.py`'s `send_error` puts `code` and
13926
+ * `message` outside and the payload in `data`. Nothing here noticed, because
13927
+ * `getApiErrorMessage` reads a `reason` at either depth and answers with the
13928
+ * same string; a consumer branching on `code` or `data.errname` would have.
13929
+ */
13930
+ error?: TrueNasErrorFrame;
13837
13931
  }
13838
13932
 
13839
13933
  declare class TrueNasSocket {
@@ -31594,50 +31688,4 @@ declare enum TrueNasAuthMechanism {
31594
31688
  Token = "TOKEN_PLAIN"
31595
31689
  }
31596
31690
 
31597
- /**
31598
- * API error types for versioned TrueNAS API
31599
- *
31600
- * Handles both JSON-RPC 2.0 standard errors and TrueNAS custom error formats.
31601
- */
31602
- /**
31603
- * JSON-RPC 2.0 standard error format
31604
- * @see https://www.jsonrpc.org/specification#error_object
31605
- */
31606
- interface JsonRpcError {
31607
- /** Error code indicating the error type */
31608
- code: number;
31609
- /** Human-readable error message */
31610
- message: string;
31611
- /** Optional additional error data */
31612
- data?: unknown;
31613
- }
31614
- /**
31615
- * TrueNAS custom error format
31616
- * Used in some API responses alongside JSON-RPC errors
31617
- */
31618
- interface TrueNasError {
31619
- /** Additional error properties */
31620
- [key: string]: unknown;
31621
- /** Human-readable error reason (TrueNAS-specific field) */
31622
- reason: string;
31623
- }
31624
- /**
31625
- * Union type for all possible API error formats
31626
- */
31627
- type ApiError = JsonRpcError | TrueNasError;
31628
- /**
31629
- * Extract a human-readable error message from an API error
31630
- *
31631
- * Handles multiple error formats:
31632
- * - JSON-RPC 2.0 with nested TrueNAS data: uses `data.reason` field
31633
- * - JSON-RPC 2.0 standard: uses `message` field
31634
- * - TrueNAS custom: uses `reason` field
31635
- * - Unknown format: returns fallback message
31636
- *
31637
- * @param error - The error object from API response
31638
- * @param fallback - Fallback message if error format is unrecognized
31639
- * @returns Human-readable error message
31640
- */
31641
- declare function getApiErrorMessage(error: unknown, fallback?: string): string;
31642
-
31643
31691
  export { type ApiCallDirectory$7 as ApiCallDirectoryV25_10_0, type ApiCallDirectory$6 as ApiCallDirectoryV25_10_1, type ApiCallDirectory$5 as ApiCallDirectoryV25_10_2, type ApiCallDirectory$4 as ApiCallDirectoryV25_10_3, type ApiCallDirectory$3 as ApiCallDirectoryV25_10_4, type ApiCallDirectory$2 as ApiCallDirectoryV25_10_5, type ApiCallDirectory$1 as ApiCallDirectoryV26_0_0, type ApiCallDirectory as ApiCallDirectoryV27_0_0, type ApiDirectoryByVersion, type ApiDirectoryShape, type ApiDirectory$7 as ApiDirectoryV25_10_0, type ApiDirectory$6 as ApiDirectoryV25_10_1, type ApiDirectory$5 as ApiDirectoryV25_10_2, type ApiDirectory$4 as ApiDirectoryV25_10_3, type ApiDirectory$3 as ApiDirectoryV25_10_4, type ApiDirectory$2 as ApiDirectoryV25_10_5, type ApiDirectory$1 as ApiDirectoryV26_0_0, type ApiDirectory as ApiDirectoryV27_0_0, type ApiError, type ApiEventDirectory$7 as ApiEventDirectoryV25_10_0, type ApiEventDirectory$6 as ApiEventDirectoryV25_10_1, type ApiEventDirectory$5 as ApiEventDirectoryV25_10_2, type ApiEventDirectory$4 as ApiEventDirectoryV25_10_3, type ApiEventDirectory$3 as ApiEventDirectoryV25_10_4, type ApiEventDirectory$2 as ApiEventDirectoryV25_10_5, type ApiEventDirectory$1 as ApiEventDirectoryV26_0_0, type ApiEventDirectory as ApiEventDirectoryV27_0_0, type ApiJobDirectory$7 as ApiJobDirectoryV25_10_0, type ApiJobDirectory$6 as ApiJobDirectoryV25_10_1, type ApiJobDirectory$5 as ApiJobDirectoryV25_10_2, type ApiJobDirectory$4 as ApiJobDirectoryV25_10_3, type ApiJobDirectory$3 as ApiJobDirectoryV25_10_4, type ApiJobDirectory$2 as ApiJobDirectoryV25_10_5, type ApiJobDirectory$1 as ApiJobDirectoryV26_0_0, type ApiJobDirectory as ApiJobDirectoryV27_0_0, type ApiKeyCreate, type ApiVersion, type ApiVersionResponse, AppState, type ApplianceProtocol, type ArgsOf, AuthError, AuthErrorCode, type AuthResponse, type BaseApiDirectory, type CallMethod, type CallParams, type CallResponse, type Container, type CreateClientOptions, type DefaultApiDirectory, type EventKind, type EventName, type EventUnion, InvalidVersionResponseError, type Job, type JobMethod, type JobParams, type JobProgress, type JobResult, JobState, type Logger, NoCompatibleVersionsError, type OperationMappings, type QueryDirectory, type QueryEntity, type QueryListOptions, type QueryMethod, type QuerySingleOptions, SUPPORTED_API_VERSIONS, type SmbStatusInfoLevel, type SmbStatusOptions, type SmbStatusRequest, type SmbStatusResponse, type SmbStatusRow, type SupportedApiVersion, TrueNasApiClient, TrueNasApiClientV2510, TrueNasApiClientV26, TrueNasApiClientV27, TrueNasAuthMechanism, type TrueNasDate, UserRole, type UserRoleName, VersionCompatibility, VersionDiscovery, VersionDiscoveryError, VersionDiscoveryNetworkError, VersionDiscoveryTimeoutError, VersionEndpointNotFoundError, VersionTooNewError, VersionTooOldError, consoleLogger, createTrueNasClient, getApiErrorMessage, isJobFinished, noopLogger, index$7 as v25_10_0, index$6 as v25_10_1, index$5 as v25_10_2, index$4 as v25_10_3, index$3 as v25_10_4, index$2 as v25_10_5, index$1 as v26_0_0, index as v27_0_0 };
package/dist/index.d.ts CHANGED
@@ -13814,6 +13814,94 @@ declare const consoleLogger: Logger;
13814
13814
  /** Logger that discards everything. The default when no logger is provided. */
13815
13815
  declare const noopLogger: Logger;
13816
13816
 
13817
+ /**
13818
+ * API error types for versioned TrueNAS API
13819
+ *
13820
+ * Handles both JSON-RPC 2.0 standard errors and TrueNAS custom error formats.
13821
+ */
13822
+ /**
13823
+ * JSON-RPC 2.0 standard error format
13824
+ * @see https://www.jsonrpc.org/specification#error_object
13825
+ */
13826
+ interface JsonRpcError {
13827
+ /** Error code indicating the error type */
13828
+ code: number;
13829
+ /** Human-readable error message */
13830
+ message: string;
13831
+ /** Optional additional error data */
13832
+ data?: unknown;
13833
+ }
13834
+ /**
13835
+ * TrueNAS custom error format
13836
+ * Used in some API responses alongside JSON-RPC errors
13837
+ */
13838
+ interface TrueNasError {
13839
+ /** Additional error properties */
13840
+ [key: string]: unknown;
13841
+ /** Human-readable error reason (TrueNAS-specific field) */
13842
+ reason: string;
13843
+ }
13844
+ /**
13845
+ * The TrueNAS payload a versioned-API error carries in its `data`.
13846
+ *
13847
+ * `/api/<version>` answers a failed method call with a JSON-RPC error whose
13848
+ * `data` holds this — `rpc.py`'s `format_truenas_error`. The legacy
13849
+ * `/websocket` endpoint sends these fields at the top level instead, which is
13850
+ * a different handler on a route this client never opens.
13851
+ */
13852
+ interface TrueNasErrorData extends TrueNasError {
13853
+ /** The errno middleware raised; `EINVAL` for anything it could not adapt. */
13854
+ error: number;
13855
+ /** `get_errname(errno)`, derived from `error` rather than chosen separately. */
13856
+ errname: string;
13857
+ /** `str(e) or repr(e)` — the repr for an exception that stringifies to nothing. */
13858
+ reason: string;
13859
+ /**
13860
+ * `null` when the appliance has nothing to add.
13861
+ *
13862
+ * `rpc.py`'s generic arm sets `extra = None` for any exception it cannot
13863
+ * adapt — `MatchNotFound` from an empty `get`, for one — and only an adapted
13864
+ * error carries a list. A validation error carries the errors themselves.
13865
+ */
13866
+ extra: unknown[] | null;
13867
+ /** The formatted traceback, or `null`, which is what a client normally sees. */
13868
+ trace: {
13869
+ class: string;
13870
+ formatted: string;
13871
+ repr: string;
13872
+ } | null;
13873
+ }
13874
+ /**
13875
+ * The error a versioned-API frame carries.
13876
+ *
13877
+ * A JSON-RPC error object throughout: `code` and `message` are always present,
13878
+ * and `data` holds the TrueNAS payload for the codes that have one. The
13879
+ * dataless codes are real — `-32601 "Method does not exist"`,
13880
+ * `-32600 "Invalid request"`, `-32000 "too many concurrent calls"` — so `data`
13881
+ * is optional rather than merely defensive.
13882
+ */
13883
+ interface TrueNasErrorFrame extends JsonRpcError {
13884
+ data?: TrueNasErrorData;
13885
+ }
13886
+ /**
13887
+ * Union type for all possible API error formats
13888
+ */
13889
+ type ApiError = JsonRpcError | TrueNasError;
13890
+ /**
13891
+ * Extract a human-readable error message from an API error
13892
+ *
13893
+ * Handles multiple error formats:
13894
+ * - JSON-RPC 2.0 with nested TrueNAS data: uses `data.reason` field
13895
+ * - JSON-RPC 2.0 standard: uses `message` field
13896
+ * - TrueNAS custom: uses `reason` field
13897
+ * - Unknown format: returns fallback message
13898
+ *
13899
+ * @param error - The error object from API response
13900
+ * @param fallback - Fallback message if error format is unrecognized
13901
+ * @returns Human-readable error message
13902
+ */
13903
+ declare function getApiErrorMessage(error: unknown, fallback?: string): string;
13904
+
13817
13905
  interface TrueNasMessage {
13818
13906
  id?: string;
13819
13907
  /** JSON-RPC 2.0 protocol version, e.g. '2.0' (present on versioned-API messages). */
@@ -13828,12 +13916,18 @@ interface TrueNasMessage {
13828
13916
  collection?: string;
13829
13917
  fields?: unknown;
13830
13918
  subs?: string[];
13831
- error?: {
13832
- error: number;
13833
- errname: string;
13834
- extra: (string | number)[];
13835
- reason: string;
13836
- };
13919
+ /**
13920
+ * The JSON-RPC error object, with the TrueNAS payload under `data`.
13921
+ *
13922
+ * This used to declare `data`'s fields at the top level, which is the shape
13923
+ * the legacy `/websocket` endpoint sends. The versioned endpoint this client
13924
+ * connects to wraps them — `main.py` routes every `/api/{version}` to
13925
+ * `RpcWebSocketHandler`, and `rpc.py`'s `send_error` puts `code` and
13926
+ * `message` outside and the payload in `data`. Nothing here noticed, because
13927
+ * `getApiErrorMessage` reads a `reason` at either depth and answers with the
13928
+ * same string; a consumer branching on `code` or `data.errname` would have.
13929
+ */
13930
+ error?: TrueNasErrorFrame;
13837
13931
  }
13838
13932
 
13839
13933
  declare class TrueNasSocket {
@@ -31594,50 +31688,4 @@ declare enum TrueNasAuthMechanism {
31594
31688
  Token = "TOKEN_PLAIN"
31595
31689
  }
31596
31690
 
31597
- /**
31598
- * API error types for versioned TrueNAS API
31599
- *
31600
- * Handles both JSON-RPC 2.0 standard errors and TrueNAS custom error formats.
31601
- */
31602
- /**
31603
- * JSON-RPC 2.0 standard error format
31604
- * @see https://www.jsonrpc.org/specification#error_object
31605
- */
31606
- interface JsonRpcError {
31607
- /** Error code indicating the error type */
31608
- code: number;
31609
- /** Human-readable error message */
31610
- message: string;
31611
- /** Optional additional error data */
31612
- data?: unknown;
31613
- }
31614
- /**
31615
- * TrueNAS custom error format
31616
- * Used in some API responses alongside JSON-RPC errors
31617
- */
31618
- interface TrueNasError {
31619
- /** Additional error properties */
31620
- [key: string]: unknown;
31621
- /** Human-readable error reason (TrueNAS-specific field) */
31622
- reason: string;
31623
- }
31624
- /**
31625
- * Union type for all possible API error formats
31626
- */
31627
- type ApiError = JsonRpcError | TrueNasError;
31628
- /**
31629
- * Extract a human-readable error message from an API error
31630
- *
31631
- * Handles multiple error formats:
31632
- * - JSON-RPC 2.0 with nested TrueNAS data: uses `data.reason` field
31633
- * - JSON-RPC 2.0 standard: uses `message` field
31634
- * - TrueNAS custom: uses `reason` field
31635
- * - Unknown format: returns fallback message
31636
- *
31637
- * @param error - The error object from API response
31638
- * @param fallback - Fallback message if error format is unrecognized
31639
- * @returns Human-readable error message
31640
- */
31641
- declare function getApiErrorMessage(error: unknown, fallback?: string): string;
31642
-
31643
31691
  export { type ApiCallDirectory$7 as ApiCallDirectoryV25_10_0, type ApiCallDirectory$6 as ApiCallDirectoryV25_10_1, type ApiCallDirectory$5 as ApiCallDirectoryV25_10_2, type ApiCallDirectory$4 as ApiCallDirectoryV25_10_3, type ApiCallDirectory$3 as ApiCallDirectoryV25_10_4, type ApiCallDirectory$2 as ApiCallDirectoryV25_10_5, type ApiCallDirectory$1 as ApiCallDirectoryV26_0_0, type ApiCallDirectory as ApiCallDirectoryV27_0_0, type ApiDirectoryByVersion, type ApiDirectoryShape, type ApiDirectory$7 as ApiDirectoryV25_10_0, type ApiDirectory$6 as ApiDirectoryV25_10_1, type ApiDirectory$5 as ApiDirectoryV25_10_2, type ApiDirectory$4 as ApiDirectoryV25_10_3, type ApiDirectory$3 as ApiDirectoryV25_10_4, type ApiDirectory$2 as ApiDirectoryV25_10_5, type ApiDirectory$1 as ApiDirectoryV26_0_0, type ApiDirectory as ApiDirectoryV27_0_0, type ApiError, type ApiEventDirectory$7 as ApiEventDirectoryV25_10_0, type ApiEventDirectory$6 as ApiEventDirectoryV25_10_1, type ApiEventDirectory$5 as ApiEventDirectoryV25_10_2, type ApiEventDirectory$4 as ApiEventDirectoryV25_10_3, type ApiEventDirectory$3 as ApiEventDirectoryV25_10_4, type ApiEventDirectory$2 as ApiEventDirectoryV25_10_5, type ApiEventDirectory$1 as ApiEventDirectoryV26_0_0, type ApiEventDirectory as ApiEventDirectoryV27_0_0, type ApiJobDirectory$7 as ApiJobDirectoryV25_10_0, type ApiJobDirectory$6 as ApiJobDirectoryV25_10_1, type ApiJobDirectory$5 as ApiJobDirectoryV25_10_2, type ApiJobDirectory$4 as ApiJobDirectoryV25_10_3, type ApiJobDirectory$3 as ApiJobDirectoryV25_10_4, type ApiJobDirectory$2 as ApiJobDirectoryV25_10_5, type ApiJobDirectory$1 as ApiJobDirectoryV26_0_0, type ApiJobDirectory as ApiJobDirectoryV27_0_0, type ApiKeyCreate, type ApiVersion, type ApiVersionResponse, AppState, type ApplianceProtocol, type ArgsOf, AuthError, AuthErrorCode, type AuthResponse, type BaseApiDirectory, type CallMethod, type CallParams, type CallResponse, type Container, type CreateClientOptions, type DefaultApiDirectory, type EventKind, type EventName, type EventUnion, InvalidVersionResponseError, type Job, type JobMethod, type JobParams, type JobProgress, type JobResult, JobState, type Logger, NoCompatibleVersionsError, type OperationMappings, type QueryDirectory, type QueryEntity, type QueryListOptions, type QueryMethod, type QuerySingleOptions, SUPPORTED_API_VERSIONS, type SmbStatusInfoLevel, type SmbStatusOptions, type SmbStatusRequest, type SmbStatusResponse, type SmbStatusRow, type SupportedApiVersion, TrueNasApiClient, TrueNasApiClientV2510, TrueNasApiClientV26, TrueNasApiClientV27, TrueNasAuthMechanism, type TrueNasDate, UserRole, type UserRoleName, VersionCompatibility, VersionDiscovery, VersionDiscoveryError, VersionDiscoveryNetworkError, VersionDiscoveryTimeoutError, VersionEndpointNotFoundError, VersionTooNewError, VersionTooOldError, consoleLogger, createTrueNasClient, getApiErrorMessage, isJobFinished, noopLogger, index$7 as v25_10_0, index$6 as v25_10_1, index$5 as v25_10_2, index$4 as v25_10_3, index$3 as v25_10_4, index$2 as v25_10_5, index$1 as v26_0_0, index as v27_0_0 };