@truenas/api-client 9.0.1 → 9.0.3
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 +22 -4
- package/dist/{chunk-U6V2Y3AE.cjs → chunk-DJCZ545I.cjs} +29 -11
- package/dist/chunk-DJCZ545I.cjs.map +1 -0
- package/dist/{chunk-K7BL6J3Z.js → chunk-K5ICTA2D.js} +29 -11
- package/dist/chunk-K5ICTA2D.js.map +1 -0
- package/dist/index.cjs +37 -37
- package/dist/index.d.cts +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.js +1 -1
- package/dist/testing/index.cjs +15 -15
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +2 -2
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +4 -4
- package/dist/testing/index.js.map +1 -1
- package/dist/{truenas-auth-mechanism.enum-Bp2XMMwK.d.cts → truenas-auth-mechanism.enum-krCGFs13.d.cts} +31 -2
- package/dist/{truenas-auth-mechanism.enum-Bp2XMMwK.d.ts → truenas-auth-mechanism.enum-krCGFs13.d.ts} +31 -2
- package/package.json +1 -1
- package/dist/chunk-K7BL6J3Z.js.map +0 -1
- package/dist/chunk-U6V2Y3AE.cjs.map +0 -1
|
@@ -2191,9 +2191,16 @@ var AuthErrorCode = /* @__PURE__ */ ((AuthErrorCode2) => {
|
|
|
2191
2191
|
return AuthErrorCode2;
|
|
2192
2192
|
})(AuthErrorCode || {});
|
|
2193
2193
|
var AuthError = class _AuthError extends Error {
|
|
2194
|
-
|
|
2194
|
+
/**
|
|
2195
|
+
* @param response - the answer middleware refused the login with, when there was one.
|
|
2196
|
+
* Its `response_type` is what tells `EXPIRED`, `DENIED` and `REDIRECT` apart from
|
|
2197
|
+
* `AUTH_ERR`; the code alone says only which mechanism failed. Absent when the login
|
|
2198
|
+
* never got an answer of that kind (an error frame, or a superseded login).
|
|
2199
|
+
*/
|
|
2200
|
+
constructor(code, message, response) {
|
|
2195
2201
|
super(message);
|
|
2196
2202
|
this.code = code;
|
|
2203
|
+
this.response = response;
|
|
2197
2204
|
this.name = "AuthError";
|
|
2198
2205
|
Object.setPrototypeOf(this, _AuthError.prototype);
|
|
2199
2206
|
}
|
|
@@ -2731,7 +2738,7 @@ function getWebSocketPath(version) {
|
|
|
2731
2738
|
// src/auth/truenas-authenticator.ts
|
|
2732
2739
|
var throwOnAuthenticationFailure = (code, message) => switchMap((response) => {
|
|
2733
2740
|
if (response.response_type === "AUTH_ERR" /* AuthErr */) {
|
|
2734
|
-
return throwError(() => new AuthError(code, message));
|
|
2741
|
+
return throwError(() => new AuthError(code, message, response));
|
|
2735
2742
|
}
|
|
2736
2743
|
return of(response);
|
|
2737
2744
|
});
|
|
@@ -2868,7 +2875,8 @@ var TrueNasAuthenticator = class _TrueNasAuthenticator {
|
|
|
2868
2875
|
}
|
|
2869
2876
|
this.authenticating$.next(false);
|
|
2870
2877
|
}
|
|
2871
|
-
loginWithUserPass(username, password) {
|
|
2878
|
+
loginWithUserPass(username, password, options = {}) {
|
|
2879
|
+
const { rememberPassword = true } = options;
|
|
2872
2880
|
const { sentDuring, callerInitiated } = this.beginLogin();
|
|
2873
2881
|
let answered = false;
|
|
2874
2882
|
const message = createJsonRpcMessage("auth.login_ex", [
|
|
@@ -2904,9 +2912,11 @@ var TrueNasAuthenticator = class _TrueNasAuthenticator {
|
|
|
2904
2912
|
tap((res) => {
|
|
2905
2913
|
if (res.response_type === "SUCCESS" /* Success */) {
|
|
2906
2914
|
this.assertNotSuperseded(sentDuring);
|
|
2907
|
-
this.credentials = { username, password, key: "" };
|
|
2915
|
+
this.credentials = rememberPassword ? { username, password, key: "" } : { username: "", password: "", key: "" };
|
|
2908
2916
|
this.sessionLifetime = res.user_info?.attributes?.preferences?.lifetime ?? _TrueNasAuthenticator.DefaultSessionLifetime;
|
|
2909
2917
|
this.authenticated$.next(true);
|
|
2918
|
+
} else if (res.response_type === "OTP_REQUIRED" /* OtpRequired */ && !rememberPassword && this.authEpoch === sentDuring) {
|
|
2919
|
+
this.credentials = { username: "", password: "", key: "" };
|
|
2910
2920
|
}
|
|
2911
2921
|
}),
|
|
2912
2922
|
finalize(() => {
|
|
@@ -3004,7 +3014,8 @@ var TrueNasAuthenticator = class _TrueNasAuthenticator {
|
|
|
3004
3014
|
if (res.response_type !== "SUCCESS" /* Success */) {
|
|
3005
3015
|
throw new AuthError(
|
|
3006
3016
|
"TOKEN_AUTH_FAILED" /* TokenAuthFailed */,
|
|
3007
|
-
`TrueNAS token authentication failed (${res.response_type}). The token may have expired or been used, or the account may no longer be permitted to log in
|
|
3017
|
+
`TrueNAS token authentication failed (${res.response_type}). The token may have expired or been used, or the account may no longer be permitted to log in.`,
|
|
3018
|
+
res
|
|
3008
3019
|
);
|
|
3009
3020
|
}
|
|
3010
3021
|
return res;
|
|
@@ -4295,6 +4306,11 @@ async function createTrueNasClient(opts) {
|
|
|
4295
4306
|
`Cannot create client for system ${uuid}: hostnames array is empty`
|
|
4296
4307
|
);
|
|
4297
4308
|
}
|
|
4309
|
+
if (opts.websocketPath !== void 0 && !opts.websocketPath.startsWith("/")) {
|
|
4310
|
+
throw new Error(
|
|
4311
|
+
`Cannot create client for system ${uuid}: websocketPath must be an absolute path, got '${opts.websocketPath}'.`
|
|
4312
|
+
);
|
|
4313
|
+
}
|
|
4298
4314
|
logger.info("Creating versioned API client", {
|
|
4299
4315
|
uuid: uuid.slice(0, 8),
|
|
4300
4316
|
hostnames: hostnames.join(", "),
|
|
@@ -4324,7 +4340,7 @@ async function createTrueNasClient(opts) {
|
|
|
4324
4340
|
logger.info("API version supplied by the caller, skipping discovery", {
|
|
4325
4341
|
uuid: uuid.slice(0, 8),
|
|
4326
4342
|
version: known.version,
|
|
4327
|
-
websocketPath: known.websocketPath
|
|
4343
|
+
websocketPath: opts.websocketPath ?? known.websocketPath
|
|
4328
4344
|
});
|
|
4329
4345
|
return instantiateClientForVersion(known, opts, logger);
|
|
4330
4346
|
}
|
|
@@ -4343,7 +4359,7 @@ async function createTrueNasClient(opts) {
|
|
|
4343
4359
|
// of them anyway.
|
|
4344
4360
|
hostname: winner.hostname,
|
|
4345
4361
|
version: version.version,
|
|
4346
|
-
websocketPath: version.websocketPath
|
|
4362
|
+
websocketPath: opts.websocketPath ?? version.websocketPath
|
|
4347
4363
|
});
|
|
4348
4364
|
} catch (error) {
|
|
4349
4365
|
const errorMessage = errorMessageOrDefault(error, "Unknown error");
|
|
@@ -4469,6 +4485,7 @@ function clientClassFor(version) {
|
|
|
4469
4485
|
function instantiateClientForVersion(version, opts, logger) {
|
|
4470
4486
|
const { uuid, hostnames, enabled, systemName } = opts;
|
|
4471
4487
|
const versionKey = clientVersionKey(version);
|
|
4488
|
+
const endpoint = opts.websocketPath === void 0 ? version : { ...version, websocketPath: opts.websocketPath };
|
|
4472
4489
|
const Client = CLIENT_BY_VERSION_KEY[versionKey];
|
|
4473
4490
|
if (!Client) {
|
|
4474
4491
|
logger.error("No client implementation for version", {
|
|
@@ -4483,12 +4500,13 @@ function instantiateClientForVersion(version, opts, logger) {
|
|
|
4483
4500
|
logger.info(`Instantiating ${Client.name}`, {
|
|
4484
4501
|
uuid: uuid.slice(0, 8),
|
|
4485
4502
|
version: version.version,
|
|
4486
|
-
versionKey
|
|
4503
|
+
versionKey,
|
|
4504
|
+
websocketPath: endpoint.websocketPath
|
|
4487
4505
|
});
|
|
4488
4506
|
return new Client(
|
|
4489
4507
|
uuid,
|
|
4490
4508
|
hostnames,
|
|
4491
|
-
|
|
4509
|
+
endpoint,
|
|
4492
4510
|
enabled,
|
|
4493
4511
|
systemName,
|
|
4494
4512
|
logger,
|
|
@@ -4513,5 +4531,5 @@ var UserRole = /* @__PURE__ */ ((UserRole2) => {
|
|
|
4513
4531
|
})(UserRole || {});
|
|
4514
4532
|
|
|
4515
4533
|
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 };
|
|
4516
|
-
//# sourceMappingURL=chunk-
|
|
4517
|
-
//# sourceMappingURL=chunk-
|
|
4534
|
+
//# sourceMappingURL=chunk-K5ICTA2D.js.map
|
|
4535
|
+
//# sourceMappingURL=chunk-K5ICTA2D.js.map
|