-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add swift readme; add release scripts for swift and c# * chore: update main README Signed-off-by: Mark Phelps <209477+markphelps@users.noreply.github.com> --------- Signed-off-by: Mark Phelps <209477+markphelps@users.noreply.github.com>
- Loading branch information
1 parent
581dab6
commit 34c6a63
Showing
6 changed files
with
188 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Flipt Client Swift | ||
|
||
[![GitHub Release](https://img.shields.io/github/v/release/flipt-io/flipt-client-sdks?filter=flipt-client-swift-*)](https://github.com/flipt-io/flipt-client-sdks/releases) | ||
|
||
The `flipt-client-swift` library contains the Swift source code for the Flipt [client-side evaluation](https://www.flipt.io/docs/integration/client) client. | ||
|
||
## Installation | ||
|
||
### Swift Package Manager | ||
|
||
Add the following to your `Package.swift` file: | ||
|
||
```swift | ||
dependencies: [ | ||
.package(url: "https://github.com/flipt-io/flipt-client-swift.git", from: "0.1.0") | ||
] | ||
``` | ||
|
||
Or add it directly through Xcode: | ||
1. File > Add Package Dependencies | ||
2. Enter package URL: `https://github.com/flipt-io/flipt-client-swift` | ||
|
||
## How Does It Work? | ||
|
||
The `flipt-client-swift` library is a wrapper around the [flipt-engine-ffi](https://github.com/flipt-io/flipt-client-sdks/tree/main/flipt-engine-ffi) library. | ||
|
||
All evaluation happens within the SDK, using the shared library built from the [flipt-engine-ffi](https://github.com/flipt-io/flipt-client-sdks/tree/main/flipt-engine-ffi) library. | ||
|
||
Because the evaluation happens within the SDK, the SDKs can be used in environments where the Flipt server is not available or reachable after the initial data is fetched. | ||
|
||
## Data Fetching | ||
|
||
Upon instantiation, the `flipt-client-swift` library will fetch the flag state from the Flipt server and store it in memory. This means that the first time you use the SDK, it will make a request to the Flipt server. | ||
|
||
### Polling (Default) | ||
|
||
By default, the SDK will poll the Flipt server for new flag state at a regular interval. This interval can be configured using the `updateInterval` option when constructing a client. The default interval is 120 seconds. | ||
|
||
### Streaming (Flipt Cloud Only) | ||
|
||
[Flipt Cloud](https://flipt.io/cloud) users can use the `streaming` fetch method to stream flag state changes from the Flipt server to the SDK. | ||
|
||
When in streaming mode, the SDK will connect to the Flipt server and open a persistent connection that will remain open until the client is closed. The SDK will then receive flag state changes in real-time. | ||
|
||
## Supported Platforms | ||
|
||
This SDK currently supports the following platforms/architectures: | ||
|
||
- iOS arm64 | ||
- iOS Simulator arm64 | ||
- macOS arm64 | ||
|
||
## Usage | ||
|
||
```swift | ||
import FliptClient | ||
|
||
// Initialize the client | ||
let client = try FliptClient( | ||
namespace: "default", | ||
url: "http://localhost:8080", | ||
authentication: .clientToken("your-token"), | ||
updateInterval: 120, | ||
fetchMode: .polling | ||
) | ||
|
||
// Evaluate a boolean flag | ||
let boolResult = try client.evaluateBoolean( | ||
flagKey: "my-flag", | ||
entityId: "user-123", | ||
context: ["key": "value"] | ||
) | ||
print("Flag enabled: \(boolResult.enabled)") | ||
|
||
// Evaluate a variant flag | ||
let variantResult = try client.evaluateVariant( | ||
flagKey: "my-variant-flag", | ||
entityId: "user-123", | ||
context: ["key": "value"] | ||
) | ||
print("Variant key: \(variantResult.variantKey)") | ||
|
||
// Don't forget to close the client when you're done | ||
defer { | ||
client.close() | ||
} | ||
``` | ||
|
||
### Authentication | ||
|
||
The `FliptClient` 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) | ||
|
||
## Memory Management | ||
|
||
The engine that is allocated on the Rust side to compute evaluations for flag state will not be properly deallocated unless you call the `close()` method on a `FliptClient` instance. | ||
|
||
**Please be sure to do this to avoid leaking memory!** | ||
|
||
```swift | ||
defer { | ||
client.close() | ||
} | ||
``` | ||
|
||
## 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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
import re | ||
from .base import SDK | ||
|
||
|
||
class CSharpSDK(SDK): | ||
def get_current_version(self): | ||
return self._get_version_from_file("src/FliptClient/FliptClient.csproj") | ||
|
||
def _get_version_from_file(self, filename): | ||
with open(os.path.join(self.path, filename), "r") as f: | ||
content = f.read() | ||
# <Version>0.0.1</Version> | ||
match = re.search(r"<Version>([\d.]+)</Version>", content) | ||
if match: | ||
return match.group(1) | ||
raise ValueError(f"Version not found in {filename}") | ||
|
||
def update_version(self, new_version): | ||
self._update_version_in_file("src/FliptClient/FliptClient.csproj", new_version) | ||
|
||
def _update_version_in_file(self, filename, new_version): | ||
file_path = os.path.join(self.path, filename) | ||
with open(file_path, "r") as f: | ||
content = f.read() | ||
|
||
updated_content = re.sub( | ||
r"<Version>([\d.]+)</Version>", f"<Version>{new_version}</Version>", content | ||
) | ||
|
||
with open(file_path, "w") as f: | ||
f.write(updated_content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import subprocess | ||
from colorama import Fore, Style | ||
from .base import SDK | ||
|
||
|
||
class SwiftSDK(SDK): | ||
def get_current_version(self) -> str: | ||
return self._get_version_from_tag(f"{self.name}-v*") | ||
|
||
def _get_version_from_tag(self, tag_pattern: str) -> str: | ||
try: | ||
result = subprocess.run( | ||
["git", "describe", "--tags", "--abbrev=0", "--match", tag_pattern], | ||
capture_output=True, | ||
text=True, | ||
check=True, | ||
) | ||
latest_tag = result.stdout.strip() | ||
return latest_tag.split("-v")[-1] | ||
except subprocess.CalledProcessError: | ||
print( | ||
f"{Fore.YELLOW}Warning: No tags found for {tag_pattern}. Using 0.0.0 as the base version.{Style.RESET_ALL}" | ||
) | ||
return "0.0.0" | ||
|
||
def update_version(self, new_version: str): | ||
print( | ||
f"{Fore.YELLOW}Note: Version for {self.name} is managed via Git tags. No files updated.{Style.RESET_ALL}" | ||
) |