clientFromDiscovery function

Future<KumihoClient> clientFromDiscovery({
  1. String? token,
  2. String? tenantHint,
  3. String? controlPlaneUrl,
  4. bool forceRefresh = false,
})

Creates a gRPC KumihoClient using Control Plane discovery.

  • Uses discovery to find the correct data-plane endpoint.
  • Sets tenantId so the base client injects x-tenant-id.
  • If token is omitted, the client falls back to the standard token loader.

Implementation

Future<KumihoClient> clientFromDiscovery({
  String? token,
  String? tenantHint,
  String? controlPlaneUrl,
  bool forceRefresh = false,
}) async {
  final record = await discoverTenant(
    controlPlaneUrl: controlPlaneUrl,
    tenantHint: tenantHint,
    forceRefresh: forceRefresh,
  );

  final uri = record.serverUrl;
  final secure = uri.scheme.toLowerCase() == 'https';
  final port = uri.hasPort ? uri.port : (secure ? 443 : 80);

  return KumihoClient(
    host: uri.host,
    port: port,
    secure: secure,
    token: token,
    tenantId: record.tenantId,
  );
}