|
| 1 | +using System.Text.Json; |
| 2 | +using PostHog; |
| 3 | +using PostHog.Api; |
| 4 | +using PostHog.Features; |
| 5 | +using PostHog.Json; |
| 6 | + |
| 7 | +namespace PostHog.Sdk; |
| 8 | + |
| 9 | +internal sealed class NoOpPostHogClient : IPostHogClient, IFeatureFlagEvaluationsHost |
| 10 | +{ |
| 11 | + static readonly IReadOnlyDictionary<string, FeatureFlag> EmptyFeatureFlags = new Dictionary<string, FeatureFlag>(); |
| 12 | + |
| 13 | + NoOpPostHogClient() |
| 14 | + { |
| 15 | + } |
| 16 | + |
| 17 | + internal static NoOpPostHogClient Instance { get; } = new(); |
| 18 | + |
| 19 | + public Task<ApiResult> AliasAsync(string previousId, string newId, CancellationToken cancellationToken) |
| 20 | + => Task.FromResult(new ApiResult(0)); |
| 21 | + |
| 22 | + public Task<ApiResult> IdentifyAsync( |
| 23 | + string distinctId, |
| 24 | + Dictionary<string, object>? personPropertiesToSet, |
| 25 | + Dictionary<string, object>? personPropertiesToSetOnce, |
| 26 | + CancellationToken cancellationToken) |
| 27 | + => Task.FromResult(new ApiResult(0)); |
| 28 | + |
| 29 | + public Task<ApiResult> GroupIdentifyAsync( |
| 30 | + string type, |
| 31 | + StringOrValue<int> key, |
| 32 | + Dictionary<string, object>? properties, |
| 33 | + CancellationToken cancellationToken) |
| 34 | + => Task.FromResult(new ApiResult(0)); |
| 35 | + |
| 36 | + public Task<ApiResult> GroupIdentifyAsync( |
| 37 | + string distinctId, |
| 38 | + string type, |
| 39 | + StringOrValue<int> key, |
| 40 | + Dictionary<string, object>? properties, |
| 41 | + CancellationToken cancellationToken) |
| 42 | + => Task.FromResult(new ApiResult(0)); |
| 43 | + |
| 44 | + public bool Capture( |
| 45 | + string distinctId, |
| 46 | + string eventName, |
| 47 | + Dictionary<string, object>? properties, |
| 48 | + GroupCollection? groups, |
| 49 | + bool sendFeatureFlags, |
| 50 | + DateTimeOffset? timestamp = null) |
| 51 | + => false; |
| 52 | + |
| 53 | + public bool Capture( |
| 54 | + string distinctId, |
| 55 | + string eventName, |
| 56 | + Dictionary<string, object>? properties, |
| 57 | + GroupCollection? groups, |
| 58 | + FeatureFlagEvaluations? flags, |
| 59 | + DateTimeOffset? timestamp = null) |
| 60 | + => false; |
| 61 | + |
| 62 | + public bool CaptureException( |
| 63 | + Exception exception, |
| 64 | + string distinctId, |
| 65 | + Dictionary<string, object>? properties, |
| 66 | + GroupCollection? groups, |
| 67 | + bool sendFeatureFlags, |
| 68 | + DateTimeOffset? timestamp = null) |
| 69 | + => false; |
| 70 | + |
| 71 | + public bool CaptureException( |
| 72 | + Exception exception, |
| 73 | + string distinctId, |
| 74 | + Dictionary<string, object>? properties, |
| 75 | + GroupCollection? groups, |
| 76 | + FeatureFlagEvaluations? flags, |
| 77 | + DateTimeOffset? timestamp = null) |
| 78 | + => false; |
| 79 | + |
| 80 | + public Task<bool> IsFeatureEnabledAsync( |
| 81 | + string featureKey, |
| 82 | + string distinctId, |
| 83 | + FeatureFlagOptions? options, |
| 84 | + CancellationToken cancellationToken) |
| 85 | + => Task.FromResult(false); |
| 86 | + |
| 87 | + public Task<FeatureFlag?> GetFeatureFlagAsync( |
| 88 | + string featureKey, |
| 89 | + string distinctId, |
| 90 | + FeatureFlagOptions? options, |
| 91 | + CancellationToken cancellationToken) |
| 92 | + => Task.FromResult<FeatureFlag?>(null); |
| 93 | + |
| 94 | + public Task<JsonDocument?> GetRemoteConfigPayloadAsync(string key, CancellationToken cancellationToken) |
| 95 | + => Task.FromResult<JsonDocument?>(null); |
| 96 | + |
| 97 | + public Task<IReadOnlyDictionary<string, FeatureFlag>> GetAllFeatureFlagsAsync( |
| 98 | + string distinctId, |
| 99 | + AllFeatureFlagsOptions? options, |
| 100 | + CancellationToken cancellationToken) |
| 101 | + => Task.FromResult(EmptyFeatureFlags); |
| 102 | + |
| 103 | + public Task<FeatureFlagEvaluations> EvaluateFlagsAsync( |
| 104 | + string distinctId, |
| 105 | + AllFeatureFlagsOptions? options, |
| 106 | + CancellationToken cancellationToken) |
| 107 | + => Task.FromResult(FeatureFlagEvaluations.Empty(this, distinctId)); |
| 108 | + |
| 109 | + public Task LoadFeatureFlagsAsync(CancellationToken cancellationToken) |
| 110 | + => Task.CompletedTask; |
| 111 | + |
| 112 | + public Task FlushAsync() |
| 113 | + => Task.CompletedTask; |
| 114 | + |
| 115 | + public string Version => Versioning.VersionConstants.Version; |
| 116 | + |
| 117 | + public void Dispose() |
| 118 | + { |
| 119 | + } |
| 120 | + |
| 121 | + public ValueTask DisposeAsync() |
| 122 | + => default; |
| 123 | + |
| 124 | + void IFeatureFlagEvaluationsHost.CaptureFeatureFlagCalled( |
| 125 | + string distinctId, |
| 126 | + string featureKey, |
| 127 | + EvaluatedFlagRecord? record, |
| 128 | + GroupCollection? groups, |
| 129 | + string? requestId, |
| 130 | + long? evaluatedAt, |
| 131 | + long? flagDefinitionsLoadedAt, |
| 132 | + IReadOnlyCollection<string> errors) |
| 133 | + { |
| 134 | + } |
| 135 | + |
| 136 | + void IFeatureFlagEvaluationsHost.LogFilterWarning(string message) |
| 137 | + { |
| 138 | + } |
| 139 | +} |
0 commit comments