diff --git a/LICENSE b/LICENSE index 47cfdfb..5479bb8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2023 Appwrite (https://appwrite.io) and individual contributors. +Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index 59c6bb7..6cfb665 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ # Appwrite Deno SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-deno.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.4.12-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.5.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 is compatible with Appwrite server version 1.4.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-deno/releases).** +**This SDK is compatible with Appwrite server version 1.5.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-deno/releases).** Appwrite is an open-source backend as a service server that abstract and simplify 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 Deno 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) -![Appwrite](https://appwrite.io/images/github.png) +![Appwrite](https://github.com/appwrite/appwrite/raw/main/public/images/github.png) ## Installation @@ -43,7 +43,7 @@ Once your SDK object is set, create any of the Appwrite service objects and choo ```typescript let users = new sdk.Users(client); -let user = await users.create(ID.unique(), 'email@example.com', 'password'); +let user = await users.create(ID.unique(), "email@example.com", "+123456789", "password", "Walter O'Brien"); console.log(user); ``` @@ -61,7 +61,7 @@ client .setSelfSigned() // Use only on dev mode with a self-signed SSL cert ; -let user = await users.create(ID.unique(), 'email@example.com', 'password'); +let user = await users.create(ID.unique(), "email@example.com", "+123456789", "password", "Walter O'Brien"); console.log(user); ``` @@ -72,7 +72,7 @@ The Appwrite Deno SDK raises `AppwriteException` object with `message`, `code` a let users = new sdk.Users(client); try { - let user = await users.create(ID.unique(), 'email@example.com', 'password'); + let user = await users.create(ID.unique(), "email@example.com", "+123456789", "password", "Walter O'Brien"); } catch(e) { console.log(e.message); } diff --git a/docs/examples/account/create-anonymous-session.md b/docs/examples/account/create-anonymous-session.md new file mode 100644 index 0000000..d3dae32 --- /dev/null +++ b/docs/examples/account/create-anonymous-session.md @@ -0,0 +1,9 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +const account = new Account(client); + +const response = await account.createAnonymousSession(); diff --git a/docs/examples/account/create-email-password-session.md b/docs/examples/account/create-email-password-session.md new file mode 100644 index 0000000..ee2d698 --- /dev/null +++ b/docs/examples/account/create-email-password-session.md @@ -0,0 +1,12 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +const account = new Account(client); + +const response = await account.createEmailPasswordSession( + 'email@example.com', // email + 'password' // password +); diff --git a/docs/examples/account/create-email-token.md b/docs/examples/account/create-email-token.md new file mode 100644 index 0000000..3a555ff --- /dev/null +++ b/docs/examples/account/create-email-token.md @@ -0,0 +1,13 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +const account = new Account(client); + +const response = await account.createEmailToken( + '', // userId + 'email@example.com', // email + false // phrase (optional) +); diff --git a/docs/examples/account/create-j-w-t.md b/docs/examples/account/create-j-w-t.md new file mode 100644 index 0000000..9b0707e --- /dev/null +++ b/docs/examples/account/create-j-w-t.md @@ -0,0 +1,9 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +const account = new Account(client); + +const response = await account.createJWT(); diff --git a/docs/examples/account/create-magic-u-r-l-token.md b/docs/examples/account/create-magic-u-r-l-token.md new file mode 100644 index 0000000..b8c2cf4 --- /dev/null +++ b/docs/examples/account/create-magic-u-r-l-token.md @@ -0,0 +1,14 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +const account = new Account(client); + +const response = await account.createMagicURLToken( + '', // userId + 'email@example.com', // email + 'https://example.com', // url (optional) + false // phrase (optional) +); diff --git a/docs/examples/account/create-mfa-authenticator.md b/docs/examples/account/create-mfa-authenticator.md new file mode 100644 index 0000000..d8206d5 --- /dev/null +++ b/docs/examples/account/create-mfa-authenticator.md @@ -0,0 +1,12 @@ +import { Client, Account, AuthenticatorType } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setSession(''); // The user session to authenticate with + +const account = new Account(client); + +const response = await account.createMfaAuthenticator( + AuthenticatorType.Totp // type +); diff --git a/docs/examples/account/create-mfa-challenge.md b/docs/examples/account/create-mfa-challenge.md new file mode 100644 index 0000000..7edc2bf --- /dev/null +++ b/docs/examples/account/create-mfa-challenge.md @@ -0,0 +1,11 @@ +import { Client, Account, AuthenticationFactor } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +const account = new Account(client); + +const response = await account.createMfaChallenge( + AuthenticationFactor.Email // factor +); diff --git a/docs/examples/account/create-mfa-recovery-codes.md b/docs/examples/account/create-mfa-recovery-codes.md new file mode 100644 index 0000000..514da0e --- /dev/null +++ b/docs/examples/account/create-mfa-recovery-codes.md @@ -0,0 +1,10 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setSession(''); // The user session to authenticate with + +const account = new Account(client); + +const response = await account.createMfaRecoveryCodes(); diff --git a/docs/examples/account/create-o-auth2token.md b/docs/examples/account/create-o-auth2token.md new file mode 100644 index 0000000..e1ff3b8 --- /dev/null +++ b/docs/examples/account/create-o-auth2token.md @@ -0,0 +1,14 @@ +import { Client, Account, OAuthProvider } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +const account = new Account(client); + +account.createOAuth2Token( + OAuthProvider.Amazon, // provider + 'https://example.com', // success (optional) + 'https://example.com', // failure (optional) + [] // scopes (optional) +); diff --git a/docs/examples/account/create-phone-token.md b/docs/examples/account/create-phone-token.md new file mode 100644 index 0000000..6dcdff9 --- /dev/null +++ b/docs/examples/account/create-phone-token.md @@ -0,0 +1,12 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +const account = new Account(client); + +const response = await account.createPhoneToken( + '', // userId + '+12065550100' // phone +); diff --git a/docs/examples/account/create-phone-verification.md b/docs/examples/account/create-phone-verification.md index fe76588..fa42f5a 100644 --- a/docs/examples/account/create-phone-verification.md +++ b/docs/examples/account/create-phone-verification.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.createPhoneVerification(); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.createPhoneVerification(); diff --git a/docs/examples/account/create-recovery.md b/docs/examples/account/create-recovery.md index e5adb2a..bf33fad 100644 --- a/docs/examples/account/create-recovery.md +++ b/docs/examples/account/create-recovery.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.createRecovery('email@example.com', 'https://example.com'); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.createRecovery( + 'email@example.com', // email + 'https://example.com' // url +); diff --git a/docs/examples/account/create-session.md b/docs/examples/account/create-session.md new file mode 100644 index 0000000..37825fe --- /dev/null +++ b/docs/examples/account/create-session.md @@ -0,0 +1,12 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +const account = new Account(client); + +const response = await account.createSession( + '', // userId + '' // secret +); diff --git a/docs/examples/account/create-verification.md b/docs/examples/account/create-verification.md index 5861278..2631b62 100644 --- a/docs/examples/account/create-verification.md +++ b/docs/examples/account/create-verification.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.createVerification('https://example.com'); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.createVerification( + 'https://example.com' // url +); diff --git a/docs/examples/account/create.md b/docs/examples/account/create.md new file mode 100644 index 0000000..422be32 --- /dev/null +++ b/docs/examples/account/create.md @@ -0,0 +1,14 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +const account = new Account(client); + +const response = await account.create( + '', // userId + 'email@example.com', // email + '', // password + '' // name (optional) +); diff --git a/docs/examples/account/delete-identity.md b/docs/examples/account/delete-identity.md index f24954e..cf69083 100644 --- a/docs/examples/account/delete-identity.md +++ b/docs/examples/account/delete-identity.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.deleteIdentity('[IDENTITY_ID]'); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.deleteIdentity( + '' // identityId +); diff --git a/docs/examples/account/delete-mfa-authenticator.md b/docs/examples/account/delete-mfa-authenticator.md new file mode 100644 index 0000000..217dde8 --- /dev/null +++ b/docs/examples/account/delete-mfa-authenticator.md @@ -0,0 +1,13 @@ +import { Client, Account, AuthenticatorType } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setSession(''); // The user session to authenticate with + +const account = new Account(client); + +const response = await account.deleteMfaAuthenticator( + AuthenticatorType.Totp, // type + '' // otp +); diff --git a/docs/examples/account/delete-session.md b/docs/examples/account/delete-session.md index 22417ac..4427794 100644 --- a/docs/examples/account/delete-session.md +++ b/docs/examples/account/delete-session.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.deleteSession('[SESSION_ID]'); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.deleteSession( + '' // sessionId +); diff --git a/docs/examples/account/delete-sessions.md b/docs/examples/account/delete-sessions.md index 2a82bd9..c698bab 100644 --- a/docs/examples/account/delete-sessions.md +++ b/docs/examples/account/delete-sessions.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.deleteSessions(); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.deleteSessions(); diff --git a/docs/examples/account/get-mfa-recovery-codes.md b/docs/examples/account/get-mfa-recovery-codes.md new file mode 100644 index 0000000..c664309 --- /dev/null +++ b/docs/examples/account/get-mfa-recovery-codes.md @@ -0,0 +1,10 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setSession(''); // The user session to authenticate with + +const account = new Account(client); + +const response = await account.getMfaRecoveryCodes(); diff --git a/docs/examples/account/get-prefs.md b/docs/examples/account/get-prefs.md index c9645d0..dc990d8 100644 --- a/docs/examples/account/get-prefs.md +++ b/docs/examples/account/get-prefs.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.getPrefs(); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.getPrefs(); diff --git a/docs/examples/account/get-session.md b/docs/examples/account/get-session.md index f2c1c94..cd49260 100644 --- a/docs/examples/account/get-session.md +++ b/docs/examples/account/get-session.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.getSession('[SESSION_ID]'); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.getSession( + '' // sessionId +); diff --git a/docs/examples/account/get.md b/docs/examples/account/get.md index 03b2230..d630fb0 100644 --- a/docs/examples/account/get.md +++ b/docs/examples/account/get.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.get(); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.get(); diff --git a/docs/examples/account/list-identities.md b/docs/examples/account/list-identities.md index c3faa7b..8e5964c 100644 --- a/docs/examples/account/list-identities.md +++ b/docs/examples/account/list-identities.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.listIdentities(); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.listIdentities( + [] // queries (optional) +); diff --git a/docs/examples/account/list-logs.md b/docs/examples/account/list-logs.md index fb79304..5360f47 100644 --- a/docs/examples/account/list-logs.md +++ b/docs/examples/account/list-logs.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.listLogs(); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.listLogs( + [] // queries (optional) +); diff --git a/docs/examples/account/list-mfa-factors.md b/docs/examples/account/list-mfa-factors.md new file mode 100644 index 0000000..d7cc93c --- /dev/null +++ b/docs/examples/account/list-mfa-factors.md @@ -0,0 +1,10 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setSession(''); // The user session to authenticate with + +const account = new Account(client); + +const response = await account.listMfaFactors(); diff --git a/docs/examples/account/list-sessions.md b/docs/examples/account/list-sessions.md index 32a7cfa..0eb7ae8 100644 --- a/docs/examples/account/list-sessions.md +++ b/docs/examples/account/list-sessions.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.listSessions(); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.listSessions(); diff --git a/docs/examples/account/update-email.md b/docs/examples/account/update-email.md index 26906d7..f68a016 100644 --- a/docs/examples/account/update-email.md +++ b/docs/examples/account/update-email.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.updateEmail('email@example.com', 'password'); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.updateEmail( + 'email@example.com', // email + 'password' // password +); diff --git a/docs/examples/account/update-m-f-a.md b/docs/examples/account/update-m-f-a.md new file mode 100644 index 0000000..4f62917 --- /dev/null +++ b/docs/examples/account/update-m-f-a.md @@ -0,0 +1,12 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setSession(''); // The user session to authenticate with + +const account = new Account(client); + +const response = await account.updateMFA( + false // mfa +); diff --git a/docs/examples/account/update-magic-u-r-l-session.md b/docs/examples/account/update-magic-u-r-l-session.md new file mode 100644 index 0000000..9cf1c6e --- /dev/null +++ b/docs/examples/account/update-magic-u-r-l-session.md @@ -0,0 +1,12 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +const account = new Account(client); + +const response = await account.updateMagicURLSession( + '', // userId + '' // secret +); diff --git a/docs/examples/account/update-mfa-authenticator.md b/docs/examples/account/update-mfa-authenticator.md new file mode 100644 index 0000000..08ecb16 --- /dev/null +++ b/docs/examples/account/update-mfa-authenticator.md @@ -0,0 +1,13 @@ +import { Client, Account, AuthenticatorType } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setSession(''); // The user session to authenticate with + +const account = new Account(client); + +const response = await account.updateMfaAuthenticator( + AuthenticatorType.Totp, // type + '' // otp +); diff --git a/docs/examples/account/update-mfa-challenge.md b/docs/examples/account/update-mfa-challenge.md new file mode 100644 index 0000000..4c75f1d --- /dev/null +++ b/docs/examples/account/update-mfa-challenge.md @@ -0,0 +1,13 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setSession(''); // The user session to authenticate with + +const account = new Account(client); + +const response = await account.updateMfaChallenge( + '', // challengeId + '' // otp +); diff --git a/docs/examples/account/update-mfa-recovery-codes.md b/docs/examples/account/update-mfa-recovery-codes.md new file mode 100644 index 0000000..0825cc0 --- /dev/null +++ b/docs/examples/account/update-mfa-recovery-codes.md @@ -0,0 +1,10 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setSession(''); // The user session to authenticate with + +const account = new Account(client); + +const response = await account.updateMfaRecoveryCodes(); diff --git a/docs/examples/account/update-name.md b/docs/examples/account/update-name.md index b1a3512..4d4f260 100644 --- a/docs/examples/account/update-name.md +++ b/docs/examples/account/update-name.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.updateName('[NAME]'); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.updateName( + '' // name +); diff --git a/docs/examples/account/update-password.md b/docs/examples/account/update-password.md index a271dfe..ab178b3 100644 --- a/docs/examples/account/update-password.md +++ b/docs/examples/account/update-password.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.updatePassword(''); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.updatePassword( + '', // password + 'password' // oldPassword (optional) +); diff --git a/docs/examples/account/update-phone-session.md b/docs/examples/account/update-phone-session.md new file mode 100644 index 0000000..9efe6b0 --- /dev/null +++ b/docs/examples/account/update-phone-session.md @@ -0,0 +1,12 @@ +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2'); // Your project ID + +const account = new Account(client); + +const response = await account.updatePhoneSession( + '', // userId + '' // secret +); diff --git a/docs/examples/account/update-phone-verification.md b/docs/examples/account/update-phone-verification.md index 064252a..ee8b488 100644 --- a/docs/examples/account/update-phone-verification.md +++ b/docs/examples/account/update-phone-verification.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.updatePhoneVerification('[USER_ID]', '[SECRET]'); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.updatePhoneVerification( + '', // userId + '' // secret +); diff --git a/docs/examples/account/update-phone.md b/docs/examples/account/update-phone.md index e023424..b8d6847 100644 --- a/docs/examples/account/update-phone.md +++ b/docs/examples/account/update-phone.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.updatePhone('+12065550100', 'password'); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.updatePhone( + '+12065550100', // phone + 'password' // password +); diff --git a/docs/examples/account/update-prefs.md b/docs/examples/account/update-prefs.md index 4a6ca88..7a1fe04 100644 --- a/docs/examples/account/update-prefs.md +++ b/docs/examples/account/update-prefs.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.updatePrefs({}); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.updatePrefs( + {} // prefs +); diff --git a/docs/examples/account/update-recovery.md b/docs/examples/account/update-recovery.md index 06916bb..f8cf494 100644 --- a/docs/examples/account/update-recovery.md +++ b/docs/examples/account/update-recovery.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.updateRecovery('[USER_ID]', '[SECRET]', 'password', 'password'); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.updateRecovery( + '', // userId + '', // secret + '' // password +); diff --git a/docs/examples/account/update-session.md b/docs/examples/account/update-session.md index 23a7ad2..199ef85 100644 --- a/docs/examples/account/update-session.md +++ b/docs/examples/account/update-session.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.updateSession('[SESSION_ID]'); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.updateSession( + '' // sessionId +); diff --git a/docs/examples/account/update-status.md b/docs/examples/account/update-status.md index 6b9b189..1430663 100644 --- a/docs/examples/account/update-status.md +++ b/docs/examples/account/update-status.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.updateStatus(); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.updateStatus(); diff --git a/docs/examples/account/update-verification.md b/docs/examples/account/update-verification.md index c11f2b7..805b1c6 100644 --- a/docs/examples/account/update-verification.md +++ b/docs/examples/account/update-verification.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Account } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let account = new sdk.Account(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = account.updateVerification('[USER_ID]', '[SECRET]'); +const account = new Account(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await account.updateVerification( + '', // userId + '' // secret +); diff --git a/docs/examples/avatars/get-browser.md b/docs/examples/avatars/get-browser.md index 44c946e..3265c6c 100644 --- a/docs/examples/avatars/get-browser.md +++ b/docs/examples/avatars/get-browser.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Avatars, Browser } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let avatars = new sdk.Avatars(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = avatars.getBrowser('aa'); +const avatars = new Avatars(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const result = avatars.getBrowser( + Browser.AvantBrowser, // code + 0, // width (optional) + 0, // height (optional) + 0 // quality (optional) +); diff --git a/docs/examples/avatars/get-credit-card.md b/docs/examples/avatars/get-credit-card.md index 0f44982..10f3198 100644 --- a/docs/examples/avatars/get-credit-card.md +++ b/docs/examples/avatars/get-credit-card.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Avatars, CreditCard } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let avatars = new sdk.Avatars(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = avatars.getCreditCard('amex'); +const avatars = new Avatars(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const result = avatars.getCreditCard( + CreditCard.AmericanExpress, // code + 0, // width (optional) + 0, // height (optional) + 0 // quality (optional) +); diff --git a/docs/examples/avatars/get-favicon.md b/docs/examples/avatars/get-favicon.md index f0a539b..a7981a6 100644 --- a/docs/examples/avatars/get-favicon.md +++ b/docs/examples/avatars/get-favicon.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Avatars } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let avatars = new sdk.Avatars(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = avatars.getFavicon('https://example.com'); +const avatars = new Avatars(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const result = avatars.getFavicon( + 'https://example.com' // url +); diff --git a/docs/examples/avatars/get-flag.md b/docs/examples/avatars/get-flag.md index c7593ae..346119f 100644 --- a/docs/examples/avatars/get-flag.md +++ b/docs/examples/avatars/get-flag.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Avatars, Flag } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let avatars = new sdk.Avatars(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = avatars.getFlag('af'); +const avatars = new Avatars(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const result = avatars.getFlag( + Flag.Afghanistan, // code + 0, // width (optional) + 0, // height (optional) + 0 // quality (optional) +); diff --git a/docs/examples/avatars/get-image.md b/docs/examples/avatars/get-image.md index 6e86307..e37c975 100644 --- a/docs/examples/avatars/get-image.md +++ b/docs/examples/avatars/get-image.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Avatars } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let avatars = new sdk.Avatars(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = avatars.getImage('https://example.com'); +const avatars = new Avatars(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const result = avatars.getImage( + 'https://example.com', // url + 0, // width (optional) + 0 // height (optional) +); diff --git a/docs/examples/avatars/get-initials.md b/docs/examples/avatars/get-initials.md index 2adba9e..988f879 100644 --- a/docs/examples/avatars/get-initials.md +++ b/docs/examples/avatars/get-initials.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Avatars } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let avatars = new sdk.Avatars(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = avatars.getInitials(); +const avatars = new Avatars(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const result = avatars.getInitials( + '', // name (optional) + 0, // width (optional) + 0, // height (optional) + '' // background (optional) +); diff --git a/docs/examples/avatars/get-q-r.md b/docs/examples/avatars/get-q-r.md index 2c5faf0..7a806f5 100644 --- a/docs/examples/avatars/get-q-r.md +++ b/docs/examples/avatars/get-q-r.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Avatars } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let avatars = new sdk.Avatars(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = avatars.getQR('[TEXT]'); +const avatars = new Avatars(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const result = avatars.getQR( + '', // text + 1, // size (optional) + 0, // margin (optional) + false // download (optional) +); diff --git a/docs/examples/databases/create-boolean-attribute.md b/docs/examples/databases/create-boolean-attribute.md index 81b6677..730adba 100644 --- a/docs/examples/databases/create-boolean-attribute.md +++ b/docs/examples/databases/create-boolean-attribute.md @@ -1,21 +1,17 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.createBooleanAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createBooleanAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + false, // default (optional) + false // array (optional) +); diff --git a/docs/examples/databases/create-collection.md b/docs/examples/databases/create-collection.md index 5d59286..72f1100 100644 --- a/docs/examples/databases/create-collection.md +++ b/docs/examples/databases/create-collection.md @@ -1,21 +1,17 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.createCollection('[DATABASE_ID]', '[COLLECTION_ID]', '[NAME]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createCollection( + '', // databaseId + '', // collectionId + '', // name + ["read("any")"], // permissions (optional) + false, // documentSecurity (optional) + false // enabled (optional) +); diff --git a/docs/examples/databases/create-datetime-attribute.md b/docs/examples/databases/create-datetime-attribute.md index c2c4eb8..62b4af4 100644 --- a/docs/examples/databases/create-datetime-attribute.md +++ b/docs/examples/databases/create-datetime-attribute.md @@ -1,21 +1,17 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.createDatetimeAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createDatetimeAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + '', // default (optional) + false // array (optional) +); diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index d38818c..a8e69de 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -1,21 +1,16 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = databases.createDocument('[DATABASE_ID]', '[COLLECTION_ID]', '[DOCUMENT_ID]', {}); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createDocument( + '', // databaseId + '', // collectionId + '', // documentId + {}, // data + ["read("any")"] // permissions (optional) +); diff --git a/docs/examples/databases/create-email-attribute.md b/docs/examples/databases/create-email-attribute.md index 4952625..24568a9 100644 --- a/docs/examples/databases/create-email-attribute.md +++ b/docs/examples/databases/create-email-attribute.md @@ -1,21 +1,17 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.createEmailAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createEmailAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + 'email@example.com', // default (optional) + false // array (optional) +); diff --git a/docs/examples/databases/create-enum-attribute.md b/docs/examples/databases/create-enum-attribute.md index d00274d..013ac96 100644 --- a/docs/examples/databases/create-enum-attribute.md +++ b/docs/examples/databases/create-enum-attribute.md @@ -1,21 +1,18 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.createEnumAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', [], false); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createEnumAttribute( + '', // databaseId + '', // collectionId + '', // key + [], // elements + false, // required + '', // default (optional) + false // array (optional) +); diff --git a/docs/examples/databases/create-float-attribute.md b/docs/examples/databases/create-float-attribute.md index c2b056f..7cd652a 100644 --- a/docs/examples/databases/create-float-attribute.md +++ b/docs/examples/databases/create-float-attribute.md @@ -1,21 +1,19 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.createFloatAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createFloatAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + null, // min (optional) + null, // max (optional) + null, // default (optional) + false // array (optional) +); diff --git a/docs/examples/databases/create-index.md b/docs/examples/databases/create-index.md index bfde8e3..d8a8aba 100644 --- a/docs/examples/databases/create-index.md +++ b/docs/examples/databases/create-index.md @@ -1,21 +1,17 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases, IndexType } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.createIndex('[DATABASE_ID]', '[COLLECTION_ID]', '', 'key', []); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createIndex( + '', // databaseId + '', // collectionId + '', // key + IndexType.Key, // type + [], // attributes + [] // orders (optional) +); diff --git a/docs/examples/databases/create-integer-attribute.md b/docs/examples/databases/create-integer-attribute.md index 2a36f41..e6a04bc 100644 --- a/docs/examples/databases/create-integer-attribute.md +++ b/docs/examples/databases/create-integer-attribute.md @@ -1,21 +1,19 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.createIntegerAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createIntegerAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + null, // min (optional) + null, // max (optional) + null, // default (optional) + false // array (optional) +); diff --git a/docs/examples/databases/create-ip-attribute.md b/docs/examples/databases/create-ip-attribute.md index 19180d6..e44ddcc 100644 --- a/docs/examples/databases/create-ip-attribute.md +++ b/docs/examples/databases/create-ip-attribute.md @@ -1,21 +1,17 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.createIpAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createIpAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + '', // default (optional) + false // array (optional) +); diff --git a/docs/examples/databases/create-relationship-attribute.md b/docs/examples/databases/create-relationship-attribute.md index e613a6f..9f751fa 100644 --- a/docs/examples/databases/create-relationship-attribute.md +++ b/docs/examples/databases/create-relationship-attribute.md @@ -1,21 +1,19 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases, RelationshipType, RelationMutate } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.createRelationshipAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '[RELATED_COLLECTION_ID]', 'oneToOne'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createRelationshipAttribute( + '', // databaseId + '', // collectionId + '', // relatedCollectionId + RelationshipType.OneToOne, // type + false, // twoWay (optional) + '', // key (optional) + '', // twoWayKey (optional) + RelationMutate.Cascade // onDelete (optional) +); diff --git a/docs/examples/databases/create-string-attribute.md b/docs/examples/databases/create-string-attribute.md index f3b0a36..37f202f 100644 --- a/docs/examples/databases/create-string-attribute.md +++ b/docs/examples/databases/create-string-attribute.md @@ -1,21 +1,19 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.createStringAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', 1, false); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createStringAttribute( + '', // databaseId + '', // collectionId + '', // key + 1, // size + false, // required + '', // default (optional) + false, // array (optional) + false // encrypt (optional) +); diff --git a/docs/examples/databases/create-url-attribute.md b/docs/examples/databases/create-url-attribute.md index 488751a..9b20d0b 100644 --- a/docs/examples/databases/create-url-attribute.md +++ b/docs/examples/databases/create-url-attribute.md @@ -1,21 +1,17 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.createUrlAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.createUrlAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + 'https://example.com', // default (optional) + false // array (optional) +); diff --git a/docs/examples/databases/create.md b/docs/examples/databases/create.md index ea1ebb6..d6bb161 100644 --- a/docs/examples/databases/create.md +++ b/docs/examples/databases/create.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.create('[DATABASE_ID]', '[NAME]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.create( + '', // databaseId + '', // name + false // enabled (optional) +); diff --git a/docs/examples/databases/delete-attribute.md b/docs/examples/databases/delete-attribute.md index e6fe082..0de42f8 100644 --- a/docs/examples/databases/delete-attribute.md +++ b/docs/examples/databases/delete-attribute.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.deleteAttribute('[DATABASE_ID]', '[COLLECTION_ID]', ''); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.deleteAttribute( + '', // databaseId + '', // collectionId + '' // key +); diff --git a/docs/examples/databases/delete-collection.md b/docs/examples/databases/delete-collection.md index 970602a..22ddaef 100644 --- a/docs/examples/databases/delete-collection.md +++ b/docs/examples/databases/delete-collection.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.deleteCollection('[DATABASE_ID]', '[COLLECTION_ID]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.deleteCollection( + '', // databaseId + '' // collectionId +); diff --git a/docs/examples/databases/delete-document.md b/docs/examples/databases/delete-document.md index 1a23e03..1b11e26 100644 --- a/docs/examples/databases/delete-document.md +++ b/docs/examples/databases/delete-document.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = databases.deleteDocument('[DATABASE_ID]', '[COLLECTION_ID]', '[DOCUMENT_ID]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.deleteDocument( + '', // databaseId + '', // collectionId + '' // documentId +); diff --git a/docs/examples/databases/delete-index.md b/docs/examples/databases/delete-index.md index 8a60505..f48eb72 100644 --- a/docs/examples/databases/delete-index.md +++ b/docs/examples/databases/delete-index.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.deleteIndex('[DATABASE_ID]', '[COLLECTION_ID]', ''); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.deleteIndex( + '', // databaseId + '', // collectionId + '' // key +); diff --git a/docs/examples/databases/delete.md b/docs/examples/databases/delete.md index b735ecc..9a42e8f 100644 --- a/docs/examples/databases/delete.md +++ b/docs/examples/databases/delete.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.delete('[DATABASE_ID]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.delete( + '' // databaseId +); diff --git a/docs/examples/databases/get-attribute.md b/docs/examples/databases/get-attribute.md index 1ec9957..a2fe4e6 100644 --- a/docs/examples/databases/get-attribute.md +++ b/docs/examples/databases/get-attribute.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.getAttribute('[DATABASE_ID]', '[COLLECTION_ID]', ''); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.getAttribute( + '', // databaseId + '', // collectionId + '' // key +); diff --git a/docs/examples/databases/get-collection.md b/docs/examples/databases/get-collection.md index bf471e3..6c49c6d 100644 --- a/docs/examples/databases/get-collection.md +++ b/docs/examples/databases/get-collection.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.getCollection('[DATABASE_ID]', '[COLLECTION_ID]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.getCollection( + '', // databaseId + '' // collectionId +); diff --git a/docs/examples/databases/get-document.md b/docs/examples/databases/get-document.md index a7248d0..dc37d41 100644 --- a/docs/examples/databases/get-document.md +++ b/docs/examples/databases/get-document.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = databases.getDocument('[DATABASE_ID]', '[COLLECTION_ID]', '[DOCUMENT_ID]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.getDocument( + '', // databaseId + '', // collectionId + '', // documentId + [] // queries (optional) +); diff --git a/docs/examples/databases/get-index.md b/docs/examples/databases/get-index.md index c1fe00c..2540e2f 100644 --- a/docs/examples/databases/get-index.md +++ b/docs/examples/databases/get-index.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.getIndex('[DATABASE_ID]', '[COLLECTION_ID]', ''); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.getIndex( + '', // databaseId + '', // collectionId + '' // key +); diff --git a/docs/examples/databases/get.md b/docs/examples/databases/get.md index 46df3aa..ffaddd7 100644 --- a/docs/examples/databases/get.md +++ b/docs/examples/databases/get.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.get('[DATABASE_ID]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.get( + '' // databaseId +); diff --git a/docs/examples/databases/list-attributes.md b/docs/examples/databases/list-attributes.md index f2b2114..193752e 100644 --- a/docs/examples/databases/list-attributes.md +++ b/docs/examples/databases/list-attributes.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.listAttributes('[DATABASE_ID]', '[COLLECTION_ID]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.listAttributes( + '', // databaseId + '', // collectionId + [] // queries (optional) +); diff --git a/docs/examples/databases/list-collections.md b/docs/examples/databases/list-collections.md index 83e4ee9..d35f4db 100644 --- a/docs/examples/databases/list-collections.md +++ b/docs/examples/databases/list-collections.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.listCollections('[DATABASE_ID]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.listCollections( + '', // databaseId + [], // queries (optional) + '' // search (optional) +); diff --git a/docs/examples/databases/list-documents.md b/docs/examples/databases/list-documents.md index c7db17e..a65d720 100644 --- a/docs/examples/databases/list-documents.md +++ b/docs/examples/databases/list-documents.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = databases.listDocuments('[DATABASE_ID]', '[COLLECTION_ID]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.listDocuments( + '', // databaseId + '', // collectionId + [] // queries (optional) +); diff --git a/docs/examples/databases/list-indexes.md b/docs/examples/databases/list-indexes.md index 69c412b..da01d72 100644 --- a/docs/examples/databases/list-indexes.md +++ b/docs/examples/databases/list-indexes.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.listIndexes('[DATABASE_ID]', '[COLLECTION_ID]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.listIndexes( + '', // databaseId + '', // collectionId + [] // queries (optional) +); diff --git a/docs/examples/databases/list.md b/docs/examples/databases/list.md index 8bb7511..e312057 100644 --- a/docs/examples/databases/list.md +++ b/docs/examples/databases/list.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.list(); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.list( + [], // queries (optional) + '' // search (optional) +); diff --git a/docs/examples/databases/update-boolean-attribute.md b/docs/examples/databases/update-boolean-attribute.md index c8b55b7..e0e74de 100644 --- a/docs/examples/databases/update-boolean-attribute.md +++ b/docs/examples/databases/update-boolean-attribute.md @@ -1,21 +1,16 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.updateBooleanAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false, false); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.updateBooleanAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + false // default +); diff --git a/docs/examples/databases/update-collection.md b/docs/examples/databases/update-collection.md index f81f46e..3a26a93 100644 --- a/docs/examples/databases/update-collection.md +++ b/docs/examples/databases/update-collection.md @@ -1,21 +1,17 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.updateCollection('[DATABASE_ID]', '[COLLECTION_ID]', '[NAME]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.updateCollection( + '', // databaseId + '', // collectionId + '', // name + ["read("any")"], // permissions (optional) + false, // documentSecurity (optional) + false // enabled (optional) +); diff --git a/docs/examples/databases/update-datetime-attribute.md b/docs/examples/databases/update-datetime-attribute.md index 25549b4..d75a2ed 100644 --- a/docs/examples/databases/update-datetime-attribute.md +++ b/docs/examples/databases/update-datetime-attribute.md @@ -1,21 +1,16 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.updateDatetimeAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false, ''); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.updateDatetimeAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + '' // default +); diff --git a/docs/examples/databases/update-document.md b/docs/examples/databases/update-document.md index 9964fdb..66113df 100644 --- a/docs/examples/databases/update-document.md +++ b/docs/examples/databases/update-document.md @@ -1,21 +1,16 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = databases.updateDocument('[DATABASE_ID]', '[COLLECTION_ID]', '[DOCUMENT_ID]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.updateDocument( + '', // databaseId + '', // collectionId + '', // documentId + {}, // data (optional) + ["read("any")"] // permissions (optional) +); diff --git a/docs/examples/databases/update-email-attribute.md b/docs/examples/databases/update-email-attribute.md index 78d2403..b238c66 100644 --- a/docs/examples/databases/update-email-attribute.md +++ b/docs/examples/databases/update-email-attribute.md @@ -1,21 +1,16 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.updateEmailAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false, 'email@example.com'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.updateEmailAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + 'email@example.com' // default +); diff --git a/docs/examples/databases/update-enum-attribute.md b/docs/examples/databases/update-enum-attribute.md index f47b96f..885ab0c 100644 --- a/docs/examples/databases/update-enum-attribute.md +++ b/docs/examples/databases/update-enum-attribute.md @@ -1,21 +1,17 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.updateEnumAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', [], false, '[DEFAULT]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.updateEnumAttribute( + '', // databaseId + '', // collectionId + '', // key + [], // elements + false, // required + '' // default +); diff --git a/docs/examples/databases/update-float-attribute.md b/docs/examples/databases/update-float-attribute.md index 62df38c..cb422a3 100644 --- a/docs/examples/databases/update-float-attribute.md +++ b/docs/examples/databases/update-float-attribute.md @@ -1,21 +1,18 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.updateFloatAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false, null, null, null); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.updateFloatAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + null, // min + null, // max + null // default +); diff --git a/docs/examples/databases/update-integer-attribute.md b/docs/examples/databases/update-integer-attribute.md index 001671e..2c4fa43 100644 --- a/docs/examples/databases/update-integer-attribute.md +++ b/docs/examples/databases/update-integer-attribute.md @@ -1,21 +1,18 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.updateIntegerAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false, null, null, null); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.updateIntegerAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + null, // min + null, // max + null // default +); diff --git a/docs/examples/databases/update-ip-attribute.md b/docs/examples/databases/update-ip-attribute.md index 8ee0d5c..37ec1e9 100644 --- a/docs/examples/databases/update-ip-attribute.md +++ b/docs/examples/databases/update-ip-attribute.md @@ -1,21 +1,16 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.updateIpAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false, ''); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.updateIpAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + '' // default +); diff --git a/docs/examples/databases/update-relationship-attribute.md b/docs/examples/databases/update-relationship-attribute.md index c12a64a..63886f9 100644 --- a/docs/examples/databases/update-relationship-attribute.md +++ b/docs/examples/databases/update-relationship-attribute.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases, RelationMutate } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.updateRelationshipAttribute('[DATABASE_ID]', '[COLLECTION_ID]', ''); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.updateRelationshipAttribute( + '', // databaseId + '', // collectionId + '', // key + RelationMutate.Cascade // onDelete (optional) +); diff --git a/docs/examples/databases/update-string-attribute.md b/docs/examples/databases/update-string-attribute.md index ab77495..33b106c 100644 --- a/docs/examples/databases/update-string-attribute.md +++ b/docs/examples/databases/update-string-attribute.md @@ -1,21 +1,16 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.updateStringAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false, '[DEFAULT]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.updateStringAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + '' // default +); diff --git a/docs/examples/databases/update-url-attribute.md b/docs/examples/databases/update-url-attribute.md index c9ab818..f06fcf9 100644 --- a/docs/examples/databases/update-url-attribute.md +++ b/docs/examples/databases/update-url-attribute.md @@ -1,21 +1,16 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.updateUrlAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false, 'https://example.com'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.updateUrlAttribute( + '', // databaseId + '', // collectionId + '', // key + false, // required + 'https://example.com' // default +); diff --git a/docs/examples/databases/update.md b/docs/examples/databases/update.md index 64886a6..ce40232 100644 --- a/docs/examples/databases/update.md +++ b/docs/examples/databases/update.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Databases } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let databases = new sdk.Databases(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = databases.update('[DATABASE_ID]', '[NAME]'); +const databases = new Databases(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await databases.update( + '', // databaseId + '', // name + false // enabled (optional) +); diff --git a/docs/examples/functions/create-build.md b/docs/examples/functions/create-build.md index 28d1010..9a58bf2 100644 --- a/docs/examples/functions/create-build.md +++ b/docs/examples/functions/create-build.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.createBuild('[FUNCTION_ID]', '[DEPLOYMENT_ID]', '[BUILD_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.createBuild( + '', // functionId + '', // deploymentId + '' // buildId +); diff --git a/docs/examples/functions/create-deployment.md b/docs/examples/functions/create-deployment.md index 167d177..ec6ea91 100644 --- a/docs/examples/functions/create-deployment.md +++ b/docs/examples/functions/create-deployment.md @@ -1,21 +1,16 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.createDeployment('[FUNCTION_ID]', InputFile.fromPath('/path/to/file.png', 'file.png'), false); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.createDeployment( + '', // functionId + InputFile.fromPath('/path/to/file.png', 'file.png'), // code + false, // activate + '', // entrypoint (optional) + '' // commands (optional) +); diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index 6ec920e..6edabb4 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -1,21 +1,17 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions, ExecutionMethod } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = functions.createExecution('[FUNCTION_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.createExecution( + '', // functionId + '', // body (optional) + false, // async (optional) + '', // path (optional) + ExecutionMethod.GET, // method (optional) + {} // headers (optional) +); diff --git a/docs/examples/functions/create-variable.md b/docs/examples/functions/create-variable.md index 375ef8b..9f933eb 100644 --- a/docs/examples/functions/create-variable.md +++ b/docs/examples/functions/create-variable.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.createVariable('[FUNCTION_ID]', '[KEY]', '[VALUE]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.createVariable( + '', // functionId + '', // key + '' // value +); diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index cd9c150..14e26a7 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -1,21 +1,31 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions, } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.create('[FUNCTION_ID]', '[NAME]', 'node-18.0'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.create( + '', // functionId + '', // name + .Node145, // runtime + ["any"], // execute (optional) + [], // events (optional) + '', // schedule (optional) + 1, // timeout (optional) + false, // enabled (optional) + false, // logging (optional) + '', // entrypoint (optional) + '', // commands (optional) + '', // installationId (optional) + '', // providerRepositoryId (optional) + '', // providerBranch (optional) + false, // providerSilentMode (optional) + '', // providerRootDirectory (optional) + '', // templateRepository (optional) + '', // templateOwner (optional) + '', // templateRootDirectory (optional) + '' // templateBranch (optional) +); diff --git a/docs/examples/functions/delete-deployment.md b/docs/examples/functions/delete-deployment.md index 7b6468b..229c084 100644 --- a/docs/examples/functions/delete-deployment.md +++ b/docs/examples/functions/delete-deployment.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.deleteDeployment('[FUNCTION_ID]', '[DEPLOYMENT_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.deleteDeployment( + '', // functionId + '' // deploymentId +); diff --git a/docs/examples/functions/delete-variable.md b/docs/examples/functions/delete-variable.md index 16bf385..5694a5f 100644 --- a/docs/examples/functions/delete-variable.md +++ b/docs/examples/functions/delete-variable.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.deleteVariable('[FUNCTION_ID]', '[VARIABLE_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.deleteVariable( + '', // functionId + '' // variableId +); diff --git a/docs/examples/functions/delete.md b/docs/examples/functions/delete.md index 48ec374..a56e5e2 100644 --- a/docs/examples/functions/delete.md +++ b/docs/examples/functions/delete.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.delete('[FUNCTION_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.delete( + '' // functionId +); diff --git a/docs/examples/functions/download-deployment.md b/docs/examples/functions/download-deployment.md index dc07358..5697c5e 100644 --- a/docs/examples/functions/download-deployment.md +++ b/docs/examples/functions/download-deployment.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.downloadDeployment('[FUNCTION_ID]', '[DEPLOYMENT_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const result = functions.downloadDeployment( + '', // functionId + '' // deploymentId +); diff --git a/docs/examples/functions/get-deployment.md b/docs/examples/functions/get-deployment.md index 854f389..30426da 100644 --- a/docs/examples/functions/get-deployment.md +++ b/docs/examples/functions/get-deployment.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.getDeployment('[FUNCTION_ID]', '[DEPLOYMENT_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.getDeployment( + '', // functionId + '' // deploymentId +); diff --git a/docs/examples/functions/get-execution.md b/docs/examples/functions/get-execution.md index 42bcdfb..7007f79 100644 --- a/docs/examples/functions/get-execution.md +++ b/docs/examples/functions/get-execution.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = functions.getExecution('[FUNCTION_ID]', '[EXECUTION_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.getExecution( + '', // functionId + '' // executionId +); diff --git a/docs/examples/functions/get-variable.md b/docs/examples/functions/get-variable.md index 2b4190e..ba335cb 100644 --- a/docs/examples/functions/get-variable.md +++ b/docs/examples/functions/get-variable.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.getVariable('[FUNCTION_ID]', '[VARIABLE_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.getVariable( + '', // functionId + '' // variableId +); diff --git a/docs/examples/functions/get.md b/docs/examples/functions/get.md index 3889582..1f76c2a 100644 --- a/docs/examples/functions/get.md +++ b/docs/examples/functions/get.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.get('[FUNCTION_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.get( + '' // functionId +); diff --git a/docs/examples/functions/list-deployments.md b/docs/examples/functions/list-deployments.md index e84bb9c..ec89f55 100644 --- a/docs/examples/functions/list-deployments.md +++ b/docs/examples/functions/list-deployments.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.listDeployments('[FUNCTION_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.listDeployments( + '', // functionId + [], // queries (optional) + '' // search (optional) +); diff --git a/docs/examples/functions/list-executions.md b/docs/examples/functions/list-executions.md index aadd19f..1d497a2 100644 --- a/docs/examples/functions/list-executions.md +++ b/docs/examples/functions/list-executions.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = functions.listExecutions('[FUNCTION_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.listExecutions( + '', // functionId + [], // queries (optional) + '' // search (optional) +); diff --git a/docs/examples/functions/list-runtimes.md b/docs/examples/functions/list-runtimes.md index 6fc7570..67a3e9a 100644 --- a/docs/examples/functions/list-runtimes.md +++ b/docs/examples/functions/list-runtimes.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.listRuntimes(); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.listRuntimes(); diff --git a/docs/examples/functions/list-variables.md b/docs/examples/functions/list-variables.md index 44a9828..edcb4d4 100644 --- a/docs/examples/functions/list-variables.md +++ b/docs/examples/functions/list-variables.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.listVariables('[FUNCTION_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.listVariables( + '' // functionId +); diff --git a/docs/examples/functions/list.md b/docs/examples/functions/list.md index 7c82760..7cbcb0b 100644 --- a/docs/examples/functions/list.md +++ b/docs/examples/functions/list.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.list(); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.list( + [], // queries (optional) + '' // search (optional) +); diff --git a/docs/examples/functions/update-deployment.md b/docs/examples/functions/update-deployment.md index 94be560..95fd450 100644 --- a/docs/examples/functions/update-deployment.md +++ b/docs/examples/functions/update-deployment.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.updateDeployment('[FUNCTION_ID]', '[DEPLOYMENT_ID]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.updateDeployment( + '', // functionId + '' // deploymentId +); diff --git a/docs/examples/functions/update-variable.md b/docs/examples/functions/update-variable.md index 1a318f1..4f4d6a5 100644 --- a/docs/examples/functions/update-variable.md +++ b/docs/examples/functions/update-variable.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.updateVariable('[FUNCTION_ID]', '[VARIABLE_ID]', '[KEY]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.updateVariable( + '', // functionId + '', // variableId + '', // key + '' // value (optional) +); diff --git a/docs/examples/functions/update.md b/docs/examples/functions/update.md index 8ed2663..1e6f385 100644 --- a/docs/examples/functions/update.md +++ b/docs/examples/functions/update.md @@ -1,21 +1,27 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Functions, } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let functions = new sdk.Functions(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = functions.update('[FUNCTION_ID]', '[NAME]'); +const functions = new Functions(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await functions.update( + '', // functionId + '', // name + .Node145, // runtime (optional) + ["any"], // execute (optional) + [], // events (optional) + '', // schedule (optional) + 1, // timeout (optional) + false, // enabled (optional) + false, // logging (optional) + '', // entrypoint (optional) + '', // commands (optional) + '', // installationId (optional) + '', // providerRepositoryId (optional) + '', // providerBranch (optional) + false, // providerSilentMode (optional) + '' // providerRootDirectory (optional) +); diff --git a/docs/examples/graphql/mutation.md b/docs/examples/graphql/mutation.md index 87beeab..a0ff9dd 100644 --- a/docs/examples/graphql/mutation.md +++ b/docs/examples/graphql/mutation.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Graphql } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let graphql = new sdk.Graphql(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = graphql.mutation({}); +const graphql = new Graphql(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await graphql.mutation( + {} // query +); diff --git a/docs/examples/graphql/query.md b/docs/examples/graphql/query.md index d2eec0a..ecec1c4 100644 --- a/docs/examples/graphql/query.md +++ b/docs/examples/graphql/query.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Graphql } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let graphql = new sdk.Graphql(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = graphql.query({}); +const graphql = new Graphql(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await graphql.query( + {} // query +); diff --git a/docs/examples/health/get-antivirus.md b/docs/examples/health/get-antivirus.md index 8d51808..8114266 100644 --- a/docs/examples/health/get-antivirus.md +++ b/docs/examples/health/get-antivirus.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getAntivirus(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getAntivirus(); diff --git a/docs/examples/health/get-cache.md b/docs/examples/health/get-cache.md index cafc301..45d4464 100644 --- a/docs/examples/health/get-cache.md +++ b/docs/examples/health/get-cache.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getCache(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getCache(); diff --git a/docs/examples/health/get-certificate.md b/docs/examples/health/get-certificate.md new file mode 100644 index 0000000..dc45602 --- /dev/null +++ b/docs/examples/health/get-certificate.md @@ -0,0 +1,12 @@ +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const health = new Health(client); + +const response = await health.getCertificate( + '' // domain (optional) +); diff --git a/docs/examples/health/get-d-b.md b/docs/examples/health/get-d-b.md index a000535..36f5a67 100644 --- a/docs/examples/health/get-d-b.md +++ b/docs/examples/health/get-d-b.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getDB(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getDB(); diff --git a/docs/examples/health/get-failed-jobs.md b/docs/examples/health/get-failed-jobs.md new file mode 100644 index 0000000..0057bbb --- /dev/null +++ b/docs/examples/health/get-failed-jobs.md @@ -0,0 +1,13 @@ +import { Client, Health, } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const health = new Health(client); + +const response = await health.getFailedJobs( + .V1Database, // name + null // threshold (optional) +); diff --git a/docs/examples/health/get-pub-sub.md b/docs/examples/health/get-pub-sub.md index 979ef0b..afa519e 100644 --- a/docs/examples/health/get-pub-sub.md +++ b/docs/examples/health/get-pub-sub.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getPubSub(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getPubSub(); diff --git a/docs/examples/health/get-queue-builds.md b/docs/examples/health/get-queue-builds.md index 4f45749..6d1c88e 100644 --- a/docs/examples/health/get-queue-builds.md +++ b/docs/examples/health/get-queue-builds.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getQueueBuilds(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getQueueBuilds( + null // threshold (optional) +); diff --git a/docs/examples/health/get-queue-certificates.md b/docs/examples/health/get-queue-certificates.md index 49dab6b..d7c0a24 100644 --- a/docs/examples/health/get-queue-certificates.md +++ b/docs/examples/health/get-queue-certificates.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getQueueCertificates(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getQueueCertificates( + null // threshold (optional) +); diff --git a/docs/examples/health/get-queue-databases.md b/docs/examples/health/get-queue-databases.md index 639d109..fb98bba 100644 --- a/docs/examples/health/get-queue-databases.md +++ b/docs/examples/health/get-queue-databases.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getQueueDatabases(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getQueueDatabases( + '', // name (optional) + null // threshold (optional) +); diff --git a/docs/examples/health/get-queue-deletes.md b/docs/examples/health/get-queue-deletes.md index 26ff3da..9e2a530 100644 --- a/docs/examples/health/get-queue-deletes.md +++ b/docs/examples/health/get-queue-deletes.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getQueueDeletes(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getQueueDeletes( + null // threshold (optional) +); diff --git a/docs/examples/health/get-queue-functions.md b/docs/examples/health/get-queue-functions.md index 74f458b..811efb3 100644 --- a/docs/examples/health/get-queue-functions.md +++ b/docs/examples/health/get-queue-functions.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getQueueFunctions(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getQueueFunctions( + null // threshold (optional) +); diff --git a/docs/examples/health/get-queue-logs.md b/docs/examples/health/get-queue-logs.md index 98948b9..17f6208 100644 --- a/docs/examples/health/get-queue-logs.md +++ b/docs/examples/health/get-queue-logs.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getQueueLogs(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getQueueLogs( + null // threshold (optional) +); diff --git a/docs/examples/health/get-queue-mails.md b/docs/examples/health/get-queue-mails.md index 478ad80..26b58fb 100644 --- a/docs/examples/health/get-queue-mails.md +++ b/docs/examples/health/get-queue-mails.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getQueueMails(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getQueueMails( + null // threshold (optional) +); diff --git a/docs/examples/health/get-queue-messaging.md b/docs/examples/health/get-queue-messaging.md index ba018ac..0198dce 100644 --- a/docs/examples/health/get-queue-messaging.md +++ b/docs/examples/health/get-queue-messaging.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getQueueMessaging(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getQueueMessaging( + null // threshold (optional) +); diff --git a/docs/examples/health/get-queue-migrations.md b/docs/examples/health/get-queue-migrations.md index d779a1d..5dfa6ea 100644 --- a/docs/examples/health/get-queue-migrations.md +++ b/docs/examples/health/get-queue-migrations.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getQueueMigrations(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getQueueMigrations( + null // threshold (optional) +); diff --git a/docs/examples/health/get-queue-usage-dump.md b/docs/examples/health/get-queue-usage-dump.md new file mode 100644 index 0000000..ccc5c1e --- /dev/null +++ b/docs/examples/health/get-queue-usage-dump.md @@ -0,0 +1,12 @@ +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const health = new Health(client); + +const response = await health.getQueueUsageDump( + null // threshold (optional) +); diff --git a/docs/examples/health/get-queue-usage.md b/docs/examples/health/get-queue-usage.md new file mode 100644 index 0000000..7c83e59 --- /dev/null +++ b/docs/examples/health/get-queue-usage.md @@ -0,0 +1,12 @@ +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const health = new Health(client); + +const response = await health.getQueueUsage( + null // threshold (optional) +); diff --git a/docs/examples/health/get-queue-webhooks.md b/docs/examples/health/get-queue-webhooks.md index 7b45c18..600d477 100644 --- a/docs/examples/health/get-queue-webhooks.md +++ b/docs/examples/health/get-queue-webhooks.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getQueueWebhooks(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getQueueWebhooks( + null // threshold (optional) +); diff --git a/docs/examples/health/get-queue.md b/docs/examples/health/get-queue.md index 4c1f675..013c93e 100644 --- a/docs/examples/health/get-queue.md +++ b/docs/examples/health/get-queue.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getQueue(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getQueue(); diff --git a/docs/examples/health/get-storage-local.md b/docs/examples/health/get-storage-local.md index 4c45d89..dd71131 100644 --- a/docs/examples/health/get-storage-local.md +++ b/docs/examples/health/get-storage-local.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getStorageLocal(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getStorageLocal(); diff --git a/docs/examples/health/get-storage.md b/docs/examples/health/get-storage.md new file mode 100644 index 0000000..ee7d34c --- /dev/null +++ b/docs/examples/health/get-storage.md @@ -0,0 +1,10 @@ +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const health = new Health(client); + +const response = await health.getStorage(); diff --git a/docs/examples/health/get-time.md b/docs/examples/health/get-time.md index 6a66a10..4d26bda 100644 --- a/docs/examples/health/get-time.md +++ b/docs/examples/health/get-time.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.getTime(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.getTime(); diff --git a/docs/examples/health/get.md b/docs/examples/health/get.md index 0b9af9d..d3e4b20 100644 --- a/docs/examples/health/get.md +++ b/docs/examples/health/get.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Health } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let health = new sdk.Health(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = health.get(); +const health = new Health(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await health.get(); diff --git a/docs/examples/locale/get.md b/docs/examples/locale/get.md index 22b9a62..f931ae4 100644 --- a/docs/examples/locale/get.md +++ b/docs/examples/locale/get.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Locale } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let locale = new sdk.Locale(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = locale.get(); +const locale = new Locale(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await locale.get(); diff --git a/docs/examples/locale/list-codes.md b/docs/examples/locale/list-codes.md index 1ca38d4..93dedef 100644 --- a/docs/examples/locale/list-codes.md +++ b/docs/examples/locale/list-codes.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Locale } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let locale = new sdk.Locale(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = locale.listCodes(); +const locale = new Locale(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await locale.listCodes(); diff --git a/docs/examples/locale/list-continents.md b/docs/examples/locale/list-continents.md index bd69f43..985b654 100644 --- a/docs/examples/locale/list-continents.md +++ b/docs/examples/locale/list-continents.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Locale } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let locale = new sdk.Locale(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = locale.listContinents(); +const locale = new Locale(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await locale.listContinents(); diff --git a/docs/examples/locale/list-countries-e-u.md b/docs/examples/locale/list-countries-e-u.md index 3d3b7b4..311ef65 100644 --- a/docs/examples/locale/list-countries-e-u.md +++ b/docs/examples/locale/list-countries-e-u.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Locale } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let locale = new sdk.Locale(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = locale.listCountriesEU(); +const locale = new Locale(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await locale.listCountriesEU(); diff --git a/docs/examples/locale/list-countries-phones.md b/docs/examples/locale/list-countries-phones.md index bc9e175..c732eda 100644 --- a/docs/examples/locale/list-countries-phones.md +++ b/docs/examples/locale/list-countries-phones.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Locale } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let locale = new sdk.Locale(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = locale.listCountriesPhones(); +const locale = new Locale(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await locale.listCountriesPhones(); diff --git a/docs/examples/locale/list-countries.md b/docs/examples/locale/list-countries.md index 0790270..73b530c 100644 --- a/docs/examples/locale/list-countries.md +++ b/docs/examples/locale/list-countries.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Locale } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let locale = new sdk.Locale(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = locale.listCountries(); +const locale = new Locale(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await locale.listCountries(); diff --git a/docs/examples/locale/list-currencies.md b/docs/examples/locale/list-currencies.md index e040312..942622c 100644 --- a/docs/examples/locale/list-currencies.md +++ b/docs/examples/locale/list-currencies.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Locale } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let locale = new sdk.Locale(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = locale.listCurrencies(); +const locale = new Locale(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await locale.listCurrencies(); diff --git a/docs/examples/locale/list-languages.md b/docs/examples/locale/list-languages.md index be5af4d..e96ccc2 100644 --- a/docs/examples/locale/list-languages.md +++ b/docs/examples/locale/list-languages.md @@ -1,21 +1,10 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Locale } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let locale = new sdk.Locale(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = locale.listLanguages(); +const locale = new Locale(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await locale.listLanguages(); diff --git a/docs/examples/messaging/create-apns-provider.md b/docs/examples/messaging/create-apns-provider.md new file mode 100644 index 0000000..8a1c6b5 --- /dev/null +++ b/docs/examples/messaging/create-apns-provider.md @@ -0,0 +1,19 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createApnsProvider( + '', // providerId + '', // name + '', // authKey (optional) + '', // authKeyId (optional) + '', // teamId (optional) + '', // bundleId (optional) + false, // sandbox (optional) + false // enabled (optional) +); diff --git a/docs/examples/messaging/create-email.md b/docs/examples/messaging/create-email.md new file mode 100644 index 0000000..28609fb --- /dev/null +++ b/docs/examples/messaging/create-email.md @@ -0,0 +1,23 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createEmail( + '', // messageId + '', // subject + '', // content + [], // topics (optional) + [], // users (optional) + [], // targets (optional) + [], // cc (optional) + [], // bcc (optional) + [], // attachments (optional) + false, // draft (optional) + false, // html (optional) + '' // scheduledAt (optional) +); diff --git a/docs/examples/messaging/create-fcm-provider.md b/docs/examples/messaging/create-fcm-provider.md new file mode 100644 index 0000000..e3b773f --- /dev/null +++ b/docs/examples/messaging/create-fcm-provider.md @@ -0,0 +1,15 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createFcmProvider( + '', // providerId + '', // name + {}, // serviceAccountJSON (optional) + false // enabled (optional) +); diff --git a/docs/examples/messaging/create-mailgun-provider.md b/docs/examples/messaging/create-mailgun-provider.md new file mode 100644 index 0000000..0ede7b6 --- /dev/null +++ b/docs/examples/messaging/create-mailgun-provider.md @@ -0,0 +1,21 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createMailgunProvider( + '', // providerId + '', // name + '', // apiKey (optional) + '', // domain (optional) + false, // isEuRegion (optional) + '', // fromName (optional) + 'email@example.com', // fromEmail (optional) + '', // replyToName (optional) + 'email@example.com', // replyToEmail (optional) + false // enabled (optional) +); diff --git a/docs/examples/messaging/create-msg91provider.md b/docs/examples/messaging/create-msg91provider.md new file mode 100644 index 0000000..4383e23 --- /dev/null +++ b/docs/examples/messaging/create-msg91provider.md @@ -0,0 +1,17 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createMsg91Provider( + '', // providerId + '', // name + '+12065550100', // from (optional) + '', // senderId (optional) + '', // authKey (optional) + false // enabled (optional) +); diff --git a/docs/examples/messaging/create-push.md b/docs/examples/messaging/create-push.md new file mode 100644 index 0000000..28fe84d --- /dev/null +++ b/docs/examples/messaging/create-push.md @@ -0,0 +1,27 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createPush( + '', // messageId + '', // title + '<BODY>', // body + [], // topics (optional) + [], // users (optional) + [], // targets (optional) + {}, // data (optional) + '<ACTION>', // action (optional) + '[ID1:ID2]', // image (optional) + '<ICON>', // icon (optional) + '<SOUND>', // sound (optional) + '<COLOR>', // color (optional) + '<TAG>', // tag (optional) + '<BADGE>', // badge (optional) + false, // draft (optional) + '' // scheduledAt (optional) +); diff --git a/docs/examples/messaging/create-sendgrid-provider.md b/docs/examples/messaging/create-sendgrid-provider.md new file mode 100644 index 0000000..fe0a791 --- /dev/null +++ b/docs/examples/messaging/create-sendgrid-provider.md @@ -0,0 +1,19 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createSendgridProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name + '<API_KEY>', // apiKey (optional) + '<FROM_NAME>', // fromName (optional) + 'email@example.com', // fromEmail (optional) + '<REPLY_TO_NAME>', // replyToName (optional) + 'email@example.com', // replyToEmail (optional) + false // enabled (optional) +); diff --git a/docs/examples/messaging/create-sms.md b/docs/examples/messaging/create-sms.md new file mode 100644 index 0000000..13fb9f5 --- /dev/null +++ b/docs/examples/messaging/create-sms.md @@ -0,0 +1,18 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createSms( + '<MESSAGE_ID>', // messageId + '<CONTENT>', // content + [], // topics (optional) + [], // users (optional) + [], // targets (optional) + false, // draft (optional) + '' // scheduledAt (optional) +); diff --git a/docs/examples/messaging/create-smtp-provider.md b/docs/examples/messaging/create-smtp-provider.md new file mode 100644 index 0000000..613045f --- /dev/null +++ b/docs/examples/messaging/create-smtp-provider.md @@ -0,0 +1,25 @@ +import { Client, Messaging, SmtpEncryption } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createSmtpProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name + '<HOST>', // host + 1, // port (optional) + '<USERNAME>', // username (optional) + '<PASSWORD>', // password (optional) + SmtpEncryption.None, // encryption (optional) + false, // autoTLS (optional) + '<MAILER>', // mailer (optional) + '<FROM_NAME>', // fromName (optional) + 'email@example.com', // fromEmail (optional) + '<REPLY_TO_NAME>', // replyToName (optional) + 'email@example.com', // replyToEmail (optional) + false // enabled (optional) +); diff --git a/docs/examples/messaging/create-subscriber.md b/docs/examples/messaging/create-subscriber.md new file mode 100644 index 0000000..daa6ce2 --- /dev/null +++ b/docs/examples/messaging/create-subscriber.md @@ -0,0 +1,14 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...'); // Your secret JSON Web Token + +const messaging = new Messaging(client); + +const response = await messaging.createSubscriber( + '<TOPIC_ID>', // topicId + '<SUBSCRIBER_ID>', // subscriberId + '<TARGET_ID>' // targetId +); diff --git a/docs/examples/messaging/create-telesign-provider.md b/docs/examples/messaging/create-telesign-provider.md new file mode 100644 index 0000000..f3da859 --- /dev/null +++ b/docs/examples/messaging/create-telesign-provider.md @@ -0,0 +1,17 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createTelesignProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name + '+12065550100', // from (optional) + '<CUSTOMER_ID>', // customerId (optional) + '<API_KEY>', // apiKey (optional) + false // enabled (optional) +); diff --git a/docs/examples/messaging/create-textmagic-provider.md b/docs/examples/messaging/create-textmagic-provider.md new file mode 100644 index 0000000..eca653d --- /dev/null +++ b/docs/examples/messaging/create-textmagic-provider.md @@ -0,0 +1,17 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createTextmagicProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name + '+12065550100', // from (optional) + '<USERNAME>', // username (optional) + '<API_KEY>', // apiKey (optional) + false // enabled (optional) +); diff --git a/docs/examples/messaging/create-topic.md b/docs/examples/messaging/create-topic.md new file mode 100644 index 0000000..0f01817 --- /dev/null +++ b/docs/examples/messaging/create-topic.md @@ -0,0 +1,14 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createTopic( + '<TOPIC_ID>', // topicId + '<NAME>', // name + ["any"] // subscribe (optional) +); diff --git a/docs/examples/messaging/create-twilio-provider.md b/docs/examples/messaging/create-twilio-provider.md new file mode 100644 index 0000000..b729354 --- /dev/null +++ b/docs/examples/messaging/create-twilio-provider.md @@ -0,0 +1,17 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createTwilioProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name + '+12065550100', // from (optional) + '<ACCOUNT_SID>', // accountSid (optional) + '<AUTH_TOKEN>', // authToken (optional) + false // enabled (optional) +); diff --git a/docs/examples/messaging/create-vonage-provider.md b/docs/examples/messaging/create-vonage-provider.md new file mode 100644 index 0000000..6236cb6 --- /dev/null +++ b/docs/examples/messaging/create-vonage-provider.md @@ -0,0 +1,17 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.createVonageProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name + '+12065550100', // from (optional) + '<API_KEY>', // apiKey (optional) + '<API_SECRET>', // apiSecret (optional) + false // enabled (optional) +); diff --git a/docs/examples/messaging/delete-provider.md b/docs/examples/messaging/delete-provider.md new file mode 100644 index 0000000..26408a4 --- /dev/null +++ b/docs/examples/messaging/delete-provider.md @@ -0,0 +1,12 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.deleteProvider( + '<PROVIDER_ID>' // providerId +); diff --git a/docs/examples/messaging/delete-subscriber.md b/docs/examples/messaging/delete-subscriber.md new file mode 100644 index 0000000..5f789a4 --- /dev/null +++ b/docs/examples/messaging/delete-subscriber.md @@ -0,0 +1,13 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...'); // Your secret JSON Web Token + +const messaging = new Messaging(client); + +const response = await messaging.deleteSubscriber( + '<TOPIC_ID>', // topicId + '<SUBSCRIBER_ID>' // subscriberId +); diff --git a/docs/examples/messaging/delete-topic.md b/docs/examples/messaging/delete-topic.md new file mode 100644 index 0000000..ec26f94 --- /dev/null +++ b/docs/examples/messaging/delete-topic.md @@ -0,0 +1,12 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.deleteTopic( + '<TOPIC_ID>' // topicId +); diff --git a/docs/examples/messaging/delete.md b/docs/examples/messaging/delete.md new file mode 100644 index 0000000..d324540 --- /dev/null +++ b/docs/examples/messaging/delete.md @@ -0,0 +1,12 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.delete( + '<MESSAGE_ID>' // messageId +); diff --git a/docs/examples/messaging/get-message.md b/docs/examples/messaging/get-message.md new file mode 100644 index 0000000..f603018 --- /dev/null +++ b/docs/examples/messaging/get-message.md @@ -0,0 +1,12 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.getMessage( + '<MESSAGE_ID>' // messageId +); diff --git a/docs/examples/messaging/get-provider.md b/docs/examples/messaging/get-provider.md new file mode 100644 index 0000000..ad1d7ab --- /dev/null +++ b/docs/examples/messaging/get-provider.md @@ -0,0 +1,12 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.getProvider( + '<PROVIDER_ID>' // providerId +); diff --git a/docs/examples/messaging/get-subscriber.md b/docs/examples/messaging/get-subscriber.md new file mode 100644 index 0000000..518bf48 --- /dev/null +++ b/docs/examples/messaging/get-subscriber.md @@ -0,0 +1,13 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.getSubscriber( + '<TOPIC_ID>', // topicId + '<SUBSCRIBER_ID>' // subscriberId +); diff --git a/docs/examples/messaging/get-topic.md b/docs/examples/messaging/get-topic.md new file mode 100644 index 0000000..2079f36 --- /dev/null +++ b/docs/examples/messaging/get-topic.md @@ -0,0 +1,12 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.getTopic( + '<TOPIC_ID>' // topicId +); diff --git a/docs/examples/messaging/list-message-logs.md b/docs/examples/messaging/list-message-logs.md new file mode 100644 index 0000000..ca72b3a --- /dev/null +++ b/docs/examples/messaging/list-message-logs.md @@ -0,0 +1,13 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.listMessageLogs( + '<MESSAGE_ID>', // messageId + [] // queries (optional) +); diff --git a/docs/examples/messaging/list-messages.md b/docs/examples/messaging/list-messages.md new file mode 100644 index 0000000..27d2fb9 --- /dev/null +++ b/docs/examples/messaging/list-messages.md @@ -0,0 +1,13 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.listMessages( + [], // queries (optional) + '<SEARCH>' // search (optional) +); diff --git a/docs/examples/messaging/list-provider-logs.md b/docs/examples/messaging/list-provider-logs.md new file mode 100644 index 0000000..f29af3a --- /dev/null +++ b/docs/examples/messaging/list-provider-logs.md @@ -0,0 +1,13 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.listProviderLogs( + '<PROVIDER_ID>', // providerId + [] // queries (optional) +); diff --git a/docs/examples/messaging/list-providers.md b/docs/examples/messaging/list-providers.md new file mode 100644 index 0000000..1a6ae91 --- /dev/null +++ b/docs/examples/messaging/list-providers.md @@ -0,0 +1,13 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.listProviders( + [], // queries (optional) + '<SEARCH>' // search (optional) +); diff --git a/docs/examples/messaging/list-subscriber-logs.md b/docs/examples/messaging/list-subscriber-logs.md new file mode 100644 index 0000000..b1c096b --- /dev/null +++ b/docs/examples/messaging/list-subscriber-logs.md @@ -0,0 +1,13 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.listSubscriberLogs( + '<SUBSCRIBER_ID>', // subscriberId + [] // queries (optional) +); diff --git a/docs/examples/messaging/list-subscribers.md b/docs/examples/messaging/list-subscribers.md new file mode 100644 index 0000000..622f68c --- /dev/null +++ b/docs/examples/messaging/list-subscribers.md @@ -0,0 +1,14 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.listSubscribers( + '<TOPIC_ID>', // topicId + [], // queries (optional) + '<SEARCH>' // search (optional) +); diff --git a/docs/examples/messaging/list-targets.md b/docs/examples/messaging/list-targets.md new file mode 100644 index 0000000..9399c49 --- /dev/null +++ b/docs/examples/messaging/list-targets.md @@ -0,0 +1,13 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.listTargets( + '<MESSAGE_ID>', // messageId + [] // queries (optional) +); diff --git a/docs/examples/messaging/list-topic-logs.md b/docs/examples/messaging/list-topic-logs.md new file mode 100644 index 0000000..cb5c46d --- /dev/null +++ b/docs/examples/messaging/list-topic-logs.md @@ -0,0 +1,13 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.listTopicLogs( + '<TOPIC_ID>', // topicId + [] // queries (optional) +); diff --git a/docs/examples/messaging/list-topics.md b/docs/examples/messaging/list-topics.md new file mode 100644 index 0000000..1992fd7 --- /dev/null +++ b/docs/examples/messaging/list-topics.md @@ -0,0 +1,13 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.listTopics( + [], // queries (optional) + '<SEARCH>' // search (optional) +); diff --git a/docs/examples/messaging/update-apns-provider.md b/docs/examples/messaging/update-apns-provider.md new file mode 100644 index 0000000..0db3da4 --- /dev/null +++ b/docs/examples/messaging/update-apns-provider.md @@ -0,0 +1,19 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateApnsProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name (optional) + false, // enabled (optional) + '<AUTH_KEY>', // authKey (optional) + '<AUTH_KEY_ID>', // authKeyId (optional) + '<TEAM_ID>', // teamId (optional) + '<BUNDLE_ID>', // bundleId (optional) + false // sandbox (optional) +); diff --git a/docs/examples/messaging/update-email.md b/docs/examples/messaging/update-email.md new file mode 100644 index 0000000..144eb20 --- /dev/null +++ b/docs/examples/messaging/update-email.md @@ -0,0 +1,22 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateEmail( + '<MESSAGE_ID>', // messageId + [], // topics (optional) + [], // users (optional) + [], // targets (optional) + '<SUBJECT>', // subject (optional) + '<CONTENT>', // content (optional) + false, // draft (optional) + false, // html (optional) + [], // cc (optional) + [], // bcc (optional) + '' // scheduledAt (optional) +); diff --git a/docs/examples/messaging/update-fcm-provider.md b/docs/examples/messaging/update-fcm-provider.md new file mode 100644 index 0000000..15cb41f --- /dev/null +++ b/docs/examples/messaging/update-fcm-provider.md @@ -0,0 +1,15 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateFcmProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name (optional) + false, // enabled (optional) + {} // serviceAccountJSON (optional) +); diff --git a/docs/examples/messaging/update-mailgun-provider.md b/docs/examples/messaging/update-mailgun-provider.md new file mode 100644 index 0000000..62efe62 --- /dev/null +++ b/docs/examples/messaging/update-mailgun-provider.md @@ -0,0 +1,21 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateMailgunProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name (optional) + '<API_KEY>', // apiKey (optional) + '<DOMAIN>', // domain (optional) + false, // isEuRegion (optional) + false, // enabled (optional) + '<FROM_NAME>', // fromName (optional) + 'email@example.com', // fromEmail (optional) + '<REPLY_TO_NAME>', // replyToName (optional) + '<REPLY_TO_EMAIL>' // replyToEmail (optional) +); diff --git a/docs/examples/messaging/update-msg91provider.md b/docs/examples/messaging/update-msg91provider.md new file mode 100644 index 0000000..3239b97 --- /dev/null +++ b/docs/examples/messaging/update-msg91provider.md @@ -0,0 +1,17 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateMsg91Provider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name (optional) + false, // enabled (optional) + '<SENDER_ID>', // senderId (optional) + '<AUTH_KEY>', // authKey (optional) + '<FROM>' // from (optional) +); diff --git a/docs/examples/messaging/update-push.md b/docs/examples/messaging/update-push.md new file mode 100644 index 0000000..a6ae3c0 --- /dev/null +++ b/docs/examples/messaging/update-push.md @@ -0,0 +1,27 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updatePush( + '<MESSAGE_ID>', // messageId + [], // topics (optional) + [], // users (optional) + [], // targets (optional) + '<TITLE>', // title (optional) + '<BODY>', // body (optional) + {}, // data (optional) + '<ACTION>', // action (optional) + '[ID1:ID2]', // image (optional) + '<ICON>', // icon (optional) + '<SOUND>', // sound (optional) + '<COLOR>', // color (optional) + '<TAG>', // tag (optional) + null, // badge (optional) + false, // draft (optional) + '' // scheduledAt (optional) +); diff --git a/docs/examples/messaging/update-sendgrid-provider.md b/docs/examples/messaging/update-sendgrid-provider.md new file mode 100644 index 0000000..64709e2 --- /dev/null +++ b/docs/examples/messaging/update-sendgrid-provider.md @@ -0,0 +1,19 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateSendgridProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name (optional) + false, // enabled (optional) + '<API_KEY>', // apiKey (optional) + '<FROM_NAME>', // fromName (optional) + 'email@example.com', // fromEmail (optional) + '<REPLY_TO_NAME>', // replyToName (optional) + '<REPLY_TO_EMAIL>' // replyToEmail (optional) +); diff --git a/docs/examples/messaging/update-sms.md b/docs/examples/messaging/update-sms.md new file mode 100644 index 0000000..dc4da7e --- /dev/null +++ b/docs/examples/messaging/update-sms.md @@ -0,0 +1,18 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateSms( + '<MESSAGE_ID>', // messageId + [], // topics (optional) + [], // users (optional) + [], // targets (optional) + '<CONTENT>', // content (optional) + false, // draft (optional) + '' // scheduledAt (optional) +); diff --git a/docs/examples/messaging/update-smtp-provider.md b/docs/examples/messaging/update-smtp-provider.md new file mode 100644 index 0000000..78eb0de --- /dev/null +++ b/docs/examples/messaging/update-smtp-provider.md @@ -0,0 +1,25 @@ +import { Client, Messaging, SmtpEncryption } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateSmtpProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name (optional) + '<HOST>', // host (optional) + 1, // port (optional) + '<USERNAME>', // username (optional) + '<PASSWORD>', // password (optional) + SmtpEncryption.None, // encryption (optional) + false, // autoTLS (optional) + '<MAILER>', // mailer (optional) + '<FROM_NAME>', // fromName (optional) + 'email@example.com', // fromEmail (optional) + '<REPLY_TO_NAME>', // replyToName (optional) + '<REPLY_TO_EMAIL>', // replyToEmail (optional) + false // enabled (optional) +); diff --git a/docs/examples/messaging/update-telesign-provider.md b/docs/examples/messaging/update-telesign-provider.md new file mode 100644 index 0000000..531b37e --- /dev/null +++ b/docs/examples/messaging/update-telesign-provider.md @@ -0,0 +1,17 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateTelesignProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name (optional) + false, // enabled (optional) + '<CUSTOMER_ID>', // customerId (optional) + '<API_KEY>', // apiKey (optional) + '<FROM>' // from (optional) +); diff --git a/docs/examples/messaging/update-textmagic-provider.md b/docs/examples/messaging/update-textmagic-provider.md new file mode 100644 index 0000000..1ae95f1 --- /dev/null +++ b/docs/examples/messaging/update-textmagic-provider.md @@ -0,0 +1,17 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateTextmagicProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name (optional) + false, // enabled (optional) + '<USERNAME>', // username (optional) + '<API_KEY>', // apiKey (optional) + '<FROM>' // from (optional) +); diff --git a/docs/examples/messaging/update-topic.md b/docs/examples/messaging/update-topic.md new file mode 100644 index 0000000..ebcbd4f --- /dev/null +++ b/docs/examples/messaging/update-topic.md @@ -0,0 +1,14 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateTopic( + '<TOPIC_ID>', // topicId + '<NAME>', // name (optional) + ["any"] // subscribe (optional) +); diff --git a/docs/examples/messaging/update-twilio-provider.md b/docs/examples/messaging/update-twilio-provider.md new file mode 100644 index 0000000..67012cf --- /dev/null +++ b/docs/examples/messaging/update-twilio-provider.md @@ -0,0 +1,17 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateTwilioProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name (optional) + false, // enabled (optional) + '<ACCOUNT_SID>', // accountSid (optional) + '<AUTH_TOKEN>', // authToken (optional) + '<FROM>' // from (optional) +); diff --git a/docs/examples/messaging/update-vonage-provider.md b/docs/examples/messaging/update-vonage-provider.md new file mode 100644 index 0000000..ba894ce --- /dev/null +++ b/docs/examples/messaging/update-vonage-provider.md @@ -0,0 +1,17 @@ +import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const messaging = new Messaging(client); + +const response = await messaging.updateVonageProvider( + '<PROVIDER_ID>', // providerId + '<NAME>', // name (optional) + false, // enabled (optional) + '<API_KEY>', // apiKey (optional) + '<API_SECRET>', // apiSecret (optional) + '<FROM>' // from (optional) +); diff --git a/docs/examples/storage/create-bucket.md b/docs/examples/storage/create-bucket.md index a25211a..6945757 100644 --- a/docs/examples/storage/create-bucket.md +++ b/docs/examples/storage/create-bucket.md @@ -1,21 +1,21 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage, } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = storage.createBucket('[BUCKET_ID]', '[NAME]'); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await storage.createBucket( + '<BUCKET_ID>', // bucketId + '<NAME>', // name + ["read("any")"], // permissions (optional) + false, // fileSecurity (optional) + false, // enabled (optional) + 1, // maximumFileSize (optional) + [], // allowedFileExtensions (optional) + .None, // compression (optional) + false, // encryption (optional) + false // antivirus (optional) +); diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index c0fe493..6f52c9b 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = storage.createFile('[BUCKET_ID]', '[FILE_ID]', InputFile.fromPath('/path/to/file.png', 'file.png')); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await storage.createFile( + '<BUCKET_ID>', // bucketId + '<FILE_ID>', // fileId + InputFile.fromPath('/path/to/file.png', 'file.png'), // file + ["read("any")"] // permissions (optional) +); diff --git a/docs/examples/storage/delete-bucket.md b/docs/examples/storage/delete-bucket.md index d468428..78a652e 100644 --- a/docs/examples/storage/delete-bucket.md +++ b/docs/examples/storage/delete-bucket.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = storage.deleteBucket('[BUCKET_ID]'); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await storage.deleteBucket( + '<BUCKET_ID>' // bucketId +); diff --git a/docs/examples/storage/delete-file.md b/docs/examples/storage/delete-file.md index e86da17..684f719 100644 --- a/docs/examples/storage/delete-file.md +++ b/docs/examples/storage/delete-file.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = storage.deleteFile('[BUCKET_ID]', '[FILE_ID]'); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await storage.deleteFile( + '<BUCKET_ID>', // bucketId + '<FILE_ID>' // fileId +); diff --git a/docs/examples/storage/get-bucket.md b/docs/examples/storage/get-bucket.md index 35d22b9..fcf3496 100644 --- a/docs/examples/storage/get-bucket.md +++ b/docs/examples/storage/get-bucket.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = storage.getBucket('[BUCKET_ID]'); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await storage.getBucket( + '<BUCKET_ID>' // bucketId +); diff --git a/docs/examples/storage/get-file-download.md b/docs/examples/storage/get-file-download.md index 206b860..10c4030 100644 --- a/docs/examples/storage/get-file-download.md +++ b/docs/examples/storage/get-file-download.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = storage.getFileDownload('[BUCKET_ID]', '[FILE_ID]'); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const result = storage.getFileDownload( + '<BUCKET_ID>', // bucketId + '<FILE_ID>' // fileId +); diff --git a/docs/examples/storage/get-file-preview.md b/docs/examples/storage/get-file-preview.md index 4815c6b..9eb8550 100644 --- a/docs/examples/storage/get-file-preview.md +++ b/docs/examples/storage/get-file-preview.md @@ -1,21 +1,24 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage, ImageGravity, ImageFormat } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = storage.getFilePreview('[BUCKET_ID]', '[FILE_ID]'); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const result = storage.getFilePreview( + '<BUCKET_ID>', // bucketId + '<FILE_ID>', // fileId + 0, // width (optional) + 0, // height (optional) + ImageGravity.Center, // gravity (optional) + 0, // quality (optional) + 0, // borderWidth (optional) + '', // borderColor (optional) + 0, // borderRadius (optional) + 0, // opacity (optional) + -360, // rotation (optional) + '', // background (optional) + ImageFormat.Jpg // output (optional) +); diff --git a/docs/examples/storage/get-file-view.md b/docs/examples/storage/get-file-view.md index 11ca8fd..4e1605c 100644 --- a/docs/examples/storage/get-file-view.md +++ b/docs/examples/storage/get-file-view.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = storage.getFileView('[BUCKET_ID]', '[FILE_ID]'); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const result = storage.getFileView( + '<BUCKET_ID>', // bucketId + '<FILE_ID>' // fileId +); diff --git a/docs/examples/storage/get-file.md b/docs/examples/storage/get-file.md index 04aa43a..6cc3423 100644 --- a/docs/examples/storage/get-file.md +++ b/docs/examples/storage/get-file.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = storage.getFile('[BUCKET_ID]', '[FILE_ID]'); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await storage.getFile( + '<BUCKET_ID>', // bucketId + '<FILE_ID>' // fileId +); diff --git a/docs/examples/storage/list-buckets.md b/docs/examples/storage/list-buckets.md index 0c31fef..c52da7d 100644 --- a/docs/examples/storage/list-buckets.md +++ b/docs/examples/storage/list-buckets.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = storage.listBuckets(); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await storage.listBuckets( + [], // queries (optional) + '<SEARCH>' // search (optional) +); diff --git a/docs/examples/storage/list-files.md b/docs/examples/storage/list-files.md index 00178aa..e569eb4 100644 --- a/docs/examples/storage/list-files.md +++ b/docs/examples/storage/list-files.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = storage.listFiles('[BUCKET_ID]'); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await storage.listFiles( + '<BUCKET_ID>', // bucketId + [], // queries (optional) + '<SEARCH>' // search (optional) +); diff --git a/docs/examples/storage/update-bucket.md b/docs/examples/storage/update-bucket.md index aca7461..9adb023 100644 --- a/docs/examples/storage/update-bucket.md +++ b/docs/examples/storage/update-bucket.md @@ -1,21 +1,21 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage, } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = storage.updateBucket('[BUCKET_ID]', '[NAME]'); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await storage.updateBucket( + '<BUCKET_ID>', // bucketId + '<NAME>', // name + ["read("any")"], // permissions (optional) + false, // fileSecurity (optional) + false, // enabled (optional) + 1, // maximumFileSize (optional) + [], // allowedFileExtensions (optional) + .None, // compression (optional) + false, // encryption (optional) + false // antivirus (optional) +); diff --git a/docs/examples/storage/update-file.md b/docs/examples/storage/update-file.md index 79f31c3..ca3f476 100644 --- a/docs/examples/storage/update-file.md +++ b/docs/examples/storage/update-file.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Storage } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let storage = new sdk.Storage(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = storage.updateFile('[BUCKET_ID]', '[FILE_ID]'); +const storage = new Storage(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await storage.updateFile( + '<BUCKET_ID>', // bucketId + '<FILE_ID>', // fileId + '<NAME>', // name (optional) + ["read("any")"] // permissions (optional) +); diff --git a/docs/examples/teams/create-membership.md b/docs/examples/teams/create-membership.md index afb6b91..1b4a56e 100644 --- a/docs/examples/teams/create-membership.md +++ b/docs/examples/teams/create-membership.md @@ -1,21 +1,18 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = teams.createMembership('[TEAM_ID]', []); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.createMembership( + '<TEAM_ID>', // teamId + [], // roles + 'email@example.com', // email (optional) + '<USER_ID>', // userId (optional) + '+12065550100', // phone (optional) + 'https://example.com', // url (optional) + '<NAME>' // name (optional) +); diff --git a/docs/examples/teams/create.md b/docs/examples/teams/create.md index 8272adb..d8a6f9d 100644 --- a/docs/examples/teams/create.md +++ b/docs/examples/teams/create.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = teams.create('[TEAM_ID]', '[NAME]'); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.create( + '<TEAM_ID>', // teamId + '<NAME>', // name + [] // roles (optional) +); diff --git a/docs/examples/teams/delete-membership.md b/docs/examples/teams/delete-membership.md index 402deb0..890a36d 100644 --- a/docs/examples/teams/delete-membership.md +++ b/docs/examples/teams/delete-membership.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = teams.deleteMembership('[TEAM_ID]', '[MEMBERSHIP_ID]'); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.deleteMembership( + '<TEAM_ID>', // teamId + '<MEMBERSHIP_ID>' // membershipId +); diff --git a/docs/examples/teams/delete.md b/docs/examples/teams/delete.md index 3b30934..2384672 100644 --- a/docs/examples/teams/delete.md +++ b/docs/examples/teams/delete.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = teams.delete('[TEAM_ID]'); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.delete( + '<TEAM_ID>' // teamId +); diff --git a/docs/examples/teams/get-membership.md b/docs/examples/teams/get-membership.md index 7d50599..b6ee8e0 100644 --- a/docs/examples/teams/get-membership.md +++ b/docs/examples/teams/get-membership.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = teams.getMembership('[TEAM_ID]', '[MEMBERSHIP_ID]'); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.getMembership( + '<TEAM_ID>', // teamId + '<MEMBERSHIP_ID>' // membershipId +); diff --git a/docs/examples/teams/get-prefs.md b/docs/examples/teams/get-prefs.md index 5a7fa4d..26940f0 100644 --- a/docs/examples/teams/get-prefs.md +++ b/docs/examples/teams/get-prefs.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = teams.getPrefs('[TEAM_ID]'); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.getPrefs( + '<TEAM_ID>' // teamId +); diff --git a/docs/examples/teams/get.md b/docs/examples/teams/get.md index 44ecdab..8c822ad 100644 --- a/docs/examples/teams/get.md +++ b/docs/examples/teams/get.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = teams.get('[TEAM_ID]'); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.get( + '<TEAM_ID>' // teamId +); diff --git a/docs/examples/teams/list-memberships.md b/docs/examples/teams/list-memberships.md index 7d73002..7a5e26e 100644 --- a/docs/examples/teams/list-memberships.md +++ b/docs/examples/teams/list-memberships.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = teams.listMemberships('[TEAM_ID]'); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.listMemberships( + '<TEAM_ID>', // teamId + [], // queries (optional) + '<SEARCH>' // search (optional) +); diff --git a/docs/examples/teams/list.md b/docs/examples/teams/list.md index c45ffdc..03c8d0e 100644 --- a/docs/examples/teams/list.md +++ b/docs/examples/teams/list.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = teams.list(); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.list( + [], // queries (optional) + '<SEARCH>' // search (optional) +); diff --git a/docs/examples/teams/update-membership-status.md b/docs/examples/teams/update-membership-status.md index 7bb57d8..7692eed 100644 --- a/docs/examples/teams/update-membership-status.md +++ b/docs/examples/teams/update-membership-status.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = teams.updateMembershipStatus('[TEAM_ID]', '[MEMBERSHIP_ID]', '[USER_ID]', '[SECRET]'); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.updateMembershipStatus( + '<TEAM_ID>', // teamId + '<MEMBERSHIP_ID>', // membershipId + '<USER_ID>', // userId + '<SECRET>' // secret +); diff --git a/docs/examples/teams/update-membership.md b/docs/examples/teams/update-membership.md index 3ada2f4..67e4d80 100644 --- a/docs/examples/teams/update-membership.md +++ b/docs/examples/teams/update-membership.md @@ -1,21 +1,14 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = teams.updateMembership('[TEAM_ID]', '[MEMBERSHIP_ID]', []); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.updateMembership( + '<TEAM_ID>', // teamId + '<MEMBERSHIP_ID>', // membershipId + [] // roles +); diff --git a/docs/examples/teams/update-name.md b/docs/examples/teams/update-name.md index 47c3fc2..faaf1e6 100644 --- a/docs/examples/teams/update-name.md +++ b/docs/examples/teams/update-name.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setSession(''); // The user session to authenticate with -let promise = teams.updateName('[TEAM_ID]', '[NAME]'); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.updateName( + '<TEAM_ID>', // teamId + '<NAME>' // name +); diff --git a/docs/examples/teams/update-prefs.md b/docs/examples/teams/update-prefs.md index 83845be..1638b06 100644 --- a/docs/examples/teams/update-prefs.md +++ b/docs/examples/teams/update-prefs.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Teams } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let teams = new sdk.Teams(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setJWT('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...') // Your secret JSON Web Token -; - + .setSession(''); // The user session to authenticate with -let promise = teams.updatePrefs('[TEAM_ID]', {}); +const teams = new Teams(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await teams.updatePrefs( + '<TEAM_ID>', // teamId + {} // prefs +); diff --git a/docs/examples/users/create-argon2user.md b/docs/examples/users/create-argon2user.md index e55b644..178fadb 100644 --- a/docs/examples/users/create-argon2user.md +++ b/docs/examples/users/create-argon2user.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.createArgon2User('[USER_ID]', 'email@example.com', 'password'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.createArgon2User( + '<USER_ID>', // userId + 'email@example.com', // email + 'password', // password + '<NAME>' // name (optional) +); diff --git a/docs/examples/users/create-bcrypt-user.md b/docs/examples/users/create-bcrypt-user.md index 325fbe4..5787a4e 100644 --- a/docs/examples/users/create-bcrypt-user.md +++ b/docs/examples/users/create-bcrypt-user.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.createBcryptUser('[USER_ID]', 'email@example.com', 'password'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.createBcryptUser( + '<USER_ID>', // userId + 'email@example.com', // email + 'password', // password + '<NAME>' // name (optional) +); diff --git a/docs/examples/users/create-m-d5user.md b/docs/examples/users/create-m-d5user.md index 8892688..5cdde63 100644 --- a/docs/examples/users/create-m-d5user.md +++ b/docs/examples/users/create-m-d5user.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.createMD5User('[USER_ID]', 'email@example.com', 'password'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.createMD5User( + '<USER_ID>', // userId + 'email@example.com', // email + 'password', // password + '<NAME>' // name (optional) +); diff --git a/docs/examples/users/create-mfa-recovery-codes.md b/docs/examples/users/create-mfa-recovery-codes.md new file mode 100644 index 0000000..350ae3c --- /dev/null +++ b/docs/examples/users/create-mfa-recovery-codes.md @@ -0,0 +1,12 @@ +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.createMfaRecoveryCodes( + '<USER_ID>' // userId +); diff --git a/docs/examples/users/create-p-h-pass-user.md b/docs/examples/users/create-p-h-pass-user.md index d7a3428..baf2f65 100644 --- a/docs/examples/users/create-p-h-pass-user.md +++ b/docs/examples/users/create-p-h-pass-user.md @@ -1,21 +1,15 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.createPHPassUser('[USER_ID]', 'email@example.com', 'password'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.createPHPassUser( + '<USER_ID>', // userId + 'email@example.com', // email + 'password', // password + '<NAME>' // name (optional) +); diff --git a/docs/examples/users/create-s-h-a-user.md b/docs/examples/users/create-s-h-a-user.md index c3ade98..995c970 100644 --- a/docs/examples/users/create-s-h-a-user.md +++ b/docs/examples/users/create-s-h-a-user.md @@ -1,21 +1,16 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users, PasswordHash } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.createSHAUser('[USER_ID]', 'email@example.com', 'password'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.createSHAUser( + '<USER_ID>', // userId + 'email@example.com', // email + 'password', // password + PasswordHash.Sha1, // passwordVersion (optional) + '<NAME>' // name (optional) +); diff --git a/docs/examples/users/create-scrypt-modified-user.md b/docs/examples/users/create-scrypt-modified-user.md index 8039a97..dfeff7c 100644 --- a/docs/examples/users/create-scrypt-modified-user.md +++ b/docs/examples/users/create-scrypt-modified-user.md @@ -1,21 +1,18 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.createScryptModifiedUser('[USER_ID]', 'email@example.com', 'password', '[PASSWORD_SALT]', '[PASSWORD_SALT_SEPARATOR]', '[PASSWORD_SIGNER_KEY]'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.createScryptModifiedUser( + '<USER_ID>', // userId + 'email@example.com', // email + 'password', // password + '<PASSWORD_SALT>', // passwordSalt + '<PASSWORD_SALT_SEPARATOR>', // passwordSaltSeparator + '<PASSWORD_SIGNER_KEY>', // passwordSignerKey + '<NAME>' // name (optional) +); diff --git a/docs/examples/users/create-scrypt-user.md b/docs/examples/users/create-scrypt-user.md index 9889855..75d4738 100644 --- a/docs/examples/users/create-scrypt-user.md +++ b/docs/examples/users/create-scrypt-user.md @@ -1,21 +1,20 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.createScryptUser('[USER_ID]', 'email@example.com', 'password', '[PASSWORD_SALT]', null, null, null, null); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.createScryptUser( + '<USER_ID>', // userId + 'email@example.com', // email + 'password', // password + '<PASSWORD_SALT>', // passwordSalt + null, // passwordCpu + null, // passwordMemory + null, // passwordParallel + null, // passwordLength + '<NAME>' // name (optional) +); diff --git a/docs/examples/users/create-session.md b/docs/examples/users/create-session.md new file mode 100644 index 0000000..1e95dc7 --- /dev/null +++ b/docs/examples/users/create-session.md @@ -0,0 +1,12 @@ +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.createSession( + '<USER_ID>' // userId +); diff --git a/docs/examples/users/create-target.md b/docs/examples/users/create-target.md new file mode 100644 index 0000000..ae63ba6 --- /dev/null +++ b/docs/examples/users/create-target.md @@ -0,0 +1,17 @@ +import { Client, Users, MessagingProviderType } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.createTarget( + '<USER_ID>', // userId + '<TARGET_ID>', // targetId + MessagingProviderType.Email, // providerType + '<IDENTIFIER>', // identifier + '<PROVIDER_ID>', // providerId (optional) + '<NAME>' // name (optional) +); diff --git a/docs/examples/users/create-token.md b/docs/examples/users/create-token.md new file mode 100644 index 0000000..705f272 --- /dev/null +++ b/docs/examples/users/create-token.md @@ -0,0 +1,14 @@ +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.createToken( + '<USER_ID>', // userId + 4, // length (optional) + 60 // expire (optional) +); diff --git a/docs/examples/users/create.md b/docs/examples/users/create.md index c56f8d8..4c1c226 100644 --- a/docs/examples/users/create.md +++ b/docs/examples/users/create.md @@ -1,21 +1,16 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.create('[USER_ID]'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.create( + '<USER_ID>', // userId + 'email@example.com', // email (optional) + '+12065550100', // phone (optional) + '', // password (optional) + '<NAME>' // name (optional) +); diff --git a/docs/examples/users/delete-identity.md b/docs/examples/users/delete-identity.md index 7d7b88a..07c1466 100644 --- a/docs/examples/users/delete-identity.md +++ b/docs/examples/users/delete-identity.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.deleteIdentity('[IDENTITY_ID]'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.deleteIdentity( + '<IDENTITY_ID>' // identityId +); diff --git a/docs/examples/users/delete-mfa-authenticator.md b/docs/examples/users/delete-mfa-authenticator.md new file mode 100644 index 0000000..26ff178 --- /dev/null +++ b/docs/examples/users/delete-mfa-authenticator.md @@ -0,0 +1,13 @@ +import { Client, Users, AuthenticatorType } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.deleteMfaAuthenticator( + '<USER_ID>', // userId + AuthenticatorType.Totp // type +); diff --git a/docs/examples/users/delete-session.md b/docs/examples/users/delete-session.md index e4ea45b..ffc359f 100644 --- a/docs/examples/users/delete-session.md +++ b/docs/examples/users/delete-session.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.deleteSession('[USER_ID]', '[SESSION_ID]'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.deleteSession( + '<USER_ID>', // userId + '<SESSION_ID>' // sessionId +); diff --git a/docs/examples/users/delete-sessions.md b/docs/examples/users/delete-sessions.md index 0e12d6d..071d2e4 100644 --- a/docs/examples/users/delete-sessions.md +++ b/docs/examples/users/delete-sessions.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.deleteSessions('[USER_ID]'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.deleteSessions( + '<USER_ID>' // userId +); diff --git a/docs/examples/users/delete-target.md b/docs/examples/users/delete-target.md new file mode 100644 index 0000000..d7c0fb5 --- /dev/null +++ b/docs/examples/users/delete-target.md @@ -0,0 +1,13 @@ +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.deleteTarget( + '<USER_ID>', // userId + '<TARGET_ID>' // targetId +); diff --git a/docs/examples/users/delete.md b/docs/examples/users/delete.md index f022302..e5df110 100644 --- a/docs/examples/users/delete.md +++ b/docs/examples/users/delete.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.delete('[USER_ID]'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.delete( + '<USER_ID>' // userId +); diff --git a/docs/examples/users/get-mfa-recovery-codes.md b/docs/examples/users/get-mfa-recovery-codes.md new file mode 100644 index 0000000..26145a9 --- /dev/null +++ b/docs/examples/users/get-mfa-recovery-codes.md @@ -0,0 +1,12 @@ +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.getMfaRecoveryCodes( + '<USER_ID>' // userId +); diff --git a/docs/examples/users/get-prefs.md b/docs/examples/users/get-prefs.md index 63953f9..281a621 100644 --- a/docs/examples/users/get-prefs.md +++ b/docs/examples/users/get-prefs.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.getPrefs('[USER_ID]'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.getPrefs( + '<USER_ID>' // userId +); diff --git a/docs/examples/users/get-target.md b/docs/examples/users/get-target.md new file mode 100644 index 0000000..ce0965c --- /dev/null +++ b/docs/examples/users/get-target.md @@ -0,0 +1,13 @@ +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.getTarget( + '<USER_ID>', // userId + '<TARGET_ID>' // targetId +); diff --git a/docs/examples/users/get.md b/docs/examples/users/get.md index c9300c5..8a2e0d4 100644 --- a/docs/examples/users/get.md +++ b/docs/examples/users/get.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.get('[USER_ID]'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.get( + '<USER_ID>' // userId +); diff --git a/docs/examples/users/list-identities.md b/docs/examples/users/list-identities.md index 6877701..e4402f7 100644 --- a/docs/examples/users/list-identities.md +++ b/docs/examples/users/list-identities.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.listIdentities(); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.listIdentities( + [], // queries (optional) + '<SEARCH>' // search (optional) +); diff --git a/docs/examples/users/list-logs.md b/docs/examples/users/list-logs.md index 7d0841f..8d7f37f 100644 --- a/docs/examples/users/list-logs.md +++ b/docs/examples/users/list-logs.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.listLogs('[USER_ID]'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.listLogs( + '<USER_ID>', // userId + [] // queries (optional) +); diff --git a/docs/examples/users/list-memberships.md b/docs/examples/users/list-memberships.md index 74f2fb7..ec5a57b 100644 --- a/docs/examples/users/list-memberships.md +++ b/docs/examples/users/list-memberships.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.listMemberships('[USER_ID]'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.listMemberships( + '<USER_ID>' // userId +); diff --git a/docs/examples/users/list-mfa-factors.md b/docs/examples/users/list-mfa-factors.md new file mode 100644 index 0000000..90bfba8 --- /dev/null +++ b/docs/examples/users/list-mfa-factors.md @@ -0,0 +1,12 @@ +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.listMfaFactors( + '<USER_ID>' // userId +); diff --git a/docs/examples/users/list-sessions.md b/docs/examples/users/list-sessions.md index 1aa4ca7..e4b0ede 100644 --- a/docs/examples/users/list-sessions.md +++ b/docs/examples/users/list-sessions.md @@ -1,21 +1,12 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.listSessions('[USER_ID]'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.listSessions( + '<USER_ID>' // userId +); diff --git a/docs/examples/users/list-targets.md b/docs/examples/users/list-targets.md new file mode 100644 index 0000000..c15847d --- /dev/null +++ b/docs/examples/users/list-targets.md @@ -0,0 +1,13 @@ +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.listTargets( + '<USER_ID>', // userId + [] // queries (optional) +); diff --git a/docs/examples/users/list.md b/docs/examples/users/list.md index 369ccd7..f605366 100644 --- a/docs/examples/users/list.md +++ b/docs/examples/users/list.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.list(); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.list( + [], // queries (optional) + '<SEARCH>' // search (optional) +); diff --git a/docs/examples/users/update-email-verification.md b/docs/examples/users/update-email-verification.md index 146cea5..a3684df 100644 --- a/docs/examples/users/update-email-verification.md +++ b/docs/examples/users/update-email-verification.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.updateEmailVerification('[USER_ID]', false); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.updateEmailVerification( + '<USER_ID>', // userId + false // emailVerification +); diff --git a/docs/examples/users/update-email.md b/docs/examples/users/update-email.md index bd7f0ff..5920791 100644 --- a/docs/examples/users/update-email.md +++ b/docs/examples/users/update-email.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.updateEmail('[USER_ID]', 'email@example.com'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.updateEmail( + '<USER_ID>', // userId + 'email@example.com' // email +); diff --git a/docs/examples/users/update-labels.md b/docs/examples/users/update-labels.md index 73aee64..847c70a 100644 --- a/docs/examples/users/update-labels.md +++ b/docs/examples/users/update-labels.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.updateLabels('[USER_ID]', []); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.updateLabels( + '<USER_ID>', // userId + [] // labels +); diff --git a/docs/examples/users/update-mfa-recovery-codes.md b/docs/examples/users/update-mfa-recovery-codes.md new file mode 100644 index 0000000..4ce52fd --- /dev/null +++ b/docs/examples/users/update-mfa-recovery-codes.md @@ -0,0 +1,12 @@ +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.updateMfaRecoveryCodes( + '<USER_ID>' // userId +); diff --git a/docs/examples/users/update-mfa.md b/docs/examples/users/update-mfa.md new file mode 100644 index 0000000..ced8232 --- /dev/null +++ b/docs/examples/users/update-mfa.md @@ -0,0 +1,13 @@ +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.updateMfa( + '<USER_ID>', // userId + false // mfa +); diff --git a/docs/examples/users/update-name.md b/docs/examples/users/update-name.md index 071c948..61042dd 100644 --- a/docs/examples/users/update-name.md +++ b/docs/examples/users/update-name.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.updateName('[USER_ID]', '[NAME]'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.updateName( + '<USER_ID>', // userId + '<NAME>' // name +); diff --git a/docs/examples/users/update-password.md b/docs/examples/users/update-password.md index e6ae8b7..cdefd18 100644 --- a/docs/examples/users/update-password.md +++ b/docs/examples/users/update-password.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.updatePassword('[USER_ID]', ''); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.updatePassword( + '<USER_ID>', // userId + '' // password +); diff --git a/docs/examples/users/update-phone-verification.md b/docs/examples/users/update-phone-verification.md index 293f876..6bcf61f 100644 --- a/docs/examples/users/update-phone-verification.md +++ b/docs/examples/users/update-phone-verification.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.updatePhoneVerification('[USER_ID]', false); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.updatePhoneVerification( + '<USER_ID>', // userId + false // phoneVerification +); diff --git a/docs/examples/users/update-phone.md b/docs/examples/users/update-phone.md index e634f59..54756ea 100644 --- a/docs/examples/users/update-phone.md +++ b/docs/examples/users/update-phone.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.updatePhone('[USER_ID]', '+12065550100'); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.updatePhone( + '<USER_ID>', // userId + '+12065550100' // number +); diff --git a/docs/examples/users/update-prefs.md b/docs/examples/users/update-prefs.md index 248fdb1..61cbb15 100644 --- a/docs/examples/users/update-prefs.md +++ b/docs/examples/users/update-prefs.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.updatePrefs('[USER_ID]', {}); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.updatePrefs( + '<USER_ID>', // userId + {} // prefs +); diff --git a/docs/examples/users/update-status.md b/docs/examples/users/update-status.md index 2f14259..2bf8fee 100644 --- a/docs/examples/users/update-status.md +++ b/docs/examples/users/update-status.md @@ -1,21 +1,13 @@ -import * as sdk from "https://deno.land/x/appwrite/mod.ts"; +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; -// Init SDK -let client = new sdk.Client(); - -let users = new sdk.Users(client); - -client +const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID - .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key -; - + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key -let promise = users.updateStatus('[USER_ID]', false); +const users = new Users(client); -promise.then(function (response) { - console.log(response); -}, function (error) { - console.log(error); -}); \ No newline at end of file +const response = await users.updateStatus( + '<USER_ID>', // userId + false // status +); diff --git a/docs/examples/users/update-target.md b/docs/examples/users/update-target.md new file mode 100644 index 0000000..a34f651 --- /dev/null +++ b/docs/examples/users/update-target.md @@ -0,0 +1,16 @@ +import { Client, Users } from "https://deno.land/x/appwrite/mod.ts"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key + +const users = new Users(client); + +const response = await users.updateTarget( + '<USER_ID>', // userId + '<TARGET_ID>', // targetId + '<IDENTIFIER>', // identifier (optional) + '<PROVIDER_ID>', // providerId (optional) + '<NAME>' // name (optional) +); diff --git a/mod.ts b/mod.ts index 0bdaaf9..09d23a4 100644 --- a/mod.ts +++ b/mod.ts @@ -12,9 +12,28 @@ import { Functions } from "./src/services/functions.ts"; import { Graphql } from "./src/services/graphql.ts"; import { Health } from "./src/services/health.ts"; import { Locale } from "./src/services/locale.ts"; +import { Messaging } from "./src/services/messaging.ts"; import { Storage } from "./src/services/storage.ts"; import { Teams } from "./src/services/teams.ts"; import { Users } from "./src/services/users.ts"; +import { AuthenticatorType } from "./src/enums/authenticator-type.ts"; +import { AuthenticationFactor } from "./src/enums/authentication-factor.ts"; +import { OAuthProvider } from "./src/enums/o-auth-provider.ts"; +import { Browser } from "./src/enums/browser.ts"; +import { CreditCard } from "./src/enums/credit-card.ts"; +import { Flag } from "./src/enums/flag.ts"; +import { RelationshipType } from "./src/enums/relationship-type.ts"; +import { RelationMutate } from "./src/enums/relation-mutate.ts"; +import { IndexType } from "./src/enums/index-type.ts"; +import { Runtime } from "./src/enums/runtime.ts"; +import { ExecutionMethod } from "./src/enums/execution-method.ts"; +import { Name } from "./src/enums/name.ts"; +import { SmtpEncryption } from "./src/enums/smtp-encryption.ts"; +import { Compression } from "./src/enums/compression.ts"; +import { ImageGravity } from "./src/enums/image-gravity.ts"; +import { ImageFormat } from "./src/enums/image-format.ts"; +import { PasswordHash } from "./src/enums/password-hash.ts"; +import { MessagingProviderType } from "./src/enums/messaging-provider-type.ts"; export { Client, @@ -31,9 +50,28 @@ export { Graphql, Health, Locale, + Messaging, Storage, Teams, Users, + AuthenticatorType, + AuthenticationFactor, + OAuthProvider, + Browser, + CreditCard, + Flag, + RelationshipType, + RelationMutate, + IndexType, + Runtime, + ExecutionMethod, + Name, + SmtpEncryption, + Compression, + ImageGravity, + ImageFormat, + PasswordHash, + MessagingProviderType, }; export type { Models } from "./src/models.d.ts"; diff --git a/src/client.ts b/src/client.ts index 046ed97..9c0c138 100644 --- a/src/client.ts +++ b/src/client.ts @@ -8,15 +8,15 @@ export class Client { static CHUNK_SIZE = 5*1024*1024; // 5MB static DENO_READ_CHUNK_SIZE = 16384; // 16kb; refference: https://github.com/denoland/deno/discussions/9906 - endpoint: string = 'https://HOSTNAME/v1'; + endpoint: string = 'https://cloud.appwrite.io/v1'; headers: Payload = { 'content-type': '', - 'user-agent' : `AppwriteDenoSDK/9.1.0 (${Deno.build.os}; ${Deno.build.arch})`, + 'user-agent' : `AppwriteDenoSDK/10.0.0 (${Deno.build.os}; ${Deno.build.arch})`, 'x-sdk-name': 'Deno', 'x-sdk-platform': 'server', 'x-sdk-language': 'deno', - 'x-sdk-version': '9.1.0', - 'X-Appwrite-Response-Format':'1.4.0', + 'x-sdk-version': '10.0.0', + 'X-Appwrite-Response-Format':'1.5.0', }; /** @@ -77,6 +77,36 @@ export class Client { return this; } + /** + * Set Session + * + * The user session to authenticate with + * + * @param string value + * + * @return self + */ + setSession(value: string): this { + this.addHeader('X-Appwrite-Session', value); + + return this; + } + + /** + * Set ForwardedUserAgent + * + * The user agent string of the client that made the request + * + * @param string value + * + * @return self + */ + setForwardedUserAgent(value: string): this { + this.addHeader('X-Forwarded-User-Agent', value); + + return this; + } + /*** * @param endpoint @@ -98,80 +128,83 @@ export class Client { return this; } - withoutHeader(key: string, headers: Payload): Payload { - return Object.keys(headers).reduce((acc: Payload, cv: string) => { - if (cv === 'content-type') return acc; - acc[cv] = headers[cv]; - return acc; - }, {}) - } + async call(method: string, path: string = "", headers: Payload = {}, params: Payload = {}, responseType: string = "json") { + headers = {...this.headers, ...headers}; + const url = new URL(this.endpoint + path); - async call(method: string, path: string = '', headers: Payload = {}, params: Payload = {}) { - headers = Object.assign({}, this.headers, headers); + let body: string | FormData | undefined = undefined; - let body; - const url = new URL(this.endpoint + path); - if (method.toUpperCase() === 'GET') { - url.search = new URLSearchParams(this.flatten(params)).toString(); - body = null; - } else if (headers['content-type'].toLowerCase().startsWith('multipart/form-data')) { - headers = this.withoutHeader('content-type', headers); + if (method.toUpperCase() === "GET") { + url.search = new URLSearchParams(Client.flatten(params)).toString(); + } else if (headers["content-type"]?.toLowerCase().startsWith("multipart/form-data")) { + delete headers["content-type"]; const formData = new FormData(); - const flatParams = this.flatten(params); - for (const key in flatParams) { - const value = flatParams[key]; - if(value && value.type && value.type === 'file') { + const flatParams = Client.flatten(params); + + for (const [key, value] of Object.entries(flatParams)) { + if (value && value.type && value.type === "file") { formData.append(key, value.file, value.filename); } else { - formData.append(key, flatParams[key]); + formData.append(key, value); } } + body = formData; } else { body = JSON.stringify(params); } - const options = { - method: method.toUpperCase(), - headers: headers, - body: body, - }; - + let response = undefined; try { - let response = await fetch(url.toString(), options); - const contentType = response.headers.get('content-type'); - - if (contentType && contentType.includes('application/json')) { - if (response.status >= 400) { - let res = await response.json(); - throw new AppwriteException(res.message, res.status, res.type ?? "", res); - } + response = await fetch(url.toString(), { + redirect: responseType === "location" ? "manual" : "follow", + method: method.toUpperCase(), + headers, + body + }); + } catch (error) { + throw new AppwriteException(error.message); + } - return response.json(); - } else { - if (response.status >= 400) { - let res = await response.text(); - throw new AppwriteException(res, response.status, "", null); - } - return response; + if (response.status >= 400) { + const text = await response.text(); + let json = undefined; + try { + json = JSON.parse(text); + } catch (error) { + throw new AppwriteException(text, response.status, "", text); } - } catch(error) { - throw new AppwriteException(error?.response?.message || error.message, error?.response?.code, error?.response?.type, error.response); + throw new AppwriteException(json.message, json.code, json.type, json); } + + if (responseType === "arraybuffer") { + const data = await response.arrayBuffer(); + return data; + } + + if (responseType === "location") { + return response.headers.get("location"); + } + + const text = await response.text(); + let json = undefined; + try { + json = JSON.parse(text); + } catch (error) { + return text; + } + return json; } - flatten(data: Payload, prefix = '') { + static flatten(data: Payload, prefix = ''): Payload { let output: Payload = {}; - for (const key in data) { - let value = data[key]; + for (const [key, value] of Object.entries(data)) { let finalKey = prefix ? prefix + '[' + key +']' : key; - if (Array.isArray(value)) { - output = { ...output, ...this.flatten(value, finalKey) }; // @todo: handle name collision here if needed - } - else { + output = { ...output, ...Client.flatten(value, finalKey) }; + } else { output[finalKey] = value; } } diff --git a/src/enums/authentication-factor.ts b/src/enums/authentication-factor.ts new file mode 100644 index 0000000..928c407 --- /dev/null +++ b/src/enums/authentication-factor.ts @@ -0,0 +1,6 @@ +export enum AuthenticationFactor { + Email = 'email', + Phone = 'phone', + Totp = 'totp', + Recoverycode = 'recoverycode', +} \ No newline at end of file diff --git a/src/enums/authenticator-type.ts b/src/enums/authenticator-type.ts new file mode 100644 index 0000000..34db0cc --- /dev/null +++ b/src/enums/authenticator-type.ts @@ -0,0 +1,3 @@ +export enum AuthenticatorType { + Totp = 'totp', +} \ No newline at end of file diff --git a/src/enums/browser.ts b/src/enums/browser.ts new file mode 100644 index 0000000..cec52fb --- /dev/null +++ b/src/enums/browser.ts @@ -0,0 +1,16 @@ +export enum Browser { + AvantBrowser = 'aa', + AndroidWebViewBeta = 'an', + GoogleChrome = 'ch', + GoogleChromeIOS = 'ci', + GoogleChromeMobile = 'cm', + Chromium = 'cr', + MozillaFirefox = 'ff', + Safari = 'sf', + MobileSafari = 'mf', + MicrosoftEdge = 'ps', + MicrosoftEdgeIOS = 'oi', + OperaMini = 'om', + Opera = 'op', + OperaNext = 'on', +} \ No newline at end of file diff --git a/src/enums/compression.ts b/src/enums/compression.ts new file mode 100644 index 0000000..1bec0e7 --- /dev/null +++ b/src/enums/compression.ts @@ -0,0 +1,5 @@ +export enum Compression { + None = 'none', + Gzip = 'gzip', + Zstd = 'zstd', +} \ No newline at end of file diff --git a/src/enums/credit-card.ts b/src/enums/credit-card.ts new file mode 100644 index 0000000..ae917a8 --- /dev/null +++ b/src/enums/credit-card.ts @@ -0,0 +1,18 @@ +export enum CreditCard { + AmericanExpress = 'amex', + Argencard = 'argencard', + Cabal = 'cabal', + Consosud = 'censosud', + DinersClub = 'diners', + Discover = 'discover', + Elo = 'elo', + Hipercard = 'hipercard', + JCB = 'jcb', + Mastercard = 'mastercard', + Naranja = 'naranja', + TarjetaShopping = 'targeta-shopping', + UnionChinaPay = 'union-china-pay', + Visa = 'visa', + MIR = 'mir', + Maestro = 'maestro', +} \ No newline at end of file diff --git a/src/enums/execution-method.ts b/src/enums/execution-method.ts new file mode 100644 index 0000000..fc63b07 --- /dev/null +++ b/src/enums/execution-method.ts @@ -0,0 +1,8 @@ +export enum ExecutionMethod { + GET = 'GET', + POST = 'POST', + PUT = 'PUT', + PATCH = 'PATCH', + DELETE = 'DELETE', + OPTIONS = 'OPTIONS', +} \ No newline at end of file diff --git a/src/enums/flag.ts b/src/enums/flag.ts new file mode 100644 index 0000000..07416a4 --- /dev/null +++ b/src/enums/flag.ts @@ -0,0 +1,196 @@ +export enum Flag { + Afghanistan = 'af', + Angola = 'ao', + Albania = 'al', + Andorra = 'ad', + UnitedArabEmirates = 'ae', + Argentina = 'ar', + Armenia = 'am', + AntiguaAndBarbuda = 'ag', + Australia = 'au', + Austria = 'at', + Azerbaijan = 'az', + Burundi = 'bi', + Belgium = 'be', + Benin = 'bj', + BurkinaFaso = 'bf', + Bangladesh = 'bd', + Bulgaria = 'bg', + Bahrain = 'bh', + Bahamas = 'bs', + BosniaAndHerzegovina = 'ba', + Belarus = 'by', + Belize = 'bz', + Bolivia = 'bo', + Brazil = 'br', + Barbados = 'bb', + BruneiDarussalam = 'bn', + Bhutan = 'bt', + Botswana = 'bw', + CentralAfricanRepublic = 'cf', + Canada = 'ca', + Switzerland = 'ch', + Chile = 'cl', + China = 'cn', + CoteDIvoire = 'ci', + Cameroon = 'cm', + DemocraticRepublicOfTheCongo = 'cd', + RepublicOfTheCongo = 'cg', + Colombia = 'co', + Comoros = 'km', + CapeVerde = 'cv', + CostaRica = 'cr', + Cuba = 'cu', + Cyprus = 'cy', + CzechRepublic = 'cz', + Germany = 'de', + Djibouti = 'dj', + Dominica = 'dm', + Denmark = 'dk', + DominicanRepublic = 'do', + Algeria = 'dz', + Ecuador = 'ec', + Egypt = 'eg', + Eritrea = 'er', + Spain = 'es', + Estonia = 'ee', + Ethiopia = 'et', + Finland = 'fi', + Fiji = 'fj', + France = 'fr', + MicronesiaFederatedStatesOf = 'fm', + Gabon = 'ga', + UnitedKingdom = 'gb', + Georgia = 'ge', + Ghana = 'gh', + Guinea = 'gn', + Gambia = 'gm', + GuineaBissau = 'gw', + EquatorialGuinea = 'gq', + Greece = 'gr', + Grenada = 'gd', + Guatemala = 'gt', + Guyana = 'gy', + Honduras = 'hn', + Croatia = 'hr', + Haiti = 'ht', + Hungary = 'hu', + Indonesia = 'id', + India = 'in', + Ireland = 'ie', + IranIslamicRepublicOf = 'ir', + Iraq = 'iq', + Iceland = 'is', + Israel = 'il', + Italy = 'it', + Jamaica = 'jm', + Jordan = 'jo', + Japan = 'jp', + Kazakhstan = 'kz', + Kenya = 'ke', + Kyrgyzstan = 'kg', + Cambodia = 'kh', + Kiribati = 'ki', + SaintKittsAndNevis = 'kn', + SouthKorea = 'kr', + Kuwait = 'kw', + LaoPeopleSDemocraticRepublic = 'la', + Lebanon = 'lb', + Liberia = 'lr', + Libya = 'ly', + SaintLucia = 'lc', + Liechtenstein = 'li', + SriLanka = 'lk', + Lesotho = 'ls', + Lithuania = 'lt', + Luxembourg = 'lu', + Latvia = 'lv', + Morocco = 'ma', + Monaco = 'mc', + Moldova = 'md', + Madagascar = 'mg', + Maldives = 'mv', + Mexico = 'mx', + MarshallIslands = 'mh', + NorthMacedonia = 'mk', + Mali = 'ml', + Malta = 'mt', + Myanmar = 'mm', + Montenegro = 'me', + Mongolia = 'mn', + Mozambique = 'mz', + Mauritania = 'mr', + Mauritius = 'mu', + Malawi = 'mw', + Malaysia = 'my', + Namibia = 'na', + Niger = 'ne', + Nigeria = 'ng', + Nicaragua = 'ni', + Netherlands = 'nl', + Norway = 'no', + Nepal = 'np', + Nauru = 'nr', + NewZealand = 'nz', + Oman = 'om', + Pakistan = 'pk', + Panama = 'pa', + Peru = 'pe', + Philippines = 'ph', + Palau = 'pw', + PapuaNewGuinea = 'pg', + Poland = 'pl', + NorthKorea = 'kp', + Portugal = 'pt', + Paraguay = 'py', + Qatar = 'qa', + Romania = 'ro', + Russia = 'ru', + Rwanda = 'rw', + SaudiArabia = 'sa', + Sudan = 'sd', + Senegal = 'sn', + Singapore = 'sg', + SolomonIslands = 'sb', + SierraLeone = 'sl', + ElSalvador = 'sv', + SanMarino = 'sm', + Somalia = 'so', + Serbia = 'rs', + SouthSudan = 'ss', + SaoTomeAndPrincipe = 'st', + Suriname = 'sr', + Slovakia = 'sk', + Slovenia = 'si', + Sweden = 'se', + Eswatini = 'sz', + Seychelles = 'sc', + Syria = 'sy', + Chad = 'td', + Togo = 'tg', + Thailand = 'th', + Tajikistan = 'tj', + Turkmenistan = 'tm', + TimorLeste = 'tl', + Tonga = 'to', + TrinidadAndTobago = 'tt', + Tunisia = 'tn', + Turkey = 'tr', + Tuvalu = 'tv', + Tanzania = 'tz', + Uganda = 'ug', + Ukraine = 'ua', + Uruguay = 'uy', + UnitedStates = 'us', + Uzbekistan = 'uz', + VaticanCity = 'va', + SaintVincentAndTheGrenadines = 'vc', + Venezuela = 've', + Vietnam = 'vn', + Vanuatu = 'vu', + Samoa = 'ws', + Yemen = 'ye', + SouthAfrica = 'za', + Zambia = 'zm', + Zimbabwe = 'zw', +} \ No newline at end of file diff --git a/src/enums/image-format.ts b/src/enums/image-format.ts new file mode 100644 index 0000000..7e96fd8 --- /dev/null +++ b/src/enums/image-format.ts @@ -0,0 +1,7 @@ +export enum ImageFormat { + Jpg = 'jpg', + Jpeg = 'jpeg', + Gif = 'gif', + Png = 'png', + Webp = 'webp', +} \ No newline at end of file diff --git a/src/enums/image-gravity.ts b/src/enums/image-gravity.ts new file mode 100644 index 0000000..4af66d4 --- /dev/null +++ b/src/enums/image-gravity.ts @@ -0,0 +1,11 @@ +export enum ImageGravity { + Center = 'center', + TopLeft = 'top-left', + Top = 'top', + TopRight = 'top-right', + Left = 'left', + Right = 'right', + BottomLeft = 'bottom-left', + Bottom = 'bottom', + BottomRight = 'bottom-right', +} \ No newline at end of file diff --git a/src/enums/index-type.ts b/src/enums/index-type.ts new file mode 100644 index 0000000..3017b1a --- /dev/null +++ b/src/enums/index-type.ts @@ -0,0 +1,5 @@ +export enum IndexType { + Key = 'key', + Fulltext = 'fulltext', + Unique = 'unique', +} \ No newline at end of file diff --git a/src/enums/messaging-provider-type.ts b/src/enums/messaging-provider-type.ts new file mode 100644 index 0000000..18c9929 --- /dev/null +++ b/src/enums/messaging-provider-type.ts @@ -0,0 +1,5 @@ +export enum MessagingProviderType { + Email = 'email', + Sms = 'sms', + Push = 'push', +} \ No newline at end of file diff --git a/src/enums/name.ts b/src/enums/name.ts new file mode 100644 index 0000000..ea9cf69 --- /dev/null +++ b/src/enums/name.ts @@ -0,0 +1,15 @@ +export enum Name { + V1Database = 'v1-database', + V1Deletes = 'v1-deletes', + V1Audits = 'v1-audits', + V1Mails = 'v1-mails', + V1Functions = 'v1-functions', + V1Usage = 'v1-usage', + V1UsageDump = 'v1-usage-dump', + Webhooksv1 = 'webhooksv1', + V1Certificates = 'v1-certificates', + V1Builds = 'v1-builds', + V1Messaging = 'v1-messaging', + V1Migrations = 'v1-migrations', + Hamsterv1 = 'hamsterv1', +} \ No newline at end of file diff --git a/src/enums/o-auth-provider.ts b/src/enums/o-auth-provider.ts new file mode 100644 index 0000000..b2bf4d1 --- /dev/null +++ b/src/enums/o-auth-provider.ts @@ -0,0 +1,41 @@ +export enum OAuthProvider { + Amazon = 'amazon', + Apple = 'apple', + Auth0 = 'auth0', + Authentik = 'authentik', + Autodesk = 'autodesk', + Bitbucket = 'bitbucket', + Bitly = 'bitly', + Box = 'box', + Dailymotion = 'dailymotion', + Discord = 'discord', + Disqus = 'disqus', + Dropbox = 'dropbox', + Etsy = 'etsy', + Facebook = 'facebook', + Github = 'github', + Gitlab = 'gitlab', + Google = 'google', + Linkedin = 'linkedin', + Microsoft = 'microsoft', + Notion = 'notion', + Oidc = 'oidc', + Okta = 'okta', + Paypal = 'paypal', + PaypalSandbox = 'paypalSandbox', + Podio = 'podio', + Salesforce = 'salesforce', + Slack = 'slack', + Spotify = 'spotify', + Stripe = 'stripe', + Tradeshift = 'tradeshift', + TradeshiftBox = 'tradeshiftBox', + Twitch = 'twitch', + Wordpress = 'wordpress', + Yahoo = 'yahoo', + Yammer = 'yammer', + Yandex = 'yandex', + Zoho = 'zoho', + Zoom = 'zoom', + Mock = 'mock', +} \ No newline at end of file diff --git a/src/enums/password-hash.ts b/src/enums/password-hash.ts new file mode 100644 index 0000000..76834af --- /dev/null +++ b/src/enums/password-hash.ts @@ -0,0 +1,13 @@ +export enum PasswordHash { + Sha1 = 'sha1', + Sha224 = 'sha224', + Sha256 = 'sha256', + Sha384 = 'sha384', + Sha512224 = 'sha512/224', + Sha512256 = 'sha512/256', + Sha512 = 'sha512', + Sha3224 = 'sha3-224', + Sha3256 = 'sha3-256', + Sha3384 = 'sha3-384', + Sha3512 = 'sha3-512', +} \ No newline at end of file diff --git a/src/enums/relation-mutate.ts b/src/enums/relation-mutate.ts new file mode 100644 index 0000000..722a757 --- /dev/null +++ b/src/enums/relation-mutate.ts @@ -0,0 +1,5 @@ +export enum RelationMutate { + Cascade = 'cascade', + Restrict = 'restrict', + SetNull = 'setNull', +} \ No newline at end of file diff --git a/src/enums/relationship-type.ts b/src/enums/relationship-type.ts new file mode 100644 index 0000000..532015a --- /dev/null +++ b/src/enums/relationship-type.ts @@ -0,0 +1,6 @@ +export enum RelationshipType { + OneToOne = 'oneToOne', + ManyToOne = 'manyToOne', + ManyToMany = 'manyToMany', + OneToMany = 'oneToMany', +} \ No newline at end of file diff --git a/src/enums/runtime.ts b/src/enums/runtime.ts new file mode 100644 index 0000000..160c2b5 --- /dev/null +++ b/src/enums/runtime.ts @@ -0,0 +1,46 @@ +export enum Runtime { + Node145 = 'node-14.5', + Node160 = 'node-16.0', + Node180 = 'node-18.0', + Node190 = 'node-19.0', + Node200 = 'node-20.0', + Node210 = 'node-21.0', + Php80 = 'php-8.0', + Php81 = 'php-8.1', + Php82 = 'php-8.2', + Php83 = 'php-8.3', + Ruby30 = 'ruby-3.0', + Ruby31 = 'ruby-3.1', + Ruby32 = 'ruby-3.2', + Ruby33 = 'ruby-3.3', + Python38 = 'python-3.8', + Python39 = 'python-3.9', + Python310 = 'python-3.10', + Python311 = 'python-3.11', + Python312 = 'python-3.12', + Deno140 = 'deno-1.40', + Dart215 = 'dart-2.15', + Dart216 = 'dart-2.16', + Dart217 = 'dart-2.17', + Dart218 = 'dart-2.18', + Dart30 = 'dart-3.0', + Dart31 = 'dart-3.1', + Dart33 = 'dart-3.3', + Dotnet31 = 'dotnet-3.1', + Dotnet60 = 'dotnet-6.0', + Dotnet70 = 'dotnet-7.0', + Java80 = 'java-8.0', + Java110 = 'java-11.0', + Java170 = 'java-17.0', + Java180 = 'java-18.0', + Java210 = 'java-21.0', + Swift55 = 'swift-5.5', + Swift58 = 'swift-5.8', + Swift59 = 'swift-5.9', + Kotlin16 = 'kotlin-1.6', + Kotlin18 = 'kotlin-1.8', + Kotlin19 = 'kotlin-1.9', + Cpp17 = 'cpp-17', + Cpp20 = 'cpp-20', + Bun10 = 'bun-1.0', +} \ No newline at end of file diff --git a/src/enums/smtp-encryption.ts b/src/enums/smtp-encryption.ts new file mode 100644 index 0000000..876177b --- /dev/null +++ b/src/enums/smtp-encryption.ts @@ -0,0 +1,5 @@ +export enum SmtpEncryption { + None = 'none', + Ssl = 'ssl', + Tls = 'tls', +} \ No newline at end of file diff --git a/src/exception.ts b/src/exception.ts index 575e3eb..6bdbef5 100644 --- a/src/exception.ts +++ b/src/exception.ts @@ -1,17 +1,17 @@ export class AppwriteException { - message: String; - code: Number; + message: string; + code: number; response: any; - type: String; + type: string; - constructor(message: String, code: Number = 0, type: String = "", response: any = "") { + constructor(message: string, code: number = 0, type: string = "", response: any = "") { this.message = message; this.code = code; this.type = type; this.response = response; } - public toString(): String { + public toString(): string { return `${this.message} - ${this.code} - ${this.type} - ${JSON.stringify(this.response)}`; } -} \ No newline at end of file +} diff --git a/src/inputFile.ts b/src/inputFile.ts index fdda97d..b122302 100644 --- a/src/inputFile.ts +++ b/src/inputFile.ts @@ -19,6 +19,12 @@ export class InputFile { return new InputFile(stream, filename, size); }; + static fromBlob = async (blob: Blob, filename: string) => { + const arrayBuffer = await blob.arrayBuffer(); + const buffer = new Uint8Array(arrayBuffer); + return InputFile.fromBuffer(buffer, filename); + }; + static fromBuffer = (buffer: Uint8Array, filename: string): InputFile => { const stream = _bufferToString(buffer); const size = buffer.byteLength; diff --git a/src/models.d.ts b/src/models.d.ts index 8f3fb65..1958924 100644 --- a/src/models.d.ts +++ b/src/models.d.ts @@ -298,6 +298,71 @@ export namespace Models { */ localeCodes: LocaleCode[]; } + /** + * Provider list + */ + export type ProviderList = { + /** + * Total number of providers documents that matched your query. + */ + total: number; + /** + * List of providers. + */ + providers: Provider[]; + } + /** + * Message list + */ + export type MessageList = { + /** + * Total number of messages documents that matched your query. + */ + total: number; + /** + * List of messages. + */ + messages: Message[]; + } + /** + * Topic list + */ + export type TopicList = { + /** + * Total number of topics documents that matched your query. + */ + total: number; + /** + * List of topics. + */ + topics: Topic[]; + } + /** + * Subscriber list + */ + export type SubscriberList = { + /** + * Total number of subscribers documents that matched your query. + */ + total: number; + /** + * List of subscribers. + */ + subscribers: Subscriber[]; + } + /** + * Target list + */ + export type TargetList = { + /** + * Total number of targets documents that matched your query. + */ + total: number; + /** + * List of targets. + */ + targets: Target[]; + } /** * Database */ @@ -986,10 +1051,18 @@ export namespace Models { * Phone verification status. */ phoneVerification: boolean; + /** + * Multi factor authentication status. + */ + mfa: boolean; /** * User preferences as a key-value object */ prefs: Preferences; + /** + * A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. + */ + targets: Target[]; /** * Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. */ @@ -1207,6 +1280,18 @@ export namespace Models { * Returns true if this the current user session. */ current: boolean; + /** + * Returns a list of active session factors. + */ + factors: string[]; + /** + * Secret used to authenticate the user. Only included if the request was made with an API key + */ + secret: string; + /** + * Most recent date in ISO 8601 format when the session successfully passed MFA challenge. + */ + mfaUpdatedAt: string; } /** * Identity @@ -1277,6 +1362,19 @@ export namespace Models { * Token expiration date in ISO 8601 format. */ 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. + */ + phrase: string; + } + /** + * JWT + */ + export type Jwt = { + /** + * JWT encoded string. + */ + jwt: string; } /** * Locale @@ -1503,6 +1601,10 @@ export namespace Models { * User confirmation status, true if the user has joined the team or false otherwise. */ confirm: boolean; + /** + * Multi factor authentication status, true if the user has MFA enabled or false otherwise. + */ + mfa: boolean; /** * User list of roles */ @@ -1965,6 +2067,35 @@ export namespace Models { */ status: string; } + /** + * Health Certificate + */ + export type HealthCertificate = { + /** + * Certificate name + */ + name: string; + /** + * Subject SN + */ + subjectSN: string; + /** + * Issuer organisation + */ + issuerOrganisation: string; + /** + * Valid from + */ + validFrom: string; + /** + * Valid to + */ + validTo: string; + /** + * Signature type SN + */ + signatureTypeSN: string; + } /** * Health Time */ @@ -1995,4 +2126,277 @@ export namespace Models { */ value: string; } + /** + * MFA Challenge + */ + export type MfaChallenge = { + /** + * Token ID. + */ + $id: string; + /** + * Token creation date in ISO 8601 format. + */ + $createdAt: string; + /** + * User ID. + */ + userId: string; + /** + * Token expiration date in ISO 8601 format. + */ + expire: string; + } + /** + * MFA Recovery Codes + */ + export type MfaRecoveryCodes = { + /** + * Recovery codes. + */ + recoveryCodes: string[]; + } + /** + * MFAType + */ + export type MfaType = { + /** + * Secret token used for TOTP factor. + */ + secret: string; + /** + * URI for authenticator apps. + */ + uri: string; + } + /** + * MFAFactors + */ + export type MfaFactors = { + /** + * TOTP + */ + totp: boolean; + /** + * Phone + */ + phone: boolean; + /** + * Email + */ + email: boolean; + } + /** + * Provider + */ + export type Provider = { + /** + * Provider ID. + */ + $id: string; + /** + * Provider creation time in ISO 8601 format. + */ + $createdAt: string; + /** + * Provider update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * The name for the provider instance. + */ + name: string; + /** + * The name of the provider service. + */ + provider: string; + /** + * Is provider enabled? + */ + enabled: boolean; + /** + * Type of provider. + */ + type: string; + /** + * Provider credentials. + */ + credentials: object; + /** + * Provider options. + */ + options?: object; + } + /** + * Message + */ + export type Message = { + /** + * Message ID. + */ + $id: string; + /** + * Message creation time in ISO 8601 format. + */ + $createdAt: string; + /** + * Message update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * Message provider type. + */ + providerType: string; + /** + * Topic IDs set as recipients. + */ + topics: string[]; + /** + * User IDs set as recipients. + */ + users: string[]; + /** + * Target IDs set as recipients. + */ + targets: string[]; + /** + * The scheduled time for message. + */ + scheduledAt?: string; + /** + * The time when the message was delivered. + */ + deliveredAt?: string; + /** + * Delivery errors if any. + */ + deliveryErrors?: string[]; + /** + * Number of recipients the message was delivered to. + */ + deliveredTotal: number; + /** + * Data of the message. + */ + data: object; + /** + * Status of delivery. + */ + status: string; + } + /** + * Topic + */ + export type Topic = { + /** + * Topic ID. + */ + $id: string; + /** + * Topic creation time in ISO 8601 format. + */ + $createdAt: string; + /** + * Topic update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * The name of the topic. + */ + name: string; + /** + * Total count of email subscribers subscribed to the topic. + */ + emailTotal: number; + /** + * Total count of SMS subscribers subscribed to the topic. + */ + smsTotal: number; + /** + * Total count of push subscribers subscribed to the topic. + */ + pushTotal: number; + /** + * Subscribe permissions. + */ + subscribe: string[]; + } + /** + * Subscriber + */ + export type Subscriber = { + /** + * Subscriber ID. + */ + $id: string; + /** + * Subscriber creation time in ISO 8601 format. + */ + $createdAt: string; + /** + * Subscriber update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * Target ID. + */ + targetId: string; + /** + * Target. + */ + target: Target; + /** + * Topic ID. + */ + userId: string; + /** + * User Name. + */ + userName: string; + /** + * Topic ID. + */ + topicId: string; + /** + * The target provider type. Can be one of the following: `email`, `sms` or `push`. + */ + providerType: string; + } + /** + * Target + */ + export type Target = { + /** + * Target ID. + */ + $id: string; + /** + * Target creation time in ISO 8601 format. + */ + $createdAt: string; + /** + * Target update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * Target Name. + */ + name: string; + /** + * User ID. + */ + userId: string; + /** + * Provider ID. + */ + providerId?: string; + /** + * The target provider type. Can be one of the following: `email`, `sms` or `push`. + */ + providerType: string; + /** + * The target identifier. + */ + identifier: string; + } } \ No newline at end of file diff --git a/src/query.ts b/src/query.ts index ce87185..98930a2 100644 --- a/src/query.ts +++ b/src/query.ts @@ -1,74 +1,104 @@ type QueryTypesSingle = string | number | boolean; -export type QueryTypesList = string[] | number[] | boolean[]; +export type QueryTypesList = string[] | number[] | boolean[] | Query[]; export type QueryTypes = QueryTypesSingle | QueryTypesList; +type AttributesTypes = string | string[]; export class Query { + method: string; + attribute: AttributesTypes | undefined; + values: QueryTypesList | undefined; + + constructor( + method: string, + attribute?: AttributesTypes, + values?: QueryTypes + ) { + this.method = method; + this.attribute = attribute; + + if (values !== undefined) { + if (Array.isArray(values)) { + this.values = values; + } else { + this.values = [values] as QueryTypesList; + } + } + } + + toString(): string { + return JSON.stringify({ + method: this.method, + attribute: this.attribute, + values: this.values, + }); + } + static equal = (attribute: string, value: QueryTypes): string => - Query.addQuery(attribute, "equal", value); + new Query("equal", attribute, value).toString(); static notEqual = (attribute: string, value: QueryTypes): string => - Query.addQuery(attribute, "notEqual", value); + new Query("notEqual", attribute, value).toString(); static lessThan = (attribute: string, value: QueryTypes): string => - Query.addQuery(attribute, "lessThan", value); + new Query("lessThan", attribute, value).toString(); static lessThanEqual = (attribute: string, value: QueryTypes): string => - Query.addQuery(attribute, "lessThanEqual", value); + new Query("lessThanEqual", attribute, value).toString(); static greaterThan = (attribute: string, value: QueryTypes): string => - Query.addQuery(attribute, "greaterThan", value); + new Query("greaterThan", attribute, value).toString(); static greaterThanEqual = (attribute: string, value: QueryTypes): string => - Query.addQuery(attribute, "greaterThanEqual", value); - - static search = (attribute: string, value: string): string => - Query.addQuery(attribute, "search", value); + new Query("greaterThanEqual", attribute, value).toString(); static isNull = (attribute: string): string => - `isNull("${attribute}")`; + new Query("isNull", attribute).toString(); static isNotNull = (attribute: string): string => - `isNotNull("${attribute}")`; + new Query("isNotNull", attribute).toString(); - static between = (attribute: string, start: string|number, end: string|number): string => - `between("${attribute}", ${Query.parseValues(start)}, ${Query.parseValues(end)})`; + static between = ( + attribute: string, + start: string | number, + end: string | number + ) => new Query("between", attribute, [start, end] as QueryTypesList).toString(); static startsWith = (attribute: string, value: string): string => - Query.addQuery(attribute, "startsWith", value); + new Query("startsWith", attribute, value).toString(); static endsWith = (attribute: string, value: string): string => - Query.addQuery(attribute, "endsWith", value); + new Query("endsWith", attribute, value).toString(); static select = (attributes: string[]): string => - `select([${attributes.map((attr: string) => `"${attr}"`).join(",")}])`; + new Query("select", undefined, attributes).toString(); + + static search = (attribute: string, value: string): string => + new Query("search", attribute, value).toString(); static orderDesc = (attribute: string): string => - `orderDesc("${attribute}")`; + new Query("orderDesc", attribute).toString(); static orderAsc = (attribute: string): string => - `orderAsc("${attribute}")`; + new Query("orderAsc", attribute).toString(); static cursorAfter = (documentId: string): string => - `cursorAfter("${documentId}")`; + new Query("cursorAfter", undefined, documentId).toString(); static cursorBefore = (documentId: string): string => - `cursorBefore("${documentId}")`; + new Query("cursorBefore", undefined, documentId).toString(); static limit = (limit: number): string => - `limit(${limit})`; + new Query("limit", undefined, limit).toString(); static offset = (offset: number): string => - `offset(${offset})`; - - private static addQuery = (attribute: string, method: string, value: QueryTypes): string => - value instanceof Array - ? `${method}("${attribute}", [${value - .map((v: QueryTypesSingle) => Query.parseValues(v)) - .join(",")}])` - : `${method}("${attribute}", [${Query.parseValues(value)}])`; - - private static parseValues = (value: QueryTypes): string => - typeof value === "string" || value instanceof String - ? `"${value}"` - : `${value}`; -} \ No newline at end of file + new Query("offset", undefined, offset).toString(); + + static contains = (attribute: string, value: string | string[]): string => + new Query("contains", attribute, value).toString(); + + static or = (queries: string[]) => + new Query("or", undefined, queries.map((query) => JSON.parse(query))).toString(); + + static and = (queries: string[]) => + new Query("and", undefined, queries.map((query) => JSON.parse(query))).toString(); +} diff --git a/src/services/account.ts b/src/services/account.ts index cde2a26..54e6a09 100644 --- a/src/services/account.ts +++ b/src/services/account.ts @@ -4,6 +4,10 @@ import { Payload, Client } from '../client.ts'; import { InputFile } from '../inputFile.ts'; import { AppwriteException } from '../exception.ts'; import type { Models } from '../models.d.ts'; +import { Query } from '../query.ts'; +import { AuthenticatorType } from '../enums/authenticator-type.ts'; +import { AuthenticationFactor } from '../enums/authentication-factor.ts'; +import { OAuthProvider } from '../enums/o-auth-provider.ts'; export type UploadProgress = { $id: string; @@ -32,9 +36,71 @@ export class Account extends Service { const apiPath = '/account'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create account + * + * Use this endpoint to allow a new user to register a new account in your + * project. After the user registration completes successfully, you can use + * the + * [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) + * route to start verifying the user email address. To allow the new user to + * login to their new account, you need to create a new [account + * session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async create<Preferences extends Models.Preferences>(userId: string, email: string, password: string, name?: string): Promise<Models.User<Preferences>> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + if (typeof password === 'undefined') { + throw new AppwriteException('Missing required parameter: "password"'); + } + + const apiPath = '/account'; + const payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + if (typeof email !== 'undefined') { + payload['email'] = email; + } + if (typeof password !== 'undefined') { + payload['password'] = password; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update email @@ -71,20 +137,26 @@ export class Account extends Service { if (typeof password !== 'undefined') { payload['password'] = password; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List Identities * * Get the list of identities for the currently logged in user. * - * @param {string} queries + * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} */ - async listIdentities(queries?: string): Promise<Models.IdentityList> { + async listIdentities(queries?: string[]): Promise<Models.IdentityList> { const apiPath = '/account/identities'; const payload: Payload = {}; @@ -92,12 +164,18 @@ export class Account extends Service { payload['queries'] = queries; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** - * Delete Identity + * Delete identity * * Delete an identity by its unique ID. * @@ -113,9 +191,41 @@ export class Account extends Service { const apiPath = '/account/identities/{identityId}'.replace('{identityId}', identityId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create JWT + * + * Use this endpoint to create a JSON Web Token. You can use the resulting JWT + * to authenticate on behalf of the current user when working with the + * Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes + * from its creation and will be invalid if the user will logout in that time + * frame. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async createJWT(): Promise<Models.Jwt> { + const apiPath = '/account/jwt'; + const payload: Payload = {}; + + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List logs @@ -135,9 +245,319 @@ export class Account extends Service { payload['queries'] = queries; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update MFA + * + * Enable or disable MFA on an account. + * + * @param {boolean} mfa + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateMFA<Preferences extends Models.Preferences>(mfa: boolean): Promise<Models.User<Preferences>> { + if (typeof mfa === 'undefined') { + throw new AppwriteException('Missing required parameter: "mfa"'); + } + + const apiPath = '/account/mfa'; + const payload: Payload = {}; + + if (typeof mfa !== 'undefined') { + payload['mfa'] = mfa; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Add Authenticator + * + * Add an authenticator app to be used as an MFA factor. Verify the + * authenticator using the [verify + * authenticator](/docs/references/cloud/client-web/account#verifyAuthenticator) + * method. + * + * @param {AuthenticatorType} type + * @throws {AppwriteException} + * @returns {Promise} + */ + async createMfaAuthenticator(type: AuthenticatorType): Promise<Models.MfaType> { + if (typeof type === 'undefined') { + throw new AppwriteException('Missing required parameter: "type"'); + } + + const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); + const payload: Payload = {}; + + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Verify Authenticator + * + * Verify an authenticator app after adding it using the [add + * authenticator](/docs/references/cloud/client-web/account#addAuthenticator) + * method. + * + * @param {AuthenticatorType} type + * @param {string} otp + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateMfaAuthenticator<Preferences extends Models.Preferences>(type: AuthenticatorType, otp: string): Promise<Models.User<Preferences>> { + if (typeof type === 'undefined') { + throw new AppwriteException('Missing required parameter: "type"'); + } + + if (typeof otp === 'undefined') { + throw new AppwriteException('Missing required parameter: "otp"'); + } + + const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); + const payload: Payload = {}; + + if (typeof otp !== 'undefined') { + payload['otp'] = otp; + } + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Delete Authenticator + * + * Delete an authenticator for a user by ID. + * + * @param {AuthenticatorType} type + * @param {string} otp + * @throws {AppwriteException} + * @returns {Promise} + */ + async deleteMfaAuthenticator<Preferences extends Models.Preferences>(type: AuthenticatorType, otp: string): Promise<Models.User<Preferences>> { + if (typeof type === 'undefined') { + throw new AppwriteException('Missing required parameter: "type"'); + } + + if (typeof otp === 'undefined') { + throw new AppwriteException('Missing required parameter: "otp"'); + } + + const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); + const payload: Payload = {}; + + if (typeof otp !== 'undefined') { + payload['otp'] = otp; + } + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create 2FA Challenge + * + * Begin the process of MFA verification after sign-in. Finish the flow with + * [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) + * method. + * + * @param {AuthenticationFactor} factor + * @throws {AppwriteException} + * @returns {Promise} + */ + async createMfaChallenge(factor: AuthenticationFactor): Promise<Models.MfaChallenge> { + if (typeof factor === 'undefined') { + throw new AppwriteException('Missing required parameter: "factor"'); + } + + const apiPath = '/account/mfa/challenge'; + const payload: Payload = {}; + + if (typeof factor !== 'undefined') { + payload['factor'] = factor; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create MFA Challenge (confirmation) + * + * Complete the MFA challenge by providing the one-time password. Finish the + * process of MFA verification by providing the one-time password. To begin + * the flow, use + * [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + * method. + * + * @param {string} challengeId + * @param {string} otp + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateMfaChallenge(challengeId: string, otp: string): Promise<Response> { + if (typeof challengeId === 'undefined') { + throw new AppwriteException('Missing required parameter: "challengeId"'); + } + + if (typeof otp === 'undefined') { + throw new AppwriteException('Missing required parameter: "otp"'); + } + + const apiPath = '/account/mfa/challenge'; + const payload: Payload = {}; + + if (typeof challengeId !== 'undefined') { + payload['challengeId'] = challengeId; + } + if (typeof otp !== 'undefined') { + payload['otp'] = otp; + } + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * List Factors + * + * List the factors available on the account to be used as a MFA challange. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async listMfaFactors(): Promise<Models.MfaFactors> { + const apiPath = '/account/mfa/factors'; + const payload: Payload = {}; + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Get MFA Recovery Codes + * + * Get recovery codes that can be used as backup for MFA flow. Before getting + * codes, they must be generated using + * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + * method. An OTP challenge is required to read recovery codes. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async getMfaRecoveryCodes(): Promise<Models.MfaRecoveryCodes> { + const apiPath = '/account/mfa/recovery-codes'; + const payload: Payload = {}; + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create MFA Recovery Codes + * + * Generate recovery codes as backup for MFA flow. It's recommended to + * generate and show then immediately after user successfully adds their + * authehticator. Recovery codes can be used as a MFA verification type in + * [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + * method. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async createMfaRecoveryCodes(): Promise<Models.MfaRecoveryCodes> { + const apiPath = '/account/mfa/recovery-codes'; + const payload: Payload = {}; + + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Regenerate MFA Recovery Codes + * + * Regenerate recovery codes that can be used as backup for MFA flow. Before + * regenerating codes, they must be first generated using + * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + * method. An OTP challenge is required to regenreate recovery codes. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateMfaRecoveryCodes(): Promise<Models.MfaRecoveryCodes> { + const apiPath = '/account/mfa/recovery-codes'; + const payload: Payload = {}; + + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update name @@ -159,9 +579,15 @@ export class Account extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update password @@ -189,9 +615,15 @@ export class Account extends Service { if (typeof oldPassword !== 'undefined') { payload['oldPassword'] = oldPassword; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update phone @@ -225,9 +657,15 @@ export class Account extends Service { if (typeof password !== 'undefined') { payload['password'] = password; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get account preferences @@ -241,9 +679,15 @@ export class Account extends Service { const apiPath = '/account/prefs'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update preferences @@ -267,9 +711,15 @@ export class Account extends Service { if (typeof prefs !== 'undefined') { payload['prefs'] = prefs; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create password recovery @@ -306,9 +756,15 @@ export class Account extends Service { if (typeof url !== 'undefined') { payload['url'] = url; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create password recovery (confirmation) @@ -327,11 +783,10 @@ export class Account extends Service { * @param {string} userId * @param {string} secret * @param {string} password - * @param {string} passwordAgain * @throws {AppwriteException} * @returns {Promise} */ - async updateRecovery(userId: string, secret: string, password: string, passwordAgain: string): Promise<Models.Token> { + async updateRecovery(userId: string, secret: string, password: string): Promise<Models.Token> { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -344,10 +799,6 @@ export class Account extends Service { throw new AppwriteException('Missing required parameter: "password"'); } - if (typeof passwordAgain === 'undefined') { - throw new AppwriteException('Missing required parameter: "passwordAgain"'); - } - const apiPath = '/account/recovery'; const payload: Payload = {}; @@ -360,12 +811,15 @@ export class Account extends Service { if (typeof password !== 'undefined') { payload['password'] = password; } - if (typeof passwordAgain !== 'undefined') { - payload['passwordAgain'] = passwordAgain; - } - return await this.client.call('put', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List sessions @@ -380,9 +834,15 @@ export class Account extends Service { const apiPath = '/account/sessions'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete sessions @@ -397,9 +857,206 @@ export class Account extends Service { const apiPath = '/account/sessions'; const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create anonymous session + * + * Use this endpoint to allow a new user to register an anonymous account in + * your project. This route will also create a new session for the user. To + * allow the new user to convert an anonymous account to a normal account, you + * need to update its [email and + * password](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) + * or create an [OAuth2 + * session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async createAnonymousSession(): Promise<Models.Session> { + const apiPath = '/account/sessions/anonymous'; + const payload: Payload = {}; + + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create email password session + * + * Allow the user to login into their account by providing a valid email and + * password combination. This route will create a new session for the user. + * + * A user is limited to 10 active sessions at a time by default. [Learn more + * about session + * limits](https://appwrite.io/docs/authentication-security#limits). + * + * @param {string} email + * @param {string} password + * @throws {AppwriteException} + * @returns {Promise} + */ + async createEmailPasswordSession(email: string, password: string): Promise<Models.Session> { + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + if (typeof password === 'undefined') { + throw new AppwriteException('Missing required parameter: "password"'); + } + + const apiPath = '/account/sessions/email'; + const payload: Payload = {}; + + if (typeof email !== 'undefined') { + payload['email'] = email; + } + if (typeof password !== 'undefined') { + payload['password'] = password; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update magic URL session + * + * Use this endpoint to create a session from token. Provide the **userId** + * and **secret** parameters from the successful response of authentication + * flows initiated by token creation. For example, magic URL and phone login. + * + * @param {string} userId + * @param {string} secret + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateMagicURLSession(userId: string, secret: string): Promise<Models.Session> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof secret === 'undefined') { + throw new AppwriteException('Missing required parameter: "secret"'); + } + + const apiPath = '/account/sessions/magic-url'; + const payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + if (typeof secret !== 'undefined') { + payload['secret'] = secret; + } + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update phone session + * + * Use this endpoint to create a session from token. Provide the **userId** + * and **secret** parameters from the successful response of authentication + * flows initiated by token creation. For example, magic URL and phone login. + * + * @param {string} userId + * @param {string} secret + * @throws {AppwriteException} + * @returns {Promise} + */ + async updatePhoneSession(userId: string, secret: string): Promise<Models.Session> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof secret === 'undefined') { + throw new AppwriteException('Missing required parameter: "secret"'); + } + + const apiPath = '/account/sessions/phone'; + const payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + if (typeof secret !== 'undefined') { + payload['secret'] = secret; + } + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create session + * + * Use this endpoint to create a session from token. Provide the **userId** + * and **secret** parameters from the successful response of authentication + * flows initiated by token creation. For example, magic URL and phone login. + * + * @param {string} userId + * @param {string} secret + * @throws {AppwriteException} + * @returns {Promise} + */ + async createSession(userId: string, secret: string): Promise<Models.Session> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof secret === 'undefined') { + throw new AppwriteException('Missing required parameter: "secret"'); + } + + const apiPath = '/account/sessions/token'; + const payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + if (typeof secret !== 'undefined') { + payload['secret'] = secret; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get session @@ -419,16 +1076,22 @@ export class Account extends Service { const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** - * Update OAuth session (refresh tokens) + * Update session * - * Access tokens have limited lifespan and expire to mitigate security risks. - * If session was created using an OAuth provider, this route can be used to - * "refresh" the access token. + * Use this endpoint to extend a session's length. Extending a session is + * useful when session expiry is short. If the session was created using an + * OAuth provider, this endpoint refreshes the access token from the provider. * * @param {string} sessionId * @throws {AppwriteException} @@ -442,9 +1105,15 @@ export class Account extends Service { const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); const payload: Payload = {}; - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete session @@ -467,9 +1136,15 @@ export class Account extends Service { const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update status @@ -485,9 +1160,229 @@ export class Account extends Service { const apiPath = '/account/status'; const payload: Payload = {}; - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create email token (OTP) + * + * Sends the user an email 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 email + * is valid for 15 minutes. + * + * A user is limited to 10 active sessions at a time by default. [Learn more + * about session + * limits](https://appwrite.io/docs/authentication-security#limits). + * + * @param {string} userId + * @param {string} email + * @param {boolean} phrase + * @throws {AppwriteException} + * @returns {Promise} + */ + async createEmailToken(userId: string, email: string, phrase?: boolean): Promise<Models.Token> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + const apiPath = '/account/tokens/email'; + const payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + if (typeof email !== 'undefined') { + payload['email'] = email; + } + if (typeof phrase !== 'undefined') { + payload['phrase'] = phrase; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create magic URL token + * + * Sends the user an email with a secret key for creating a session. If the + * provided user ID has not been registered, a new user will be created. When + * the user clicks the link in the email, the user is redirected back to the + * URL you provided with the secret key and userId values attached to the URL + * query string. Use the query string parameters to 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 link sent to the user's email + * address is valid for 1 hour. If you are on a mobile device you can leave + * the URL parameter empty, so that the login completion will be handled by + * your Appwrite instance by default. + * + * A user is limited to 10 active sessions at a time by default. [Learn more + * about session + * limits](https://appwrite.io/docs/authentication-security#limits). + * + * + * @param {string} userId + * @param {string} email + * @param {string} url + * @param {boolean} phrase + * @throws {AppwriteException} + * @returns {Promise} + */ + async createMagicURLToken(userId: string, email: string, url?: string, phrase?: boolean): Promise<Models.Token> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + const apiPath = '/account/tokens/magic-url'; + const payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + if (typeof email !== 'undefined') { + payload['email'] = email; + } + if (typeof url !== 'undefined') { + payload['url'] = url; + } + if (typeof phrase !== 'undefined') { + payload['phrase'] = phrase; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create OAuth2 token + * + * Allow the user to login to their account using the OAuth2 provider of their + * choice. Each OAuth2 provider should be enabled from the Appwrite console + * first. Use the success and failure arguments to provide a redirect URL's + * back to your app when login is completed. + * + * If authentication succeeds, `userId` and `secret` of a token will be + * appended to the success URL as query parameters. These can be used to + * create a new session using the [Create + * session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + * endpoint. + * + * A user is limited to 10 active sessions at a time by default. [Learn more + * about session + * limits](https://appwrite.io/docs/authentication-security#limits). + * + * @param {OAuthProvider} provider + * @param {string} success + * @param {string} failure + * @param {string[]} scopes + * @throws {AppwriteException} + * @returns {Promise} + */ + async createOAuth2Token(provider: OAuthProvider, success?: string, failure?: string, scopes?: string[]): Promise<string> { + if (typeof provider === 'undefined') { + throw new AppwriteException('Missing required parameter: "provider"'); + } + + const apiPath = '/account/tokens/oauth2/{provider}'.replace('{provider}', provider); + const payload: Payload = {}; + + if (typeof success !== 'undefined') { + payload['success'] = success; + } + + if (typeof failure !== 'undefined') { + payload['failure'] = failure; + } + + if (typeof scopes !== 'undefined') { + payload['scopes'] = scopes; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'location' + ); + } + /** + * Create phone token + * + * 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. + * + * A user is limited to 10 active sessions at a time by default. [Learn more + * about session + * limits](https://appwrite.io/docs/authentication-security#limits). + * + * @param {string} userId + * @param {string} phone + * @throws {AppwriteException} + * @returns {Promise} + */ + async createPhoneToken(userId: string, phone: string): Promise<Models.Token> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof phone === 'undefined') { + throw new AppwriteException('Missing required parameter: "phone"'); + } + + const apiPath = '/account/tokens/phone'; + const payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + if (typeof phone !== 'undefined') { + payload['phone'] = phone; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create email verification @@ -523,9 +1418,15 @@ export class Account extends Service { if (typeof url !== 'undefined') { payload['url'] = url; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create email verification (confirmation) @@ -558,9 +1459,15 @@ export class Account extends Service { if (typeof secret !== 'undefined') { payload['secret'] = secret; } - return await this.client.call('put', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create phone verification @@ -581,9 +1488,15 @@ export class Account extends Service { const apiPath = '/account/verification/phone'; const payload: Payload = {}; - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create phone verification (confirmation) @@ -616,8 +1529,14 @@ export class Account extends Service { if (typeof secret !== 'undefined') { payload['secret'] = secret; } - return await this.client.call('put', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } } \ No newline at end of file diff --git a/src/services/avatars.ts b/src/services/avatars.ts index f49457e..1f18324 100644 --- a/src/services/avatars.ts +++ b/src/services/avatars.ts @@ -4,6 +4,10 @@ import { Payload, Client } from '../client.ts'; import { InputFile } from '../inputFile.ts'; import { AppwriteException } from '../exception.ts'; import type { Models } from '../models.d.ts'; +import { Query } from '../query.ts'; +import { Browser } from '../enums/browser.ts'; +import { CreditCard } from '../enums/credit-card.ts'; +import { Flag } from '../enums/flag.ts'; export type UploadProgress = { $id: string; @@ -34,14 +38,14 @@ export class Avatars extends Service { * image at source quality. If dimensions are not specified, the default size * of image returned is 100x100px. * - * @param {string} code + * @param {Browser} code * @param {number} width * @param {number} height * @param {number} quality * @throws {AppwriteException} * @returns {Promise} */ - async getBrowser(code: string, width?: number, height?: number, quality?: number): Promise<Response> { + async getBrowser(code: Browser, width?: number, height?: number, quality?: number): Promise<ArrayBuffer> { if (typeof code === 'undefined') { throw new AppwriteException('Missing required parameter: "code"'); } @@ -61,9 +65,15 @@ export class Avatars extends Service { payload['quality'] = quality; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'arraybuffer' + ); } /** * Get credit card icon @@ -78,14 +88,14 @@ export class Avatars extends Service { * of image returned is 100x100px. * * - * @param {string} code + * @param {CreditCard} code * @param {number} width * @param {number} height * @param {number} quality * @throws {AppwriteException} * @returns {Promise} */ - async getCreditCard(code: string, width?: number, height?: number, quality?: number): Promise<Response> { + async getCreditCard(code: CreditCard, width?: number, height?: number, quality?: number): Promise<ArrayBuffer> { if (typeof code === 'undefined') { throw new AppwriteException('Missing required parameter: "code"'); } @@ -105,9 +115,15 @@ export class Avatars extends Service { payload['quality'] = quality; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'arraybuffer' + ); } /** * Get favicon @@ -120,7 +136,7 @@ export class Avatars extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async getFavicon(url: string): Promise<Response> { + async getFavicon(url: string): Promise<ArrayBuffer> { if (typeof url === 'undefined') { throw new AppwriteException('Missing required parameter: "url"'); } @@ -132,9 +148,15 @@ export class Avatars extends Service { payload['url'] = url; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'arraybuffer' + ); } /** * Get country flag @@ -150,14 +172,14 @@ export class Avatars extends Service { * of image returned is 100x100px. * * - * @param {string} code + * @param {Flag} code * @param {number} width * @param {number} height * @param {number} quality * @throws {AppwriteException} * @returns {Promise} */ - async getFlag(code: string, width?: number, height?: number, quality?: number): Promise<Response> { + async getFlag(code: Flag, width?: number, height?: number, quality?: number): Promise<ArrayBuffer> { if (typeof code === 'undefined') { throw new AppwriteException('Missing required parameter: "code"'); } @@ -177,9 +199,15 @@ export class Avatars extends Service { payload['quality'] = quality; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'arraybuffer' + ); } /** * Get image from URL @@ -201,7 +229,7 @@ export class Avatars extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async getImage(url: string, width?: number, height?: number): Promise<Response> { + async getImage(url: string, width?: number, height?: number): Promise<ArrayBuffer> { if (typeof url === 'undefined') { throw new AppwriteException('Missing required parameter: "url"'); } @@ -221,9 +249,15 @@ export class Avatars extends Service { payload['height'] = height; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'arraybuffer' + ); } /** * Get user initials @@ -252,7 +286,7 @@ export class Avatars extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async getInitials(name?: string, width?: number, height?: number, background?: string): Promise<Response> { + async getInitials(name?: string, width?: number, height?: number, background?: string): Promise<ArrayBuffer> { const apiPath = '/avatars/initials'; const payload: Payload = {}; @@ -272,9 +306,15 @@ export class Avatars extends Service { payload['background'] = background; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'arraybuffer' + ); } /** * Get QR code @@ -290,7 +330,7 @@ export class Avatars extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async getQR(text: string, size?: number, margin?: number, download?: boolean): Promise<Response> { + async getQR(text: string, size?: number, margin?: number, download?: boolean): Promise<ArrayBuffer> { if (typeof text === 'undefined') { throw new AppwriteException('Missing required parameter: "text"'); } @@ -314,8 +354,14 @@ export class Avatars extends Service { payload['download'] = download; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'arraybuffer' + ); } } \ No newline at end of file diff --git a/src/services/databases.ts b/src/services/databases.ts index 9008fd4..13be3bd 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -4,6 +4,10 @@ import { Payload, Client } from '../client.ts'; import { InputFile } from '../inputFile.ts'; import { AppwriteException } from '../exception.ts'; import type { Models } from '../models.d.ts'; +import { Query } from '../query.ts'; +import { RelationshipType } from '../enums/relationship-type.ts'; +import { RelationMutate } from '../enums/relation-mutate.ts'; +import { IndexType } from '../enums/index-type.ts'; export type UploadProgress = { $id: string; @@ -43,9 +47,15 @@ export class Databases extends Service { payload['search'] = search; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create database @@ -80,9 +90,15 @@ export class Databases extends Service { if (typeof enabled !== 'undefined') { payload['enabled'] = enabled; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get database @@ -102,9 +118,15 @@ export class Databases extends Service { const apiPath = '/databases/{databaseId}'.replace('{databaseId}', databaseId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update database @@ -135,9 +157,15 @@ export class Databases extends Service { if (typeof enabled !== 'undefined') { payload['enabled'] = enabled; } - return await this.client.call('put', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete database @@ -157,9 +185,15 @@ export class Databases extends Service { const apiPath = '/databases/{databaseId}'.replace('{databaseId}', databaseId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List collections @@ -189,9 +223,15 @@ export class Databases extends Service { payload['search'] = search; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create collection @@ -241,9 +281,15 @@ export class Databases extends Service { if (typeof enabled !== 'undefined') { payload['enabled'] = enabled; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get collection @@ -268,9 +314,15 @@ export class Databases extends Service { const apiPath = '/databases/{databaseId}/collections/{collectionId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update collection @@ -314,9 +366,15 @@ export class Databases extends Service { if (typeof enabled !== 'undefined') { payload['enabled'] = enabled; } - return await this.client.call('put', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete collection @@ -341,13 +399,21 @@ export class Databases extends Service { const apiPath = '/databases/{databaseId}/collections/{collectionId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List attributes * + * List attributes in the collection. + * * @param {string} databaseId * @param {string} collectionId * @param {string[]} queries @@ -370,9 +436,15 @@ export class Databases extends Service { payload['queries'] = queries; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create boolean attribute @@ -421,13 +493,22 @@ export class Databases extends Service { if (typeof array !== 'undefined') { payload['array'] = array; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update boolean attribute * + * Update a boolean attribute. Changing the `default` value will not update + * already existing documents. + * * @param {string} databaseId * @param {string} collectionId * @param {string} key @@ -466,13 +547,21 @@ export class Databases extends Service { if (typeof xdefault !== 'undefined') { payload['default'] = xdefault; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create datetime attribute * + * Create a date time attribute according to the ISO 8601 standard. + * * @param {string} databaseId * @param {string} collectionId * @param {string} key @@ -514,13 +603,22 @@ export class Databases extends Service { if (typeof array !== 'undefined') { payload['array'] = array; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update dateTime attribute * + * Update a date time attribute. Changing the `default` value will not update + * already existing documents. + * * @param {string} databaseId * @param {string} collectionId * @param {string} key @@ -559,9 +657,15 @@ export class Databases extends Service { if (typeof xdefault !== 'undefined') { payload['default'] = xdefault; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create email attribute @@ -610,9 +714,15 @@ export class Databases extends Service { if (typeof array !== 'undefined') { payload['array'] = array; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update email attribute @@ -659,13 +769,23 @@ export class Databases extends Service { if (typeof xdefault !== 'undefined') { payload['default'] = xdefault; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create enum attribute * + * Create an enumeration attribute. The `elements` param acts as a white-list + * of accepted values for this attribute. + * + * * @param {string} databaseId * @param {string} collectionId * @param {string} key @@ -715,9 +835,15 @@ export class Databases extends Service { if (typeof array !== 'undefined') { payload['array'] = array; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update enum attribute @@ -772,9 +898,15 @@ export class Databases extends Service { if (typeof xdefault !== 'undefined') { payload['default'] = xdefault; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create float attribute @@ -832,9 +964,15 @@ export class Databases extends Service { if (typeof array !== 'undefined') { payload['array'] = array; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update float attribute @@ -897,9 +1035,15 @@ export class Databases extends Service { if (typeof xdefault !== 'undefined') { payload['default'] = xdefault; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create integer attribute @@ -957,9 +1101,15 @@ export class Databases extends Service { if (typeof array !== 'undefined') { payload['array'] = array; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update integer attribute @@ -1022,9 +1172,15 @@ export class Databases extends Service { if (typeof xdefault !== 'undefined') { payload['default'] = xdefault; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create IP address attribute @@ -1073,9 +1229,15 @@ export class Databases extends Service { if (typeof array !== 'undefined') { payload['array'] = array; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update IP address attribute @@ -1122,9 +1284,15 @@ export class Databases extends Service { if (typeof xdefault !== 'undefined') { payload['default'] = xdefault; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create relationship attribute @@ -1136,15 +1304,15 @@ export class Databases extends Service { * @param {string} databaseId * @param {string} collectionId * @param {string} relatedCollectionId - * @param {string} type + * @param {RelationshipType} type * @param {boolean} twoWay * @param {string} key * @param {string} twoWayKey - * @param {string} onDelete + * @param {RelationMutate} onDelete * @throws {AppwriteException} * @returns {Promise} */ - async createRelationshipAttribute(databaseId: string, collectionId: string, relatedCollectionId: string, type: string, twoWay?: boolean, key?: string, twoWayKey?: string, onDelete?: string): Promise<Models.AttributeRelationship> { + async createRelationshipAttribute(databaseId: string, collectionId: string, relatedCollectionId: string, type: RelationshipType, twoWay?: boolean, key?: string, twoWayKey?: string, onDelete?: RelationMutate): Promise<Models.AttributeRelationship> { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -1182,9 +1350,15 @@ export class Databases extends Service { if (typeof onDelete !== 'undefined') { payload['onDelete'] = onDelete; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create string attribute @@ -1245,9 +1419,15 @@ export class Databases extends Service { if (typeof encrypt !== 'undefined') { payload['encrypt'] = encrypt; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update string attribute @@ -1294,9 +1474,15 @@ export class Databases extends Service { if (typeof xdefault !== 'undefined') { payload['default'] = xdefault; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create URL attribute @@ -1345,9 +1531,15 @@ export class Databases extends Service { if (typeof array !== 'undefined') { payload['array'] = array; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update URL attribute @@ -1394,13 +1586,21 @@ export class Databases extends Service { if (typeof xdefault !== 'undefined') { payload['default'] = xdefault; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get attribute * + * Get attribute by ID. + * * @param {string} databaseId * @param {string} collectionId * @param {string} key @@ -1423,13 +1623,21 @@ export class Databases extends Service { const apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete attribute * + * Deletes an attribute. + * * @param {string} databaseId * @param {string} collectionId * @param {string} key @@ -1452,9 +1660,15 @@ export class Databases extends Service { const apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update relationship attribute @@ -1466,11 +1680,11 @@ export class Databases extends Service { * @param {string} databaseId * @param {string} collectionId * @param {string} key - * @param {string} onDelete + * @param {RelationMutate} onDelete * @throws {AppwriteException} * @returns {Promise} */ - async updateRelationshipAttribute(databaseId: string, collectionId: string, key: string, onDelete?: string): Promise<Models.AttributeRelationship> { + async updateRelationshipAttribute(databaseId: string, collectionId: string, key: string, onDelete?: RelationMutate): Promise<Models.AttributeRelationship> { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -1489,9 +1703,15 @@ export class Databases extends Service { if (typeof onDelete !== 'undefined') { payload['onDelete'] = onDelete; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List documents @@ -1521,9 +1741,15 @@ export class Databases extends Service { payload['queries'] = queries; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create document @@ -1570,9 +1796,15 @@ export class Databases extends Service { if (typeof permissions !== 'undefined') { payload['permissions'] = permissions; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get document @@ -1607,9 +1839,15 @@ export class Databases extends Service { payload['queries'] = queries; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update document @@ -1647,9 +1885,15 @@ export class Databases extends Service { if (typeof permissions !== 'undefined') { payload['permissions'] = permissions; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete document @@ -1678,13 +1922,21 @@ export class Databases extends Service { const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List indexes * + * List indexes in the collection. + * * @param {string} databaseId * @param {string} collectionId * @param {string[]} queries @@ -1707,23 +1959,33 @@ export class Databases extends Service { payload['queries'] = queries; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create index * + * Creates an index on the attributes listed. Your index should include all + * the attributes you will query in a single request. + * Attributes can be `key`, `fulltext`, and `unique`. + * * @param {string} databaseId * @param {string} collectionId * @param {string} key - * @param {string} type + * @param {IndexType} type * @param {string[]} attributes * @param {string[]} orders * @throws {AppwriteException} * @returns {Promise} */ - async createIndex(databaseId: string, collectionId: string, key: string, type: string, attributes: string[], orders?: string[]): Promise<Models.Index> { + async createIndex(databaseId: string, collectionId: string, key: string, type: IndexType, attributes: string[], orders?: string[]): Promise<Models.Index> { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -1759,13 +2021,21 @@ export class Databases extends Service { if (typeof orders !== 'undefined') { payload['orders'] = orders; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get index * + * Get index by ID. + * * @param {string} databaseId * @param {string} collectionId * @param {string} key @@ -1788,13 +2058,21 @@ export class Databases extends Service { const apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete index * + * Delete an index. + * * @param {string} databaseId * @param {string} collectionId * @param {string} key @@ -1817,8 +2095,14 @@ export class Databases extends Service { const apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } } \ No newline at end of file diff --git a/src/services/functions.ts b/src/services/functions.ts index 2dd063c..8db85dc 100644 --- a/src/services/functions.ts +++ b/src/services/functions.ts @@ -4,6 +4,9 @@ import { Payload, Client } from '../client.ts'; import { InputFile } from '../inputFile.ts'; import { AppwriteException } from '../exception.ts'; import type { Models } from '../models.d.ts'; +import { Query } from '../query.ts'; +import { Runtime } from '../enums/runtime.ts'; +import { ExecutionMethod } from '../enums/execution-method.ts'; export type UploadProgress = { $id: string; @@ -43,9 +46,15 @@ export class Functions extends Service { payload['search'] = search; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create function @@ -57,7 +66,7 @@ export class Functions extends Service { * * @param {string} functionId * @param {string} name - * @param {string} runtime + * @param {Runtime} runtime * @param {string[]} execute * @param {string[]} events * @param {string} schedule @@ -78,7 +87,7 @@ export class Functions extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async create(functionId: string, name: string, runtime: string, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, templateRepository?: string, templateOwner?: string, templateRootDirectory?: string, templateBranch?: string): Promise<Models.Function> { + async create(functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, templateRepository?: string, templateOwner?: string, templateRootDirectory?: string, templateBranch?: string): Promise<Models.Function> { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -154,9 +163,15 @@ export class Functions extends Service { if (typeof templateBranch !== 'undefined') { payload['templateBranch'] = templateBranch; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List runtimes @@ -170,9 +185,15 @@ export class Functions extends Service { const apiPath = '/functions/runtimes'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get function @@ -191,9 +212,15 @@ export class Functions extends Service { const apiPath = '/functions/{functionId}'.replace('{functionId}', functionId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update function @@ -202,7 +229,7 @@ export class Functions extends Service { * * @param {string} functionId * @param {string} name - * @param {string} runtime + * @param {Runtime} runtime * @param {string[]} execute * @param {string[]} events * @param {string} schedule @@ -219,7 +246,7 @@ export class Functions extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async update(functionId: string, name: string, runtime?: string, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string): Promise<Models.Function> { + async update(functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string): Promise<Models.Function> { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -276,9 +303,15 @@ export class Functions extends Service { if (typeof providerRootDirectory !== 'undefined') { payload['providerRootDirectory'] = providerRootDirectory; } - return await this.client.call('put', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete function @@ -297,9 +330,15 @@ export class Functions extends Service { const apiPath = '/functions/{functionId}'.replace('{functionId}', functionId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List deployments @@ -329,9 +368,15 @@ export class Functions extends Service { payload['search'] = search; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create deployment @@ -406,7 +451,11 @@ export class Functions extends Service { } const start = ((currentChunk - 1) * Client.CHUNK_SIZE); - const end = start + currentPosition; + let end = start + currentPosition; + + if (end === size) { + end -= 1; + } if(!lastUpload || currentChunk !== 1) { apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size; @@ -491,9 +540,15 @@ export class Functions extends Service { const apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update function deployment @@ -519,9 +574,15 @@ export class Functions extends Service { const apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); const payload: Payload = {}; - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete deployment @@ -545,9 +606,15 @@ export class Functions extends Service { const apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create build @@ -577,9 +644,15 @@ export class Functions extends Service { const apiPath = '/functions/{functionId}/deployments/{deploymentId}/builds/{buildId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId).replace('{buildId}', buildId); const payload: Payload = {}; - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Download Deployment @@ -592,7 +665,7 @@ export class Functions extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async downloadDeployment(functionId: string, deploymentId: string): Promise<Response> { + async downloadDeployment(functionId: string, deploymentId: string): Promise<ArrayBuffer> { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -604,9 +677,15 @@ export class Functions extends Service { const apiPath = '/functions/{functionId}/deployments/{deploymentId}/download'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'arraybuffer' + ); } /** * List executions @@ -636,9 +715,15 @@ export class Functions extends Service { payload['search'] = search; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create execution @@ -652,12 +737,12 @@ export class Functions extends Service { * @param {string} body * @param {boolean} async * @param {string} xpath - * @param {string} method + * @param {ExecutionMethod} method * @param {object} headers * @throws {AppwriteException} * @returns {Promise} */ - async createExecution(functionId: string, body?: string, async?: boolean, xpath?: string, method?: string, headers?: object): Promise<Models.Execution> { + async createExecution(functionId: string, body?: string, async?: boolean, xpath?: string, method?: ExecutionMethod, headers?: object): Promise<Models.Execution> { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -680,9 +765,15 @@ export class Functions extends Service { if (typeof headers !== 'undefined') { payload['headers'] = headers; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get execution @@ -706,9 +797,15 @@ export class Functions extends Service { const apiPath = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List variables @@ -727,9 +824,15 @@ export class Functions extends Service { const apiPath = '/functions/{functionId}/variables'.replace('{functionId}', functionId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create variable @@ -765,9 +868,15 @@ export class Functions extends Service { if (typeof value !== 'undefined') { payload['value'] = value; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get variable @@ -791,9 +900,15 @@ export class Functions extends Service { const apiPath = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update variable @@ -829,9 +944,15 @@ export class Functions extends Service { if (typeof value !== 'undefined') { payload['value'] = value; } - return await this.client.call('put', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete variable @@ -855,8 +976,14 @@ export class Functions extends Service { const apiPath = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } } \ No newline at end of file diff --git a/src/services/graphql.ts b/src/services/graphql.ts index 3bb06f9..3f250e6 100644 --- a/src/services/graphql.ts +++ b/src/services/graphql.ts @@ -4,6 +4,7 @@ import { Payload, Client } from '../client.ts'; import { InputFile } from '../inputFile.ts'; import { AppwriteException } from '../exception.ts'; import type { Models } from '../models.d.ts'; +import { Query } from '../query.ts'; export type UploadProgress = { $id: string; @@ -40,10 +41,16 @@ export class Graphql extends Service { if (typeof query !== 'undefined') { payload['query'] = query; } - return await this.client.call('post', apiPath, { - 'x-sdk-graphql': 'true', - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'x-sdk-graphql': 'true', + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * GraphQL endpoint @@ -65,9 +72,15 @@ export class Graphql extends Service { if (typeof query !== 'undefined') { payload['query'] = query; } - return await this.client.call('post', apiPath, { - 'x-sdk-graphql': 'true', - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'x-sdk-graphql': 'true', + 'content-type': 'application/json', + }, + payload, + 'json' + ); } } \ No newline at end of file diff --git a/src/services/health.ts b/src/services/health.ts index 5b7a437..557f3d1 100644 --- a/src/services/health.ts +++ b/src/services/health.ts @@ -4,6 +4,8 @@ import { Payload, Client } from '../client.ts'; import { InputFile } from '../inputFile.ts'; import { AppwriteException } from '../exception.ts'; import type { Models } from '../models.d.ts'; +import { Query } from '../query.ts'; +import { Name } from '../enums/name.ts'; export type UploadProgress = { $id: string; @@ -32,9 +34,15 @@ export class Health extends Service { const apiPath = '/health'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get antivirus @@ -48,9 +56,15 @@ export class Health extends Service { const apiPath = '/health/anti-virus'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get cache @@ -65,9 +79,42 @@ export class Health extends Service { const apiPath = '/health/cache'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Get the SSL certificate for a domain + * + * Get the SSL certificate for a domain + * + * @param {string} domain + * @throws {AppwriteException} + * @returns {Promise} + */ + async getCertificate(domain?: string): Promise<Models.HealthCertificate> { + const apiPath = '/health/certificate'; + const payload: Payload = {}; + + if (typeof domain !== 'undefined') { + payload['domain'] = domain; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get DB @@ -81,9 +128,15 @@ export class Health extends Service { const apiPath = '/health/db'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get pubsub @@ -97,9 +150,15 @@ export class Health extends Service { const apiPath = '/health/pubsub'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get queue @@ -114,9 +173,15 @@ export class Health extends Service { const apiPath = '/health/queue'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get builds queue @@ -136,9 +201,15 @@ export class Health extends Service { payload['threshold'] = threshold; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get certificates queue @@ -159,9 +230,15 @@ export class Health extends Service { payload['threshold'] = threshold; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get databases queue @@ -186,9 +263,15 @@ export class Health extends Service { payload['threshold'] = threshold; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get deletes queue @@ -208,13 +291,55 @@ export class Health extends Service { payload['threshold'] = threshold; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Get number of failed queue jobs + * + * Returns the amount of failed jobs in a given queue. + * + * + * @param {Name} name + * @param {number} threshold + * @throws {AppwriteException} + * @returns {Promise} + */ + async getFailedJobs(name: Name, threshold?: number): Promise<Models.HealthQueue> { + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/health/queue/failed/{name}'.replace('{name}', name); + const payload: Payload = {}; + + if (typeof threshold !== 'undefined') { + payload['threshold'] = threshold; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get functions queue * + * Get the number of function executions that are waiting to be processed in + * the Appwrite internal queue server. + * * @param {number} threshold * @throws {AppwriteException} * @returns {Promise} @@ -227,9 +352,15 @@ export class Health extends Service { payload['threshold'] = threshold; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get logs queue @@ -249,9 +380,15 @@ export class Health extends Service { payload['threshold'] = threshold; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get mails queue @@ -271,9 +408,15 @@ export class Health extends Service { payload['threshold'] = threshold; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get messaging queue @@ -293,9 +436,15 @@ export class Health extends Service { payload['threshold'] = threshold; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get migrations queue @@ -315,9 +464,71 @@ export class Health extends Service { payload['threshold'] = threshold; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Get usage queue + * + * Get the number of metrics that are waiting to be processed in the Appwrite + * internal queue server. + * + * @param {number} threshold + * @throws {AppwriteException} + * @returns {Promise} + */ + async getQueueUsage(threshold?: number): Promise<Models.HealthQueue> { + const apiPath = '/health/queue/usage'; + const payload: Payload = {}; + + if (typeof threshold !== 'undefined') { + payload['threshold'] = threshold; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Get usage dump queue + * + * Get the number of projects containing metrics that are waiting to be + * processed in the Appwrite internal queue server. + * + * @param {number} threshold + * @throws {AppwriteException} + * @returns {Promise} + */ + async getQueueUsageDump(threshold?: number): Promise<Models.HealthQueue> { + const apiPath = '/health/queue/usage-dump'; + const payload: Payload = {}; + + if (typeof threshold !== 'undefined') { + payload['threshold'] = threshold; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get webhooks queue @@ -337,9 +548,37 @@ export class Health extends Service { payload['threshold'] = threshold; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Get storage + * + * Check the Appwrite storage device is up and connection is successful. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async getStorage(): Promise<Models.HealthStatus> { + const apiPath = '/health/storage'; + const payload: Payload = {}; + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get local storage @@ -353,9 +592,15 @@ export class Health extends Service { const apiPath = '/health/storage/local'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get time @@ -375,8 +620,14 @@ export class Health extends Service { const apiPath = '/health/time'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } } \ No newline at end of file diff --git a/src/services/locale.ts b/src/services/locale.ts index cd58f4a..432d9d1 100644 --- a/src/services/locale.ts +++ b/src/services/locale.ts @@ -4,6 +4,7 @@ import { Payload, Client } from '../client.ts'; import { InputFile } from '../inputFile.ts'; import { AppwriteException } from '../exception.ts'; import type { Models } from '../models.d.ts'; +import { Query } from '../query.ts'; export type UploadProgress = { $id: string; @@ -37,9 +38,15 @@ export class Locale extends Service { const apiPath = '/locale'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List Locale Codes @@ -54,9 +61,15 @@ export class Locale extends Service { const apiPath = '/locale/codes'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List continents @@ -71,9 +84,15 @@ export class Locale extends Service { const apiPath = '/locale/continents'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List countries @@ -88,9 +107,15 @@ export class Locale extends Service { const apiPath = '/locale/countries'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List EU countries @@ -105,9 +130,15 @@ export class Locale extends Service { const apiPath = '/locale/countries/eu'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List countries phone codes @@ -122,9 +153,15 @@ export class Locale extends Service { const apiPath = '/locale/countries/phones'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List currencies @@ -140,9 +177,15 @@ export class Locale extends Service { const apiPath = '/locale/currencies'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List languages @@ -157,8 +200,14 @@ export class Locale extends Service { const apiPath = '/locale/languages'; const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } } \ No newline at end of file diff --git a/src/services/messaging.ts b/src/services/messaging.ts new file mode 100644 index 0000000..77e0a59 --- /dev/null +++ b/src/services/messaging.ts @@ -0,0 +1,2242 @@ +import { basename } from "https://deno.land/std@0.122.0/path/mod.ts"; +import { Service } from '../service.ts'; +import { Payload, Client } from '../client.ts'; +import { InputFile } from '../inputFile.ts'; +import { AppwriteException } from '../exception.ts'; +import type { Models } from '../models.d.ts'; +import { Query } from '../query.ts'; +import { SmtpEncryption } from '../enums/smtp-encryption.ts'; + +export type UploadProgress = { + $id: string; + progress: number; + sizeUploaded: number; + chunksTotal: number; + chunksUploaded: number; +} + +export class Messaging extends Service { + + constructor(client: Client) + { + super(client); + } + + /** + * List messages + * + * Get a list of all messages from the current Appwrite project. + * + * @param {string[]} queries + * @param {string} search + * @throws {AppwriteException} + * @returns {Promise} + */ + async listMessages(queries?: string[], search?: string): Promise<Models.MessageList> { + const apiPath = '/messaging/messages'; + const payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + if (typeof search !== 'undefined') { + payload['search'] = search; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create email + * + * Create a new email message. + * + * @param {string} messageId + * @param {string} subject + * @param {string} content + * @param {string[]} topics + * @param {string[]} users + * @param {string[]} targets + * @param {string[]} cc + * @param {string[]} bcc + * @param {string[]} attachments + * @param {boolean} draft + * @param {boolean} html + * @param {string} scheduledAt + * @throws {AppwriteException} + * @returns {Promise} + */ + async createEmail(messageId: string, subject: string, content: string, topics?: string[], users?: string[], targets?: string[], cc?: string[], bcc?: string[], attachments?: string[], draft?: boolean, html?: boolean, scheduledAt?: string): Promise<Models.Message> { + if (typeof messageId === 'undefined') { + throw new AppwriteException('Missing required parameter: "messageId"'); + } + + if (typeof subject === 'undefined') { + throw new AppwriteException('Missing required parameter: "subject"'); + } + + if (typeof content === 'undefined') { + throw new AppwriteException('Missing required parameter: "content"'); + } + + const apiPath = '/messaging/messages/email'; + const payload: Payload = {}; + + if (typeof messageId !== 'undefined') { + payload['messageId'] = messageId; + } + if (typeof subject !== 'undefined') { + payload['subject'] = subject; + } + if (typeof content !== 'undefined') { + payload['content'] = content; + } + if (typeof topics !== 'undefined') { + payload['topics'] = topics; + } + if (typeof users !== 'undefined') { + payload['users'] = users; + } + if (typeof targets !== 'undefined') { + payload['targets'] = targets; + } + if (typeof cc !== 'undefined') { + payload['cc'] = cc; + } + if (typeof bcc !== 'undefined') { + payload['bcc'] = bcc; + } + if (typeof attachments !== 'undefined') { + payload['attachments'] = attachments; + } + if (typeof draft !== 'undefined') { + payload['draft'] = draft; + } + if (typeof html !== 'undefined') { + payload['html'] = html; + } + if (typeof scheduledAt !== 'undefined') { + payload['scheduledAt'] = scheduledAt; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update email + * + * Update an email message by its unique ID. + * + * + * @param {string} messageId + * @param {string[]} topics + * @param {string[]} users + * @param {string[]} targets + * @param {string} subject + * @param {string} content + * @param {boolean} draft + * @param {boolean} html + * @param {string[]} cc + * @param {string[]} bcc + * @param {string} scheduledAt + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateEmail(messageId: string, topics?: string[], users?: string[], targets?: string[], subject?: string, content?: string, draft?: boolean, html?: boolean, cc?: string[], bcc?: string[], scheduledAt?: string): Promise<Models.Message> { + if (typeof messageId === 'undefined') { + throw new AppwriteException('Missing required parameter: "messageId"'); + } + + const apiPath = '/messaging/messages/email/{messageId}'.replace('{messageId}', messageId); + const payload: Payload = {}; + + if (typeof topics !== 'undefined') { + payload['topics'] = topics; + } + if (typeof users !== 'undefined') { + payload['users'] = users; + } + if (typeof targets !== 'undefined') { + payload['targets'] = targets; + } + if (typeof subject !== 'undefined') { + payload['subject'] = subject; + } + if (typeof content !== 'undefined') { + payload['content'] = content; + } + if (typeof draft !== 'undefined') { + payload['draft'] = draft; + } + if (typeof html !== 'undefined') { + payload['html'] = html; + } + if (typeof cc !== 'undefined') { + payload['cc'] = cc; + } + if (typeof bcc !== 'undefined') { + payload['bcc'] = bcc; + } + if (typeof scheduledAt !== 'undefined') { + payload['scheduledAt'] = scheduledAt; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create push notification + * + * Create a new push notification. + * + * @param {string} messageId + * @param {string} title + * @param {string} body + * @param {string[]} topics + * @param {string[]} users + * @param {string[]} targets + * @param {object} data + * @param {string} action + * @param {string} image + * @param {string} icon + * @param {string} sound + * @param {string} color + * @param {string} tag + * @param {string} badge + * @param {boolean} draft + * @param {string} scheduledAt + * @throws {AppwriteException} + * @returns {Promise} + */ + async createPush(messageId: string, title: string, body: string, topics?: string[], users?: string[], targets?: string[], data?: object, action?: string, image?: string, icon?: string, sound?: string, color?: string, tag?: string, badge?: string, draft?: boolean, scheduledAt?: string): Promise<Models.Message> { + if (typeof messageId === 'undefined') { + throw new AppwriteException('Missing required parameter: "messageId"'); + } + + if (typeof title === 'undefined') { + throw new AppwriteException('Missing required parameter: "title"'); + } + + if (typeof body === 'undefined') { + throw new AppwriteException('Missing required parameter: "body"'); + } + + const apiPath = '/messaging/messages/push'; + const payload: Payload = {}; + + if (typeof messageId !== 'undefined') { + payload['messageId'] = messageId; + } + if (typeof title !== 'undefined') { + payload['title'] = title; + } + if (typeof body !== 'undefined') { + payload['body'] = body; + } + if (typeof topics !== 'undefined') { + payload['topics'] = topics; + } + if (typeof users !== 'undefined') { + payload['users'] = users; + } + if (typeof targets !== 'undefined') { + payload['targets'] = targets; + } + if (typeof data !== 'undefined') { + payload['data'] = data; + } + if (typeof action !== 'undefined') { + payload['action'] = action; + } + if (typeof image !== 'undefined') { + payload['image'] = image; + } + if (typeof icon !== 'undefined') { + payload['icon'] = icon; + } + if (typeof sound !== 'undefined') { + payload['sound'] = sound; + } + if (typeof color !== 'undefined') { + payload['color'] = color; + } + if (typeof tag !== 'undefined') { + payload['tag'] = tag; + } + if (typeof badge !== 'undefined') { + payload['badge'] = badge; + } + if (typeof draft !== 'undefined') { + payload['draft'] = draft; + } + if (typeof scheduledAt !== 'undefined') { + payload['scheduledAt'] = scheduledAt; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update push notification + * + * Update a push notification by its unique ID. + * + * + * @param {string} messageId + * @param {string[]} topics + * @param {string[]} users + * @param {string[]} targets + * @param {string} title + * @param {string} body + * @param {object} data + * @param {string} action + * @param {string} image + * @param {string} icon + * @param {string} sound + * @param {string} color + * @param {string} tag + * @param {number} badge + * @param {boolean} draft + * @param {string} scheduledAt + * @throws {AppwriteException} + * @returns {Promise} + */ + async updatePush(messageId: string, topics?: string[], users?: string[], targets?: string[], title?: string, body?: string, data?: object, action?: string, image?: string, icon?: string, sound?: string, color?: string, tag?: string, badge?: number, draft?: boolean, scheduledAt?: string): Promise<Models.Message> { + if (typeof messageId === 'undefined') { + throw new AppwriteException('Missing required parameter: "messageId"'); + } + + const apiPath = '/messaging/messages/push/{messageId}'.replace('{messageId}', messageId); + const payload: Payload = {}; + + if (typeof topics !== 'undefined') { + payload['topics'] = topics; + } + if (typeof users !== 'undefined') { + payload['users'] = users; + } + if (typeof targets !== 'undefined') { + payload['targets'] = targets; + } + if (typeof title !== 'undefined') { + payload['title'] = title; + } + if (typeof body !== 'undefined') { + payload['body'] = body; + } + if (typeof data !== 'undefined') { + payload['data'] = data; + } + if (typeof action !== 'undefined') { + payload['action'] = action; + } + if (typeof image !== 'undefined') { + payload['image'] = image; + } + if (typeof icon !== 'undefined') { + payload['icon'] = icon; + } + if (typeof sound !== 'undefined') { + payload['sound'] = sound; + } + if (typeof color !== 'undefined') { + payload['color'] = color; + } + if (typeof tag !== 'undefined') { + payload['tag'] = tag; + } + if (typeof badge !== 'undefined') { + payload['badge'] = badge; + } + if (typeof draft !== 'undefined') { + payload['draft'] = draft; + } + if (typeof scheduledAt !== 'undefined') { + payload['scheduledAt'] = scheduledAt; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create SMS + * + * Create a new SMS message. + * + * @param {string} messageId + * @param {string} content + * @param {string[]} topics + * @param {string[]} users + * @param {string[]} targets + * @param {boolean} draft + * @param {string} scheduledAt + * @throws {AppwriteException} + * @returns {Promise} + */ + async createSms(messageId: string, content: string, topics?: string[], users?: string[], targets?: string[], draft?: boolean, scheduledAt?: string): Promise<Models.Message> { + if (typeof messageId === 'undefined') { + throw new AppwriteException('Missing required parameter: "messageId"'); + } + + if (typeof content === 'undefined') { + throw new AppwriteException('Missing required parameter: "content"'); + } + + const apiPath = '/messaging/messages/sms'; + const payload: Payload = {}; + + if (typeof messageId !== 'undefined') { + payload['messageId'] = messageId; + } + if (typeof content !== 'undefined') { + payload['content'] = content; + } + if (typeof topics !== 'undefined') { + payload['topics'] = topics; + } + if (typeof users !== 'undefined') { + payload['users'] = users; + } + if (typeof targets !== 'undefined') { + payload['targets'] = targets; + } + if (typeof draft !== 'undefined') { + payload['draft'] = draft; + } + if (typeof scheduledAt !== 'undefined') { + payload['scheduledAt'] = scheduledAt; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update SMS + * + * Update an email message by its unique ID. + * + * + * @param {string} messageId + * @param {string[]} topics + * @param {string[]} users + * @param {string[]} targets + * @param {string} content + * @param {boolean} draft + * @param {string} scheduledAt + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateSms(messageId: string, topics?: string[], users?: string[], targets?: string[], content?: string, draft?: boolean, scheduledAt?: string): Promise<Models.Message> { + if (typeof messageId === 'undefined') { + throw new AppwriteException('Missing required parameter: "messageId"'); + } + + const apiPath = '/messaging/messages/sms/{messageId}'.replace('{messageId}', messageId); + const payload: Payload = {}; + + if (typeof topics !== 'undefined') { + payload['topics'] = topics; + } + if (typeof users !== 'undefined') { + payload['users'] = users; + } + if (typeof targets !== 'undefined') { + payload['targets'] = targets; + } + if (typeof content !== 'undefined') { + payload['content'] = content; + } + if (typeof draft !== 'undefined') { + payload['draft'] = draft; + } + if (typeof scheduledAt !== 'undefined') { + payload['scheduledAt'] = scheduledAt; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Get message + * + * Get a message by its unique ID. + * + * + * @param {string} messageId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getMessage(messageId: string): Promise<Models.Message> { + if (typeof messageId === 'undefined') { + throw new AppwriteException('Missing required parameter: "messageId"'); + } + + const apiPath = '/messaging/messages/{messageId}'.replace('{messageId}', messageId); + const payload: Payload = {}; + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Delete message + * + * Delete a message. If the message is not a draft or scheduled, but has been + * sent, this will not recall the message. + * + * @param {string} messageId + * @throws {AppwriteException} + * @returns {Promise} + */ + async delete(messageId: string): Promise<Response> { + if (typeof messageId === 'undefined') { + throw new AppwriteException('Missing required parameter: "messageId"'); + } + + const apiPath = '/messaging/messages/{messageId}'.replace('{messageId}', messageId); + const payload: Payload = {}; + + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * List message logs + * + * Get the message activity logs listed by its unique ID. + * + * @param {string} messageId + * @param {string[]} queries + * @throws {AppwriteException} + * @returns {Promise} + */ + async listMessageLogs(messageId: string, queries?: string[]): Promise<Models.LogList> { + if (typeof messageId === 'undefined') { + throw new AppwriteException('Missing required parameter: "messageId"'); + } + + const apiPath = '/messaging/messages/{messageId}/logs'.replace('{messageId}', messageId); + const payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * List message targets + * + * Get a list of the targets associated with a message. + * + * @param {string} messageId + * @param {string[]} queries + * @throws {AppwriteException} + * @returns {Promise} + */ + async listTargets(messageId: string, queries?: string[]): Promise<Models.TargetList> { + if (typeof messageId === 'undefined') { + throw new AppwriteException('Missing required parameter: "messageId"'); + } + + const apiPath = '/messaging/messages/{messageId}/targets'.replace('{messageId}', messageId); + const payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * List providers + * + * Get a list of all providers from the current Appwrite project. + * + * @param {string[]} queries + * @param {string} search + * @throws {AppwriteException} + * @returns {Promise} + */ + async listProviders(queries?: string[], search?: string): Promise<Models.ProviderList> { + const apiPath = '/messaging/providers'; + const payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + if (typeof search !== 'undefined') { + payload['search'] = search; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create APNS provider + * + * Create a new Apple Push Notification service provider. + * + * @param {string} providerId + * @param {string} name + * @param {string} authKey + * @param {string} authKeyId + * @param {string} teamId + * @param {string} bundleId + * @param {boolean} sandbox + * @param {boolean} enabled + * @throws {AppwriteException} + * @returns {Promise} + */ + async createApnsProvider(providerId: string, name: string, authKey?: string, authKeyId?: string, teamId?: string, bundleId?: string, sandbox?: boolean, enabled?: boolean): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/messaging/providers/apns'; + const payload: Payload = {}; + + if (typeof providerId !== 'undefined') { + payload['providerId'] = providerId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof authKey !== 'undefined') { + payload['authKey'] = authKey; + } + if (typeof authKeyId !== 'undefined') { + payload['authKeyId'] = authKeyId; + } + if (typeof teamId !== 'undefined') { + payload['teamId'] = teamId; + } + if (typeof bundleId !== 'undefined') { + payload['bundleId'] = bundleId; + } + if (typeof sandbox !== 'undefined') { + payload['sandbox'] = sandbox; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update APNS provider + * + * Update a Apple Push Notification service provider by its unique ID. + * + * @param {string} providerId + * @param {string} name + * @param {boolean} enabled + * @param {string} authKey + * @param {string} authKeyId + * @param {string} teamId + * @param {string} bundleId + * @param {boolean} sandbox + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateApnsProvider(providerId: string, name?: string, enabled?: boolean, authKey?: string, authKeyId?: string, teamId?: string, bundleId?: string, sandbox?: boolean): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/apns/{providerId}'.replace('{providerId}', providerId); + const payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + if (typeof authKey !== 'undefined') { + payload['authKey'] = authKey; + } + if (typeof authKeyId !== 'undefined') { + payload['authKeyId'] = authKeyId; + } + if (typeof teamId !== 'undefined') { + payload['teamId'] = teamId; + } + if (typeof bundleId !== 'undefined') { + payload['bundleId'] = bundleId; + } + if (typeof sandbox !== 'undefined') { + payload['sandbox'] = sandbox; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create FCM provider + * + * Create a new Firebase Cloud Messaging provider. + * + * @param {string} providerId + * @param {string} name + * @param {object} serviceAccountJSON + * @param {boolean} enabled + * @throws {AppwriteException} + * @returns {Promise} + */ + async createFcmProvider(providerId: string, name: string, serviceAccountJSON?: object, enabled?: boolean): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/messaging/providers/fcm'; + const payload: Payload = {}; + + if (typeof providerId !== 'undefined') { + payload['providerId'] = providerId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof serviceAccountJSON !== 'undefined') { + payload['serviceAccountJSON'] = serviceAccountJSON; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update FCM provider + * + * Update a Firebase Cloud Messaging provider by its unique ID. + * + * @param {string} providerId + * @param {string} name + * @param {boolean} enabled + * @param {object} serviceAccountJSON + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateFcmProvider(providerId: string, name?: string, enabled?: boolean, serviceAccountJSON?: object): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/fcm/{providerId}'.replace('{providerId}', providerId); + const payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + if (typeof serviceAccountJSON !== 'undefined') { + payload['serviceAccountJSON'] = serviceAccountJSON; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create Mailgun provider + * + * Create a new Mailgun provider. + * + * @param {string} providerId + * @param {string} name + * @param {string} apiKey + * @param {string} domain + * @param {boolean} isEuRegion + * @param {string} fromName + * @param {string} fromEmail + * @param {string} replyToName + * @param {string} replyToEmail + * @param {boolean} enabled + * @throws {AppwriteException} + * @returns {Promise} + */ + async createMailgunProvider(providerId: string, name: string, apiKey?: string, domain?: string, isEuRegion?: boolean, fromName?: string, fromEmail?: string, replyToName?: string, replyToEmail?: string, enabled?: boolean): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/messaging/providers/mailgun'; + const payload: Payload = {}; + + if (typeof providerId !== 'undefined') { + payload['providerId'] = providerId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof apiKey !== 'undefined') { + payload['apiKey'] = apiKey; + } + if (typeof domain !== 'undefined') { + payload['domain'] = domain; + } + if (typeof isEuRegion !== 'undefined') { + payload['isEuRegion'] = isEuRegion; + } + if (typeof fromName !== 'undefined') { + payload['fromName'] = fromName; + } + if (typeof fromEmail !== 'undefined') { + payload['fromEmail'] = fromEmail; + } + if (typeof replyToName !== 'undefined') { + payload['replyToName'] = replyToName; + } + if (typeof replyToEmail !== 'undefined') { + payload['replyToEmail'] = replyToEmail; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update Mailgun provider + * + * Update a Mailgun provider by its unique ID. + * + * @param {string} providerId + * @param {string} name + * @param {string} apiKey + * @param {string} domain + * @param {boolean} isEuRegion + * @param {boolean} enabled + * @param {string} fromName + * @param {string} fromEmail + * @param {string} replyToName + * @param {string} replyToEmail + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateMailgunProvider(providerId: string, name?: string, apiKey?: string, domain?: string, isEuRegion?: boolean, enabled?: boolean, fromName?: string, fromEmail?: string, replyToName?: string, replyToEmail?: string): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/mailgun/{providerId}'.replace('{providerId}', providerId); + const payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof apiKey !== 'undefined') { + payload['apiKey'] = apiKey; + } + if (typeof domain !== 'undefined') { + payload['domain'] = domain; + } + if (typeof isEuRegion !== 'undefined') { + payload['isEuRegion'] = isEuRegion; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + if (typeof fromName !== 'undefined') { + payload['fromName'] = fromName; + } + if (typeof fromEmail !== 'undefined') { + payload['fromEmail'] = fromEmail; + } + if (typeof replyToName !== 'undefined') { + payload['replyToName'] = replyToName; + } + if (typeof replyToEmail !== 'undefined') { + payload['replyToEmail'] = replyToEmail; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create Msg91 provider + * + * Create a new MSG91 provider. + * + * @param {string} providerId + * @param {string} name + * @param {string} from + * @param {string} senderId + * @param {string} authKey + * @param {boolean} enabled + * @throws {AppwriteException} + * @returns {Promise} + */ + async createMsg91Provider(providerId: string, name: string, from?: string, senderId?: string, authKey?: string, enabled?: boolean): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/messaging/providers/msg91'; + const payload: Payload = {}; + + if (typeof providerId !== 'undefined') { + payload['providerId'] = providerId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof from !== 'undefined') { + payload['from'] = from; + } + if (typeof senderId !== 'undefined') { + payload['senderId'] = senderId; + } + if (typeof authKey !== 'undefined') { + payload['authKey'] = authKey; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update Msg91 provider + * + * Update a MSG91 provider by its unique ID. + * + * @param {string} providerId + * @param {string} name + * @param {boolean} enabled + * @param {string} senderId + * @param {string} authKey + * @param {string} from + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateMsg91Provider(providerId: string, name?: string, enabled?: boolean, senderId?: string, authKey?: string, from?: string): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/msg91/{providerId}'.replace('{providerId}', providerId); + const payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + if (typeof senderId !== 'undefined') { + payload['senderId'] = senderId; + } + if (typeof authKey !== 'undefined') { + payload['authKey'] = authKey; + } + if (typeof from !== 'undefined') { + payload['from'] = from; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create Sendgrid provider + * + * Create a new Sendgrid provider. + * + * @param {string} providerId + * @param {string} name + * @param {string} apiKey + * @param {string} fromName + * @param {string} fromEmail + * @param {string} replyToName + * @param {string} replyToEmail + * @param {boolean} enabled + * @throws {AppwriteException} + * @returns {Promise} + */ + async createSendgridProvider(providerId: string, name: string, apiKey?: string, fromName?: string, fromEmail?: string, replyToName?: string, replyToEmail?: string, enabled?: boolean): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/messaging/providers/sendgrid'; + const payload: Payload = {}; + + if (typeof providerId !== 'undefined') { + payload['providerId'] = providerId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof apiKey !== 'undefined') { + payload['apiKey'] = apiKey; + } + if (typeof fromName !== 'undefined') { + payload['fromName'] = fromName; + } + if (typeof fromEmail !== 'undefined') { + payload['fromEmail'] = fromEmail; + } + if (typeof replyToName !== 'undefined') { + payload['replyToName'] = replyToName; + } + if (typeof replyToEmail !== 'undefined') { + payload['replyToEmail'] = replyToEmail; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update Sendgrid provider + * + * Update a Sendgrid provider by its unique ID. + * + * @param {string} providerId + * @param {string} name + * @param {boolean} enabled + * @param {string} apiKey + * @param {string} fromName + * @param {string} fromEmail + * @param {string} replyToName + * @param {string} replyToEmail + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateSendgridProvider(providerId: string, name?: string, enabled?: boolean, apiKey?: string, fromName?: string, fromEmail?: string, replyToName?: string, replyToEmail?: string): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/sendgrid/{providerId}'.replace('{providerId}', providerId); + const payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + if (typeof apiKey !== 'undefined') { + payload['apiKey'] = apiKey; + } + if (typeof fromName !== 'undefined') { + payload['fromName'] = fromName; + } + if (typeof fromEmail !== 'undefined') { + payload['fromEmail'] = fromEmail; + } + if (typeof replyToName !== 'undefined') { + payload['replyToName'] = replyToName; + } + if (typeof replyToEmail !== 'undefined') { + payload['replyToEmail'] = replyToEmail; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create SMTP provider + * + * Create a new SMTP provider. + * + * @param {string} providerId + * @param {string} name + * @param {string} host + * @param {number} port + * @param {string} username + * @param {string} password + * @param {SmtpEncryption} encryption + * @param {boolean} autoTLS + * @param {string} mailer + * @param {string} fromName + * @param {string} fromEmail + * @param {string} replyToName + * @param {string} replyToEmail + * @param {boolean} enabled + * @throws {AppwriteException} + * @returns {Promise} + */ + async createSmtpProvider(providerId: string, name: string, host: string, port?: number, username?: string, password?: string, encryption?: SmtpEncryption, autoTLS?: boolean, mailer?: string, fromName?: string, fromEmail?: string, replyToName?: string, replyToEmail?: string, enabled?: boolean): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + if (typeof host === 'undefined') { + throw new AppwriteException('Missing required parameter: "host"'); + } + + const apiPath = '/messaging/providers/smtp'; + const payload: Payload = {}; + + if (typeof providerId !== 'undefined') { + payload['providerId'] = providerId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof host !== 'undefined') { + payload['host'] = host; + } + if (typeof port !== 'undefined') { + payload['port'] = port; + } + if (typeof username !== 'undefined') { + payload['username'] = username; + } + if (typeof password !== 'undefined') { + payload['password'] = password; + } + if (typeof encryption !== 'undefined') { + payload['encryption'] = encryption; + } + if (typeof autoTLS !== 'undefined') { + payload['autoTLS'] = autoTLS; + } + if (typeof mailer !== 'undefined') { + payload['mailer'] = mailer; + } + if (typeof fromName !== 'undefined') { + payload['fromName'] = fromName; + } + if (typeof fromEmail !== 'undefined') { + payload['fromEmail'] = fromEmail; + } + if (typeof replyToName !== 'undefined') { + payload['replyToName'] = replyToName; + } + if (typeof replyToEmail !== 'undefined') { + payload['replyToEmail'] = replyToEmail; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update SMTP provider + * + * Update a SMTP provider by its unique ID. + * + * @param {string} providerId + * @param {string} name + * @param {string} host + * @param {number} port + * @param {string} username + * @param {string} password + * @param {SmtpEncryption} encryption + * @param {boolean} autoTLS + * @param {string} mailer + * @param {string} fromName + * @param {string} fromEmail + * @param {string} replyToName + * @param {string} replyToEmail + * @param {boolean} enabled + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateSmtpProvider(providerId: string, name?: string, host?: string, port?: number, username?: string, password?: string, encryption?: SmtpEncryption, autoTLS?: boolean, mailer?: string, fromName?: string, fromEmail?: string, replyToName?: string, replyToEmail?: string, enabled?: boolean): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/smtp/{providerId}'.replace('{providerId}', providerId); + const payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof host !== 'undefined') { + payload['host'] = host; + } + if (typeof port !== 'undefined') { + payload['port'] = port; + } + if (typeof username !== 'undefined') { + payload['username'] = username; + } + if (typeof password !== 'undefined') { + payload['password'] = password; + } + if (typeof encryption !== 'undefined') { + payload['encryption'] = encryption; + } + if (typeof autoTLS !== 'undefined') { + payload['autoTLS'] = autoTLS; + } + if (typeof mailer !== 'undefined') { + payload['mailer'] = mailer; + } + if (typeof fromName !== 'undefined') { + payload['fromName'] = fromName; + } + if (typeof fromEmail !== 'undefined') { + payload['fromEmail'] = fromEmail; + } + if (typeof replyToName !== 'undefined') { + payload['replyToName'] = replyToName; + } + if (typeof replyToEmail !== 'undefined') { + payload['replyToEmail'] = replyToEmail; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create Telesign provider + * + * Create a new Telesign provider. + * + * @param {string} providerId + * @param {string} name + * @param {string} from + * @param {string} customerId + * @param {string} apiKey + * @param {boolean} enabled + * @throws {AppwriteException} + * @returns {Promise} + */ + async createTelesignProvider(providerId: string, name: string, from?: string, customerId?: string, apiKey?: string, enabled?: boolean): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/messaging/providers/telesign'; + const payload: Payload = {}; + + if (typeof providerId !== 'undefined') { + payload['providerId'] = providerId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof from !== 'undefined') { + payload['from'] = from; + } + if (typeof customerId !== 'undefined') { + payload['customerId'] = customerId; + } + if (typeof apiKey !== 'undefined') { + payload['apiKey'] = apiKey; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update Telesign provider + * + * Update a Telesign provider by its unique ID. + * + * @param {string} providerId + * @param {string} name + * @param {boolean} enabled + * @param {string} customerId + * @param {string} apiKey + * @param {string} from + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateTelesignProvider(providerId: string, name?: string, enabled?: boolean, customerId?: string, apiKey?: string, from?: string): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/telesign/{providerId}'.replace('{providerId}', providerId); + const payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + if (typeof customerId !== 'undefined') { + payload['customerId'] = customerId; + } + if (typeof apiKey !== 'undefined') { + payload['apiKey'] = apiKey; + } + if (typeof from !== 'undefined') { + payload['from'] = from; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create Textmagic provider + * + * Create a new Textmagic provider. + * + * @param {string} providerId + * @param {string} name + * @param {string} from + * @param {string} username + * @param {string} apiKey + * @param {boolean} enabled + * @throws {AppwriteException} + * @returns {Promise} + */ + async createTextmagicProvider(providerId: string, name: string, from?: string, username?: string, apiKey?: string, enabled?: boolean): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/messaging/providers/textmagic'; + const payload: Payload = {}; + + if (typeof providerId !== 'undefined') { + payload['providerId'] = providerId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof from !== 'undefined') { + payload['from'] = from; + } + if (typeof username !== 'undefined') { + payload['username'] = username; + } + if (typeof apiKey !== 'undefined') { + payload['apiKey'] = apiKey; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update Textmagic provider + * + * Update a Textmagic provider by its unique ID. + * + * @param {string} providerId + * @param {string} name + * @param {boolean} enabled + * @param {string} username + * @param {string} apiKey + * @param {string} from + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateTextmagicProvider(providerId: string, name?: string, enabled?: boolean, username?: string, apiKey?: string, from?: string): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/textmagic/{providerId}'.replace('{providerId}', providerId); + const payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + if (typeof username !== 'undefined') { + payload['username'] = username; + } + if (typeof apiKey !== 'undefined') { + payload['apiKey'] = apiKey; + } + if (typeof from !== 'undefined') { + payload['from'] = from; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create Twilio provider + * + * Create a new Twilio provider. + * + * @param {string} providerId + * @param {string} name + * @param {string} from + * @param {string} accountSid + * @param {string} authToken + * @param {boolean} enabled + * @throws {AppwriteException} + * @returns {Promise} + */ + async createTwilioProvider(providerId: string, name: string, from?: string, accountSid?: string, authToken?: string, enabled?: boolean): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/messaging/providers/twilio'; + const payload: Payload = {}; + + if (typeof providerId !== 'undefined') { + payload['providerId'] = providerId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof from !== 'undefined') { + payload['from'] = from; + } + if (typeof accountSid !== 'undefined') { + payload['accountSid'] = accountSid; + } + if (typeof authToken !== 'undefined') { + payload['authToken'] = authToken; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update Twilio provider + * + * Update a Twilio provider by its unique ID. + * + * @param {string} providerId + * @param {string} name + * @param {boolean} enabled + * @param {string} accountSid + * @param {string} authToken + * @param {string} from + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateTwilioProvider(providerId: string, name?: string, enabled?: boolean, accountSid?: string, authToken?: string, from?: string): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/twilio/{providerId}'.replace('{providerId}', providerId); + const payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + if (typeof accountSid !== 'undefined') { + payload['accountSid'] = accountSid; + } + if (typeof authToken !== 'undefined') { + payload['authToken'] = authToken; + } + if (typeof from !== 'undefined') { + payload['from'] = from; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create Vonage provider + * + * Create a new Vonage provider. + * + * @param {string} providerId + * @param {string} name + * @param {string} from + * @param {string} apiKey + * @param {string} apiSecret + * @param {boolean} enabled + * @throws {AppwriteException} + * @returns {Promise} + */ + async createVonageProvider(providerId: string, name: string, from?: string, apiKey?: string, apiSecret?: string, enabled?: boolean): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/messaging/providers/vonage'; + const payload: Payload = {}; + + if (typeof providerId !== 'undefined') { + payload['providerId'] = providerId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof from !== 'undefined') { + payload['from'] = from; + } + if (typeof apiKey !== 'undefined') { + payload['apiKey'] = apiKey; + } + if (typeof apiSecret !== 'undefined') { + payload['apiSecret'] = apiSecret; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update Vonage provider + * + * Update a Vonage provider by its unique ID. + * + * @param {string} providerId + * @param {string} name + * @param {boolean} enabled + * @param {string} apiKey + * @param {string} apiSecret + * @param {string} from + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateVonageProvider(providerId: string, name?: string, enabled?: boolean, apiKey?: string, apiSecret?: string, from?: string): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/vonage/{providerId}'.replace('{providerId}', providerId); + const payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + if (typeof apiKey !== 'undefined') { + payload['apiKey'] = apiKey; + } + if (typeof apiSecret !== 'undefined') { + payload['apiSecret'] = apiSecret; + } + if (typeof from !== 'undefined') { + payload['from'] = from; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Get provider + * + * Get a provider by its unique ID. + * + * + * @param {string} providerId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getProvider(providerId: string): Promise<Models.Provider> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/{providerId}'.replace('{providerId}', providerId); + const payload: Payload = {}; + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Delete provider + * + * Delete a provider by its unique ID. + * + * @param {string} providerId + * @throws {AppwriteException} + * @returns {Promise} + */ + async deleteProvider(providerId: string): Promise<Response> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/{providerId}'.replace('{providerId}', providerId); + const payload: Payload = {}; + + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * List provider logs + * + * Get the provider activity logs listed by its unique ID. + * + * @param {string} providerId + * @param {string[]} queries + * @throws {AppwriteException} + * @returns {Promise} + */ + async listProviderLogs(providerId: string, queries?: string[]): Promise<Models.LogList> { + if (typeof providerId === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerId"'); + } + + const apiPath = '/messaging/providers/{providerId}/logs'.replace('{providerId}', providerId); + const payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * List subscriber logs + * + * Get the subscriber activity logs listed by its unique ID. + * + * @param {string} subscriberId + * @param {string[]} queries + * @throws {AppwriteException} + * @returns {Promise} + */ + async listSubscriberLogs(subscriberId: string, queries?: string[]): Promise<Models.LogList> { + if (typeof subscriberId === 'undefined') { + throw new AppwriteException('Missing required parameter: "subscriberId"'); + } + + const apiPath = '/messaging/subscribers/{subscriberId}/logs'.replace('{subscriberId}', subscriberId); + const payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * List topics + * + * Get a list of all topics from the current Appwrite project. + * + * @param {string[]} queries + * @param {string} search + * @throws {AppwriteException} + * @returns {Promise} + */ + async listTopics(queries?: string[], search?: string): Promise<Models.TopicList> { + const apiPath = '/messaging/topics'; + const payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + if (typeof search !== 'undefined') { + payload['search'] = search; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create topic + * + * Create a new topic. + * + * @param {string} topicId + * @param {string} name + * @param {string[]} subscribe + * @throws {AppwriteException} + * @returns {Promise} + */ + async createTopic(topicId: string, name: string, subscribe?: string[]): Promise<Models.Topic> { + if (typeof topicId === 'undefined') { + throw new AppwriteException('Missing required parameter: "topicId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/messaging/topics'; + const payload: Payload = {}; + + if (typeof topicId !== 'undefined') { + payload['topicId'] = topicId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof subscribe !== 'undefined') { + payload['subscribe'] = subscribe; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Get topic + * + * Get a topic by its unique ID. + * + * + * @param {string} topicId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getTopic(topicId: string): Promise<Models.Topic> { + if (typeof topicId === 'undefined') { + throw new AppwriteException('Missing required parameter: "topicId"'); + } + + const apiPath = '/messaging/topics/{topicId}'.replace('{topicId}', topicId); + const payload: Payload = {}; + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update topic + * + * Update a topic by its unique ID. + * + * + * @param {string} topicId + * @param {string} name + * @param {string[]} subscribe + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateTopic(topicId: string, name?: string, subscribe?: string[]): Promise<Models.Topic> { + if (typeof topicId === 'undefined') { + throw new AppwriteException('Missing required parameter: "topicId"'); + } + + const apiPath = '/messaging/topics/{topicId}'.replace('{topicId}', topicId); + const payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof subscribe !== 'undefined') { + payload['subscribe'] = subscribe; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Delete topic + * + * Delete a topic by its unique ID. + * + * @param {string} topicId + * @throws {AppwriteException} + * @returns {Promise} + */ + async deleteTopic(topicId: string): Promise<Response> { + if (typeof topicId === 'undefined') { + throw new AppwriteException('Missing required parameter: "topicId"'); + } + + const apiPath = '/messaging/topics/{topicId}'.replace('{topicId}', topicId); + const payload: Payload = {}; + + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * List topic logs + * + * Get the topic activity logs listed by its unique ID. + * + * @param {string} topicId + * @param {string[]} queries + * @throws {AppwriteException} + * @returns {Promise} + */ + async listTopicLogs(topicId: string, queries?: string[]): Promise<Models.LogList> { + if (typeof topicId === 'undefined') { + throw new AppwriteException('Missing required parameter: "topicId"'); + } + + const apiPath = '/messaging/topics/{topicId}/logs'.replace('{topicId}', topicId); + const payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * List subscribers + * + * Get a list of all subscribers from the current Appwrite project. + * + * @param {string} topicId + * @param {string[]} queries + * @param {string} search + * @throws {AppwriteException} + * @returns {Promise} + */ + async listSubscribers(topicId: string, queries?: string[], search?: string): Promise<Models.SubscriberList> { + if (typeof topicId === 'undefined') { + throw new AppwriteException('Missing required parameter: "topicId"'); + } + + const apiPath = '/messaging/topics/{topicId}/subscribers'.replace('{topicId}', topicId); + const payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + if (typeof search !== 'undefined') { + payload['search'] = search; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create subscriber + * + * Create a new subscriber. + * + * @param {string} topicId + * @param {string} subscriberId + * @param {string} targetId + * @throws {AppwriteException} + * @returns {Promise} + */ + async createSubscriber(topicId: string, subscriberId: string, targetId: string): Promise<Models.Subscriber> { + if (typeof topicId === 'undefined') { + throw new AppwriteException('Missing required parameter: "topicId"'); + } + + if (typeof subscriberId === 'undefined') { + throw new AppwriteException('Missing required parameter: "subscriberId"'); + } + + if (typeof targetId === 'undefined') { + throw new AppwriteException('Missing required parameter: "targetId"'); + } + + const apiPath = '/messaging/topics/{topicId}/subscribers'.replace('{topicId}', topicId); + const payload: Payload = {}; + + if (typeof subscriberId !== 'undefined') { + payload['subscriberId'] = subscriberId; + } + if (typeof targetId !== 'undefined') { + payload['targetId'] = targetId; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Get subscriber + * + * Get a subscriber by its unique ID. + * + * + * @param {string} topicId + * @param {string} subscriberId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getSubscriber(topicId: string, subscriberId: string): Promise<Models.Subscriber> { + if (typeof topicId === 'undefined') { + throw new AppwriteException('Missing required parameter: "topicId"'); + } + + if (typeof subscriberId === 'undefined') { + throw new AppwriteException('Missing required parameter: "subscriberId"'); + } + + const apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replace('{topicId}', topicId).replace('{subscriberId}', subscriberId); + const payload: Payload = {}; + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Delete subscriber + * + * Delete a subscriber by its unique ID. + * + * @param {string} topicId + * @param {string} subscriberId + * @throws {AppwriteException} + * @returns {Promise} + */ + async deleteSubscriber(topicId: string, subscriberId: string): Promise<Response> { + if (typeof topicId === 'undefined') { + throw new AppwriteException('Missing required parameter: "topicId"'); + } + + if (typeof subscriberId === 'undefined') { + throw new AppwriteException('Missing required parameter: "subscriberId"'); + } + + const apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replace('{topicId}', topicId).replace('{subscriberId}', subscriberId); + const payload: Payload = {}; + + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } +} \ No newline at end of file diff --git a/src/services/storage.ts b/src/services/storage.ts index a5a52f5..20c8aae 100644 --- a/src/services/storage.ts +++ b/src/services/storage.ts @@ -4,6 +4,10 @@ import { Payload, Client } from '../client.ts'; import { InputFile } from '../inputFile.ts'; import { AppwriteException } from '../exception.ts'; import type { Models } from '../models.d.ts'; +import { Query } from '../query.ts'; +import { Compression } from '../enums/compression.ts'; +import { ImageGravity } from '../enums/image-gravity.ts'; +import { ImageFormat } from '../enums/image-format.ts'; export type UploadProgress = { $id: string; @@ -43,9 +47,15 @@ export class Storage extends Service { payload['search'] = search; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create bucket @@ -59,13 +69,13 @@ export class Storage extends Service { * @param {boolean} enabled * @param {number} maximumFileSize * @param {string[]} allowedFileExtensions - * @param {string} compression + * @param {Compression} compression * @param {boolean} encryption * @param {boolean} antivirus * @throws {AppwriteException} * @returns {Promise} */ - async createBucket(bucketId: string, name: string, permissions?: string[], fileSecurity?: boolean, enabled?: boolean, maximumFileSize?: number, allowedFileExtensions?: string[], compression?: string, encryption?: boolean, antivirus?: boolean): Promise<Models.Bucket> { + async createBucket(bucketId: string, name: string, permissions?: string[], fileSecurity?: boolean, enabled?: boolean, maximumFileSize?: number, allowedFileExtensions?: string[], compression?: Compression, encryption?: boolean, antivirus?: boolean): Promise<Models.Bucket> { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -107,9 +117,15 @@ export class Storage extends Service { if (typeof antivirus !== 'undefined') { payload['antivirus'] = antivirus; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get bucket @@ -129,9 +145,15 @@ export class Storage extends Service { const apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update bucket @@ -145,13 +167,13 @@ export class Storage extends Service { * @param {boolean} enabled * @param {number} maximumFileSize * @param {string[]} allowedFileExtensions - * @param {string} compression + * @param {Compression} compression * @param {boolean} encryption * @param {boolean} antivirus * @throws {AppwriteException} * @returns {Promise} */ - async updateBucket(bucketId: string, name: string, permissions?: string[], fileSecurity?: boolean, enabled?: boolean, maximumFileSize?: number, allowedFileExtensions?: string[], compression?: string, encryption?: boolean, antivirus?: boolean): Promise<Models.Bucket> { + async updateBucket(bucketId: string, name: string, permissions?: string[], fileSecurity?: boolean, enabled?: boolean, maximumFileSize?: number, allowedFileExtensions?: string[], compression?: Compression, encryption?: boolean, antivirus?: boolean): Promise<Models.Bucket> { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -190,9 +212,15 @@ export class Storage extends Service { if (typeof antivirus !== 'undefined') { payload['antivirus'] = antivirus; } - return await this.client.call('put', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete bucket @@ -211,9 +239,15 @@ export class Storage extends Service { const apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List files @@ -243,9 +277,15 @@ export class Storage extends Service { payload['search'] = search; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create file @@ -315,7 +355,11 @@ export class Storage extends Service { if(fileId != 'unique()') { try { - response = await this.client.call('get', apiPath + '/' + fileId, apiHeaders); + response = await this.client.call( + 'get', + apiPath + '/' + fileId, + apiHeaders + ); chunksUploaded = response.chunksUploaded; } catch(e) { } @@ -331,7 +375,11 @@ export class Storage extends Service { } const start = ((currentChunk - 1) * Client.CHUNK_SIZE); - const end = start + currentPosition; + let end = start + currentPosition; + + if (end === size) { + end -= 1; + } if(!lastUpload || currentChunk !== 1) { apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size; @@ -417,9 +465,15 @@ export class Storage extends Service { const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update file @@ -452,9 +506,15 @@ export class Storage extends Service { if (typeof permissions !== 'undefined') { payload['permissions'] = permissions; } - return await this.client.call('put', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete File @@ -479,9 +539,15 @@ export class Storage extends Service { const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get file for download @@ -495,7 +561,7 @@ export class Storage extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async getFileDownload(bucketId: string, fileId: string): Promise<Response> { + async getFileDownload(bucketId: string, fileId: string): Promise<ArrayBuffer> { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -507,9 +573,15 @@ export class Storage extends Service { const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'arraybuffer' + ); } /** * Get file preview @@ -524,7 +596,7 @@ export class Storage extends Service { * @param {string} fileId * @param {number} width * @param {number} height - * @param {string} gravity + * @param {ImageGravity} gravity * @param {number} quality * @param {number} borderWidth * @param {string} borderColor @@ -532,11 +604,11 @@ export class Storage extends Service { * @param {number} opacity * @param {number} rotation * @param {string} background - * @param {string} output + * @param {ImageFormat} output * @throws {AppwriteException} * @returns {Promise} */ - async getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: string, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: string): Promise<Response> { + async getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: ImageGravity, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: ImageFormat): Promise<ArrayBuffer> { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -592,9 +664,15 @@ export class Storage extends Service { payload['output'] = output; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'arraybuffer' + ); } /** * Get file for view @@ -608,7 +686,7 @@ export class Storage extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async getFileView(bucketId: string, fileId: string): Promise<Response> { + async getFileView(bucketId: string, fileId: string): Promise<ArrayBuffer> { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -620,8 +698,14 @@ export class Storage extends Service { const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'arraybuffer' + ); } } \ No newline at end of file diff --git a/src/services/teams.ts b/src/services/teams.ts index 9c09b8e..cdbdc6d 100644 --- a/src/services/teams.ts +++ b/src/services/teams.ts @@ -4,6 +4,7 @@ import { Payload, Client } from '../client.ts'; import { InputFile } from '../inputFile.ts'; import { AppwriteException } from '../exception.ts'; import type { Models } from '../models.d.ts'; +import { Query } from '../query.ts'; export type UploadProgress = { $id: string; @@ -43,9 +44,15 @@ export class Teams extends Service { payload['search'] = search; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create team @@ -81,9 +88,15 @@ export class Teams extends Service { if (typeof roles !== 'undefined') { payload['roles'] = roles; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get team @@ -102,9 +115,15 @@ export class Teams extends Service { const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update name @@ -131,9 +150,15 @@ export class Teams extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - return await this.client.call('put', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete team @@ -153,9 +178,15 @@ export class Teams extends Service { const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List team memberships @@ -185,9 +216,15 @@ export class Teams extends Service { payload['search'] = search; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create team membership @@ -254,9 +291,15 @@ export class Teams extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get team membership @@ -281,9 +324,15 @@ export class Teams extends Service { const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update membership @@ -318,9 +367,15 @@ export class Teams extends Service { if (typeof roles !== 'undefined') { payload['roles'] = roles; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete team membership @@ -346,9 +401,15 @@ export class Teams extends Service { const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update team membership status @@ -394,9 +455,15 @@ export class Teams extends Service { if (typeof secret !== 'undefined') { payload['secret'] = secret; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get team preferences @@ -417,9 +484,15 @@ export class Teams extends Service { const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update preferences @@ -448,8 +521,14 @@ export class Teams extends Service { if (typeof prefs !== 'undefined') { payload['prefs'] = prefs; } - return await this.client.call('put', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } } \ No newline at end of file diff --git a/src/services/users.ts b/src/services/users.ts index ab6708c..f60cff7 100644 --- a/src/services/users.ts +++ b/src/services/users.ts @@ -4,6 +4,10 @@ import { Payload, Client } from '../client.ts'; import { InputFile } from '../inputFile.ts'; import { AppwriteException } from '../exception.ts'; import type { Models } from '../models.d.ts'; +import { Query } from '../query.ts'; +import { PasswordHash } from '../enums/password-hash.ts'; +import { AuthenticatorType } from '../enums/authenticator-type.ts'; +import { MessagingProviderType } from '../enums/messaging-provider-type.ts'; export type UploadProgress = { $id: string; @@ -43,9 +47,15 @@ export class Users extends Service { payload['search'] = search; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create user @@ -83,9 +93,15 @@ export class Users extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create user with Argon2 password @@ -130,9 +146,15 @@ export class Users extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create user with bcrypt password @@ -177,21 +199,27 @@ export class Users extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List Identities * * Get identities for all users. * - * @param {string} queries + * @param {string[]} queries * @param {string} search * @throws {AppwriteException} * @returns {Promise} */ - async listIdentities(queries?: string, search?: string): Promise<Models.IdentityList> { + async listIdentities(queries?: string[], search?: string): Promise<Models.IdentityList> { const apiPath = '/users/identities'; const payload: Payload = {}; @@ -203,12 +231,18 @@ export class Users extends Service { payload['search'] = search; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** - * Delete Identity + * Delete identity * * Delete an identity by its unique ID. * @@ -224,9 +258,15 @@ export class Users extends Service { const apiPath = '/users/identities/{identityId}'.replace('{identityId}', identityId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create user with MD5 password @@ -271,9 +311,15 @@ export class Users extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create user with PHPass password @@ -318,9 +364,15 @@ export class Users extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create user with Scrypt password @@ -405,9 +457,15 @@ export class Users extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create user with Scrypt modified password @@ -477,9 +535,15 @@ export class Users extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Create user with SHA password @@ -492,12 +556,12 @@ export class Users extends Service { * @param {string} userId * @param {string} email * @param {string} password - * @param {string} passwordVersion + * @param {PasswordHash} passwordVersion * @param {string} name * @throws {AppwriteException} * @returns {Promise} */ - async createSHAUser<Preferences extends Models.Preferences>(userId: string, email: string, password: string, passwordVersion?: string, name?: string): Promise<Models.User<Preferences>> { + async createSHAUser<Preferences extends Models.Preferences>(userId: string, email: string, password: string, passwordVersion?: PasswordHash, name?: string): Promise<Models.User<Preferences>> { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -528,9 +592,15 @@ export class Users extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - return await this.client.call('post', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get user @@ -549,9 +619,15 @@ export class Users extends Service { const apiPath = '/users/{userId}'.replace('{userId}', userId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete user @@ -575,9 +651,15 @@ export class Users extends Service { const apiPath = '/users/{userId}'.replace('{userId}', userId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update email @@ -604,9 +686,15 @@ export class Users extends Service { if (typeof email !== 'undefined') { payload['email'] = email; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update user labels @@ -638,9 +726,15 @@ export class Users extends Service { if (typeof labels !== 'undefined') { payload['labels'] = labels; } - return await this.client.call('put', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List user logs @@ -664,9 +758,15 @@ export class Users extends Service { payload['queries'] = queries; } - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List user memberships @@ -685,9 +785,199 @@ export class Users extends Service { const apiPath = '/users/{userId}/memberships'.replace('{userId}', userId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update MFA + * + * Enable or disable MFA on a user account. + * + * @param {string} userId + * @param {boolean} mfa + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateMfa<Preferences extends Models.Preferences>(userId: string, mfa: boolean): Promise<Models.User<Preferences>> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof mfa === 'undefined') { + throw new AppwriteException('Missing required parameter: "mfa"'); + } + + const apiPath = '/users/{userId}/mfa'.replace('{userId}', userId); + const payload: Payload = {}; + + if (typeof mfa !== 'undefined') { + payload['mfa'] = mfa; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Delete Authenticator + * + * Delete an authenticator app. + * + * @param {string} userId + * @param {AuthenticatorType} type + * @throws {AppwriteException} + * @returns {Promise} + */ + async deleteMfaAuthenticator<Preferences extends Models.Preferences>(userId: string, type: AuthenticatorType): Promise<Models.User<Preferences>> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof type === 'undefined') { + throw new AppwriteException('Missing required parameter: "type"'); + } + + const apiPath = '/users/{userId}/mfa/authenticators/{type}'.replace('{userId}', userId).replace('{type}', type); + const payload: Payload = {}; + + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * List Factors + * + * List the factors available on the account to be used as a MFA challange. + * + * @param {string} userId + * @throws {AppwriteException} + * @returns {Promise} + */ + async listMfaFactors(userId: string): Promise<Models.MfaFactors> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + const apiPath = '/users/{userId}/mfa/factors'.replace('{userId}', userId); + const payload: Payload = {}; + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Get MFA Recovery Codes + * + * Get recovery codes that can be used as backup for MFA flow by User ID. + * Before getting codes, they must be generated using + * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + * method. + * + * @param {string} userId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getMfaRecoveryCodes(userId: string): Promise<Models.MfaRecoveryCodes> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + const apiPath = '/users/{userId}/mfa/recovery-codes'.replace('{userId}', userId); + const payload: Payload = {}; + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Regenerate MFA Recovery Codes + * + * Regenerate recovery codes that can be used as backup for MFA flow by User + * ID. Before regenerating codes, they must be first generated using + * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + * method. + * + * @param {string} userId + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateMfaRecoveryCodes(userId: string): Promise<Models.MfaRecoveryCodes> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + const apiPath = '/users/{userId}/mfa/recovery-codes'.replace('{userId}', userId); + const payload: Payload = {}; + + return await this.client.call( + 'put', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create MFA Recovery Codes + * + * Generate recovery codes used as backup for MFA flow for User ID. Recovery + * codes can be used as a MFA verification type in + * [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + * method by client SDK. + * + * @param {string} userId + * @throws {AppwriteException} + * @returns {Promise} + */ + async createMfaRecoveryCodes(userId: string): Promise<Models.MfaRecoveryCodes> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + const apiPath = '/users/{userId}/mfa/recovery-codes'.replace('{userId}', userId); + const payload: Payload = {}; + + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update name @@ -714,9 +1004,15 @@ export class Users extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update password @@ -743,9 +1039,15 @@ export class Users extends Service { if (typeof password !== 'undefined') { payload['password'] = password; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update phone @@ -772,9 +1074,15 @@ export class Users extends Service { if (typeof number !== 'undefined') { payload['number'] = number; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Get user preferences @@ -793,9 +1101,15 @@ export class Users extends Service { const apiPath = '/users/{userId}/prefs'.replace('{userId}', userId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update user preferences @@ -824,9 +1138,15 @@ export class Users extends Service { if (typeof prefs !== 'undefined') { payload['prefs'] = prefs; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * List user sessions @@ -845,9 +1165,47 @@ export class Users extends Service { const apiPath = '/users/{userId}/sessions'.replace('{userId}', userId); const payload: Payload = {}; - return await this.client.call('get', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create session + * + * Creates a session for a user. Returns an immediately usable session object. + * + * If you want to generate a token for a custom authentication flow, use the + * [POST + * /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) + * endpoint. + * + * @param {string} userId + * @throws {AppwriteException} + * @returns {Promise} + */ + async createSession(userId: string): Promise<Models.Session> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + const apiPath = '/users/{userId}/sessions'.replace('{userId}', userId); + const payload: Payload = {}; + + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete user sessions @@ -866,9 +1224,15 @@ export class Users extends Service { const apiPath = '/users/{userId}/sessions'.replace('{userId}', userId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Delete user session @@ -892,9 +1256,15 @@ export class Users extends Service { const apiPath = '/users/{userId}/sessions/{sessionId}'.replace('{userId}', userId).replace('{sessionId}', sessionId); const payload: Payload = {}; - return await this.client.call('delete', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update user status @@ -922,9 +1292,253 @@ export class Users extends Service { if (typeof status !== 'undefined') { payload['status'] = status; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * List User Targets + * + * List the messaging targets that are associated with a user. + * + * @param {string} userId + * @param {string[]} queries + * @throws {AppwriteException} + * @returns {Promise} + */ + async listTargets(userId: string, queries?: string[]): Promise<Models.TargetList> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + const apiPath = '/users/{userId}/targets'.replace('{userId}', userId); + const payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create User Target + * + * Create a messaging target. + * + * @param {string} userId + * @param {string} targetId + * @param {MessagingProviderType} providerType + * @param {string} identifier + * @param {string} providerId + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async createTarget(userId: string, targetId: string, providerType: MessagingProviderType, identifier: string, providerId?: string, name?: string): Promise<Models.Target> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof targetId === 'undefined') { + throw new AppwriteException('Missing required parameter: "targetId"'); + } + + if (typeof providerType === 'undefined') { + throw new AppwriteException('Missing required parameter: "providerType"'); + } + + if (typeof identifier === 'undefined') { + throw new AppwriteException('Missing required parameter: "identifier"'); + } + + const apiPath = '/users/{userId}/targets'.replace('{userId}', userId); + const payload: Payload = {}; + + if (typeof targetId !== 'undefined') { + payload['targetId'] = targetId; + } + if (typeof providerType !== 'undefined') { + payload['providerType'] = providerType; + } + if (typeof identifier !== 'undefined') { + payload['identifier'] = identifier; + } + if (typeof providerId !== 'undefined') { + payload['providerId'] = providerId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Get User Target + * + * Get a user's push notification target by ID. + * + * @param {string} userId + * @param {string} targetId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getTarget(userId: string, targetId: string): Promise<Models.Target> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof targetId === 'undefined') { + throw new AppwriteException('Missing required parameter: "targetId"'); + } + + const apiPath = '/users/{userId}/targets/{targetId}'.replace('{userId}', userId).replace('{targetId}', targetId); + const payload: Payload = {}; + + return await this.client.call( + 'get', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Update User target + * + * Update a messaging target. + * + * @param {string} userId + * @param {string} targetId + * @param {string} identifier + * @param {string} providerId + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateTarget(userId: string, targetId: string, identifier?: string, providerId?: string, name?: string): Promise<Models.Target> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof targetId === 'undefined') { + throw new AppwriteException('Missing required parameter: "targetId"'); + } + + const apiPath = '/users/{userId}/targets/{targetId}'.replace('{userId}', userId).replace('{targetId}', targetId); + const payload: Payload = {}; + + if (typeof identifier !== 'undefined') { + payload['identifier'] = identifier; + } + if (typeof providerId !== 'undefined') { + payload['providerId'] = providerId; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Delete user target + * + * Delete a messaging target. + * + * @param {string} userId + * @param {string} targetId + * @throws {AppwriteException} + * @returns {Promise} + */ + async deleteTarget(userId: string, targetId: string): Promise<Response> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof targetId === 'undefined') { + throw new AppwriteException('Missing required parameter: "targetId"'); + } + + const apiPath = '/users/{userId}/targets/{targetId}'.replace('{userId}', userId).replace('{targetId}', targetId); + const payload: Payload = {}; + + return await this.client.call( + 'delete', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); + } + /** + * Create token + * + * Returns a token 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 [PUT + * /account/sessions/custom](https://appwrite.io/docs/references/cloud/client-web/account#updateCustomSession) + * endpoint to complete the login process. + * + * @param {string} userId + * @param {number} length + * @param {number} expire + * @throws {AppwriteException} + * @returns {Promise} + */ + async createToken(userId: string, length?: number, expire?: number): Promise<Models.Token> { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + const apiPath = '/users/{userId}/tokens'.replace('{userId}', userId); + const payload: Payload = {}; + + if (typeof length !== 'undefined') { + payload['length'] = length; + } + if (typeof expire !== 'undefined') { + payload['expire'] = expire; + } + return await this.client.call( + 'post', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update email verification @@ -951,9 +1565,15 @@ export class Users extends Service { if (typeof emailVerification !== 'undefined') { payload['emailVerification'] = emailVerification; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } /** * Update phone verification @@ -980,8 +1600,14 @@ export class Users extends Service { if (typeof phoneVerification !== 'undefined') { payload['phoneVerification'] = phoneVerification; } - return await this.client.call('patch', apiPath, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'patch', + apiPath, + { + 'content-type': 'application/json', + }, + payload, + 'json' + ); } } \ No newline at end of file diff --git a/test/id.test.ts b/test/id.test.ts new file mode 100644 index 0000000..6e7dcbe --- /dev/null +++ b/test/id.test.ts @@ -0,0 +1,8 @@ +import {assertEquals} from "https://deno.land/std@0.204.0/assert/mod.ts"; +import {describe, it as test} from "https://deno.land/std@0.149.0/testing/bdd.ts"; +import {ID} from "../src/id.ts"; + +describe("ID", () => { + test('unique', () => assertEquals(ID.unique(), 'unique()')); + test('custom', () => assertEquals(ID.custom('custom'), 'custom')); +}); diff --git a/test/permission.test.ts b/test/permission.test.ts new file mode 100644 index 0000000..a9366fd --- /dev/null +++ b/test/permission.test.ts @@ -0,0 +1,12 @@ +import { assertEquals } from "https://deno.land/std@0.204.0/assert/mod.ts"; +import { describe, it as test } from "https://deno.land/std@0.149.0/testing/bdd.ts"; +import {Permission} from "../src/permission.ts"; +import {Role} from "../src/role.ts"; + +describe('Permission', () => { + test('read', () => assertEquals(Permission.read(Role.any()), 'read("any")')); + test('write', () => assertEquals(Permission.write(Role.any()), 'write("any")')); + test('create', () => assertEquals(Permission.create(Role.any()), 'create("any")')); + test('update', () => assertEquals(Permission.update(Role.any()), 'update("any")')); + test('delete', () => assertEquals(Permission.delete(Role.any()), 'delete("any")')); +}) diff --git a/test/query.test.ts b/test/query.test.ts new file mode 100644 index 0000000..d1fac7f --- /dev/null +++ b/test/query.test.ts @@ -0,0 +1,175 @@ +import {describe, it as test} from "https://deno.land/std@0.149.0/testing/bdd.ts"; +import {assertEquals} from "https://deno.land/std@0.204.0/assert/assert_equals.ts"; +import {Query, QueryTypes} from "../src/query.ts"; + +type BasicFilterQueryTest = { + description: string; + value: QueryTypes; + expectedValues: string; +} + +const tests: BasicFilterQueryTest[] = [ + { + description: 'with a string', + value: 's', + expectedValues: '["s"]' + }, + { + description: 'with a integer', + value: 1, + expectedValues: '[1]' + }, + { + description: 'with a double', + value: 1.2, + expectedValues: '[1.2]' + }, + { + description: 'with a whole number double', + value: 1.0, + expectedValues: '[1]' + }, + { + description: 'with a bool', + value: false, + expectedValues: '[false]' + }, + { + description: 'with a list', + value: ['a', 'b', 'c'], + expectedValues: '["a","b","c"]' + } +]; + +describe('Query', () => { + describe('basic filter equal', () => { + for (const t of tests) { + test(t.description, () => + assertEquals( + Query.equal("attr", t.value).toString(), + `{"method":"equal","attribute":"attr","values":${t.expectedValues}}`, + ) + ) + } + }) + + describe('basic filter notEqual', () => { + for (const t of tests) { + test(t.description, () => + assertEquals( + Query.notEqual("attr", t.value).toString(), + `{"method":"notEqual","attribute":"attr","values":${t.expectedValues}}`, + ) + ) + } + }); + + describe('basic filter lessThan', () => { + for (const t of tests) { + test(t.description, () => + assertEquals( + Query.lessThan("attr", t.value).toString(), + `{"method":"lessThan","attribute":"attr","values":${t.expectedValues}}`, + ) + ) + } + }); + + describe('basic filter lessThanEqual', () => { + for (const t of tests) { + test(t.description, () => + assertEquals( + Query.lessThanEqual("attr", t.value).toString(), + `{"method":"lessThanEqual","attribute":"attr","values":${t.expectedValues}}`, + ) + ) + } + }); + + describe('basic filter greaterThan', () => { + for (const t of tests) { + test(t.description, () => + assertEquals( + Query.greaterThan("attr", t.value).toString(), + `{"method":"greaterThan","attribute":"attr","values":${t.expectedValues}}`, + ) + ) + } + }); + + describe('basic filter greaterThanEqual', () => { + for (const t of tests) { + test(t.description, () => + assertEquals( + Query.greaterThanEqual("attr", t.value).toString(), + `{"method":"greaterThanEqual","attribute":"attr","values":${t.expectedValues}}`, + ) + ) + } + }); + + test('search', () => assertEquals( + Query.search('attr', 'keyword1 keyword2').toString(), + '{"method":"search","attribute":"attr","values":["keyword1 keyword2"]}', + )); + + test('isNull', () => assertEquals( + Query.isNull('attr').toString(), + `{"method":"isNull","attribute":"attr","values":[]}`, + )); + + test('isNotNull', () => assertEquals( + Query.isNotNull('attr').toString(), + `{"method":"isNotNull","attribute":"attr","values":[]}`, + )); + + describe('between', () => { + test('with integers', () => assertEquals( + Query.between('attr', 1, 2).toString(), + `{"method":"between","attribute":"attr","values":[1,2]}`, + )); + test('with doubles', () => assertEquals( + Query.between('attr', 1.2, 2.2).toString(), + `{"method":"between","attribute":"attr","values":[1.2,2.2]}`, + )); + test('with strings', () => assertEquals( + Query.between('attr', "a", "z").toString(), + `{"method":"between","attribute":"attr","values":["a","z"]}`, + )); + }); + + test('select', () => assertEquals( + Query.select(['attr1', 'attr2']).toString(), + `{"method":"select","attribute":["attr1","attr2"]}`, + )); + + test('orderAsc', () => assertEquals( + Query.orderAsc('attr').toString(), + `{"method":"orderAsc","attribute":"attr"}`, + )); + + test('orderDesc', () => assertEquals( + Query.orderDesc('attr').toString(), + `{"method":"orderDesc","attribute":"attr"}`, + )); + + test('cursorBefore', () => assertEquals( + Query.cursorBefore('attr').toString(), + `{"method":"cursorBefore","attribute":"attr"}`, + )); + + test('cursorAfter', () => assertEquals( + Query.cursorAfter('attr').toString(), + `{"method":"cursorAfter","attribute":"attr"}`, + )); + + test('limit', () => assertEquals( + Query.limit(1).toString(), + `{"method":"limit","values":[1]}`, + )); + + test('offset', () => assertEquals( + Query.offset(1).toString(), + `{"method":"offset","values":[1]}`, + )); +}) diff --git a/test/role.test.ts b/test/role.test.ts new file mode 100644 index 0000000..e3f155d --- /dev/null +++ b/test/role.test.ts @@ -0,0 +1,16 @@ +import { assertEquals } from "https://deno.land/std@0.204.0/assert/mod.ts"; +import { describe, it as test } from "https://deno.land/std@0.149.0/testing/bdd.ts"; +import {Role} from "../src/role.ts"; + +describe('Role', () => { + test('any', () => assertEquals(Role.any(), 'any')); + test('user without status', () => assertEquals(Role.user('custom'), 'user:custom')); + test('user with status', () => assertEquals(Role.user('custom', 'verified'), 'user:custom/verified')); + test('users without status', () => assertEquals(Role.users(), 'users')); + test('users with status', () => assertEquals(Role.users('verified'), 'users/verified')); + test('guests', () => assertEquals(Role.guests(), 'guests')); + test('team without role', () => assertEquals(Role.team('custom'), 'team:custom')) + test('team with role', () => assertEquals(Role.team('custom', 'owner'), 'team:custom/owner')) + test('member', () => assertEquals(Role.member('custom'), 'member:custom')) + test('label', () => assertEquals(Role.label('admin'), 'label:admin')) +}) diff --git a/test/services/account.test.ts b/test/services/account.test.ts new file mode 100644 index 0000000..11ebba3 --- /dev/null +++ b/test/services/account.test.ts @@ -0,0 +1,1071 @@ +import {afterEach, describe, it as test} from "https://deno.land/std@0.204.0/testing/bdd.ts"; +import {restore, stub} from "https://deno.land/std@0.204.0/testing/mock.ts"; +import {assertEquals} from "https://deno.land/std@0.204.0/assert/assert_equals.ts"; +import { Account } from "../../src/services/account.ts"; +import {Client} from "../../src/client.ts"; +import {InputFile} from "../../src/inputFile.ts" + +describe('Account service', () => { + const client = new Client(); + const account = new Account(client); + + afterEach(() => restore()) + + + test('test method get()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.get( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method create()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.create( + '<USER_ID>', + 'email@example.com', + '', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateEmail()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updateEmail( + 'email@example.com', + 'password', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listIdentities()', async () => { + const data = { + 'total': 5, + 'identities': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.listIdentities( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteIdentity()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await account.deleteIdentity( + '<IDENTITY_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method createJWT()', async () => { + const data = { + 'jwt': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createJWT( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listLogs()', async () => { + const data = { + 'total': 5, + 'logs': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.listLogs( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateMFA()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updateMFA( + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createMfaAuthenticator()', async () => { + const data = { + 'secret': '1', + 'uri': '1',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createMfaAuthenticator( + 'totp', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateMfaAuthenticator()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updateMfaAuthenticator( + 'totp', + '<OTP>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteMfaAuthenticator()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.deleteMfaAuthenticator( + 'totp', + '<OTP>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createMfaChallenge()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createMfaChallenge( + 'email', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateMfaChallenge()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await account.updateMfaChallenge( + '<CHALLENGE_ID>', + '<OTP>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method listMfaFactors()', async () => { + const data = { + 'totp': true, + 'phone': true, + 'email': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.listMfaFactors( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getMfaRecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.getMfaRecoveryCodes( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createMfaRecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createMfaRecoveryCodes( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateMfaRecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updateMfaRecoveryCodes( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateName()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updateName( + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updatePassword()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updatePassword( + '', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updatePhone()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updatePhone( + '+12065550100', + 'password', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getPrefs()', async () => { + const data = {}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.getPrefs( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updatePrefs()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updatePrefs( + {}, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createRecovery()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createRecovery( + 'email@example.com', + 'https://example.com', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateRecovery()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updateRecovery( + '<USER_ID>', + '<SECRET>', + '', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listSessions()', async () => { + const data = { + 'total': 5, + 'sessions': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.listSessions( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteSessions()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await account.deleteSessions( + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method createAnonymousSession()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createAnonymousSession( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createEmailPasswordSession()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createEmailPasswordSession( + 'email@example.com', + 'password', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateMagicURLSession()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updateMagicURLSession( + '<USER_ID>', + '<SECRET>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updatePhoneSession()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updatePhoneSession( + '<USER_ID>', + '<SECRET>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createSession()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createSession( + '<USER_ID>', + '<SECRET>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getSession()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.getSession( + '<SESSION_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateSession()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updateSession( + '<SESSION_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteSession()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await account.deleteSession( + '<SESSION_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method updateStatus()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updateStatus( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createEmailToken()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createEmailToken( + '<USER_ID>', + 'email@example.com', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createMagicURLToken()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createMagicURLToken( + '<USER_ID>', + 'email@example.com', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createOAuth2Token()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await account.createOAuth2Token( + 'amazon', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method createPhoneToken()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createPhoneToken( + '<USER_ID>', + '+12065550100', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createVerification()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createVerification( + 'https://example.com', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateVerification()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updateVerification( + '<USER_ID>', + '<SECRET>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createPhoneVerification()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.createPhoneVerification( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updatePhoneVerification()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await account.updatePhoneVerification( + '<USER_ID>', + '<SECRET>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + }) diff --git a/test/services/avatars.test.ts b/test/services/avatars.test.ts new file mode 100644 index 0000000..a2afcdd --- /dev/null +++ b/test/services/avatars.test.ts @@ -0,0 +1,118 @@ +import {afterEach, describe, it as test} from "https://deno.land/std@0.204.0/testing/bdd.ts"; +import {restore, stub} from "https://deno.land/std@0.204.0/testing/mock.ts"; +import {assertEquals} from "https://deno.land/std@0.204.0/assert/assert_equals.ts"; +import { Avatars } from "../../src/services/avatars.ts"; +import {Client} from "../../src/client.ts"; +import {InputFile} from "../../src/inputFile.ts" + +describe('Avatars service', () => { + const client = new Client(); + const avatars = new Avatars(client); + + afterEach(() => restore()) + + + test('test method getBrowser()', async () => { + const data = new Uint8Array(0); + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data.buffer))); + + const response = await avatars.getBrowser( + 'aa', + ); + + const buffer = await response.arrayBuffer(); + assertEquals(buffer.byteLength, 0); + stubbedFetch.restore(); + }); + + + test('test method getCreditCard()', async () => { + const data = new Uint8Array(0); + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data.buffer))); + + const response = await avatars.getCreditCard( + 'amex', + ); + + const buffer = await response.arrayBuffer(); + assertEquals(buffer.byteLength, 0); + stubbedFetch.restore(); + }); + + + test('test method getFavicon()', async () => { + const data = new Uint8Array(0); + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data.buffer))); + + const response = await avatars.getFavicon( + 'https://example.com', + ); + + const buffer = await response.arrayBuffer(); + assertEquals(buffer.byteLength, 0); + stubbedFetch.restore(); + }); + + + test('test method getFlag()', async () => { + const data = new Uint8Array(0); + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data.buffer))); + + const response = await avatars.getFlag( + 'af', + ); + + const buffer = await response.arrayBuffer(); + assertEquals(buffer.byteLength, 0); + stubbedFetch.restore(); + }); + + + test('test method getImage()', async () => { + const data = new Uint8Array(0); + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data.buffer))); + + const response = await avatars.getImage( + 'https://example.com', + ); + + const buffer = await response.arrayBuffer(); + assertEquals(buffer.byteLength, 0); + stubbedFetch.restore(); + }); + + + test('test method getInitials()', async () => { + const data = new Uint8Array(0); + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data.buffer))); + + const response = await avatars.getInitials( + ); + + const buffer = await response.arrayBuffer(); + assertEquals(buffer.byteLength, 0); + stubbedFetch.restore(); + }); + + + test('test method getQR()', async () => { + const data = new Uint8Array(0); + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data.buffer))); + + const response = await avatars.getQR( + '<TEXT>', + ); + + const buffer = await response.arrayBuffer(); + assertEquals(buffer.byteLength, 0); + stubbedFetch.restore(); + }); + + }) diff --git a/test/services/databases.test.ts b/test/services/databases.test.ts new file mode 100644 index 0000000..f856843 --- /dev/null +++ b/test/services/databases.test.ts @@ -0,0 +1,923 @@ +import {afterEach, describe, it as test} from "https://deno.land/std@0.204.0/testing/bdd.ts"; +import {restore, stub} from "https://deno.land/std@0.204.0/testing/mock.ts"; +import {assertEquals} from "https://deno.land/std@0.204.0/assert/assert_equals.ts"; +import { Databases } from "../../src/services/databases.ts"; +import {Client} from "../../src/client.ts"; +import {InputFile} from "../../src/inputFile.ts" + +describe('Databases service', () => { + const client = new Client(); + const databases = new Databases(client); + + afterEach(() => restore()) + + + test('test method list()', async () => { + const data = { + 'total': 5, + 'databases': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.list( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method create()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'name': 'My Database', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'enabled': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.create( + '<DATABASE_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method get()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'name': 'My Database', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'enabled': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.get( + '<DATABASE_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method update()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'name': 'My Database', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'enabled': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.update( + '<DATABASE_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method delete()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await databases.delete( + '<DATABASE_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method listCollections()', async () => { + const data = { + 'total': 5, + 'collections': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.listCollections( + '<DATABASE_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createCollection()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'databaseId': '5e5ea5c16897e', + 'name': 'My Collection', + 'enabled': true, + 'documentSecurity': true, + 'attributes': [], + 'indexes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createCollection( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getCollection()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'databaseId': '5e5ea5c16897e', + 'name': 'My Collection', + 'enabled': true, + 'documentSecurity': true, + 'attributes': [], + 'indexes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.getCollection( + '<DATABASE_ID>', + '<COLLECTION_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateCollection()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'databaseId': '5e5ea5c16897e', + 'name': 'My Collection', + 'enabled': true, + 'documentSecurity': true, + 'attributes': [], + 'indexes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.updateCollection( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteCollection()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await databases.deleteCollection( + '<DATABASE_ID>', + '<COLLECTION_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method listAttributes()', async () => { + const data = { + 'total': 5, + 'attributes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.listAttributes( + '<DATABASE_ID>', + '<COLLECTION_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createBooleanAttribute()', async () => { + const data = { + 'key': 'isEnabled', + 'type': 'boolean', + 'status': 'available', + 'error': 'string', + 'required': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createBooleanAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateBooleanAttribute()', async () => { + const data = { + 'key': 'isEnabled', + 'type': 'boolean', + 'status': 'available', + 'error': 'string', + 'required': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.updateBooleanAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createDatetimeAttribute()', async () => { + const data = { + 'key': 'birthDay', + 'type': 'datetime', + 'status': 'available', + 'error': 'string', + 'required': true, + 'format': 'datetime',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createDatetimeAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateDatetimeAttribute()', async () => { + const data = { + 'key': 'birthDay', + 'type': 'datetime', + 'status': 'available', + 'error': 'string', + 'required': true, + 'format': 'datetime',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.updateDatetimeAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + '', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createEmailAttribute()', async () => { + const data = { + 'key': 'userEmail', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + 'format': 'email',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createEmailAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateEmailAttribute()', async () => { + const data = { + 'key': 'userEmail', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + 'format': 'email',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.updateEmailAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + 'email@example.com', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createEnumAttribute()', async () => { + const data = { + 'key': 'status', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + 'elements': [], + 'format': 'enum',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createEnumAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + [], + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateEnumAttribute()', async () => { + const data = { + 'key': 'status', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + 'elements': [], + 'format': 'enum',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.updateEnumAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + [], + true, + '<DEFAULT>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createFloatAttribute()', async () => { + const data = { + 'key': 'percentageCompleted', + 'type': 'double', + 'status': 'available', + 'error': 'string', + 'required': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createFloatAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateFloatAttribute()', async () => { + const data = { + 'key': 'percentageCompleted', + 'type': 'double', + 'status': 'available', + 'error': 'string', + 'required': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.updateFloatAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + 1.0, + 1.0, + 1.0, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createIntegerAttribute()', async () => { + const data = { + 'key': 'count', + 'type': 'integer', + 'status': 'available', + 'error': 'string', + 'required': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createIntegerAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateIntegerAttribute()', async () => { + const data = { + 'key': 'count', + 'type': 'integer', + 'status': 'available', + 'error': 'string', + 'required': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.updateIntegerAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + 1, + 1, + 1, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createIpAttribute()', async () => { + const data = { + 'key': 'ipAddress', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + 'format': 'ip',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createIpAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateIpAttribute()', async () => { + const data = { + 'key': 'ipAddress', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + 'format': 'ip',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.updateIpAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + '', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createRelationshipAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + 'relatedCollection': 'collection', + 'relationType': 'oneToOne|oneToMany|manyToOne|manyToMany', + 'twoWay': true, + 'twoWayKey': 'string', + 'onDelete': 'restrict|cascade|setNull', + 'side': 'parent|child',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createRelationshipAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '<RELATED_COLLECTION_ID>', + 'oneToOne', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createStringAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + 'size': 128,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createStringAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + 1, + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateStringAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + 'size': 128,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.updateStringAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + '<DEFAULT>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createUrlAttribute()', async () => { + const data = { + 'key': 'githubUrl', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + 'format': 'url',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createUrlAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateUrlAttribute()', async () => { + const data = { + 'key': 'githubUrl', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + 'format': 'url',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.updateUrlAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + true, + 'https://example.com', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getAttribute()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await databases.getAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method deleteAttribute()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await databases.deleteAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method updateRelationshipAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + 'relatedCollection': 'collection', + 'relationType': 'oneToOne|oneToMany|manyToOne|manyToMany', + 'twoWay': true, + 'twoWayKey': 'string', + 'onDelete': 'restrict|cascade|setNull', + 'side': 'parent|child',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.updateRelationshipAttribute( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listDocuments()', async () => { + const data = { + 'total': 5, + 'documents': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.listDocuments( + '<DATABASE_ID>', + '<COLLECTION_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createDocument()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$collectionId': '5e5ea5c15117e', + '\$databaseId': '5e5ea5c15117e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createDocument( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '<DOCUMENT_ID>', + {}, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getDocument()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$collectionId': '5e5ea5c15117e', + '\$databaseId': '5e5ea5c15117e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.getDocument( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '<DOCUMENT_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateDocument()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$collectionId': '5e5ea5c15117e', + '\$databaseId': '5e5ea5c15117e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.updateDocument( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '<DOCUMENT_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteDocument()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await databases.deleteDocument( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '<DOCUMENT_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method listIndexes()', async () => { + const data = { + 'total': 5, + 'indexes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.listIndexes( + '<DATABASE_ID>', + '<COLLECTION_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createIndex()', async () => { + const data = { + 'key': 'index1', + 'type': 'primary', + 'status': 'available', + 'error': 'string', + 'attributes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.createIndex( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + 'key', + [], + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getIndex()', async () => { + const data = { + 'key': 'index1', + 'type': 'primary', + 'status': 'available', + 'error': 'string', + 'attributes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await databases.getIndex( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteIndex()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await databases.deleteIndex( + '<DATABASE_ID>', + '<COLLECTION_ID>', + '', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + }) diff --git a/test/services/functions.test.ts b/test/services/functions.test.ts new file mode 100644 index 0000000..b3eef45 --- /dev/null +++ b/test/services/functions.test.ts @@ -0,0 +1,526 @@ +import {afterEach, describe, it as test} from "https://deno.land/std@0.204.0/testing/bdd.ts"; +import {restore, stub} from "https://deno.land/std@0.204.0/testing/mock.ts"; +import {assertEquals} from "https://deno.land/std@0.204.0/assert/assert_equals.ts"; +import { Functions } from "../../src/services/functions.ts"; +import {Client} from "../../src/client.ts"; +import {InputFile} from "../../src/inputFile.ts" + +describe('Functions service', () => { + const client = new Client(); + const functions = new Functions(client); + + afterEach(() => restore()) + + + test('test method list()', async () => { + const data = { + 'total': 5, + 'functions': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.list( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method create()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'execute': [], + 'name': 'My Function', + 'enabled': true, + 'live': true, + 'logging': true, + 'runtime': 'python-3.8', + 'deployment': '5e5ea5c16897e', + 'vars': [], + 'events': [], + 'schedule': '5 4 * * *', + 'timeout': 300, + 'entrypoint': 'index.js', + 'commands': 'npm install', + 'version': 'v2', + 'installationId': '6m40at4ejk5h2u9s1hboo', + 'providerRepositoryId': 'appwrite', + 'providerBranch': 'main', + 'providerRootDirectory': 'functions/helloWorld', + 'providerSilentMode': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.create( + '<FUNCTION_ID>', + '<NAME>', + 'node-14.5', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listRuntimes()', async () => { + const data = { + 'total': 5, + 'runtimes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.listRuntimes( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method get()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'execute': [], + 'name': 'My Function', + 'enabled': true, + 'live': true, + 'logging': true, + 'runtime': 'python-3.8', + 'deployment': '5e5ea5c16897e', + 'vars': [], + 'events': [], + 'schedule': '5 4 * * *', + 'timeout': 300, + 'entrypoint': 'index.js', + 'commands': 'npm install', + 'version': 'v2', + 'installationId': '6m40at4ejk5h2u9s1hboo', + 'providerRepositoryId': 'appwrite', + 'providerBranch': 'main', + 'providerRootDirectory': 'functions/helloWorld', + 'providerSilentMode': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.get( + '<FUNCTION_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method update()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'execute': [], + 'name': 'My Function', + 'enabled': true, + 'live': true, + 'logging': true, + 'runtime': 'python-3.8', + 'deployment': '5e5ea5c16897e', + 'vars': [], + 'events': [], + 'schedule': '5 4 * * *', + 'timeout': 300, + 'entrypoint': 'index.js', + 'commands': 'npm install', + 'version': 'v2', + 'installationId': '6m40at4ejk5h2u9s1hboo', + 'providerRepositoryId': 'appwrite', + 'providerBranch': 'main', + 'providerRootDirectory': 'functions/helloWorld', + 'providerSilentMode': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.update( + '<FUNCTION_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method delete()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await functions.delete( + '<FUNCTION_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method listDeployments()', async () => { + const data = { + 'total': 5, + 'deployments': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.listDeployments( + '<FUNCTION_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'size': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildTime': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerBranch': '0.7.x', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.createDeployment( + '<FUNCTION_ID>', + InputFile.fromBuffer(new Uint8Array(0), 'image.png'), + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'size': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildTime': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerBranch': '0.7.x', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.getDeployment( + '<FUNCTION_ID>', + '<DEPLOYMENT_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'execute': [], + 'name': 'My Function', + 'enabled': true, + 'live': true, + 'logging': true, + 'runtime': 'python-3.8', + 'deployment': '5e5ea5c16897e', + 'vars': [], + 'events': [], + 'schedule': '5 4 * * *', + 'timeout': 300, + 'entrypoint': 'index.js', + 'commands': 'npm install', + 'version': 'v2', + 'installationId': '6m40at4ejk5h2u9s1hboo', + 'providerRepositoryId': 'appwrite', + 'providerBranch': 'main', + 'providerRootDirectory': 'functions/helloWorld', + 'providerSilentMode': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.updateDeployment( + '<FUNCTION_ID>', + '<DEPLOYMENT_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteDeployment()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await functions.deleteDeployment( + '<FUNCTION_ID>', + '<DEPLOYMENT_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method createBuild()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await functions.createBuild( + '<FUNCTION_ID>', + '<DEPLOYMENT_ID>', + '<BUILD_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method downloadDeployment()', async () => { + const data = new Uint8Array(0); + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data.buffer))); + + const response = await functions.downloadDeployment( + '<FUNCTION_ID>', + '<DEPLOYMENT_ID>', + ); + + const buffer = await response.arrayBuffer(); + assertEquals(buffer.byteLength, 0); + stubbedFetch.restore(); + }); + + + test('test method listExecutions()', async () => { + const data = { + 'total': 5, + 'executions': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.listExecutions( + '<FUNCTION_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createExecution()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'functionId': '5e5ea6g16897e', + 'trigger': 'http', + 'status': 'processing', + 'requestMethod': 'GET', + 'requestPath': '/articles?id=5', + 'requestHeaders': [], + 'responseStatusCode': 200, + 'responseBody': 'Developers are awesome.', + 'responseHeaders': [], + 'logs': '', + 'errors': '', + 'duration': 0.4,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.createExecution( + '<FUNCTION_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getExecution()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'functionId': '5e5ea6g16897e', + 'trigger': 'http', + 'status': 'processing', + 'requestMethod': 'GET', + 'requestPath': '/articles?id=5', + 'requestHeaders': [], + 'responseStatusCode': 200, + 'responseBody': 'Developers are awesome.', + 'responseHeaders': [], + 'logs': '', + 'errors': '', + 'duration': 0.4,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.getExecution( + '<FUNCTION_ID>', + '<EXECUTION_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listVariables()', async () => { + const data = { + 'total': 5, + 'variables': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.listVariables( + '<FUNCTION_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createVariable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'API_KEY', + 'value': 'myPa\$\$word1', + 'resourceType': 'function', + 'resourceId': 'myAwesomeFunction',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.createVariable( + '<FUNCTION_ID>', + '<KEY>', + '<VALUE>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getVariable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'API_KEY', + 'value': 'myPa\$\$word1', + 'resourceType': 'function', + 'resourceId': 'myAwesomeFunction',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.getVariable( + '<FUNCTION_ID>', + '<VARIABLE_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateVariable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'API_KEY', + 'value': 'myPa\$\$word1', + 'resourceType': 'function', + 'resourceId': 'myAwesomeFunction',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await functions.updateVariable( + '<FUNCTION_ID>', + '<VARIABLE_ID>', + '<KEY>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteVariable()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await functions.deleteVariable( + '<FUNCTION_ID>', + '<VARIABLE_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + }) diff --git a/test/services/graphql.test.ts b/test/services/graphql.test.ts new file mode 100644 index 0000000..565af8d --- /dev/null +++ b/test/services/graphql.test.ts @@ -0,0 +1,44 @@ +import {afterEach, describe, it as test} from "https://deno.land/std@0.204.0/testing/bdd.ts"; +import {restore, stub} from "https://deno.land/std@0.204.0/testing/mock.ts"; +import {assertEquals} from "https://deno.land/std@0.204.0/assert/assert_equals.ts"; +import { Graphql } from "../../src/services/graphql.ts"; +import {Client} from "../../src/client.ts"; +import {InputFile} from "../../src/inputFile.ts" + +describe('Graphql service', () => { + const client = new Client(); + const graphql = new Graphql(client); + + afterEach(() => restore()) + + + test('test method query()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await graphql.query( + {}, + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method mutation()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await graphql.mutation( + {}, + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + }) diff --git a/test/services/health.test.ts b/test/services/health.test.ts new file mode 100644 index 0000000..7b1ecd2 --- /dev/null +++ b/test/services/health.test.ts @@ -0,0 +1,359 @@ +import {afterEach, describe, it as test} from "https://deno.land/std@0.204.0/testing/bdd.ts"; +import {restore, stub} from "https://deno.land/std@0.204.0/testing/mock.ts"; +import {assertEquals} from "https://deno.land/std@0.204.0/assert/assert_equals.ts"; +import { Health } from "../../src/services/health.ts"; +import {Client} from "../../src/client.ts"; +import {InputFile} from "../../src/inputFile.ts" + +describe('Health service', () => { + const client = new Client(); + const health = new Health(client); + + afterEach(() => restore()) + + + test('test method get()', async () => { + const data = { + 'name': 'database', + 'ping': 128, + 'status': 'pass',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.get( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getAntivirus()', async () => { + const data = { + 'version': '1.0.0', + 'status': 'online',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getAntivirus( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getCache()', async () => { + const data = { + 'name': 'database', + 'ping': 128, + 'status': 'pass',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getCache( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getCertificate()', async () => { + const data = { + 'name': '/CN=www.google.com', + 'subjectSN': '', + 'issuerOrganisation': '', + 'validFrom': '1704200998', + 'validTo': '1711458597', + 'signatureTypeSN': 'RSA-SHA256',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getCertificate( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getDB()', async () => { + const data = { + 'name': 'database', + 'ping': 128, + 'status': 'pass',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getDB( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getPubSub()', async () => { + const data = { + 'name': 'database', + 'ping': 128, + 'status': 'pass',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getPubSub( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueue()', async () => { + const data = { + 'name': 'database', + 'ping': 128, + 'status': 'pass',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueue( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueueBuilds()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueueBuilds( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueueCertificates()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueueCertificates( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueueDatabases()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueueDatabases( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueueDeletes()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueueDeletes( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getFailedJobs()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getFailedJobs( + 'v1-database', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueueFunctions()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueueFunctions( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueueLogs()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueueLogs( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueueMails()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueueMails( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueueMessaging()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueueMessaging( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueueMigrations()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueueMigrations( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueueUsage()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueueUsage( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueueUsageDump()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueueUsageDump( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getQueueWebhooks()', async () => { + const data = { + 'size': 8,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getQueueWebhooks( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getStorage()', async () => { + const data = { + 'name': 'database', + 'ping': 128, + 'status': 'pass',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getStorage( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getStorageLocal()', async () => { + const data = { + 'name': 'database', + 'ping': 128, + 'status': 'pass',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getStorageLocal( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getTime()', async () => { + const data = { + 'remoteTime': 1639490751, + 'localTime': 1639490844, + 'diff': 93,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await health.getTime( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + }) diff --git a/test/services/locale.test.ts b/test/services/locale.test.ts new file mode 100644 index 0000000..468a656 --- /dev/null +++ b/test/services/locale.test.ts @@ -0,0 +1,139 @@ +import {afterEach, describe, it as test} from "https://deno.land/std@0.204.0/testing/bdd.ts"; +import {restore, stub} from "https://deno.land/std@0.204.0/testing/mock.ts"; +import {assertEquals} from "https://deno.land/std@0.204.0/assert/assert_equals.ts"; +import { Locale } from "../../src/services/locale.ts"; +import {Client} from "../../src/client.ts"; +import {InputFile} from "../../src/inputFile.ts" + +describe('Locale service', () => { + const client = new Client(); + const locale = new Locale(client); + + afterEach(() => restore()) + + + test('test method get()', async () => { + const data = { + 'ip': '127.0.0.1', + 'countryCode': 'US', + 'country': 'United States', + 'continentCode': 'NA', + 'continent': 'North America', + 'eu': true, + 'currency': 'USD',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await locale.get( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listCodes()', async () => { + const data = { + 'total': 5, + 'localeCodes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await locale.listCodes( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listContinents()', async () => { + const data = { + 'total': 5, + 'continents': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await locale.listContinents( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listCountries()', async () => { + const data = { + 'total': 5, + 'countries': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await locale.listCountries( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listCountriesEU()', async () => { + const data = { + 'total': 5, + 'countries': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await locale.listCountriesEU( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listCountriesPhones()', async () => { + const data = { + 'total': 5, + 'phones': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await locale.listCountriesPhones( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listCurrencies()', async () => { + const data = { + 'total': 5, + 'currencies': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await locale.listCurrencies( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listLanguages()', async () => { + const data = { + 'total': 5, + 'languages': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await locale.listLanguages( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + }) diff --git a/test/services/messaging.test.ts b/test/services/messaging.test.ts new file mode 100644 index 0000000..6705652 --- /dev/null +++ b/test/services/messaging.test.ts @@ -0,0 +1,978 @@ +import {afterEach, describe, it as test} from "https://deno.land/std@0.204.0/testing/bdd.ts"; +import {restore, stub} from "https://deno.land/std@0.204.0/testing/mock.ts"; +import {assertEquals} from "https://deno.land/std@0.204.0/assert/assert_equals.ts"; +import { Messaging } from "../../src/services/messaging.ts"; +import {Client} from "../../src/client.ts"; +import {InputFile} from "../../src/inputFile.ts" + +describe('Messaging service', () => { + const client = new Client(); + const messaging = new Messaging(client); + + afterEach(() => restore()) + + + test('test method listMessages()', async () => { + const data = { + 'total': 5, + 'messages': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.listMessages( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createEmail()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'Message status can be one of the following: draft, processing, scheduled, sent, or failed.',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createEmail( + '<MESSAGE_ID>', + '<SUBJECT>', + '<CONTENT>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateEmail()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'Message status can be one of the following: draft, processing, scheduled, sent, or failed.',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateEmail( + '<MESSAGE_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createPush()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'Message status can be one of the following: draft, processing, scheduled, sent, or failed.',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createPush( + '<MESSAGE_ID>', + '<TITLE>', + '<BODY>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updatePush()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'Message status can be one of the following: draft, processing, scheduled, sent, or failed.',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updatePush( + '<MESSAGE_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createSms()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'Message status can be one of the following: draft, processing, scheduled, sent, or failed.',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createSms( + '<MESSAGE_ID>', + '<CONTENT>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateSms()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'Message status can be one of the following: draft, processing, scheduled, sent, or failed.',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateSms( + '<MESSAGE_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getMessage()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'Message status can be one of the following: draft, processing, scheduled, sent, or failed.',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.getMessage( + '<MESSAGE_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method delete()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await messaging.delete( + '<MESSAGE_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method listMessageLogs()', async () => { + const data = { + 'total': 5, + 'logs': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.listMessageLogs( + '<MESSAGE_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listTargets()', async () => { + const data = { + 'total': 5, + 'targets': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.listTargets( + '<MESSAGE_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listProviders()', async () => { + const data = { + 'total': 5, + 'providers': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.listProviders( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createApnsProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createApnsProvider( + '<PROVIDER_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateApnsProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateApnsProvider( + '<PROVIDER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createFcmProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createFcmProvider( + '<PROVIDER_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateFcmProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateFcmProvider( + '<PROVIDER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createMailgunProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createMailgunProvider( + '<PROVIDER_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateMailgunProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateMailgunProvider( + '<PROVIDER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createMsg91Provider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createMsg91Provider( + '<PROVIDER_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateMsg91Provider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateMsg91Provider( + '<PROVIDER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createSendgridProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createSendgridProvider( + '<PROVIDER_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateSendgridProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateSendgridProvider( + '<PROVIDER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createSmtpProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createSmtpProvider( + '<PROVIDER_ID>', + '<NAME>', + '<HOST>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateSmtpProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateSmtpProvider( + '<PROVIDER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createTelesignProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createTelesignProvider( + '<PROVIDER_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateTelesignProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateTelesignProvider( + '<PROVIDER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createTextmagicProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createTextmagicProvider( + '<PROVIDER_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateTextmagicProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateTextmagicProvider( + '<PROVIDER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createTwilioProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createTwilioProvider( + '<PROVIDER_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateTwilioProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateTwilioProvider( + '<PROVIDER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createVonageProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createVonageProvider( + '<PROVIDER_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateVonageProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateVonageProvider( + '<PROVIDER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.getProvider( + '<PROVIDER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteProvider()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await messaging.deleteProvider( + '<PROVIDER_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method listProviderLogs()', async () => { + const data = { + 'total': 5, + 'logs': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.listProviderLogs( + '<PROVIDER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listSubscriberLogs()', async () => { + const data = { + 'total': 5, + 'logs': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.listSubscriberLogs( + '<SUBSCRIBER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listTopics()', async () => { + const data = { + 'total': 5, + 'topics': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.listTopics( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createTopic()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'events', + 'emailTotal': 100, + 'smsTotal': 100, + 'pushTotal': 100, + 'subscribe': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createTopic( + '<TOPIC_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getTopic()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'events', + 'emailTotal': 100, + 'smsTotal': 100, + 'pushTotal': 100, + 'subscribe': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.getTopic( + '<TOPIC_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateTopic()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'events', + 'emailTotal': 100, + 'smsTotal': 100, + 'pushTotal': 100, + 'subscribe': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.updateTopic( + '<TOPIC_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteTopic()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await messaging.deleteTopic( + '<TOPIC_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method listTopicLogs()', async () => { + const data = { + 'total': 5, + 'logs': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.listTopicLogs( + '<TOPIC_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listSubscribers()', async () => { + const data = { + 'total': 5, + 'subscribers': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.listSubscribers( + '<TOPIC_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createSubscriber()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'targetId': '259125845563242502', + 'target': {}, + 'userId': '5e5ea5c16897e', + 'userName': 'Aegon Targaryen', + 'topicId': '259125845563242502', + 'providerType': 'email',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.createSubscriber( + '<TOPIC_ID>', + '<SUBSCRIBER_ID>', + '<TARGET_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getSubscriber()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'targetId': '259125845563242502', + 'target': {}, + 'userId': '5e5ea5c16897e', + 'userName': 'Aegon Targaryen', + 'topicId': '259125845563242502', + 'providerType': 'email',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await messaging.getSubscriber( + '<TOPIC_ID>', + '<SUBSCRIBER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteSubscriber()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await messaging.deleteSubscriber( + '<TOPIC_ID>', + '<SUBSCRIBER_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + }) diff --git a/test/services/storage.test.ts b/test/services/storage.test.ts new file mode 100644 index 0000000..1ed135b --- /dev/null +++ b/test/services/storage.test.ts @@ -0,0 +1,283 @@ +import {afterEach, describe, it as test} from "https://deno.land/std@0.204.0/testing/bdd.ts"; +import {restore, stub} from "https://deno.land/std@0.204.0/testing/mock.ts"; +import {assertEquals} from "https://deno.land/std@0.204.0/assert/assert_equals.ts"; +import { Storage } from "../../src/services/storage.ts"; +import {Client} from "../../src/client.ts"; +import {InputFile} from "../../src/inputFile.ts" + +describe('Storage service', () => { + const client = new Client(); + const storage = new Storage(client); + + afterEach(() => restore()) + + + test('test method listBuckets()', async () => { + const data = { + 'total': 5, + 'buckets': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await storage.listBuckets( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createBucket()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'fileSecurity': true, + 'name': 'Documents', + 'enabled': true, + 'maximumFileSize': 100, + 'allowedFileExtensions': [], + 'compression': 'gzip', + 'encryption': true, + 'antivirus': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await storage.createBucket( + '<BUCKET_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getBucket()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'fileSecurity': true, + 'name': 'Documents', + 'enabled': true, + 'maximumFileSize': 100, + 'allowedFileExtensions': [], + 'compression': 'gzip', + 'encryption': true, + 'antivirus': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await storage.getBucket( + '<BUCKET_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateBucket()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'fileSecurity': true, + 'name': 'Documents', + 'enabled': true, + 'maximumFileSize': 100, + 'allowedFileExtensions': [], + 'compression': 'gzip', + 'encryption': true, + 'antivirus': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await storage.updateBucket( + '<BUCKET_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteBucket()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await storage.deleteBucket( + '<BUCKET_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method listFiles()', async () => { + const data = { + 'total': 5, + 'files': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await storage.listFiles( + '<BUCKET_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createFile()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'bucketId': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'name': 'Pink.png', + 'signature': '5d529fd02b544198ae075bd57c1762bb', + 'mimeType': 'image/png', + 'sizeOriginal': 17890, + 'chunksTotal': 17890, + 'chunksUploaded': 17890,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await storage.createFile( + '<BUCKET_ID>', + '<FILE_ID>', + InputFile.fromBuffer(new Uint8Array(0), 'image.png'), + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getFile()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'bucketId': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'name': 'Pink.png', + 'signature': '5d529fd02b544198ae075bd57c1762bb', + 'mimeType': 'image/png', + 'sizeOriginal': 17890, + 'chunksTotal': 17890, + 'chunksUploaded': 17890,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await storage.getFile( + '<BUCKET_ID>', + '<FILE_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateFile()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'bucketId': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'name': 'Pink.png', + 'signature': '5d529fd02b544198ae075bd57c1762bb', + 'mimeType': 'image/png', + 'sizeOriginal': 17890, + 'chunksTotal': 17890, + 'chunksUploaded': 17890,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await storage.updateFile( + '<BUCKET_ID>', + '<FILE_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteFile()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await storage.deleteFile( + '<BUCKET_ID>', + '<FILE_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method getFileDownload()', async () => { + const data = new Uint8Array(0); + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data.buffer))); + + const response = await storage.getFileDownload( + '<BUCKET_ID>', + '<FILE_ID>', + ); + + const buffer = await response.arrayBuffer(); + assertEquals(buffer.byteLength, 0); + stubbedFetch.restore(); + }); + + + test('test method getFilePreview()', async () => { + const data = new Uint8Array(0); + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data.buffer))); + + const response = await storage.getFilePreview( + '<BUCKET_ID>', + '<FILE_ID>', + ); + + const buffer = await response.arrayBuffer(); + assertEquals(buffer.byteLength, 0); + stubbedFetch.restore(); + }); + + + test('test method getFileView()', async () => { + const data = new Uint8Array(0); + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data.buffer))); + + const response = await storage.getFileView( + '<BUCKET_ID>', + '<FILE_ID>', + ); + + const buffer = await response.arrayBuffer(); + assertEquals(buffer.byteLength, 0); + stubbedFetch.restore(); + }); + + }) diff --git a/test/services/teams.test.ts b/test/services/teams.test.ts new file mode 100644 index 0000000..3389c70 --- /dev/null +++ b/test/services/teams.test.ts @@ -0,0 +1,282 @@ +import {afterEach, describe, it as test} from "https://deno.land/std@0.204.0/testing/bdd.ts"; +import {restore, stub} from "https://deno.land/std@0.204.0/testing/mock.ts"; +import {assertEquals} from "https://deno.land/std@0.204.0/assert/assert_equals.ts"; +import { Teams } from "../../src/services/teams.ts"; +import {Client} from "../../src/client.ts"; +import {InputFile} from "../../src/inputFile.ts" + +describe('Teams service', () => { + const client = new Client(); + const teams = new Teams(client); + + afterEach(() => restore()) + + + test('test method list()', async () => { + const data = { + 'total': 5, + 'teams': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await teams.list( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method create()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'VIP', + 'total': 7, + 'prefs': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await teams.create( + '<TEAM_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method get()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'VIP', + 'total': 7, + 'prefs': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await teams.get( + '<TEAM_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateName()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'VIP', + 'total': 7, + 'prefs': {},}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await teams.updateName( + '<TEAM_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method delete()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await teams.delete( + '<TEAM_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method listMemberships()', async () => { + const data = { + 'total': 5, + 'memberships': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await teams.listMemberships( + '<TEAM_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createMembership()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'userName': 'John Doe', + 'userEmail': 'john@appwrite.io', + 'teamId': '5e5ea5c16897e', + 'teamName': 'VIP', + 'invited': '2020-10-15T06:38:00.000+00:00', + 'joined': '2020-10-15T06:38:00.000+00:00', + 'confirm': true, + 'mfa': true, + 'roles': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await teams.createMembership( + '<TEAM_ID>', + [], + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getMembership()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'userName': 'John Doe', + 'userEmail': 'john@appwrite.io', + 'teamId': '5e5ea5c16897e', + 'teamName': 'VIP', + 'invited': '2020-10-15T06:38:00.000+00:00', + 'joined': '2020-10-15T06:38:00.000+00:00', + 'confirm': true, + 'mfa': true, + 'roles': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await teams.getMembership( + '<TEAM_ID>', + '<MEMBERSHIP_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateMembership()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'userName': 'John Doe', + 'userEmail': 'john@appwrite.io', + 'teamId': '5e5ea5c16897e', + 'teamName': 'VIP', + 'invited': '2020-10-15T06:38:00.000+00:00', + 'joined': '2020-10-15T06:38:00.000+00:00', + 'confirm': true, + 'mfa': true, + 'roles': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await teams.updateMembership( + '<TEAM_ID>', + '<MEMBERSHIP_ID>', + [], + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteMembership()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await teams.deleteMembership( + '<TEAM_ID>', + '<MEMBERSHIP_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method updateMembershipStatus()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'userName': 'John Doe', + 'userEmail': 'john@appwrite.io', + 'teamId': '5e5ea5c16897e', + 'teamName': 'VIP', + 'invited': '2020-10-15T06:38:00.000+00:00', + 'joined': '2020-10-15T06:38:00.000+00:00', + 'confirm': true, + 'mfa': true, + 'roles': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await teams.updateMembershipStatus( + '<TEAM_ID>', + '<MEMBERSHIP_ID>', + '<USER_ID>', + '<SECRET>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getPrefs()', async () => { + const data = {}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await teams.getPrefs( + '<TEAM_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updatePrefs()', async () => { + const data = {}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await teams.updatePrefs( + '<TEAM_ID>', + {}, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + }) diff --git a/test/services/users.test.ts b/test/services/users.test.ts new file mode 100644 index 0000000..dac746c --- /dev/null +++ b/test/services/users.test.ts @@ -0,0 +1,1008 @@ +import {afterEach, describe, it as test} from "https://deno.land/std@0.204.0/testing/bdd.ts"; +import {restore, stub} from "https://deno.land/std@0.204.0/testing/mock.ts"; +import {assertEquals} from "https://deno.land/std@0.204.0/assert/assert_equals.ts"; +import { Users } from "../../src/services/users.ts"; +import {Client} from "../../src/client.ts"; +import {InputFile} from "../../src/inputFile.ts" + +describe('Users service', () => { + const client = new Client(); + const users = new Users(client); + + afterEach(() => restore()) + + + test('test method list()', async () => { + const data = { + 'total': 5, + 'users': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.list( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method create()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.create( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createArgon2User()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.createArgon2User( + '<USER_ID>', + 'email@example.com', + 'password', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createBcryptUser()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.createBcryptUser( + '<USER_ID>', + 'email@example.com', + 'password', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listIdentities()', async () => { + const data = { + 'total': 5, + 'identities': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.listIdentities( + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteIdentity()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await users.deleteIdentity( + '<IDENTITY_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method createMD5User()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.createMD5User( + '<USER_ID>', + 'email@example.com', + 'password', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createPHPassUser()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.createPHPassUser( + '<USER_ID>', + 'email@example.com', + 'password', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createScryptUser()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.createScryptUser( + '<USER_ID>', + 'email@example.com', + 'password', + '<PASSWORD_SALT>', + 1, + 1, + 1, + 1, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createScryptModifiedUser()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.createScryptModifiedUser( + '<USER_ID>', + 'email@example.com', + 'password', + '<PASSWORD_SALT>', + '<PASSWORD_SALT_SEPARATOR>', + '<PASSWORD_SIGNER_KEY>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createSHAUser()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.createSHAUser( + '<USER_ID>', + 'email@example.com', + 'password', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method get()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.get( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method delete()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await users.delete( + '<USER_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method updateEmail()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.updateEmail( + '<USER_ID>', + 'email@example.com', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateLabels()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.updateLabels( + '<USER_ID>', + [], + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listLogs()', async () => { + const data = { + 'total': 5, + 'logs': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.listLogs( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listMemberships()', async () => { + const data = { + 'total': 5, + 'memberships': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.listMemberships( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateMfa()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.updateMfa( + '<USER_ID>', + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteMfaAuthenticator()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.deleteMfaAuthenticator( + '<USER_ID>', + 'totp', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listMfaFactors()', async () => { + const data = { + 'totp': true, + 'phone': true, + 'email': true,}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.listMfaFactors( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getMfaRecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.getMfaRecoveryCodes( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateMfaRecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.updateMfaRecoveryCodes( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createMfaRecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.createMfaRecoveryCodes( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateName()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.updateName( + '<USER_ID>', + '<NAME>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updatePassword()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.updatePassword( + '<USER_ID>', + '', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updatePhone()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.updatePhone( + '<USER_ID>', + '+12065550100', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getPrefs()', async () => { + const data = {}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.getPrefs( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updatePrefs()', async () => { + const data = {}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.updatePrefs( + '<USER_ID>', + {}, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listSessions()', async () => { + const data = { + 'total': 5, + 'sessions': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.listSessions( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createSession()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.createSession( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteSessions()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await users.deleteSessions( + '<USER_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method deleteSession()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await users.deleteSession( + '<USER_ID>', + '<SESSION_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method updateStatus()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.updateStatus( + '<USER_ID>', + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method listTargets()', async () => { + const data = { + 'total': 5, + 'targets': [],}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.listTargets( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method createTarget()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Aegon apple token', + 'userId': '259125845563242502', + 'providerType': 'email', + 'identifier': 'token',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.createTarget( + '<USER_ID>', + '<TARGET_ID>', + 'email', + '<IDENTIFIER>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method getTarget()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Aegon apple token', + 'userId': '259125845563242502', + 'providerType': 'email', + 'identifier': 'token',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.getTarget( + '<USER_ID>', + '<TARGET_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateTarget()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Aegon apple token', + 'userId': '259125845563242502', + 'providerType': 'email', + 'identifier': 'token',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.updateTarget( + '<USER_ID>', + '<TARGET_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method deleteTarget()', async () => { + const data = ''; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data))) + + const response = await users.deleteTarget( + '<USER_ID>', + '<TARGET_ID>', + ); + + const text = await response.text(); + assertEquals(text, data); + stubbedFetch.restore(); + }); + + + test('test method createToken()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.createToken( + '<USER_ID>', + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updateEmailVerification()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.updateEmailVerification( + '<USER_ID>', + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + + test('test method updatePhoneVerification()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data))); + + const response = await users.updatePhoneVerification( + '<USER_ID>', + true, + ); + + assertEquals(response, data); + stubbedFetch.restore(); + }); + + })