Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Change Log

## 23.3.0

* Updated: `project.listEnvironments`, `project.createEnvironment`, `project.getEnvironment`, `project.updateEnvironment` return `Environment` models instead of `Project`
* Added: `account.createDevice`, `account.getDevice`, `account.deleteDevice` and `account.updateDeviceSession`, and the `Device` model
* Added: `project.updateAccountDevicesPolicy`, `ProjectPolicyId.accountDevices` and the `PolicyAccountDevices` model
* Added: `project.updateOAuth2Vipps`, `project.updateOAuth2VippsSandbox` and the `OAuth2Vipps` model
* Added: `OAuthProvider.vipps` and `OAuthProvider.vippsSandbox`
* Added: `proxy.updateFunctionRule`, `proxy.updateRedirectRule` and `proxy.updateSiteRule`
* Added: optional `schedule` on `waf` rule create and update methods and on `WafRule*` models
* Added: `project.getPrefs` and `project.updatePrefs` for project preferences
* Added: `Client.setEnvironment` to act in a project environment
* Added: `AppwriteMigrationResource.projectPreferences` to migrate project preferences
* Added: `monitors.read`, `monitors.write`, `alerts.read`, `alerts.write`, `reviews.read` and `reviews.write` to `ProjectKeyScopes`
* Added: `Organization.budgetNotify`, `budgetCritical` and `educationExpiresAt`
* Added: `Project.environmentId`, `Session.userName` and `ActivityEvent.reason`
* Added: `ProxyRule.expireAt` and `certificateStatus`
* Updated: requests send response format `2.7.1`; README targets Appwrite 2.7.x

## 23.2.0

* Updated: requests send response format `2.6.2`
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Appwrite Swift SDK

![Swift Package Manager](https://img.shields.io/badge/swift%20package%20manager-23.2.0-green.svg?style=flat-square)
![Swift Package Manager](https://img.shields.io/badge/swift%20package%20manager-23.3.0-green.svg?style=flat-square)
![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-2.6.2-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-2.7.1-blue.svg?style=flat-square)
[![X Account](https://img.shields.io/badge/follow-%40appwrite-000000?logo=x&style=flat-square)](https://x.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

**This SDK targets Appwrite server version 2.6.x as shipped on Appwrite Cloud.** Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from [previous releases](https://github.com/appwrite/sdk-for-swift/releases) when APIs differ.
**This SDK targets Appwrite server version 2.7.x as shipped on Appwrite Cloud.** Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from [previous releases](https://github.com/appwrite/sdk-for-swift/releases) when APIs differ.

> This is the Swift SDK for integrating with Appwrite from your Swift server-side code. If you're looking for the Apple SDK you should check [appwrite/sdk-for-apple](https://github.com/appwrite/sdk-for-apple)

Expand All @@ -22,7 +22,7 @@ Requires Swift 6.1 or later (Xcode 16.3 or later). Supported platforms are iOS 1

1. In Xcode, select **File > Add Package Dependencies...**
2. Enter `https://github.com/appwrite/sdk-for-swift` in the search field and select `sdk-for-swift`.
3. Choose a dependency rule, for example **Up to Next Major Version** from `23.2.0`, and click **Add Package**.
3. Choose a dependency rule, for example **Up to Next Major Version** from `23.3.0`, and click **Add Package**.
4. Add the `Appwrite` library to your app target and click **Add Package**.

### Swift Package Manager
Expand All @@ -31,7 +31,7 @@ Add the package to the dependencies in your `Package.swift`:

```swift
dependencies: [
.package(url: "https://github.com/appwrite/sdk-for-swift", from: "23.2.0"),
.package(url: "https://github.com/appwrite/sdk-for-swift", from: "23.3.0"),
],
```

Expand Down
19 changes: 17 additions & 2 deletions Sources/Appwrite/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ open class Client {
"x-sdk-name": "Swift",
"x-sdk-platform": "server",
"x-sdk-language": "swift",
"x-sdk-version": "23.2.0",
"x-appwrite-response-format": "2.6.2",
"x-sdk-version": "23.3.0",
"x-appwrite-response-format": "2.7.1",
]

internal var config: [String: String] = [:]
Expand Down Expand Up @@ -199,6 +199,21 @@ open class Client {
return self
}

///
/// Set Environment
///
/// The ID of the project environment to act in, alongside the project ID. Used with Appwrite Cloud projects that have environments.
///
/// @param String value
///
/// @return Client
///
open func setEnvironment(_ value: String) -> Client {
config["environment"] = value
_ = addHeader(key: "X-Appwrite-Environment", value: value)
return self
}

///
/// Set Session
///
Expand Down
170 changes: 170 additions & 0 deletions Sources/Appwrite/Services/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,176 @@ open class Account: Service {
)
}
///
/// Create an account switching device. A device is a container, scoped to one
/// browser or app install, that holds multiple sessions and tracks which one
/// is active. Once a device exists, session creation endpoints attach the new
/// session to it automatically, so a single browser can stay signed in to
/// several accounts and switch between them. A device holds at most one
/// session per user: signing in again as a user it already holds replaces that
/// user's session. The device lives as long as its newest session.
///
/// The device secret is returned in a cookie. Run this on app start: if the
/// browser already has a valid device, the existing one is returned with the
/// same status code instead of an error, so it is always safe to call.
///
/// Every session that joins the device rotates the device secret and re-issues
/// the cookie, so an earlier copy of the secret stops working. A client that
/// keeps the secret itself, rather than relying on the cookie, must replace it
/// from each session response.
///
/// - Throws: Exception if the request fails
/// - Returns: AppwriteModels.Device
///
open func createDevice() async throws -> AppwriteModels.Device {
let apiPath: String = "/account/devices"

let apiParams: [String: Any] = [:]

let apiHeaders: [String: String] = [
"X-Appwrite-Project": client.config["project"] ?? "",
"content-type": "application/json",
"accept": "application/json",
]

let converter: (Any) throws -> AppwriteModels.Device = { response in
return AppwriteModels.Device.from(map: response as! [String: Any])
}

return try await client.call(
method: "POST",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Get the account switching device for the current browser, including every
/// session it holds, the name of the user each session belongs to, and the ID
/// of the active session. Use the string 'current' to reference the current
/// browser's device.
///
/// - Parameters:
/// - deviceId: String
/// - Throws: Exception if the request fails
/// - Returns: AppwriteModels.Device
///
open func getDevice(
deviceId: String
) async throws -> AppwriteModels.Device {
if deviceId.isEmpty {
throw AppwriteError(message: "Missing required parameter: \"deviceId\"")
}

let apiPath: String = "/account/devices/{deviceId}"
.replacingOccurrences(of: "{deviceId}", with: try Client.encodePath(deviceId))

let apiParams: [String: Any] = [:]

let apiHeaders: [String: String] = [
"X-Appwrite-Project": client.config["project"] ?? "",
"accept": "application/json",
]

let converter: (Any) throws -> AppwriteModels.Device = { response in
return AppwriteModels.Device.from(map: response as! [String: Any])
}

return try await client.call(
method: "GET",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Delete the account switching device for the current browser. Every session
/// the device holds is signed out, each firing its own session delete event,
/// the device is removed, and both the device and session cookies are cleared.
/// Use the string 'current' to reference the current browser's device.
///
/// - Parameters:
/// - deviceId: String
/// - Throws: Exception if the request fails
/// - Returns: Any
///
open func deleteDevice(
deviceId: String
) async throws -> Any {
if deviceId.isEmpty {
throw AppwriteError(message: "Missing required parameter: \"deviceId\"")
}

let apiPath: String = "/account/devices/{deviceId}"
.replacingOccurrences(of: "{deviceId}", with: try Client.encodePath(deviceId))

let apiParams: [String: Any] = [:]

let apiHeaders: [String: String] = [
"X-Appwrite-Project": client.config["project"] ?? "",
"content-type": "application/json",
"accept": "application/json",
]

return try await client.call(
method: "DELETE",
path: apiPath,
headers: apiHeaders,
params: apiParams
)
}
///
/// Switch the active account on an account switching device to one of the
/// sessions it holds. The chosen session becomes active and its secret is
/// written to the browser's session cookie, so subsequent requests
/// authenticate as that account. Use the string 'current' to reference the
/// current browser's device.
///
/// Switching rotates the chosen session's secret. Any other holder of that
/// session, such as a copy kept elsewhere, stops working, so a session should
/// not be shared across devices.
///
/// - Parameters:
/// - deviceId: String
/// - sessionId: String
/// - Throws: Exception if the request fails
/// - Returns: AppwriteModels.Session
///
open func updateDeviceSession(
deviceId: String,
sessionId: String
) async throws -> AppwriteModels.Session {
if deviceId.isEmpty {
throw AppwriteError(message: "Missing required parameter: \"deviceId\"")
}

let apiPath: String = "/account/devices/{deviceId}/session"
.replacingOccurrences(of: "{deviceId}", with: try Client.encodePath(deviceId))

let apiParams: [String: Any?] = [
"sessionId": sessionId
]

let apiHeaders: [String: String] = [
"X-Appwrite-Project": client.config["project"] ?? "",
"content-type": "application/json",
"accept": "application/json",
]

let converter: (Any) throws -> AppwriteModels.Session = { response in
return AppwriteModels.Session.from(map: response as! [String: Any])
}

return try await client.call(
method: "PATCH",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Update currently logged in user account email address. After changing user
/// address, the user confirmation status will get reset. A new confirmation
/// email is not sent automatically however you can use the send confirmation
Expand Down
Loading