Skip to content

Commit

Permalink
feat: add dart client (#351)
Browse files Browse the repository at this point in the history
* feat: add dart-client

Signed-off-by: Mark Phelps <[email protected]>

* chore: fix readme

Signed-off-by: Mark Phelps <[email protected]>

* chore: add to pubspec

Signed-off-by: Mark Phelps <[email protected]>

* feat: evaluate batch impl

Signed-off-by: Mark Phelps <[email protected]>

* chore: impl list flags

Signed-off-by: Mark Phelps <[email protected]>

* chore: fix linter errors

Signed-off-by: Mark Phelps <[email protected]>

* chore: update dart readme to remove await

Signed-off-by: Mark Phelps <[email protected]>

* chore: update dart readme

Signed-off-by: Mark Phelps <[email protected]>

* chore: fix per PR feedback

Signed-off-by: Mark Phelps <[email protected]>

---------

Signed-off-by: Mark Phelps <[email protected]>
  • Loading branch information
markphelps authored Sep 7, 2024
1 parent f1ed36e commit 2cd64f8
Show file tree
Hide file tree
Showing 20 changed files with 1,049 additions and 0 deletions.
8 changes: 8 additions & 0 deletions flipt-client-browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,11 @@ npm run build
npm install
npm test
```

## Contributing

Contributions are welcome! Please feel free to open an issue or submit a Pull Request.

## License

This project is licensed under the [MIT License](LICENSE).
11 changes: 11 additions & 0 deletions flipt-client-dart/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock

# Shared libraries
lib/src/ffi/**/*.so
lib/src/ffi/**/*.dylib
21 changes: 21 additions & 0 deletions flipt-client-dart/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Flipt Software Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
91 changes: 91 additions & 0 deletions flipt-client-dart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Flipt Client Dart

[![pub package](https://img.shields.io/pub/v/flipt_client.svg)](https://pub.dev/packages/flipt_client)

The `flipt-client-dart` library contains the Dart source code for the Flipt [client-side evaluation](https://www.flipt.io/docs/integration/client) client.

## Installation

Add this to your package's `pubspec.yaml` file:

```yaml
dependencies:
flipt_client: ^0.1.0
```
Then run `dart pub get` to install the package.

## Supported Architectures

This SDK currently supports the following OSes/architectures:

- Linux x86_64
- Linux arm64
- MacOS x86_64
- MacOS arm64

> [!IMPORTANT]
> This SDK currently only supports desktop platforms (MacOS and Linux).
> We are working on adding support for mobile platforms such as iOS and Android.

## Usage

```dart
import 'package:flipt_client/flipt_client.dart';
void main() {
// Initialize the client
final client = FliptEvaluationClient(
'default',
Options.withClientToken(
'your-token',
url: 'http://localhost:8080',
),
);
// Evaluate a variant flag
final result = client.evaluateVariant(
flagKey: 'flag1',
entityId: 'someentity',
context: {'fizz': 'buzz'},
);
print('Variant: ${result.variantKey}');
// Evaluate a boolean flag
final result = client.evaluateBoolean(
flagKey: 'flag2',
entityId: 'user123',
context: {'key': 'value'},
);
print('Enabled: ${result.enabled}');
// Don't forget to close the client when you're done
client.close();
}
```

### Authentication

The `FliptEvaluationClient` supports the following authentication strategies:

- No Authentication (default)
- [Client Token Authentication](https://docs.flipt.io/authentication/using-tokens)
- [JWT Authentication](https://docs.flipt.io/authentication/using-jwts)

## Development

To generate the JSON serialization code, run:

```bash
dart run build_runner build --delete-conflicting-outputs
```

## Contributing

Contributions are welcome! Please feel free to open an issue or submit a Pull Request.

## License

This project is licensed under the [MIT License](LICENSE).
30 changes: 30 additions & 0 deletions flipt-client-dart/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
10 changes: 10 additions & 0 deletions flipt-client-dart/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
targets:
$default:
sources:
exclude:
- 'example/**'
builders:
json_serializable:
options:
explicit_to_json: true
field_rename: snake
4 changes: 4 additions & 0 deletions flipt-client-dart/lib/flipt_client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library flipt_client;

export 'src/models.dart';
export 'src/flipt_evaluation_client.dart';
Empty file.
Loading

0 comments on commit 2cd64f8

Please sign in to comment.