algoliasearch-helper-flutter icon indicating copy to clipboard operation
algoliasearch-helper-flutter copied to clipboard

Add Interceptor to Client Options

Open SdxCoder opened this issue 7 months ago • 0 comments

Is your feature request related to a problem? Please describe 🙏
We are using secure api keys which needs to be injected as our jwt token refreshes, and to acheive that we have to use interceptor. Recently on HitSearcher api, client options have been been added but inteceptor is missing. Resolved Issue https://github.com/algolia/algoliasearch-helper-flutter/issues/129

Describe the solution you'd like 🤔
If client options can expose all these props that would be great

final class ClientOptions {
  /// The list of hosts that the client can connect to.
  final Iterable<Host>? hosts;

  /// The maximum duration to wait for a connection to establish before timing out.
  final Duration connectTimeout;

  /// The maximum duration to wait for a write operation to complete before timing out.
  final Duration writeTimeout;

  /// The maximum duration to wait for a read operation to complete before timing out.
  final Duration readTimeout;

  /// Default headers to include in each HTTP request.
  final Map<String, dynamic>? headers;

  /// List of agent segments for the Algolia service.
  final Iterable<AgentSegment>? agentSegments;

  /// Custom logger for http operations.
  final Function(Object?)? logger;

  /// Custom requester used to send HTTP requests.
  final Requester? requester;

  /// List of Dio interceptors.
  /// Used only in case of using the default (dio) requester.
  final Iterable<Interceptor>? interceptors;

  /// Constructs a [ClientOptions] instance with the provided parameters.
  const ClientOptions(
      {this.connectTimeout = const Duration(seconds: 2),
      this.writeTimeout = const Duration(seconds: 30),
      this.readTimeout = const Duration(seconds: 5),
      this.hosts,
      this.headers,
      this.agentSegments,
      this.requester,
      this.logger,
      this.interceptors});

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is ClientOptions &&
          runtimeType == other.runtimeType &&
          hosts == other.hosts &&
          connectTimeout == other.connectTimeout &&
          writeTimeout == other.writeTimeout &&
          readTimeout == other.readTimeout &&
          headers == other.headers &&
          agentSegments == other.agentSegments &&
          logger == other.logger &&
          requester == other.requester &&
          interceptors == other.interceptors;

  @override
  int get hashCode =>
      hosts.hashCode ^
      connectTimeout.hashCode ^
      writeTimeout.hashCode ^
      readTimeout.hashCode ^
      headers.hashCode ^
      agentSegments.hashCode ^
      logger.hashCode ^
      requester.hashCode ^
      interceptors.hashCode;

  @override
  String toString() {
    return 'ClientOptions{hosts: $hosts, connectTimeout: $connectTimeout, writeTimeout: $writeTimeout, readTimeout: $readTimeout, headers: $headers, agentSegments: $agentSegments, logger: $logger, requester: $requester, interceptors: $interceptors}';
  }
}

Describe alternatives you've considered ✨
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Here is the client options added to HitSearcher and it doesn't has inteceptors exposed https://pub.dev/documentation/algolia_helper_flutter/latest/algolia_helper_flutter/ClientOptions-class.html

SdxCoder avatar Jul 18 '24 13:07 SdxCoder