@truenas/api-client 9.0.2 → 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 CHANGED
@@ -171,6 +171,21 @@ client you get. A named `version` skips discovery and also selects the
171
171
  WebSocket endpoint, so name the version the appliance actually runs. The types
172
172
  follow it when the version is a literal.
173
173
 
174
+ To be written against one version but run against whatever the appliance
175
+ serves, as an appliance's own UI is, keep the `version` and move the socket:
176
+
177
+ ```typescript
178
+ const client = await createTrueNasClient({
179
+ ...options,
180
+ version: 'v28.0.0', // the surface you compile against
181
+ websocketPath: '/api/current', // the appliance's newest version, whichever it is
182
+ });
183
+ ```
184
+
185
+ The client then works against an older or newer release call for call; a
186
+ method or field that release lacks fails when it is called rather than at
187
+ compile time.
188
+
174
189
  For code that must run against any supported release, use `client.ops`. It
175
190
  offers the same calls on every version and maps them onto whatever that version
176
191
  provides:
@@ -4308,6 +4308,11 @@ async function createTrueNasClient(opts) {
4308
4308
  `Cannot create client for system ${uuid}: hostnames array is empty`
4309
4309
  );
4310
4310
  }
4311
+ if (opts.websocketPath !== void 0 && !opts.websocketPath.startsWith("/")) {
4312
+ throw new Error(
4313
+ `Cannot create client for system ${uuid}: websocketPath must be an absolute path, got '${opts.websocketPath}'.`
4314
+ );
4315
+ }
4311
4316
  logger.info("Creating versioned API client", {
4312
4317
  uuid: uuid.slice(0, 8),
4313
4318
  hostnames: hostnames.join(", "),
@@ -4337,7 +4342,7 @@ async function createTrueNasClient(opts) {
4337
4342
  logger.info("API version supplied by the caller, skipping discovery", {
4338
4343
  uuid: uuid.slice(0, 8),
4339
4344
  version: known.version,
4340
- websocketPath: known.websocketPath
4345
+ websocketPath: opts.websocketPath ?? known.websocketPath
4341
4346
  });
4342
4347
  return instantiateClientForVersion(known, opts, logger);
4343
4348
  }
@@ -4356,7 +4361,7 @@ async function createTrueNasClient(opts) {
4356
4361
  // of them anyway.
4357
4362
  hostname: winner.hostname,
4358
4363
  version: version.version,
4359
- websocketPath: version.websocketPath
4364
+ websocketPath: opts.websocketPath ?? version.websocketPath
4360
4365
  });
4361
4366
  } catch (error) {
4362
4367
  const errorMessage = errorMessageOrDefault(error, "Unknown error");
@@ -4482,6 +4487,7 @@ function clientClassFor(version) {
4482
4487
  function instantiateClientForVersion(version, opts, logger) {
4483
4488
  const { uuid, hostnames, enabled, systemName } = opts;
4484
4489
  const versionKey = clientVersionKey(version);
4490
+ const endpoint = opts.websocketPath === void 0 ? version : { ...version, websocketPath: opts.websocketPath };
4485
4491
  const Client = CLIENT_BY_VERSION_KEY[versionKey];
4486
4492
  if (!Client) {
4487
4493
  logger.error("No client implementation for version", {
@@ -4496,12 +4502,13 @@ function instantiateClientForVersion(version, opts, logger) {
4496
4502
  logger.info(`Instantiating ${Client.name}`, {
4497
4503
  uuid: uuid.slice(0, 8),
4498
4504
  version: version.version,
4499
- versionKey
4505
+ versionKey,
4506
+ websocketPath: endpoint.websocketPath
4500
4507
  });
4501
4508
  return new Client(
4502
4509
  uuid,
4503
4510
  hostnames,
4504
- version,
4511
+ endpoint,
4505
4512
  enabled,
4506
4513
  systemName,
4507
4514
  logger,
@@ -4568,5 +4575,5 @@ exports.v25_10_4_exports = v25_10_4_exports;
4568
4575
  exports.v25_10_5_exports = v25_10_5_exports;
4569
4576
  exports.v27_0_0_exports = v27_0_0_exports;
4570
4577
  exports.v28_0_0_exports = v28_0_0_exports;
4571
- //# sourceMappingURL=chunk-MJFFBJJE.cjs.map
4572
- //# sourceMappingURL=chunk-MJFFBJJE.cjs.map
4578
+ //# sourceMappingURL=chunk-DJCZ545I.cjs.map
4579
+ //# sourceMappingURL=chunk-DJCZ545I.cjs.map