diff --git a/CHANGELOG.md b/CHANGELOG.md index 21f1b0c..f99fb1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,28 +1,25 @@ # Change Log -## 29.1.0-rc.3 - -* Added: first background subscription auto-requests `POST_NOTIFICATIONS` (Android 13+) from the visible activity -* Fixed: `onOpen`/`onClose` callbacks fire correctly when joining or leaving the background host -* Fixed: notification taps are recorded after launching the app, so tap-opened screens land on top - -## 29.1.0-rc.2 - -* Added: `getInitialNotification()`, `onNotificationOpened()`, and the `PushNotificationOpened` data class (topic + data) +## 30.0.0 + +* Breaking: `Oauth2` `resource` parameter is now `List` instead of `String` +* Breaking: `Teams.createMembership` takes `membershipId` after `roles`; positional callers must update +* Added: `Account.listPasskeys`, `createPasskey`, `getPasskey`, `updatePasskey` and `deletePasskey` +* Added: `Account.updatePasskeyVerification` to finish registering a passkey +* Added: `Account.createPasskeyToken` and `Account.updatePasskeyToken` for passkey sign-in +* Added: `Passkey`, `PasskeyList`, `PasskeyChallenge` and `TokenSecret` models +* Added: `Analytics` service with `createEvent` +* Added: `state` parameter to `Account.createOAuth2Session` and `Account.createOAuth2Token` +* Added: background push notifications render the server `notification` title, body, and image +* Added: `getInitialNotification()`, `onNotificationOpened()` and the `PushNotificationOpened` data class * Added: `onOpen`/`onClose` callbacks now fire for background push connections +* Added: first background subscription requests `POST_NOTIFICATIONS` (Android 13+) from the visible activity * Added: push auth falls back to the client's cookie-store session -* Fixed: a foreground message with no live callback now still posts a notification -* Updated: notification taps route through an internal `PushOpenActivity` - -## 29.1.0-rc.1 - -* Updated: regenerated with sdk-generator 5.5.0; no SDK code changes - -## 29.1.0-rc.0 - * Added: optional `method` param on `Client.chunkedUpload()` to set the upload HTTP method -* Added: background push notifications render the server `notification` title, body, and image +* Fixed: response models fill missing fields from spec defaults instead of throwing * Updated: `Avatars.updatePhoto()` uploads via `PUT` +* Updated: SDK now targets Appwrite 2.4 (`x-appwrite-response-format: 2.4.0`) +* Fixed: a foreground message with no live callback now still posts a notification * Fixed: an exactly-chunk-sized file uploads in a single request ## 29.0.0 diff --git a/README.md b/README.md index afcc18e..b67b5bc 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ ![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-android.svg?color=green&style=flat-square) ![License](https://img.shields.io/github/license/appwrite/sdk-for-android.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-2.3.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-2.4.0-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.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.3.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-android/releases) when APIs differ. +**This SDK targets Appwrite server version 2.4.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-android/releases) when APIs differ. Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Android SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:29.1.0-rc.3") +implementation("io.appwrite:sdk-for-android:30.0.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 29.1.0-rc.3 + 30.0.0 ``` diff --git a/docs/examples/java/account/create-o-auth-2-session.md b/docs/examples/java/account/create-o-auth-2-session.md index da54742..f2a07ef 100644 --- a/docs/examples/java/account/create-o-auth-2-session.md +++ b/docs/examples/java/account/create-o-auth-2-session.md @@ -17,6 +17,7 @@ account.createOAuth2Session( "https://example.com", // success (optional) "https://example.com", // failure (optional) List.of(), // scopes (optional) + "", // state (optional) new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); diff --git a/docs/examples/java/account/create-o-auth-2-token.md b/docs/examples/java/account/create-o-auth-2-token.md index ae68585..885c066 100644 --- a/docs/examples/java/account/create-o-auth-2-token.md +++ b/docs/examples/java/account/create-o-auth-2-token.md @@ -17,6 +17,7 @@ account.createOAuth2Token( "https://example.com", // success (optional) "https://example.com", // failure (optional) List.of(), // scopes (optional) + "", // state (optional) new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); diff --git a/docs/examples/java/account/create-passkey-token.md b/docs/examples/java/account/create-passkey-token.md new file mode 100644 index 0000000..12db5fe --- /dev/null +++ b/docs/examples/java/account/create-passkey-token.md @@ -0,0 +1,22 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Account account = new Account(client); + +account.createPasskeyToken(new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); +})); +``` diff --git a/docs/examples/java/account/create-passkey.md b/docs/examples/java/account/create-passkey.md new file mode 100644 index 0000000..39a9a29 --- /dev/null +++ b/docs/examples/java/account/create-passkey.md @@ -0,0 +1,27 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Account account = new Account(client); + +account.createPasskey( + "", // passkeyId (optional) + "", // name (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/account/delete-passkey.md b/docs/examples/java/account/delete-passkey.md new file mode 100644 index 0000000..a59d384 --- /dev/null +++ b/docs/examples/java/account/delete-passkey.md @@ -0,0 +1,26 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Account account = new Account(client); + +account.deletePasskey( + "", // passkeyId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/account/get-passkey.md b/docs/examples/java/account/get-passkey.md new file mode 100644 index 0000000..5d988e8 --- /dev/null +++ b/docs/examples/java/account/get-passkey.md @@ -0,0 +1,26 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Account account = new Account(client); + +account.getPasskey( + "", // passkeyId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/account/list-passkeys.md b/docs/examples/java/account/list-passkeys.md new file mode 100644 index 0000000..6b04b1f --- /dev/null +++ b/docs/examples/java/account/list-passkeys.md @@ -0,0 +1,27 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Account account = new Account(client); + +account.listPasskeys( + List.of(), // queries (optional) + false, // total (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/account/update-passkey-token.md b/docs/examples/java/account/update-passkey-token.md new file mode 100644 index 0000000..6370aaa --- /dev/null +++ b/docs/examples/java/account/update-passkey-token.md @@ -0,0 +1,27 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Account account = new Account(client); + +account.updatePasskeyToken( + "", // challengeId + Map.of("a", "b"), // credential + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/account/update-passkey-verification.md b/docs/examples/java/account/update-passkey-verification.md new file mode 100644 index 0000000..53eed3a --- /dev/null +++ b/docs/examples/java/account/update-passkey-verification.md @@ -0,0 +1,27 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Account account = new Account(client); + +account.updatePasskeyVerification( + "", // passkeyId + Map.of("a", "b"), // credential + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/account/update-passkey.md b/docs/examples/java/account/update-passkey.md new file mode 100644 index 0000000..3cf1078 --- /dev/null +++ b/docs/examples/java/account/update-passkey.md @@ -0,0 +1,27 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Account account = new Account(client); + +account.updatePasskey( + "", // passkeyId + "", // name + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/analytics/create-event.md b/docs/examples/java/analytics/create-event.md new file mode 100644 index 0000000..e2b8dbe --- /dev/null +++ b/docs/examples/java/analytics/create-event.md @@ -0,0 +1,38 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Analytics; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Analytics analytics = new Analytics(client); + +analytics.createEvent( + "", // propertyId + "", // name + "https://example.com", // url + "", // domain (optional) + "", // referrer (optional) + 0L, // screenWidth (optional) + "", // sessionHash (optional) + 0L, // scrollDepth (optional) + 0L, // engagementTime (optional) + List.of(), // props (optional) + "", // userId (optional) + "", // ip (optional) + "", // userAgent (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/oauth2/authorize-post.md b/docs/examples/java/oauth2/authorize-post.md index 99ed6b8..077546f 100644 --- a/docs/examples/java/oauth2/authorize-post.md +++ b/docs/examples/java/oauth2/authorize-post.md @@ -23,7 +23,7 @@ oauth2.authorizePost( "", // prompt (optional) 0L, // max_age (optional) "", // authorization_details (optional) - "", // resource (optional) + List.of(), // resource (optional) "", // audience (optional) "", // request_uri (optional) new CoroutineCallback<>((result, error) -> { diff --git a/docs/examples/java/oauth2/authorize.md b/docs/examples/java/oauth2/authorize.md index 62a452c..d5b72cf 100644 --- a/docs/examples/java/oauth2/authorize.md +++ b/docs/examples/java/oauth2/authorize.md @@ -23,7 +23,7 @@ oauth2.authorize( "", // prompt (optional) 0L, // max_age (optional) "", // authorization_details (optional) - "", // resource (optional) + List.of(), // resource (optional) "", // audience (optional) "", // request_uri (optional) new CoroutineCallback<>((result, error) -> { diff --git a/docs/examples/java/oauth2/create-device-authorization.md b/docs/examples/java/oauth2/create-device-authorization.md index 0b65a1a..c2fc4ad 100644 --- a/docs/examples/java/oauth2/create-device-authorization.md +++ b/docs/examples/java/oauth2/create-device-authorization.md @@ -15,7 +15,7 @@ oauth2.createDeviceAuthorization( "", // client_id (optional) "", // scope (optional) "", // authorization_details (optional) - "", // resource (optional) + List.of(), // resource (optional) "", // audience (optional) new CoroutineCallback<>((result, error) -> { if (error != null) { diff --git a/docs/examples/java/oauth2/create-par.md b/docs/examples/java/oauth2/create-par.md index e65bdb5..e1f14de 100644 --- a/docs/examples/java/oauth2/create-par.md +++ b/docs/examples/java/oauth2/create-par.md @@ -23,7 +23,7 @@ oauth2.createPAR( "", // prompt (optional) 0L, // max_age (optional) "", // authorization_details (optional) - "", // resource (optional) + List.of(), // resource (optional) "", // audience (optional) new CoroutineCallback<>((result, error) -> { if (error != null) { diff --git a/docs/examples/java/oauth2/create-token.md b/docs/examples/java/oauth2/create-token.md index 39b6fa2..5c808df 100644 --- a/docs/examples/java/oauth2/create-token.md +++ b/docs/examples/java/oauth2/create-token.md @@ -20,7 +20,7 @@ oauth2.createToken( "", // client_secret (optional) "", // code_verifier (optional) "https://example.com", // redirect_uri (optional) - "", // resource (optional) + List.of(), // resource (optional) "", // audience (optional) new CoroutineCallback<>((result, error) -> { if (error != null) { diff --git a/docs/examples/java/teams/create-membership.md b/docs/examples/java/teams/create-membership.md index d7fba7c..1b7195e 100644 --- a/docs/examples/java/teams/create-membership.md +++ b/docs/examples/java/teams/create-membership.md @@ -14,6 +14,7 @@ Teams teams = new Teams(client); teams.createMembership( "", // teamId List.of("editor"), // roles + "", // membershipId (optional) "email@example.com", // email (optional) "", // userId (optional) "+12065550100", // phone (optional) diff --git a/docs/examples/kotlin/account/create-o-auth-2-session.md b/docs/examples/kotlin/account/create-o-auth-2-session.md index cde941c..c9b3a92 100644 --- a/docs/examples/kotlin/account/create-o-auth-2-session.md +++ b/docs/examples/kotlin/account/create-o-auth-2-session.md @@ -15,5 +15,6 @@ account.createOAuth2Session( success = "https://example.com", // (optional) failure = "https://example.com", // (optional) scopes = listOf(), // (optional) + state = "", // (optional) ) ``` diff --git a/docs/examples/kotlin/account/create-o-auth-2-token.md b/docs/examples/kotlin/account/create-o-auth-2-token.md index 5e90564..3d5b0d7 100644 --- a/docs/examples/kotlin/account/create-o-auth-2-token.md +++ b/docs/examples/kotlin/account/create-o-auth-2-token.md @@ -15,5 +15,6 @@ account.createOAuth2Token( success = "https://example.com", // (optional) failure = "https://example.com", // (optional) scopes = listOf(), // (optional) + state = "", // (optional) ) ``` diff --git a/docs/examples/kotlin/account/create-passkey-token.md b/docs/examples/kotlin/account/create-passkey-token.md new file mode 100644 index 0000000..52b6bf3 --- /dev/null +++ b/docs/examples/kotlin/account/create-passkey-token.md @@ -0,0 +1,13 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val account = Account(client) + +val result = account.createPasskeyToken() +``` diff --git a/docs/examples/kotlin/account/create-passkey.md b/docs/examples/kotlin/account/create-passkey.md new file mode 100644 index 0000000..69a0651 --- /dev/null +++ b/docs/examples/kotlin/account/create-passkey.md @@ -0,0 +1,16 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val account = Account(client) + +val result = account.createPasskey( + passkeyId = "", // (optional) + name = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/account/delete-passkey.md b/docs/examples/kotlin/account/delete-passkey.md new file mode 100644 index 0000000..08bf8fd --- /dev/null +++ b/docs/examples/kotlin/account/delete-passkey.md @@ -0,0 +1,15 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val account = Account(client) + +val result = account.deletePasskey( + passkeyId = "", +) +``` diff --git a/docs/examples/kotlin/account/get-passkey.md b/docs/examples/kotlin/account/get-passkey.md new file mode 100644 index 0000000..ddf9e83 --- /dev/null +++ b/docs/examples/kotlin/account/get-passkey.md @@ -0,0 +1,15 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val account = Account(client) + +val result = account.getPasskey( + passkeyId = "", +) +``` diff --git a/docs/examples/kotlin/account/list-passkeys.md b/docs/examples/kotlin/account/list-passkeys.md new file mode 100644 index 0000000..74c8add --- /dev/null +++ b/docs/examples/kotlin/account/list-passkeys.md @@ -0,0 +1,16 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val account = Account(client) + +val result = account.listPasskeys( + queries = listOf(), // (optional) + total = false, // (optional) +) +``` diff --git a/docs/examples/kotlin/account/update-passkey-token.md b/docs/examples/kotlin/account/update-passkey-token.md new file mode 100644 index 0000000..f48e29f --- /dev/null +++ b/docs/examples/kotlin/account/update-passkey-token.md @@ -0,0 +1,16 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val account = Account(client) + +val result = account.updatePasskeyToken( + challengeId = "", + credential = mapOf( "a" to "b" ), +) +``` diff --git a/docs/examples/kotlin/account/update-passkey-verification.md b/docs/examples/kotlin/account/update-passkey-verification.md new file mode 100644 index 0000000..41c016a --- /dev/null +++ b/docs/examples/kotlin/account/update-passkey-verification.md @@ -0,0 +1,16 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val account = Account(client) + +val result = account.updatePasskeyVerification( + passkeyId = "", + credential = mapOf( "a" to "b" ), +) +``` diff --git a/docs/examples/kotlin/account/update-passkey.md b/docs/examples/kotlin/account/update-passkey.md new file mode 100644 index 0000000..c8c2bc3 --- /dev/null +++ b/docs/examples/kotlin/account/update-passkey.md @@ -0,0 +1,16 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val account = Account(client) + +val result = account.updatePasskey( + passkeyId = "", + name = "", +) +``` diff --git a/docs/examples/kotlin/analytics/create-event.md b/docs/examples/kotlin/analytics/create-event.md new file mode 100644 index 0000000..820e0ba --- /dev/null +++ b/docs/examples/kotlin/analytics/create-event.md @@ -0,0 +1,27 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Analytics + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val analytics = Analytics(client) + +val result = analytics.createEvent( + propertyId = "", + name = "", + url = "https://example.com", + domain = "", // (optional) + referrer = "", // (optional) + screenWidth = 0, // (optional) + sessionHash = "", // (optional) + scrollDepth = 0, // (optional) + engagementTime = 0, // (optional) + props = listOf(), // (optional) + userId = "", // (optional) + ip = "", // (optional) + userAgent = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/oauth2/authorize-post.md b/docs/examples/kotlin/oauth2/authorize-post.md index 88bc4ee..ea49099 100644 --- a/docs/examples/kotlin/oauth2/authorize-post.md +++ b/docs/examples/kotlin/oauth2/authorize-post.md @@ -21,7 +21,7 @@ val result = oauth2.authorizePost( prompt = "", // (optional) maxAge = 0, // (optional) authorizationDetails = "", // (optional) - resource = "", // (optional) + resource = listOf(), // (optional) audience = "", // (optional) requestUri = "", // (optional) ) diff --git a/docs/examples/kotlin/oauth2/authorize.md b/docs/examples/kotlin/oauth2/authorize.md index 4d307e8..6c59834 100644 --- a/docs/examples/kotlin/oauth2/authorize.md +++ b/docs/examples/kotlin/oauth2/authorize.md @@ -21,7 +21,7 @@ val result = oauth2.authorize( prompt = "", // (optional) maxAge = 0, // (optional) authorizationDetails = "", // (optional) - resource = "", // (optional) + resource = listOf(), // (optional) audience = "", // (optional) requestUri = "", // (optional) ) diff --git a/docs/examples/kotlin/oauth2/create-device-authorization.md b/docs/examples/kotlin/oauth2/create-device-authorization.md index ab307c3..d4fb9b0 100644 --- a/docs/examples/kotlin/oauth2/create-device-authorization.md +++ b/docs/examples/kotlin/oauth2/create-device-authorization.md @@ -13,7 +13,7 @@ val result = oauth2.createDeviceAuthorization( clientId = "", // (optional) scope = "", // (optional) authorizationDetails = "", // (optional) - resource = "", // (optional) + resource = listOf(), // (optional) audience = "", // (optional) ) ``` diff --git a/docs/examples/kotlin/oauth2/create-par.md b/docs/examples/kotlin/oauth2/create-par.md index 752c64e..213096c 100644 --- a/docs/examples/kotlin/oauth2/create-par.md +++ b/docs/examples/kotlin/oauth2/create-par.md @@ -21,7 +21,7 @@ val result = oauth2.createPAR( prompt = "", // (optional) maxAge = 0, // (optional) authorizationDetails = "", // (optional) - resource = "", // (optional) + resource = listOf(), // (optional) audience = "", // (optional) ) ``` diff --git a/docs/examples/kotlin/oauth2/create-token.md b/docs/examples/kotlin/oauth2/create-token.md index 5e23344..a0e4f20 100644 --- a/docs/examples/kotlin/oauth2/create-token.md +++ b/docs/examples/kotlin/oauth2/create-token.md @@ -18,7 +18,7 @@ val result = oauth2.createToken( clientSecret = "", // (optional) codeVerifier = "", // (optional) redirectUri = "https://example.com", // (optional) - resource = "", // (optional) + resource = listOf(), // (optional) audience = "", // (optional) ) ``` diff --git a/docs/examples/kotlin/teams/create-membership.md b/docs/examples/kotlin/teams/create-membership.md index 219119a..9d2608e 100644 --- a/docs/examples/kotlin/teams/create-membership.md +++ b/docs/examples/kotlin/teams/create-membership.md @@ -12,6 +12,7 @@ val teams = Teams(client) val result = teams.createMembership( teamId = "", roles = listOf("editor"), + membershipId = "", // (optional) email = "email@example.com", // (optional) userId = "", // (optional) phone = "+12065550100", // (optional) diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 3df991a..7b9ad2d 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -101,8 +101,8 @@ class Client @JvmOverloads constructor( "x-sdk-name" to "Android", "x-sdk-platform" to "client", "x-sdk-language" to "android", - "x-sdk-version" to "29.1.0-rc.3", - "x-appwrite-response-format" to "2.3.0" + "x-sdk-version" to "30.0.0", + "x-appwrite-response-format" to "2.4.0" ) config = mutableMapOf() diff --git a/library/src/main/java/io/appwrite/models/Account.kt b/library/src/main/java/io/appwrite/models/Account.kt index 38865ff..c998b9d 100644 --- a/library/src/main/java/io/appwrite/models/Account.kt +++ b/library/src/main/java/io/appwrite/models/Account.kt @@ -237,28 +237,28 @@ data class Account( map: Map, nestedType: Class ) = Account( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - name = map["name"] as String, - registration = map["registration"] as String, - status = map["status"] as Boolean, - labels = map["labels"] as List, - passwordUpdate = map["passwordUpdate"] as String, - email = map["email"] as String, - phone = map["phone"] as String, - emailVerification = map["emailVerification"] as Boolean, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + name = (if (map.containsKey("name")) map["name"] else "") as String, + registration = (if (map.containsKey("registration")) map["registration"] else "") as String, + status = (if (map.containsKey("status")) map["status"] else true) as Boolean, + labels = (if (map.containsKey("labels")) map["labels"] else listOf()) as List, + passwordUpdate = (if (map.containsKey("passwordUpdate")) map["passwordUpdate"] else "") as String, + email = (if (map.containsKey("email")) map["email"] else "") as String, + phone = (if (map.containsKey("phone")) map["phone"] else "") as String, + emailVerification = (if (map.containsKey("emailVerification")) map["emailVerification"] else false) as Boolean, emailCanonical = map["emailCanonical"] as? String, emailIsFree = map["emailIsFree"] as? Boolean, emailIsDisposable = map["emailIsDisposable"] as? Boolean, emailIsCorporate = map["emailIsCorporate"] as? Boolean, emailIsCanonical = map["emailIsCanonical"] as? Boolean, passwordPwned = map["passwordPwned"] as? Boolean, - phoneVerification = map["phoneVerification"] as Boolean, - mfa = map["mfa"] as Boolean, + phoneVerification = (if (map.containsKey("phoneVerification")) map["phoneVerification"] else false) as Boolean, + mfa = (if (map.containsKey("mfa")) map["mfa"] else false) as Boolean, prefs = Preferences.from(map = map["prefs"] as Map, nestedType), targets = (map["targets"] as List>).map { Target.from(map = it) }, - accessedAt = map["accessedAt"] as String, + accessedAt = (if (map.containsKey("accessedAt")) map["accessedAt"] else "") as String, impersonator = map["impersonator"] as? Boolean, impersonatorUserId = map["impersonatorUserId"] as? String, ) diff --git a/library/src/main/java/io/appwrite/models/AlgoArgon2.kt b/library/src/main/java/io/appwrite/models/AlgoArgon2.kt index 3977332..1d26dfd 100644 --- a/library/src/main/java/io/appwrite/models/AlgoArgon2.kt +++ b/library/src/main/java/io/appwrite/models/AlgoArgon2.kt @@ -44,10 +44,10 @@ data class AlgoArgon2( fun from( map: Map, ) = AlgoArgon2( - type = map["type"] as String, - memoryCost = (map["memoryCost"] as Number).toLong(), - timeCost = (map["timeCost"] as Number).toLong(), - threads = (map["threads"] as Number).toLong(), + type = (if (map.containsKey("type")) map["type"] else "argon2") as String, + memoryCost = ((if (map.containsKey("memoryCost")) map["memoryCost"] else 0) as Number).toLong(), + timeCost = ((if (map.containsKey("timeCost")) map["timeCost"] else 0) as Number).toLong(), + threads = ((if (map.containsKey("threads")) map["threads"] else 0) as Number).toLong(), ) } } diff --git a/library/src/main/java/io/appwrite/models/AlgoBcrypt.kt b/library/src/main/java/io/appwrite/models/AlgoBcrypt.kt index 3831780..2a99dad 100644 --- a/library/src/main/java/io/appwrite/models/AlgoBcrypt.kt +++ b/library/src/main/java/io/appwrite/models/AlgoBcrypt.kt @@ -23,7 +23,7 @@ data class AlgoBcrypt( fun from( map: Map, ) = AlgoBcrypt( - type = map["type"] as String, + type = (if (map.containsKey("type")) map["type"] else "bcrypt") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/AlgoMd5.kt b/library/src/main/java/io/appwrite/models/AlgoMd5.kt index e46eb99..d683ea7 100644 --- a/library/src/main/java/io/appwrite/models/AlgoMd5.kt +++ b/library/src/main/java/io/appwrite/models/AlgoMd5.kt @@ -23,7 +23,7 @@ data class AlgoMd5( fun from( map: Map, ) = AlgoMd5( - type = map["type"] as String, + type = (if (map.containsKey("type")) map["type"] else "md5") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/AlgoPhpass.kt b/library/src/main/java/io/appwrite/models/AlgoPhpass.kt index d457a81..3eba6ca 100644 --- a/library/src/main/java/io/appwrite/models/AlgoPhpass.kt +++ b/library/src/main/java/io/appwrite/models/AlgoPhpass.kt @@ -23,7 +23,7 @@ data class AlgoPhpass( fun from( map: Map, ) = AlgoPhpass( - type = map["type"] as String, + type = (if (map.containsKey("type")) map["type"] else "phpass") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/AlgoScrypt.kt b/library/src/main/java/io/appwrite/models/AlgoScrypt.kt index 9214704..789061f 100644 --- a/library/src/main/java/io/appwrite/models/AlgoScrypt.kt +++ b/library/src/main/java/io/appwrite/models/AlgoScrypt.kt @@ -51,11 +51,11 @@ data class AlgoScrypt( fun from( map: Map, ) = AlgoScrypt( - type = map["type"] as String, - costCpu = (map["costCpu"] as Number).toLong(), - costMemory = (map["costMemory"] as Number).toLong(), - costParallel = (map["costParallel"] as Number).toLong(), - length = (map["length"] as Number).toLong(), + type = (if (map.containsKey("type")) map["type"] else "scrypt") as String, + costCpu = ((if (map.containsKey("costCpu")) map["costCpu"] else 8) as Number).toLong(), + costMemory = ((if (map.containsKey("costMemory")) map["costMemory"] else 14) as Number).toLong(), + costParallel = ((if (map.containsKey("costParallel")) map["costParallel"] else 1) as Number).toLong(), + length = ((if (map.containsKey("length")) map["length"] else 64) as Number).toLong(), ) } } diff --git a/library/src/main/java/io/appwrite/models/AlgoScryptModified.kt b/library/src/main/java/io/appwrite/models/AlgoScryptModified.kt index 539828a..ff306fa 100644 --- a/library/src/main/java/io/appwrite/models/AlgoScryptModified.kt +++ b/library/src/main/java/io/appwrite/models/AlgoScryptModified.kt @@ -44,10 +44,10 @@ data class AlgoScryptModified( fun from( map: Map, ) = AlgoScryptModified( - type = map["type"] as String, - salt = map["salt"] as String, - saltSeparator = map["saltSeparator"] as String, - signerKey = map["signerKey"] as String, + type = (if (map.containsKey("type")) map["type"] else "scryptMod") as String, + salt = (if (map.containsKey("salt")) map["salt"] else "") as String, + saltSeparator = (if (map.containsKey("saltSeparator")) map["saltSeparator"] else "") as String, + signerKey = (if (map.containsKey("signerKey")) map["signerKey"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/AlgoSha.kt b/library/src/main/java/io/appwrite/models/AlgoSha.kt index 45fb010..5c52f08 100644 --- a/library/src/main/java/io/appwrite/models/AlgoSha.kt +++ b/library/src/main/java/io/appwrite/models/AlgoSha.kt @@ -23,7 +23,7 @@ data class AlgoSha( fun from( map: Map, ) = AlgoSha( - type = map["type"] as String, + type = (if (map.containsKey("type")) map["type"] else "sha") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/App.kt b/library/src/main/java/io/appwrite/models/App.kt index f4a715c..6173b70 100644 --- a/library/src/main/java/io/appwrite/models/App.kt +++ b/library/src/main/java/io/appwrite/models/App.kt @@ -198,31 +198,31 @@ data class App( fun from( map: Map, ) = App( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - name = map["name"] as String, - description = map["description"] as String, - clientUri = map["clientUri"] as String, - logoUri = map["logoUri"] as String, - privacyPolicyUrl = map["privacyPolicyUrl"] as String, - termsUrl = map["termsUrl"] as String, - contacts = map["contacts"] as List, - tagline = map["tagline"] as String, - tags = map["tags"] as List, - labels = map["labels"] as List, - images = map["images"] as List, - supportUrl = map["supportUrl"] as String, - dataDeletionUrl = map["dataDeletionUrl"] as String, - redirectUris = map["redirectUris"] as List, - postLogoutRedirectUris = map["postLogoutRedirectUris"] as List, - enabled = map["enabled"] as Boolean, - type = map["type"] as String, - deviceFlow = map["deviceFlow"] as Boolean, - teamId = map["teamId"] as String, - userId = map["userId"] as String, - installationScopes = map["installationScopes"] as List, - installationRedirectUrl = map["installationRedirectUrl"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + name = (if (map.containsKey("name")) map["name"] else "") as String, + description = (if (map.containsKey("description")) map["description"] else "") as String, + clientUri = (if (map.containsKey("clientUri")) map["clientUri"] else "") as String, + logoUri = (if (map.containsKey("logoUri")) map["logoUri"] else "") as String, + privacyPolicyUrl = (if (map.containsKey("privacyPolicyUrl")) map["privacyPolicyUrl"] else "") as String, + termsUrl = (if (map.containsKey("termsUrl")) map["termsUrl"] else "") as String, + contacts = (if (map.containsKey("contacts")) map["contacts"] else listOf()) as List, + tagline = (if (map.containsKey("tagline")) map["tagline"] else "") as String, + tags = (if (map.containsKey("tags")) map["tags"] else listOf()) as List, + labels = (if (map.containsKey("labels")) map["labels"] else listOf()) as List, + images = (if (map.containsKey("images")) map["images"] else listOf()) as List, + supportUrl = (if (map.containsKey("supportUrl")) map["supportUrl"] else "") as String, + dataDeletionUrl = (if (map.containsKey("dataDeletionUrl")) map["dataDeletionUrl"] else "") as String, + redirectUris = (if (map.containsKey("redirectUris")) map["redirectUris"] else listOf()) as List, + postLogoutRedirectUris = (if (map.containsKey("postLogoutRedirectUris")) map["postLogoutRedirectUris"] else listOf()) as List, + enabled = (if (map.containsKey("enabled")) map["enabled"] else true) as Boolean, + type = (if (map.containsKey("type")) map["type"] else "confidential") as String, + deviceFlow = (if (map.containsKey("deviceFlow")) map["deviceFlow"] else false) as Boolean, + teamId = (if (map.containsKey("teamId")) map["teamId"] else "") as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, + installationScopes = (if (map.containsKey("installationScopes")) map["installationScopes"] else listOf()) as List, + installationRedirectUrl = (if (map.containsKey("installationRedirectUrl")) map["installationRedirectUrl"] else "") as String, secrets = (map["secrets"] as List>).map { AppSecret.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/AppInstallation.kt b/library/src/main/java/io/appwrite/models/AppInstallation.kt index 46bf907..3c6d1f6 100644 --- a/library/src/main/java/io/appwrite/models/AppInstallation.kt +++ b/library/src/main/java/io/appwrite/models/AppInstallation.kt @@ -86,15 +86,15 @@ data class AppInstallation( fun from( map: Map, ) = AppInstallation( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - appId = map["appId"] as String, - teamId = map["teamId"] as String, - scopes = map["scopes"] as List, - authorizationDetails = map["authorizationDetails"] as List>, - createdById = map["createdById"] as String, - createdByName = map["createdByName"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + appId = (if (map.containsKey("appId")) map["appId"] else "") as String, + teamId = (if (map.containsKey("teamId")) map["teamId"] else "") as String, + scopes = (if (map.containsKey("scopes")) map["scopes"] else listOf()) as List, + authorizationDetails = (if (map.containsKey("authorizationDetails")) map["authorizationDetails"] else listOf()) as List>, + createdById = (if (map.containsKey("createdById")) map["createdById"] else "") as String, + createdByName = (if (map.containsKey("createdByName")) map["createdByName"] else "") as String, lastAccessedAt = map["lastAccessedAt"] as? String, ) } diff --git a/library/src/main/java/io/appwrite/models/AppInstallationList.kt b/library/src/main/java/io/appwrite/models/AppInstallationList.kt index f7434cf..a62371d 100644 --- a/library/src/main/java/io/appwrite/models/AppInstallationList.kt +++ b/library/src/main/java/io/appwrite/models/AppInstallationList.kt @@ -30,7 +30,7 @@ data class AppInstallationList( fun from( map: Map, ) = AppInstallationList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), installations = (map["installations"] as List>).map { AppInstallation.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/AppKey.kt b/library/src/main/java/io/appwrite/models/AppKey.kt index f59e8d5..7348cd3 100644 --- a/library/src/main/java/io/appwrite/models/AppKey.kt +++ b/library/src/main/java/io/appwrite/models/AppKey.kt @@ -79,14 +79,14 @@ data class AppKey( fun from( map: Map, ) = AppKey( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - appId = map["appId"] as String, - secret = map["secret"] as String, - hint = map["hint"] as String, - createdById = map["createdById"] as String, - createdByName = map["createdByName"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + appId = (if (map.containsKey("appId")) map["appId"] else "") as String, + secret = (if (map.containsKey("secret")) map["secret"] else "") as String, + hint = (if (map.containsKey("hint")) map["hint"] else "") as String, + createdById = (if (map.containsKey("createdById")) map["createdById"] else "") as String, + createdByName = (if (map.containsKey("createdByName")) map["createdByName"] else "") as String, lastAccessedAt = map["lastAccessedAt"] as? String, ) } diff --git a/library/src/main/java/io/appwrite/models/AppKeyList.kt b/library/src/main/java/io/appwrite/models/AppKeyList.kt index ea4b1cc..4351465 100644 --- a/library/src/main/java/io/appwrite/models/AppKeyList.kt +++ b/library/src/main/java/io/appwrite/models/AppKeyList.kt @@ -30,7 +30,7 @@ data class AppKeyList( fun from( map: Map, ) = AppKeyList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), keys = (map["keys"] as List>).map { AppKey.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/AppScope.kt b/library/src/main/java/io/appwrite/models/AppScope.kt index 4cc7fe9..dbacafc 100644 --- a/library/src/main/java/io/appwrite/models/AppScope.kt +++ b/library/src/main/java/io/appwrite/models/AppScope.kt @@ -51,11 +51,11 @@ data class AppScope( fun from( map: Map, ) = AppScope( - value = map["value"] as String, - description = map["description"] as String, - type = map["type"] as String, - category = map["category"] as String, - deprecated = map["deprecated"] as Boolean, + value = (if (map.containsKey("value")) map["value"] else "") as String, + description = (if (map.containsKey("description")) map["description"] else "") as String, + type = (if (map.containsKey("type")) map["type"] else "") as String, + category = (if (map.containsKey("category")) map["category"] else "") as String, + deprecated = (if (map.containsKey("deprecated")) map["deprecated"] else false) as Boolean, ) } } diff --git a/library/src/main/java/io/appwrite/models/AppScopeList.kt b/library/src/main/java/io/appwrite/models/AppScopeList.kt index cbcf91f..7abb6dc 100644 --- a/library/src/main/java/io/appwrite/models/AppScopeList.kt +++ b/library/src/main/java/io/appwrite/models/AppScopeList.kt @@ -30,7 +30,7 @@ data class AppScopeList( fun from( map: Map, ) = AppScopeList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), scopes = (map["scopes"] as List>).map { AppScope.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/AppSecret.kt b/library/src/main/java/io/appwrite/models/AppSecret.kt index 0349ffb..b7d7092 100644 --- a/library/src/main/java/io/appwrite/models/AppSecret.kt +++ b/library/src/main/java/io/appwrite/models/AppSecret.kt @@ -79,14 +79,14 @@ data class AppSecret( fun from( map: Map, ) = AppSecret( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - appId = map["appId"] as String, - secret = map["secret"] as String, - hint = map["hint"] as String, - createdById = map["createdById"] as String, - createdByName = map["createdByName"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + appId = (if (map.containsKey("appId")) map["appId"] else "") as String, + secret = (if (map.containsKey("secret")) map["secret"] else "") as String, + hint = (if (map.containsKey("hint")) map["hint"] else "") as String, + createdById = (if (map.containsKey("createdById")) map["createdById"] else "") as String, + createdByName = (if (map.containsKey("createdByName")) map["createdByName"] else "") as String, lastAccessedAt = map["lastAccessedAt"] as? String, ) } diff --git a/library/src/main/java/io/appwrite/models/AppSecretList.kt b/library/src/main/java/io/appwrite/models/AppSecretList.kt index 04d2ebb..f1c00f2 100644 --- a/library/src/main/java/io/appwrite/models/AppSecretList.kt +++ b/library/src/main/java/io/appwrite/models/AppSecretList.kt @@ -30,7 +30,7 @@ data class AppSecretList( fun from( map: Map, ) = AppSecretList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), secrets = (map["secrets"] as List>).map { AppSecret.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/AppSecretPlaintext.kt b/library/src/main/java/io/appwrite/models/AppSecretPlaintext.kt index 098b7f1..7464598 100644 --- a/library/src/main/java/io/appwrite/models/AppSecretPlaintext.kt +++ b/library/src/main/java/io/appwrite/models/AppSecretPlaintext.kt @@ -79,14 +79,14 @@ data class AppSecretPlaintext( fun from( map: Map, ) = AppSecretPlaintext( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - appId = map["appId"] as String, - secret = map["secret"] as String, - hint = map["hint"] as String, - createdById = map["createdById"] as String, - createdByName = map["createdByName"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + appId = (if (map.containsKey("appId")) map["appId"] else "") as String, + secret = (if (map.containsKey("secret")) map["secret"] else "") as String, + hint = (if (map.containsKey("hint")) map["hint"] else "") as String, + createdById = (if (map.containsKey("createdById")) map["createdById"] else "") as String, + createdByName = (if (map.containsKey("createdByName")) map["createdByName"] else "") as String, lastAccessedAt = map["lastAccessedAt"] as? String, ) } diff --git a/library/src/main/java/io/appwrite/models/AppsList.kt b/library/src/main/java/io/appwrite/models/AppsList.kt index 5dcff82..1f2ab92 100644 --- a/library/src/main/java/io/appwrite/models/AppsList.kt +++ b/library/src/main/java/io/appwrite/models/AppsList.kt @@ -30,7 +30,7 @@ data class AppsList( fun from( map: Map, ) = AppsList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), apps = (map["apps"] as List>).map { App.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Continent.kt b/library/src/main/java/io/appwrite/models/Continent.kt index 0adbb5f..e8599a0 100644 --- a/library/src/main/java/io/appwrite/models/Continent.kt +++ b/library/src/main/java/io/appwrite/models/Continent.kt @@ -30,8 +30,8 @@ data class Continent( fun from( map: Map, ) = Continent( - name = map["name"] as String, - code = map["code"] as String, + name = (if (map.containsKey("name")) map["name"] else "") as String, + code = (if (map.containsKey("code")) map["code"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/ContinentList.kt b/library/src/main/java/io/appwrite/models/ContinentList.kt index 53f95f2..ed2056e 100644 --- a/library/src/main/java/io/appwrite/models/ContinentList.kt +++ b/library/src/main/java/io/appwrite/models/ContinentList.kt @@ -30,7 +30,7 @@ data class ContinentList( fun from( map: Map, ) = ContinentList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), continents = (map["continents"] as List>).map { Continent.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Country.kt b/library/src/main/java/io/appwrite/models/Country.kt index 7b104f0..1c3065e 100644 --- a/library/src/main/java/io/appwrite/models/Country.kt +++ b/library/src/main/java/io/appwrite/models/Country.kt @@ -30,8 +30,8 @@ data class Country( fun from( map: Map, ) = Country( - name = map["name"] as String, - code = map["code"] as String, + name = (if (map.containsKey("name")) map["name"] else "") as String, + code = (if (map.containsKey("code")) map["code"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/CountryList.kt b/library/src/main/java/io/appwrite/models/CountryList.kt index 322cdaf..22c692f 100644 --- a/library/src/main/java/io/appwrite/models/CountryList.kt +++ b/library/src/main/java/io/appwrite/models/CountryList.kt @@ -30,7 +30,7 @@ data class CountryList( fun from( map: Map, ) = CountryList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), countries = (map["countries"] as List>).map { Country.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Currency.kt b/library/src/main/java/io/appwrite/models/Currency.kt index 95ff13a..d78a90c 100644 --- a/library/src/main/java/io/appwrite/models/Currency.kt +++ b/library/src/main/java/io/appwrite/models/Currency.kt @@ -65,13 +65,13 @@ data class Currency( fun from( map: Map, ) = Currency( - symbol = map["symbol"] as String, - name = map["name"] as String, - symbolNative = map["symbolNative"] as String, - decimalDigits = (map["decimalDigits"] as Number).toLong(), - rounding = (map["rounding"] as Number).toDouble(), - code = map["code"] as String, - namePlural = map["namePlural"] as String, + symbol = (if (map.containsKey("symbol")) map["symbol"] else "") as String, + name = (if (map.containsKey("name")) map["name"] else "") as String, + symbolNative = (if (map.containsKey("symbolNative")) map["symbolNative"] else "") as String, + decimalDigits = ((if (map.containsKey("decimalDigits")) map["decimalDigits"] else 0) as Number).toLong(), + rounding = ((if (map.containsKey("rounding")) map["rounding"] else 0.0) as Number).toDouble(), + code = (if (map.containsKey("code")) map["code"] else "") as String, + namePlural = (if (map.containsKey("namePlural")) map["namePlural"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/CurrencyList.kt b/library/src/main/java/io/appwrite/models/CurrencyList.kt index 8082a2f..52977c5 100644 --- a/library/src/main/java/io/appwrite/models/CurrencyList.kt +++ b/library/src/main/java/io/appwrite/models/CurrencyList.kt @@ -30,7 +30,7 @@ data class CurrencyList( fun from( map: Map, ) = CurrencyList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), currencies = (map["currencies"] as List>).map { Currency.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Document.kt b/library/src/main/java/io/appwrite/models/Document.kt index 20e803e..8d121de 100644 --- a/library/src/main/java/io/appwrite/models/Document.kt +++ b/library/src/main/java/io/appwrite/models/Document.kt @@ -92,12 +92,12 @@ data class Document( map: Map, nestedType: Class ) = Document( - id = map["\$id"] as String, - sequence = map["\$sequence"] as String, - collectionId = map["\$collectionId"] as String, - databaseId = map["\$databaseId"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + sequence = (if (map.containsKey("\$sequence")) map["\$sequence"] else "") as String, + collectionId = (if (map.containsKey("\$collectionId")) map["\$collectionId"] else "") as String, + databaseId = (if (map.containsKey("\$databaseId")) map["\$databaseId"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, permissions = map["\$permissions"] as List, data = map["data"]?.jsonCast(to = nestedType) ?: map.jsonCast(to = nestedType) ) diff --git a/library/src/main/java/io/appwrite/models/DocumentList.kt b/library/src/main/java/io/appwrite/models/DocumentList.kt index d8741ea..fe29c14 100644 --- a/library/src/main/java/io/appwrite/models/DocumentList.kt +++ b/library/src/main/java/io/appwrite/models/DocumentList.kt @@ -39,7 +39,7 @@ data class DocumentList( map: Map, nestedType: Class ) = DocumentList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), documents = (map["documents"] as List>).map { Document.from(map = it, nestedType) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Execution.kt b/library/src/main/java/io/appwrite/models/Execution.kt index c698d9c..10bb0ef 100644 --- a/library/src/main/java/io/appwrite/models/Execution.kt +++ b/library/src/main/java/io/appwrite/models/Execution.kt @@ -152,24 +152,24 @@ data class Execution( fun from( map: Map, ) = Execution( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, permissions = map["\$permissions"] as List, - resourceId = map["resourceId"] as String, - resourceType = ExecutionResourceType.values().find { it.value == map["resourceType"] as String }!!, - deploymentId = map["deploymentId"] as String, + resourceId = (if (map.containsKey("resourceId")) map["resourceId"] else "") as String, + resourceType = ExecutionResourceType.values().find { it.value == (if (map.containsKey("resourceType")) map["resourceType"] else "functions") as String }!!, + deploymentId = (if (map.containsKey("deploymentId")) map["deploymentId"] else "") as String, trigger = ExecutionTrigger.values().find { it.value == map["trigger"] as String }!!, status = ExecutionStatus.values().find { it.value == map["status"] as String }!!, - requestMethod = map["requestMethod"] as String, - requestPath = map["requestPath"] as String, + requestMethod = (if (map.containsKey("requestMethod")) map["requestMethod"] else "") as String, + requestPath = (if (map.containsKey("requestPath")) map["requestPath"] else "") as String, requestHeaders = (map["requestHeaders"] as List>).map { Headers.from(map = it) }, - responseStatusCode = (map["responseStatusCode"] as Number).toLong(), - responseBody = map["responseBody"] as String, + responseStatusCode = ((if (map.containsKey("responseStatusCode")) map["responseStatusCode"] else 0) as Number).toLong(), + responseBody = (if (map.containsKey("responseBody")) map["responseBody"] else "") as String, responseHeaders = (map["responseHeaders"] as List>).map { Headers.from(map = it) }, - logs = map["logs"] as String, - errors = map["errors"] as String, - duration = (map["duration"] as Number).toDouble(), + logs = (if (map.containsKey("logs")) map["logs"] else "") as String, + errors = (if (map.containsKey("errors")) map["errors"] else "") as String, + duration = ((if (map.containsKey("duration")) map["duration"] else 0.0) as Number).toDouble(), scheduledAt = map["scheduledAt"] as? String, ) } diff --git a/library/src/main/java/io/appwrite/models/ExecutionList.kt b/library/src/main/java/io/appwrite/models/ExecutionList.kt index 4eac1d8..ef55d37 100644 --- a/library/src/main/java/io/appwrite/models/ExecutionList.kt +++ b/library/src/main/java/io/appwrite/models/ExecutionList.kt @@ -30,7 +30,7 @@ data class ExecutionList( fun from( map: Map, ) = ExecutionList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), executions = (map["executions"] as List>).map { Execution.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/File.kt b/library/src/main/java/io/appwrite/models/File.kt index d15a55b..049bbae 100644 --- a/library/src/main/java/io/appwrite/models/File.kt +++ b/library/src/main/java/io/appwrite/models/File.kt @@ -128,22 +128,22 @@ data class File( fun from( map: Map, ) = File( - id = map["\$id"] as String, - bucketId = map["bucketId"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - permissions = map["\$permissions"] as List, - name = map["name"] as String, - folder = map["folder"] as String, - key = map["key"] as String, - signature = map["signature"] as String, - mimeType = map["mimeType"] as String, - sizeOriginal = (map["sizeOriginal"] as Number).toLong(), - sizeActual = (map["sizeActual"] as Number).toLong(), - chunksTotal = (map["chunksTotal"] as Number).toLong(), - chunksUploaded = (map["chunksUploaded"] as Number).toLong(), - encryption = map["encryption"] as Boolean, - compression = map["compression"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + bucketId = (if (map.containsKey("bucketId")) map["bucketId"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + permissions = (if (map.containsKey("\$permissions")) map["\$permissions"] else listOf()) as List, + name = (if (map.containsKey("name")) map["name"] else "") as String, + folder = (if (map.containsKey("folder")) map["folder"] else "") as String, + key = (if (map.containsKey("key")) map["key"] else "") as String, + signature = (if (map.containsKey("signature")) map["signature"] else "") as String, + mimeType = (if (map.containsKey("mimeType")) map["mimeType"] else "") as String, + sizeOriginal = ((if (map.containsKey("sizeOriginal")) map["sizeOriginal"] else 0) as Number).toLong(), + sizeActual = ((if (map.containsKey("sizeActual")) map["sizeActual"] else 0) as Number).toLong(), + chunksTotal = ((if (map.containsKey("chunksTotal")) map["chunksTotal"] else 0) as Number).toLong(), + chunksUploaded = ((if (map.containsKey("chunksUploaded")) map["chunksUploaded"] else 0) as Number).toLong(), + encryption = (if (map.containsKey("encryption")) map["encryption"] else false) as Boolean, + compression = (if (map.containsKey("compression")) map["compression"] else "none") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/FileList.kt b/library/src/main/java/io/appwrite/models/FileList.kt index 7a462dc..752787b 100644 --- a/library/src/main/java/io/appwrite/models/FileList.kt +++ b/library/src/main/java/io/appwrite/models/FileList.kt @@ -30,7 +30,7 @@ data class FileList( fun from( map: Map, ) = FileList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), files = (map["files"] as List>).map { File.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Headers.kt b/library/src/main/java/io/appwrite/models/Headers.kt index 4fece1e..d2c2777 100644 --- a/library/src/main/java/io/appwrite/models/Headers.kt +++ b/library/src/main/java/io/appwrite/models/Headers.kt @@ -30,8 +30,8 @@ data class Headers( fun from( map: Map, ) = Headers( - name = map["name"] as String, - value = map["value"] as String, + name = (if (map.containsKey("name")) map["name"] else "") as String, + value = (if (map.containsKey("value")) map["value"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/Identity.kt b/library/src/main/java/io/appwrite/models/Identity.kt index 011c32e..0269400 100644 --- a/library/src/main/java/io/appwrite/models/Identity.kt +++ b/library/src/main/java/io/appwrite/models/Identity.kt @@ -93,17 +93,17 @@ data class Identity( fun from( map: Map, ) = Identity( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - userId = map["userId"] as String, - provider = map["provider"] as String, - providerUid = map["providerUid"] as String, - providerEmail = map["providerEmail"] as String, - providerAccessToken = map["providerAccessToken"] as String, - providerAccessTokenExpiry = map["providerAccessTokenExpiry"] as String, - providerRefreshToken = map["providerRefreshToken"] as String, - providerIdToken = map["providerIdToken"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, + provider = (if (map.containsKey("provider")) map["provider"] else "") as String, + providerUid = (if (map.containsKey("providerUid")) map["providerUid"] else "") as String, + providerEmail = (if (map.containsKey("providerEmail")) map["providerEmail"] else "") as String, + providerAccessToken = (if (map.containsKey("providerAccessToken")) map["providerAccessToken"] else "") as String, + providerAccessTokenExpiry = (if (map.containsKey("providerAccessTokenExpiry")) map["providerAccessTokenExpiry"] else "") as String, + providerRefreshToken = (if (map.containsKey("providerRefreshToken")) map["providerRefreshToken"] else "") as String, + providerIdToken = (if (map.containsKey("providerIdToken")) map["providerIdToken"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/IdentityList.kt b/library/src/main/java/io/appwrite/models/IdentityList.kt index b92f4e6..e91cf08 100644 --- a/library/src/main/java/io/appwrite/models/IdentityList.kt +++ b/library/src/main/java/io/appwrite/models/IdentityList.kt @@ -30,7 +30,7 @@ data class IdentityList( fun from( map: Map, ) = IdentityList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), identities = (map["identities"] as List>).map { Identity.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Jwt.kt b/library/src/main/java/io/appwrite/models/Jwt.kt index c188a85..7b27865 100644 --- a/library/src/main/java/io/appwrite/models/Jwt.kt +++ b/library/src/main/java/io/appwrite/models/Jwt.kt @@ -23,7 +23,7 @@ data class Jwt( fun from( map: Map, ) = Jwt( - jwt = map["jwt"] as String, + jwt = (if (map.containsKey("jwt")) map["jwt"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/Language.kt b/library/src/main/java/io/appwrite/models/Language.kt index be1f30e..01eb45b 100644 --- a/library/src/main/java/io/appwrite/models/Language.kt +++ b/library/src/main/java/io/appwrite/models/Language.kt @@ -37,9 +37,9 @@ data class Language( fun from( map: Map, ) = Language( - name = map["name"] as String, - code = map["code"] as String, - nativeName = map["nativeName"] as String, + name = (if (map.containsKey("name")) map["name"] else "") as String, + code = (if (map.containsKey("code")) map["code"] else "") as String, + nativeName = (if (map.containsKey("nativeName")) map["nativeName"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/LanguageList.kt b/library/src/main/java/io/appwrite/models/LanguageList.kt index e1b0e6e..c7f8788 100644 --- a/library/src/main/java/io/appwrite/models/LanguageList.kt +++ b/library/src/main/java/io/appwrite/models/LanguageList.kt @@ -30,7 +30,7 @@ data class LanguageList( fun from( map: Map, ) = LanguageList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), languages = (map["languages"] as List>).map { Language.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Locale.kt b/library/src/main/java/io/appwrite/models/Locale.kt index 689de89..dc6a1ad 100644 --- a/library/src/main/java/io/appwrite/models/Locale.kt +++ b/library/src/main/java/io/appwrite/models/Locale.kt @@ -142,13 +142,13 @@ data class Locale( fun from( map: Map, ) = Locale( - ip = map["ip"] as String, - countryCode = map["countryCode"] as String, - country = map["country"] as String, - continentCode = map["continentCode"] as String, - continent = map["continent"] as String, - eu = map["eu"] as Boolean, - currency = map["currency"] as String, + ip = (if (map.containsKey("ip")) map["ip"] else "") as String, + countryCode = (if (map.containsKey("countryCode")) map["countryCode"] else "") as String, + country = (if (map.containsKey("country")) map["country"] else "") as String, + continentCode = (if (map.containsKey("continentCode")) map["continentCode"] else "") as String, + continent = (if (map.containsKey("continent")) map["continent"] else "") as String, + eu = (if (map.containsKey("eu")) map["eu"] else false) as Boolean, + currency = (if (map.containsKey("currency")) map["currency"] else "") as String, city = map["city"] as? String, timeZone = map["timeZone"] as? String, postalCode = map["postalCode"] as? String, diff --git a/library/src/main/java/io/appwrite/models/LocaleCode.kt b/library/src/main/java/io/appwrite/models/LocaleCode.kt index 602d9ed..3bee528 100644 --- a/library/src/main/java/io/appwrite/models/LocaleCode.kt +++ b/library/src/main/java/io/appwrite/models/LocaleCode.kt @@ -30,8 +30,8 @@ data class LocaleCode( fun from( map: Map, ) = LocaleCode( - code = map["code"] as String, - name = map["name"] as String, + code = (if (map.containsKey("code")) map["code"] else "") as String, + name = (if (map.containsKey("name")) map["name"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/LocaleCodeList.kt b/library/src/main/java/io/appwrite/models/LocaleCodeList.kt index e0c568a..9d50e77 100644 --- a/library/src/main/java/io/appwrite/models/LocaleCodeList.kt +++ b/library/src/main/java/io/appwrite/models/LocaleCodeList.kt @@ -30,7 +30,7 @@ data class LocaleCodeList( fun from( map: Map, ) = LocaleCodeList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), localeCodes = (map["localeCodes"] as List>).map { LocaleCode.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Membership.kt b/library/src/main/java/io/appwrite/models/Membership.kt index 7d5b963..3d0c37b 100644 --- a/library/src/main/java/io/appwrite/models/Membership.kt +++ b/library/src/main/java/io/appwrite/models/Membership.kt @@ -121,21 +121,21 @@ data class Membership( fun from( map: Map, ) = Membership( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - userId = map["userId"] as String, - userName = map["userName"] as String, - userEmail = map["userEmail"] as String, - userPhone = map["userPhone"] as String, - teamId = map["teamId"] as String, - teamName = map["teamName"] as String, - invited = map["invited"] as String, - joined = map["joined"] as String, - confirm = map["confirm"] as Boolean, - mfa = map["mfa"] as Boolean, - userAccessedAt = map["userAccessedAt"] as String, - roles = map["roles"] as List, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, + userName = (if (map.containsKey("userName")) map["userName"] else "") as String, + userEmail = (if (map.containsKey("userEmail")) map["userEmail"] else "") as String, + userPhone = (if (map.containsKey("userPhone")) map["userPhone"] else "") as String, + teamId = (if (map.containsKey("teamId")) map["teamId"] else "") as String, + teamName = (if (map.containsKey("teamName")) map["teamName"] else "") as String, + invited = (if (map.containsKey("invited")) map["invited"] else "") as String, + joined = (if (map.containsKey("joined")) map["joined"] else "") as String, + confirm = (if (map.containsKey("confirm")) map["confirm"] else false) as Boolean, + mfa = (if (map.containsKey("mfa")) map["mfa"] else false) as Boolean, + userAccessedAt = (if (map.containsKey("userAccessedAt")) map["userAccessedAt"] else "") as String, + roles = (if (map.containsKey("roles")) map["roles"] else listOf()) as List, ) } } diff --git a/library/src/main/java/io/appwrite/models/MembershipList.kt b/library/src/main/java/io/appwrite/models/MembershipList.kt index 8376bc9..cc3a1f1 100644 --- a/library/src/main/java/io/appwrite/models/MembershipList.kt +++ b/library/src/main/java/io/appwrite/models/MembershipList.kt @@ -30,7 +30,7 @@ data class MembershipList( fun from( map: Map, ) = MembershipList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), memberships = (map["memberships"] as List>).map { Membership.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/MfaChallenge.kt b/library/src/main/java/io/appwrite/models/MfaChallenge.kt index b3e9f6b..c17e792 100644 --- a/library/src/main/java/io/appwrite/models/MfaChallenge.kt +++ b/library/src/main/java/io/appwrite/models/MfaChallenge.kt @@ -44,10 +44,10 @@ data class MfaChallenge( fun from( map: Map, ) = MfaChallenge( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - userId = map["userId"] as String, - expire = map["expire"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, + expire = (if (map.containsKey("expire")) map["expire"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/MfaFactors.kt b/library/src/main/java/io/appwrite/models/MfaFactors.kt index 20f7bb3..42872fa 100644 --- a/library/src/main/java/io/appwrite/models/MfaFactors.kt +++ b/library/src/main/java/io/appwrite/models/MfaFactors.kt @@ -51,11 +51,11 @@ data class MfaFactors( fun from( map: Map, ) = MfaFactors( - totp = map["totp"] as Boolean, - phone = map["phone"] as Boolean, - email = map["email"] as Boolean, - recoveryCode = map["recoveryCode"] as Boolean, - custom = map["custom"] as Boolean, + totp = (if (map.containsKey("totp")) map["totp"] else false) as Boolean, + phone = (if (map.containsKey("phone")) map["phone"] else false) as Boolean, + email = (if (map.containsKey("email")) map["email"] else false) as Boolean, + recoveryCode = (if (map.containsKey("recoveryCode")) map["recoveryCode"] else false) as Boolean, + custom = (if (map.containsKey("custom")) map["custom"] else false) as Boolean, ) } } diff --git a/library/src/main/java/io/appwrite/models/MfaRecoveryCodes.kt b/library/src/main/java/io/appwrite/models/MfaRecoveryCodes.kt index a896749..25e783c 100644 --- a/library/src/main/java/io/appwrite/models/MfaRecoveryCodes.kt +++ b/library/src/main/java/io/appwrite/models/MfaRecoveryCodes.kt @@ -23,7 +23,7 @@ data class MfaRecoveryCodes( fun from( map: Map, ) = MfaRecoveryCodes( - recoveryCodes = map["recoveryCodes"] as List, + recoveryCodes = (if (map.containsKey("recoveryCodes")) map["recoveryCodes"] else listOf()) as List, ) } } diff --git a/library/src/main/java/io/appwrite/models/MfaType.kt b/library/src/main/java/io/appwrite/models/MfaType.kt index e20b7f6..5b7b971 100644 --- a/library/src/main/java/io/appwrite/models/MfaType.kt +++ b/library/src/main/java/io/appwrite/models/MfaType.kt @@ -30,8 +30,8 @@ data class MfaType( fun from( map: Map, ) = MfaType( - secret = map["secret"] as String, - uri = map["uri"] as String, + secret = (if (map.containsKey("secret")) map["secret"] else "") as String, + uri = (if (map.containsKey("uri")) map["uri"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/Oauth2Approve.kt b/library/src/main/java/io/appwrite/models/Oauth2Approve.kt index e09ab9e..0aabf4d 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2Approve.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2Approve.kt @@ -23,7 +23,7 @@ data class Oauth2Approve( fun from( map: Map, ) = Oauth2Approve( - redirectUrl = map["redirectUrl"] as String, + redirectUrl = (if (map.containsKey("redirectUrl")) map["redirectUrl"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/Oauth2Authorize.kt b/library/src/main/java/io/appwrite/models/Oauth2Authorize.kt index e0812f7..fe878e3 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2Authorize.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2Authorize.kt @@ -30,8 +30,8 @@ data class Oauth2Authorize( fun from( map: Map, ) = Oauth2Authorize( - grantId = map["grantId"] as String, - redirectUrl = map["redirectUrl"] as String, + grantId = (if (map.containsKey("grantId")) map["grantId"] else "") as String, + redirectUrl = (if (map.containsKey("redirectUrl")) map["redirectUrl"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/Oauth2Consent.kt b/library/src/main/java/io/appwrite/models/Oauth2Consent.kt index 7769e9b..28cde91 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2Consent.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2Consent.kt @@ -86,16 +86,16 @@ data class Oauth2Consent( fun from( map: Map, ) = Oauth2Consent( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - userId = map["userId"] as String, - appId = map["appId"] as String, - cimdUrl = map["cimdUrl"] as String, - scopes = map["scopes"] as List, - resources = map["resources"] as List, - authorizationDetails = map["authorizationDetails"] as String, - expire = map["expire"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, + appId = (if (map.containsKey("appId")) map["appId"] else "") as String, + cimdUrl = (if (map.containsKey("cimdUrl")) map["cimdUrl"] else "") as String, + scopes = (if (map.containsKey("scopes")) map["scopes"] else listOf()) as List, + resources = (if (map.containsKey("resources")) map["resources"] else listOf()) as List, + authorizationDetails = (if (map.containsKey("authorizationDetails")) map["authorizationDetails"] else "[]") as String, + expire = (if (map.containsKey("expire")) map["expire"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/Oauth2ConsentList.kt b/library/src/main/java/io/appwrite/models/Oauth2ConsentList.kt index da6acd3..3516972 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2ConsentList.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2ConsentList.kt @@ -30,7 +30,7 @@ data class Oauth2ConsentList( fun from( map: Map, ) = Oauth2ConsentList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), consents = (map["consents"] as List>).map { Oauth2Consent.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Oauth2ConsentToken.kt b/library/src/main/java/io/appwrite/models/Oauth2ConsentToken.kt index 31f6249..1f5c1df 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2ConsentToken.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2ConsentToken.kt @@ -93,17 +93,17 @@ data class Oauth2ConsentToken( fun from( map: Map, ) = Oauth2ConsentToken( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - consentId = map["consentId"] as String, - userId = map["userId"] as String, - appId = map["appId"] as String, - cimdUrl = map["cimdUrl"] as String, - scopes = map["scopes"] as List, - resources = map["resources"] as List, - authorizationDetails = map["authorizationDetails"] as String, - expire = map["expire"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + consentId = (if (map.containsKey("consentId")) map["consentId"] else "") as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, + appId = (if (map.containsKey("appId")) map["appId"] else "") as String, + cimdUrl = (if (map.containsKey("cimdUrl")) map["cimdUrl"] else "") as String, + scopes = (if (map.containsKey("scopes")) map["scopes"] else listOf()) as List, + resources = (if (map.containsKey("resources")) map["resources"] else listOf()) as List, + authorizationDetails = (if (map.containsKey("authorizationDetails")) map["authorizationDetails"] else "[]") as String, + expire = (if (map.containsKey("expire")) map["expire"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/Oauth2ConsentTokenList.kt b/library/src/main/java/io/appwrite/models/Oauth2ConsentTokenList.kt index 09278f4..0bc789f 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2ConsentTokenList.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2ConsentTokenList.kt @@ -30,7 +30,7 @@ data class Oauth2ConsentTokenList( fun from( map: Map, ) = Oauth2ConsentTokenList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), tokens = (map["tokens"] as List>).map { Oauth2ConsentToken.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Oauth2DeviceAuthorization.kt b/library/src/main/java/io/appwrite/models/Oauth2DeviceAuthorization.kt index 58c7e5e..f4ca6e6 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2DeviceAuthorization.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2DeviceAuthorization.kt @@ -58,12 +58,12 @@ data class Oauth2DeviceAuthorization( fun from( map: Map, ) = Oauth2DeviceAuthorization( - device_code = map["device_code"] as String, - user_code = map["user_code"] as String, - verification_uri = map["verification_uri"] as String, - verification_uri_complete = map["verification_uri_complete"] as String, - expires_in = (map["expires_in"] as Number).toLong(), - interval = (map["interval"] as Number).toLong(), + device_code = (if (map.containsKey("device_code")) map["device_code"] else "") as String, + user_code = (if (map.containsKey("user_code")) map["user_code"] else "") as String, + verification_uri = (if (map.containsKey("verification_uri")) map["verification_uri"] else "") as String, + verification_uri_complete = (if (map.containsKey("verification_uri_complete")) map["verification_uri_complete"] else "") as String, + expires_in = ((if (map.containsKey("expires_in")) map["expires_in"] else 0) as Number).toLong(), + interval = ((if (map.containsKey("interval")) map["interval"] else 0) as Number).toLong(), ) } } diff --git a/library/src/main/java/io/appwrite/models/Oauth2Grant.kt b/library/src/main/java/io/appwrite/models/Oauth2Grant.kt index ef1a7c3..914b6f3 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2Grant.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2Grant.kt @@ -100,18 +100,18 @@ data class Oauth2Grant( fun from( map: Map, ) = Oauth2Grant( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - userId = map["userId"] as String, - appId = map["appId"] as String, - scopes = map["scopes"] as List, - resources = map["resources"] as List, - authorizationDetails = map["authorizationDetails"] as String, - prompt = map["prompt"] as String, - redirectUri = map["redirectUri"] as String, - authTime = (map["authTime"] as Number).toLong(), - expire = map["expire"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, + appId = (if (map.containsKey("appId")) map["appId"] else "") as String, + scopes = (if (map.containsKey("scopes")) map["scopes"] else listOf()) as List, + resources = (if (map.containsKey("resources")) map["resources"] else listOf()) as List, + authorizationDetails = (if (map.containsKey("authorizationDetails")) map["authorizationDetails"] else "[]") as String, + prompt = (if (map.containsKey("prompt")) map["prompt"] else "") as String, + redirectUri = (if (map.containsKey("redirectUri")) map["redirectUri"] else "") as String, + authTime = ((if (map.containsKey("authTime")) map["authTime"] else 0) as Number).toLong(), + expire = (if (map.containsKey("expire")) map["expire"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/Oauth2Organization.kt b/library/src/main/java/io/appwrite/models/Oauth2Organization.kt index 605916a..47b6a8f 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2Organization.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2Organization.kt @@ -23,7 +23,7 @@ data class Oauth2Organization( fun from( map: Map, ) = Oauth2Organization( - id = map["\$id"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/Oauth2OrganizationList.kt b/library/src/main/java/io/appwrite/models/Oauth2OrganizationList.kt index b90ee63..9b98c6c 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2OrganizationList.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2OrganizationList.kt @@ -30,7 +30,7 @@ data class Oauth2OrganizationList( fun from( map: Map, ) = Oauth2OrganizationList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), organizations = (map["organizations"] as List>).map { Oauth2Organization.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Oauth2PAR.kt b/library/src/main/java/io/appwrite/models/Oauth2PAR.kt index 94d175e..1091bdd 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2PAR.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2PAR.kt @@ -30,8 +30,8 @@ data class Oauth2PAR( fun from( map: Map, ) = Oauth2PAR( - request_uri = map["request_uri"] as String, - expires_in = (map["expires_in"] as Number).toLong(), + request_uri = (if (map.containsKey("request_uri")) map["request_uri"] else "") as String, + expires_in = ((if (map.containsKey("expires_in")) map["expires_in"] else 0) as Number).toLong(), ) } } diff --git a/library/src/main/java/io/appwrite/models/Oauth2Project.kt b/library/src/main/java/io/appwrite/models/Oauth2Project.kt index eb085dc..95c79e0 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2Project.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2Project.kt @@ -37,9 +37,9 @@ data class Oauth2Project( fun from( map: Map, ) = Oauth2Project( - id = map["\$id"] as String, - region = map["region"] as String, - endpoint = map["endpoint"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + region = (if (map.containsKey("region")) map["region"] else "") as String, + endpoint = (if (map.containsKey("endpoint")) map["endpoint"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/Oauth2ProjectList.kt b/library/src/main/java/io/appwrite/models/Oauth2ProjectList.kt index 551b9ee..4c11bfe 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2ProjectList.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2ProjectList.kt @@ -30,7 +30,7 @@ data class Oauth2ProjectList( fun from( map: Map, ) = Oauth2ProjectList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), projects = (map["projects"] as List>).map { Oauth2Project.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Oauth2Reject.kt b/library/src/main/java/io/appwrite/models/Oauth2Reject.kt index b23f308..42b3a3a 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2Reject.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2Reject.kt @@ -23,7 +23,7 @@ data class Oauth2Reject( fun from( map: Map, ) = Oauth2Reject( - redirectUrl = map["redirectUrl"] as String, + redirectUrl = (if (map.containsKey("redirectUrl")) map["redirectUrl"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/Oauth2Token.kt b/library/src/main/java/io/appwrite/models/Oauth2Token.kt index f36f776..53547c2 100644 --- a/library/src/main/java/io/appwrite/models/Oauth2Token.kt +++ b/library/src/main/java/io/appwrite/models/Oauth2Token.kt @@ -65,11 +65,11 @@ data class Oauth2Token( fun from( map: Map, ) = Oauth2Token( - access_token = map["access_token"] as String, - token_type = map["token_type"] as String, - expires_in = (map["expires_in"] as Number).toLong(), - refresh_token = map["refresh_token"] as String, - scope = map["scope"] as String, + access_token = (if (map.containsKey("access_token")) map["access_token"] else "") as String, + token_type = (if (map.containsKey("token_type")) map["token_type"] else "Bearer") as String, + expires_in = ((if (map.containsKey("expires_in")) map["expires_in"] else 0) as Number).toLong(), + refresh_token = (if (map.containsKey("refresh_token")) map["refresh_token"] else "") as String, + scope = (if (map.containsKey("scope")) map["scope"] else "") as String, authorization_details = map["authorization_details"] as? String, id_token = map["id_token"] as? String, ) diff --git a/library/src/main/java/io/appwrite/models/Passkey.kt b/library/src/main/java/io/appwrite/models/Passkey.kt new file mode 100644 index 0000000..90f0e49 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/Passkey.kt @@ -0,0 +1,61 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * Passkey + */ +data class Passkey( + /** + * Passkey ID. + */ + @SerializedName("\$id") + val id: String, + + /** + * Passkey creation date in ISO 8601 format. + */ + @SerializedName("\$createdAt") + val createdAt: String, + + /** + * Passkey update date in ISO 8601 format. + */ + @SerializedName("\$updatedAt") + val updatedAt: String, + + /** + * Passkey name. + */ + @SerializedName("name") + val name: String, + + /** + * Most recent sign-in with this passkey in ISO 8601 format. Empty until the passkey is used to sign in. + */ + @SerializedName("accessedAt") + val accessedAt: String, + +) { + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "\$createdAt" to createdAt as Any, + "\$updatedAt" to updatedAt as Any, + "name" to name as Any, + "accessedAt" to accessedAt as Any, + ) + + companion object { + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = Passkey( + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + name = (if (map.containsKey("name")) map["name"] else "") as String, + accessedAt = (if (map.containsKey("accessedAt")) map["accessedAt"] else "") as String, + ) + } +} diff --git a/library/src/main/java/io/appwrite/models/PasskeyChallenge.kt b/library/src/main/java/io/appwrite/models/PasskeyChallenge.kt new file mode 100644 index 0000000..dcdcb77 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/PasskeyChallenge.kt @@ -0,0 +1,61 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * Passkey Challenge + */ +data class PasskeyChallenge( + /** + * Challenge ID. When signing in, pass it back with the credential to receive a token. + */ + @SerializedName("\$id") + val id: String, + + /** + * Challenge creation date in ISO 8601 format. + */ + @SerializedName("\$createdAt") + val createdAt: String, + + /** + * ID of the passkey being registered. Empty for sign-in challenges. + */ + @SerializedName("passkeyId") + val passkeyId: String, + + /** + * Challenge expiration date in ISO 8601 format. + */ + @SerializedName("expire") + val expire: String, + + /** + * WebAuthn options in JSON form. Pass them to `PublicKeyCredential.parseCreationOptionsFromJSON()` when registering, or `PublicKeyCredential.parseRequestOptionsFromJSON()` when signing in. + */ + @SerializedName("publicKey") + val publicKey: Map, + +) { + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "\$createdAt" to createdAt as Any, + "passkeyId" to passkeyId as Any, + "expire" to expire as Any, + "publicKey" to publicKey as Any, + ) + + companion object { + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = PasskeyChallenge( + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + passkeyId = (if (map.containsKey("passkeyId")) map["passkeyId"] else "") as String, + expire = (if (map.containsKey("expire")) map["expire"] else "") as String, + publicKey = (if (map.containsKey("publicKey")) map["publicKey"] else mapOf()) as Map, + ) + } +} diff --git a/library/src/main/java/io/appwrite/models/PasskeyList.kt b/library/src/main/java/io/appwrite/models/PasskeyList.kt new file mode 100644 index 0000000..41b1df3 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/PasskeyList.kt @@ -0,0 +1,37 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * Passkeys List + */ +data class PasskeyList( + /** + * Total number of passkeys that matched your query. + */ + @SerializedName("total") + val total: Long, + + /** + * List of passkeys. + */ + @SerializedName("passkeys") + val passkeys: List, + +) { + fun toMap(): Map = mapOf( + "total" to total as Any, + "passkeys" to passkeys.map { it.toMap() } as Any, + ) + + companion object { + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = PasskeyList( + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), + passkeys = (map["passkeys"] as List>).map { Passkey.from(map = it) }, + ) + } +} diff --git a/library/src/main/java/io/appwrite/models/Phone.kt b/library/src/main/java/io/appwrite/models/Phone.kt index 74bfa51..12c8eb6 100644 --- a/library/src/main/java/io/appwrite/models/Phone.kt +++ b/library/src/main/java/io/appwrite/models/Phone.kt @@ -37,9 +37,9 @@ data class Phone( fun from( map: Map, ) = Phone( - code = map["code"] as String, - countryCode = map["countryCode"] as String, - countryName = map["countryName"] as String, + code = (if (map.containsKey("code")) map["code"] else "") as String, + countryCode = (if (map.containsKey("countryCode")) map["countryCode"] else "") as String, + countryName = (if (map.containsKey("countryName")) map["countryName"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/PhoneList.kt b/library/src/main/java/io/appwrite/models/PhoneList.kt index fc0ffa3..72df666 100644 --- a/library/src/main/java/io/appwrite/models/PhoneList.kt +++ b/library/src/main/java/io/appwrite/models/PhoneList.kt @@ -30,7 +30,7 @@ data class PhoneList( fun from( map: Map, ) = PhoneList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), phones = (map["phones"] as List>).map { Phone.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Presence.kt b/library/src/main/java/io/appwrite/models/Presence.kt index c7f6073..47d9951 100644 --- a/library/src/main/java/io/appwrite/models/Presence.kt +++ b/library/src/main/java/io/appwrite/models/Presence.kt @@ -79,13 +79,13 @@ data class Presence( fun from( map: Map, ) = Presence( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, permissions = map["\$permissions"] as List, - userId = map["userId"] as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, status = map["status"] as? String, - source = map["source"] as String, + source = (if (map.containsKey("source")) map["source"] else "") as String, expiresAt = map["expiresAt"] as? String, metadata = map["metadata"] as? Map, ) diff --git a/library/src/main/java/io/appwrite/models/PresenceList.kt b/library/src/main/java/io/appwrite/models/PresenceList.kt index b69d3e1..937840a 100644 --- a/library/src/main/java/io/appwrite/models/PresenceList.kt +++ b/library/src/main/java/io/appwrite/models/PresenceList.kt @@ -30,7 +30,7 @@ data class PresenceList( fun from( map: Map, ) = PresenceList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), presences = (map["presences"] as List>).map { Presence.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Row.kt b/library/src/main/java/io/appwrite/models/Row.kt index 1f19010..2a50758 100644 --- a/library/src/main/java/io/appwrite/models/Row.kt +++ b/library/src/main/java/io/appwrite/models/Row.kt @@ -92,12 +92,12 @@ data class Row( map: Map, nestedType: Class ) = Row( - id = map["\$id"] as String, - sequence = map["\$sequence"] as String, - tableId = map["\$tableId"] as String, - databaseId = map["\$databaseId"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + sequence = (if (map.containsKey("\$sequence")) map["\$sequence"] else "") as String, + tableId = (if (map.containsKey("\$tableId")) map["\$tableId"] else "") as String, + databaseId = (if (map.containsKey("\$databaseId")) map["\$databaseId"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, permissions = map["\$permissions"] as List, data = map["data"]?.jsonCast(to = nestedType) ?: map.jsonCast(to = nestedType) ) diff --git a/library/src/main/java/io/appwrite/models/RowList.kt b/library/src/main/java/io/appwrite/models/RowList.kt index f9c8f61..501b16f 100644 --- a/library/src/main/java/io/appwrite/models/RowList.kt +++ b/library/src/main/java/io/appwrite/models/RowList.kt @@ -39,7 +39,7 @@ data class RowList( map: Map, nestedType: Class ) = RowList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), rows = (map["rows"] as List>).map { Row.from(map = it, nestedType) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Session.kt b/library/src/main/java/io/appwrite/models/Session.kt index c9c3950..884d581 100644 --- a/library/src/main/java/io/appwrite/models/Session.kt +++ b/library/src/main/java/io/appwrite/models/Session.kt @@ -219,35 +219,35 @@ data class Session( fun from( map: Map, ) = Session( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - userId = map["userId"] as String, - expire = map["expire"] as String, - provider = map["provider"] as String, - providerUid = map["providerUid"] as String, - providerAccessToken = map["providerAccessToken"] as String, - providerAccessTokenExpiry = map["providerAccessTokenExpiry"] as String, - providerRefreshToken = map["providerRefreshToken"] as String, - ip = map["ip"] as String, - osCode = map["osCode"] as String, - osName = map["osName"] as String, - osVersion = map["osVersion"] as String, - clientType = map["clientType"] as String, - clientCode = map["clientCode"] as String, - clientName = map["clientName"] as String, - clientVersion = map["clientVersion"] as String, - clientEngine = map["clientEngine"] as String, - clientEngineVersion = map["clientEngineVersion"] as String, - deviceName = map["deviceName"] as String, - deviceBrand = map["deviceBrand"] as String, - deviceModel = map["deviceModel"] as String, - countryCode = map["countryCode"] as String, - countryName = map["countryName"] as String, - current = map["current"] as Boolean, - factors = map["factors"] as List, - secret = map["secret"] as String, - mfaUpdatedAt = map["mfaUpdatedAt"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, + expire = (if (map.containsKey("expire")) map["expire"] else "") as String, + provider = (if (map.containsKey("provider")) map["provider"] else "") as String, + providerUid = (if (map.containsKey("providerUid")) map["providerUid"] else "") as String, + providerAccessToken = (if (map.containsKey("providerAccessToken")) map["providerAccessToken"] else "") as String, + providerAccessTokenExpiry = (if (map.containsKey("providerAccessTokenExpiry")) map["providerAccessTokenExpiry"] else "") as String, + providerRefreshToken = (if (map.containsKey("providerRefreshToken")) map["providerRefreshToken"] else "") as String, + ip = (if (map.containsKey("ip")) map["ip"] else "") as String, + osCode = (if (map.containsKey("osCode")) map["osCode"] else "") as String, + osName = (if (map.containsKey("osName")) map["osName"] else "") as String, + osVersion = (if (map.containsKey("osVersion")) map["osVersion"] else "") as String, + clientType = (if (map.containsKey("clientType")) map["clientType"] else "") as String, + clientCode = (if (map.containsKey("clientCode")) map["clientCode"] else "") as String, + clientName = (if (map.containsKey("clientName")) map["clientName"] else "") as String, + clientVersion = (if (map.containsKey("clientVersion")) map["clientVersion"] else "") as String, + clientEngine = (if (map.containsKey("clientEngine")) map["clientEngine"] else "") as String, + clientEngineVersion = (if (map.containsKey("clientEngineVersion")) map["clientEngineVersion"] else "") as String, + deviceName = (if (map.containsKey("deviceName")) map["deviceName"] else "") as String, + deviceBrand = (if (map.containsKey("deviceBrand")) map["deviceBrand"] else "") as String, + deviceModel = (if (map.containsKey("deviceModel")) map["deviceModel"] else "") as String, + countryCode = (if (map.containsKey("countryCode")) map["countryCode"] else "") as String, + countryName = (if (map.containsKey("countryName")) map["countryName"] else "") as String, + current = (if (map.containsKey("current")) map["current"] else false) as Boolean, + factors = (if (map.containsKey("factors")) map["factors"] else listOf()) as List, + secret = (if (map.containsKey("secret")) map["secret"] else "") as String, + mfaUpdatedAt = (if (map.containsKey("mfaUpdatedAt")) map["mfaUpdatedAt"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/SessionList.kt b/library/src/main/java/io/appwrite/models/SessionList.kt index bda39fc..6540525 100644 --- a/library/src/main/java/io/appwrite/models/SessionList.kt +++ b/library/src/main/java/io/appwrite/models/SessionList.kt @@ -30,7 +30,7 @@ data class SessionList( fun from( map: Map, ) = SessionList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), sessions = (map["sessions"] as List>).map { Session.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Subscriber.kt b/library/src/main/java/io/appwrite/models/Subscriber.kt index 931b65d..adcd8c5 100644 --- a/library/src/main/java/io/appwrite/models/Subscriber.kt +++ b/library/src/main/java/io/appwrite/models/Subscriber.kt @@ -79,15 +79,15 @@ data class Subscriber( fun from( map: Map, ) = Subscriber( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - targetId = map["targetId"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + targetId = (if (map.containsKey("targetId")) map["targetId"] else "") as String, target = Target.from(map = map["target"] as Map), - userId = map["userId"] as String, - userName = map["userName"] as String, - topicId = map["topicId"] as String, - providerType = map["providerType"] as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, + userName = (if (map.containsKey("userName")) map["userName"] else "") as String, + topicId = (if (map.containsKey("topicId")) map["topicId"] else "") as String, + providerType = (if (map.containsKey("providerType")) map["providerType"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/Target.kt b/library/src/main/java/io/appwrite/models/Target.kt index 3e89e08..d67a716 100644 --- a/library/src/main/java/io/appwrite/models/Target.kt +++ b/library/src/main/java/io/appwrite/models/Target.kt @@ -79,15 +79,15 @@ data class Target( fun from( map: Map, ) = Target( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - name = map["name"] as String, - userId = map["userId"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + name = (if (map.containsKey("name")) map["name"] else "") as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, providerId = map["providerId"] as? String, - providerType = map["providerType"] as String, - identifier = map["identifier"] as String, - expired = map["expired"] as Boolean, + providerType = (if (map.containsKey("providerType")) map["providerType"] else "") as String, + identifier = (if (map.containsKey("identifier")) map["identifier"] else "") as String, + expired = (if (map.containsKey("expired")) map["expired"] else false) as Boolean, ) } } diff --git a/library/src/main/java/io/appwrite/models/Team.kt b/library/src/main/java/io/appwrite/models/Team.kt index 6cd7dbc..dc780c8 100644 --- a/library/src/main/java/io/appwrite/models/Team.kt +++ b/library/src/main/java/io/appwrite/models/Team.kt @@ -75,11 +75,11 @@ data class Team( map: Map, nestedType: Class ) = Team( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - name = map["name"] as String, - total = (map["total"] as Number).toLong(), + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + name = (if (map.containsKey("name")) map["name"] else "") as String, + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), prefs = Preferences.from(map = map["prefs"] as Map, nestedType), ) } diff --git a/library/src/main/java/io/appwrite/models/TeamList.kt b/library/src/main/java/io/appwrite/models/TeamList.kt index 8e490f5..901999d 100644 --- a/library/src/main/java/io/appwrite/models/TeamList.kt +++ b/library/src/main/java/io/appwrite/models/TeamList.kt @@ -39,7 +39,7 @@ data class TeamList( map: Map, nestedType: Class ) = TeamList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), teams = (map["teams"] as List>).map { Team.from(map = it, nestedType) }, ) } diff --git a/library/src/main/java/io/appwrite/models/Token.kt b/library/src/main/java/io/appwrite/models/Token.kt index 625e308..c376239 100644 --- a/library/src/main/java/io/appwrite/models/Token.kt +++ b/library/src/main/java/io/appwrite/models/Token.kt @@ -58,12 +58,12 @@ data class Token( fun from( map: Map, ) = Token( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - userId = map["userId"] as String, - secret = map["secret"] as String, - expire = map["expire"] as String, - phrase = map["phrase"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, + secret = (if (map.containsKey("secret")) map["secret"] else "") as String, + expire = (if (map.containsKey("expire")) map["expire"] else "") as String, + phrase = (if (map.containsKey("phrase")) map["phrase"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/TokenSecret.kt b/library/src/main/java/io/appwrite/models/TokenSecret.kt new file mode 100644 index 0000000..fe2dd92 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/TokenSecret.kt @@ -0,0 +1,69 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * Token Secret + */ +data class TokenSecret( + /** + * Token ID. + */ + @SerializedName("\$id") + val id: String, + + /** + * Token creation date in ISO 8601 format. + */ + @SerializedName("\$createdAt") + val createdAt: String, + + /** + * User ID. + */ + @SerializedName("userId") + val userId: String, + + /** + * Token secret key. Exchange it for a session with the create session endpoint. + */ + @SerializedName("secret") + val secret: String, + + /** + * Token expiration date in ISO 8601 format. + */ + @SerializedName("expire") + val expire: String, + + /** + * Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. + */ + @SerializedName("phrase") + val phrase: String, + +) { + fun toMap(): Map = mapOf( + "\$id" to id as Any, + "\$createdAt" to createdAt as Any, + "userId" to userId as Any, + "secret" to secret as Any, + "expire" to expire as Any, + "phrase" to phrase as Any, + ) + + companion object { + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = TokenSecret( + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + userId = (if (map.containsKey("userId")) map["userId"] else "") as String, + secret = (if (map.containsKey("secret")) map["secret"] else "") as String, + expire = (if (map.containsKey("expire")) map["expire"] else "") as String, + phrase = (if (map.containsKey("phrase")) map["phrase"] else "") as String, + ) + } +} diff --git a/library/src/main/java/io/appwrite/models/Transaction.kt b/library/src/main/java/io/appwrite/models/Transaction.kt index 8f09860..bb5f39b 100644 --- a/library/src/main/java/io/appwrite/models/Transaction.kt +++ b/library/src/main/java/io/appwrite/models/Transaction.kt @@ -58,12 +58,12 @@ data class Transaction( fun from( map: Map, ) = Transaction( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - status = map["status"] as String, - operations = (map["operations"] as Number).toLong(), - expiresAt = map["expiresAt"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + status = (if (map.containsKey("status")) map["status"] else "pending") as String, + operations = ((if (map.containsKey("operations")) map["operations"] else 0) as Number).toLong(), + expiresAt = (if (map.containsKey("expiresAt")) map["expiresAt"] else "") as String, ) } } diff --git a/library/src/main/java/io/appwrite/models/TransactionList.kt b/library/src/main/java/io/appwrite/models/TransactionList.kt index c55a731..4537fba 100644 --- a/library/src/main/java/io/appwrite/models/TransactionList.kt +++ b/library/src/main/java/io/appwrite/models/TransactionList.kt @@ -30,7 +30,7 @@ data class TransactionList( fun from( map: Map, ) = TransactionList( - total = (map["total"] as Number).toLong(), + total = ((if (map.containsKey("total")) map["total"] else 0) as Number).toLong(), transactions = (map["transactions"] as List>).map { Transaction.from(map = it) }, ) } diff --git a/library/src/main/java/io/appwrite/models/User.kt b/library/src/main/java/io/appwrite/models/User.kt index 0eea3b0..019d40d 100644 --- a/library/src/main/java/io/appwrite/models/User.kt +++ b/library/src/main/java/io/appwrite/models/User.kt @@ -264,31 +264,31 @@ data class User( map: Map, nestedType: Class ) = User( - id = map["\$id"] as String, - createdAt = map["\$createdAt"] as String, - updatedAt = map["\$updatedAt"] as String, - name = map["name"] as String, + id = (if (map.containsKey("\$id")) map["\$id"] else "") as String, + createdAt = (if (map.containsKey("\$createdAt")) map["\$createdAt"] else "") as String, + updatedAt = (if (map.containsKey("\$updatedAt")) map["\$updatedAt"] else "") as String, + name = (if (map.containsKey("name")) map["name"] else "") as String, password = map["password"] as? String, hash = map["hash"] as? String, hashOptions = map["hashOptions"] as? Map, - registration = map["registration"] as String, - status = map["status"] as Boolean, - labels = map["labels"] as List, - passwordUpdate = map["passwordUpdate"] as String, - email = map["email"] as String, - phone = map["phone"] as String, - emailVerification = map["emailVerification"] as Boolean, + registration = (if (map.containsKey("registration")) map["registration"] else "") as String, + status = (if (map.containsKey("status")) map["status"] else true) as Boolean, + labels = (if (map.containsKey("labels")) map["labels"] else listOf()) as List, + passwordUpdate = (if (map.containsKey("passwordUpdate")) map["passwordUpdate"] else "") as String, + email = (if (map.containsKey("email")) map["email"] else "") as String, + phone = (if (map.containsKey("phone")) map["phone"] else "") as String, + emailVerification = (if (map.containsKey("emailVerification")) map["emailVerification"] else false) as Boolean, emailCanonical = map["emailCanonical"] as? String, emailIsFree = map["emailIsFree"] as? Boolean, emailIsDisposable = map["emailIsDisposable"] as? Boolean, emailIsCorporate = map["emailIsCorporate"] as? Boolean, emailIsCanonical = map["emailIsCanonical"] as? Boolean, passwordPwned = map["passwordPwned"] as? Boolean, - phoneVerification = map["phoneVerification"] as Boolean, - mfa = map["mfa"] as Boolean, + phoneVerification = (if (map.containsKey("phoneVerification")) map["phoneVerification"] else false) as Boolean, + mfa = (if (map.containsKey("mfa")) map["mfa"] else false) as Boolean, prefs = Preferences.from(map = map["prefs"] as Map, nestedType), targets = (map["targets"] as List>).map { Target.from(map = it) }, - accessedAt = map["accessedAt"] as String, + accessedAt = (if (map.containsKey("accessedAt")) map["accessedAt"] else "") as String, impersonator = map["impersonator"] as? Boolean, impersonatorUserId = map["impersonatorUserId"] as? String, ) diff --git a/library/src/main/java/io/appwrite/services/Account.kt b/library/src/main/java/io/appwrite/services/Account.kt index 8df3822..de1a93c 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -1200,6 +1200,219 @@ class Account(client: Client) : Service(client) { nestedType = classOf(), ) + /** + * Get the list of verified passkeys registered by the currently logged in user. + * + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter and order on the following attributes: $id, $createdAt, $updatedAt, name, accessedAt + * @param total When set to false, the total count returned will be 0 and will not be calculated. + * @return [io.appwrite.models.PasskeyList] + */ + @JvmOverloads + suspend fun listPasskeys( + queries: List? = null, + total: Boolean? = null, + ): io.appwrite.models.PasskeyList { + val apiPath = "/account/passkeys" + val apiParams = mutableMapOf( + "queries" to queries, + "total" to total, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.PasskeyList = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.PasskeyList.from(map = it as Map) + } + return client.call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.PasskeyList::class.java, + converter, + ) + } + + /** + * Start registering a passkey for the currently logged in user. The session must have signed in or completed an MFA challenge within the last 10 minutes. Pass the returned `publicKey` options to `navigator.credentials.create()`, then complete the registration with [Update passkey verification](/docs/references/cloud/client-web/account#updatePasskeyVerification). The passkey stays pending until verified, and the challenge expires after 5 minutes. + * + * @param passkeyId Passkey ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param name Passkey name, shown when listing passkeys. Max length: 128 chars. + * @return [io.appwrite.models.PasskeyChallenge] + */ + @JvmOverloads + suspend fun createPasskey( + passkeyId: String? = null, + name: String? = null, + ): io.appwrite.models.PasskeyChallenge { + val apiPath = "/account/passkeys" + val apiParams = mutableMapOf( + "passkeyId" to passkeyId, + "name" to name, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.PasskeyChallenge = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.PasskeyChallenge.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.PasskeyChallenge::class.java, + converter, + ) + } + + /** + * Get a verified passkey of the currently logged in user by its unique ID. + * + * @param passkeyId Passkey ID. + * @return [io.appwrite.models.Passkey] + */ + suspend fun getPasskey( + passkeyId: String, + ): io.appwrite.models.Passkey { + if (passkeyId.isEmpty()) { + throw AppwriteException("Missing required parameter: \"passkeyId\"") + } + val apiPath = ("/account/passkeys/{passkeyId}" + .replace("{passkeyId}", passkeyId) + ) + val apiParams = mutableMapOf() + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Passkey = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Passkey.from(map = it as Map) + } + return client.call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Passkey::class.java, + converter, + ) + } + + /** + * Rename a passkey of the currently logged in user. + * + * @param passkeyId Passkey ID. + * @param name Passkey name. Max length: 128 chars. + * @return [io.appwrite.models.Passkey] + */ + suspend fun updatePasskey( + passkeyId: String, + name: String, + ): io.appwrite.models.Passkey { + if (passkeyId.isEmpty()) { + throw AppwriteException("Missing required parameter: \"passkeyId\"") + } + val apiPath = ("/account/passkeys/{passkeyId}" + .replace("{passkeyId}", passkeyId) + ) + val apiParams = mutableMapOf( + "name" to name, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Passkey = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Passkey.from(map = it as Map) + } + return client.call( + "PATCH", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Passkey::class.java, + converter, + ) + } + + /** + * Delete a passkey from the currently logged in user. The passkey can no longer be used to sign in, although it may remain stored on the user's device. The session must have signed in or completed an MFA challenge within the last 10 minutes. + * + * @param passkeyId Passkey ID. + * @return [Any] + */ + suspend fun deletePasskey( + passkeyId: String, + ): Any { + if (passkeyId.isEmpty()) { + throw AppwriteException("Missing required parameter: \"passkeyId\"") + } + val apiPath = ("/account/passkeys/{passkeyId}" + .replace("{passkeyId}", passkeyId) + ) + val apiParams = mutableMapOf() + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + return client.call( + "DELETE", + apiPath, + apiHeaders, + apiParams, + responseType = Any::class.java, + ) + } + + /** + * Complete a passkey registration started with [Create passkey](/docs/references/cloud/client-web/account#createPasskey). Pass the JSON form of the credential returned by `navigator.credentials.create()`, for example `credential.toJSON()`. Each registration can be verified once; a failed attempt requires starting it again. + * + * @param passkeyId Passkey ID. + * @param credential Registration credential returned by the authenticator, in the JSON form produced by `PublicKeyCredential.toJSON()`. + * @return [io.appwrite.models.Passkey] + */ + suspend fun updatePasskeyVerification( + passkeyId: String, + credential: Map, + ): io.appwrite.models.Passkey { + if (passkeyId.isEmpty()) { + throw AppwriteException("Missing required parameter: \"passkeyId\"") + } + val apiPath = ("/account/passkeys/{passkeyId}/verification" + .replace("{passkeyId}", passkeyId) + ) + val apiParams = mutableMapOf( + "credential" to credential, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Passkey = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Passkey.from(map = it as Map) + } + return client.call( + "PUT", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Passkey::class.java, + converter, + ) + } + /** * Update currently logged in user password. For validation, user is required to pass in the new password, and the old password. For users created with OAuth, Team Invites and Magic URL, oldPassword is optional. * @@ -1784,6 +1997,7 @@ class Account(client: Client) : Service(client) { * @param success URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param failure URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param scopes A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. + * @param state An opaque value your app generates and keeps, for example in a cookie. It is returned unchanged as the `state` query parameter on the success and failure URLs, so your app can check that the sign-in it receives is one it started. Printable ASCII only (RFC 6749 Appendix A.5). Max length: 256 chars. */ @JvmOverloads suspend fun createOAuth2Session( @@ -1792,6 +2006,7 @@ class Account(client: Client) : Service(client) { success: String? = null, failure: String? = null, scopes: List? = null, + state: String? = null, ) { val apiPath = ("/account/sessions/oauth2/{provider}" .replace("{provider}", provider.value) @@ -1800,6 +2015,7 @@ class Account(client: Client) : Service(client) { "success" to success, "failure" to failure, "scopes" to scopes, + "state" to state, "project" to client.config["project"], ) val apiQuery = mutableListOf() @@ -2268,6 +2484,7 @@ class Account(client: Client) : Service(client) { * @param success URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param failure URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param scopes A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. + * @param state An opaque value your app generates and keeps, for example in a cookie. It is returned unchanged as the `state` query parameter on the success and failure URLs, so your app can check that the sign-in it receives is one it started. Printable ASCII only (RFC 6749 Appendix A.5). Max length: 256 chars. */ @JvmOverloads suspend fun createOAuth2Token( @@ -2276,6 +2493,7 @@ class Account(client: Client) : Service(client) { success: String? = null, failure: String? = null, scopes: List? = null, + state: String? = null, ) { val apiPath = ("/account/tokens/oauth2/{provider}" .replace("{provider}", provider.value) @@ -2284,6 +2502,7 @@ class Account(client: Client) : Service(client) { "success" to success, "failure" to failure, "scopes" to scopes, + "state" to state, "project" to client.config["project"], ) val apiQuery = mutableListOf() @@ -2332,6 +2551,68 @@ class Account(client: Client) : Service(client) { } } + /** + * Start signing in with a passkey. No email or user ID is needed: pass the returned `publicKey` options to `navigator.credentials.get()` and the user picks one of their passkeys. Then call [Update passkey token](/docs/references/cloud/client-web/account#updatePasskeyToken) with the credential to receive a token, and exchange it with [Create session](/docs/references/cloud/client-web/account#createSession). The challenge expires after 5 minutes. + * + * @return [io.appwrite.models.PasskeyChallenge] + */ + suspend fun createPasskeyToken(): io.appwrite.models.PasskeyChallenge { + val apiPath = "/account/tokens/passkey" + val apiParams = mutableMapOf() + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.PasskeyChallenge = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.PasskeyChallenge.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.PasskeyChallenge::class.java, + converter, + ) + } + + /** + * Complete a passkey sign-in started with [Create passkey token](/docs/references/cloud/client-web/account#createPasskeyToken). Pass the challenge ID and the JSON form of the credential returned by `navigator.credentials.get()`, for example `credential.toJSON()`. The returned token includes its secret and expires after 1 minute: exchange it for a session with [Create session](/docs/references/cloud/client-web/account#createSession). Passkeys require user verification, so the session also satisfies MFA. Each challenge can only be used once. + * + * @param challengeId Challenge ID returned by createPasskeyToken. + * @param credential Authentication credential returned by the authenticator, in the JSON form produced by `PublicKeyCredential.toJSON()`. + * @return [io.appwrite.models.TokenSecret] + */ + suspend fun updatePasskeyToken( + challengeId: String, + credential: Map, + ): io.appwrite.models.TokenSecret { + val apiPath = "/account/tokens/passkey" + val apiParams = mutableMapOf( + "challengeId" to challengeId, + "credential" to credential, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.TokenSecret = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.TokenSecret.from(map = it as Map) + } + return client.call( + "PUT", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.TokenSecret::class.java, + converter, + ) + } + /** * Sends the user an SMS with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The secret sent to the user's phone is valid for 15 minutes. * diff --git a/library/src/main/java/io/appwrite/services/Analytics.kt b/library/src/main/java/io/appwrite/services/Analytics.kt new file mode 100644 index 0000000..1949f76 --- /dev/null +++ b/library/src/main/java/io/appwrite/services/Analytics.kt @@ -0,0 +1,83 @@ +package io.appwrite.services + +import android.net.Uri +import io.appwrite.Client +import io.appwrite.Service +import io.appwrite.exceptions.AppwriteException +import io.appwrite.extensions.classOf +import io.appwrite.models.* +import okhttp3.Cookie +import java.io.File + +/** + * + */ +class Analytics(client: Client) : Service(client) { + /** + * Send a tracking event from a browser, native app, or server-side SDK. + * + * @param propertyId Analytics property ID. + * @param name Event name. "pageview" is just a conventional event name; events are not modeled specially. + * @param url Full page URL or screen identifier. + * @param domain Hostname (e.g. example.com). + * @param referrer Referrer URL. + * @param screenWidth Viewport width in CSS pixels. + * @param sessionHash Optional session hash (provided by SDK). + * @param scrollDepth Scroll depth percentage 0-100. + * @param engagementTime Engagement time in seconds, 0-4294967295. + * @param props Custom string properties as a flat key=value list (max 32 entries, alternating key,value). + * @param userId Override user ID. Requires API-key auth with analytics.write scope. + * @param ip Override IP address. Requires API-key auth with analytics.write scope. + * @param userAgent Override user agent. Requires API-key auth with analytics.write scope. + * @return [Any] + */ + @JvmOverloads + suspend fun createEvent( + propertyId: String, + name: String, + url: String, + domain: String? = null, + referrer: String? = null, + screenWidth: Long? = null, + sessionHash: String? = null, + scrollDepth: Long? = null, + engagementTime: Long? = null, + props: List? = null, + userId: String? = null, + ip: String? = null, + userAgent: String? = null, + ): Any { + if (propertyId.isEmpty()) { + throw AppwriteException("Missing required parameter: \"propertyId\"") + } + val apiPath = ("/analytics/properties/{propertyId}/events" + .replace("{propertyId}", propertyId) + ) + val apiParams = mutableMapOf( + "name" to name, + "url" to url, + "domain" to domain, + "referrer" to referrer, + "screenWidth" to screenWidth, + "sessionHash" to sessionHash, + "scrollDepth" to scrollDepth, + "engagementTime" to engagementTime, + "props" to props, + "userId" to userId, + "ip" to ip, + "userAgent" to userAgent, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = Any::class.java, + ) + } +} diff --git a/library/src/main/java/io/appwrite/services/Oauth2.kt b/library/src/main/java/io/appwrite/services/Oauth2.kt index 030f4ce..f5cbc3c 100644 --- a/library/src/main/java/io/appwrite/services/Oauth2.kt +++ b/library/src/main/java/io/appwrite/services/Oauth2.kt @@ -85,7 +85,7 @@ class Oauth2(client: Client) : Service(client) { prompt: String? = null, maxAge: Long? = null, authorizationDetails: String? = null, - resource: String? = null, + resource: List? = null, audience: String? = null, requestUri: String? = null, ): io.appwrite.models.Oauth2Authorize { @@ -157,7 +157,7 @@ class Oauth2(client: Client) : Service(client) { prompt: String? = null, maxAge: Long? = null, authorizationDetails: String? = null, - resource: String? = null, + resource: List? = null, audience: String? = null, requestUri: String? = null, ): io.appwrite.models.Oauth2Authorize { @@ -213,7 +213,7 @@ class Oauth2(client: Client) : Service(client) { clientId: String? = null, scope: String? = null, authorizationDetails: String? = null, - resource: String? = null, + resource: List? = null, audience: String? = null, ): io.appwrite.models.Oauth2DeviceAuthorization { val apiPath = ("/oauth2/{project_id}/device_authorization" @@ -468,7 +468,7 @@ class Oauth2(client: Client) : Service(client) { prompt: String? = null, maxAge: Long? = null, authorizationDetails: String? = null, - resource: String? = null, + resource: List? = null, audience: String? = null, ): io.appwrite.models.Oauth2PAR { val apiPath = ("/oauth2/{project_id}/par" @@ -642,7 +642,7 @@ class Oauth2(client: Client) : Service(client) { clientSecret: String? = null, codeVerifier: String? = null, redirectUri: String? = null, - resource: String? = null, + resource: List? = null, audience: String? = null, ): io.appwrite.models.Oauth2Token { val apiPath = ("/oauth2/{project_id}/token" diff --git a/library/src/main/java/io/appwrite/services/Teams.kt b/library/src/main/java/io/appwrite/services/Teams.kt index 7227eba..da5c3f6 100644 --- a/library/src/main/java/io/appwrite/services/Teams.kt +++ b/library/src/main/java/io/appwrite/services/Teams.kt @@ -534,6 +534,7 @@ class Teams(client: Client) : Service(client) { * * @param teamId Team ID. * @param roles Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 81 characters long. + * @param membershipId Membership ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @param email Email of the new team member. * @param userId ID of the user to be added to a team. * @param phone Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. @@ -545,6 +546,7 @@ class Teams(client: Client) : Service(client) { suspend fun createMembership( teamId: String, roles: List, + membershipId: String? = null, email: String? = null, userId: String? = null, phone: String? = null, @@ -558,6 +560,7 @@ class Teams(client: Client) : Service(client) { .replace("{teamId}", teamId) ) val apiParams = mutableMapOf( + "membershipId" to membershipId, "email" to email, "userId" to userId, "phone" to phone,