├── .github ├── ISSUE_TEMPLATE │ ├── bug.yaml │ ├── documentation.yaml │ └── feature.yaml └── workflows │ ├── autoclose.yml │ └── publish.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── dist ├── cjs │ └── package.json └── esm │ └── package.json ├── docs └── examples │ ├── account │ ├── create-anonymous-session.md │ ├── create-email-password-session.md │ ├── create-email-token.md │ ├── create-j-w-t.md │ ├── create-magic-u-r-l-token.md │ ├── create-mfa-authenticator.md │ ├── create-mfa-challenge.md │ ├── create-mfa-recovery-codes.md │ ├── create-o-auth2session.md │ ├── create-o-auth2token.md │ ├── create-phone-token.md │ ├── create-phone-verification.md │ ├── create-push-target.md │ ├── create-recovery.md │ ├── create-session.md │ ├── create-verification.md │ ├── create.md │ ├── delete-identity.md │ ├── delete-mfa-authenticator.md │ ├── delete-push-target.md │ ├── delete-session.md │ ├── delete-sessions.md │ ├── get-mfa-recovery-codes.md │ ├── get-prefs.md │ ├── get-session.md │ ├── get.md │ ├── list-identities.md │ ├── list-logs.md │ ├── list-mfa-factors.md │ ├── list-sessions.md │ ├── update-email.md │ ├── update-m-f-a.md │ ├── update-magic-u-r-l-session.md │ ├── update-mfa-authenticator.md │ ├── update-mfa-challenge.md │ ├── update-mfa-recovery-codes.md │ ├── update-name.md │ ├── update-password.md │ ├── update-phone-session.md │ ├── update-phone-verification.md │ ├── update-phone.md │ ├── update-prefs.md │ ├── update-push-target.md │ ├── update-recovery.md │ ├── update-session.md │ ├── update-status.md │ └── update-verification.md │ ├── avatars │ ├── get-browser.md │ ├── get-credit-card.md │ ├── get-favicon.md │ ├── get-flag.md │ ├── get-image.md │ ├── get-initials.md │ └── get-q-r.md │ ├── databases │ ├── create-document.md │ ├── delete-document.md │ ├── get-document.md │ ├── list-documents.md │ ├── update-document.md │ └── upsert-document.md │ ├── functions │ ├── create-execution.md │ ├── get-execution.md │ └── list-executions.md │ ├── graphql │ ├── mutation.md │ └── query.md │ ├── locale │ ├── get.md │ ├── list-codes.md │ ├── list-continents.md │ ├── list-countries-e-u.md │ ├── list-countries-phones.md │ ├── list-countries.md │ ├── list-currencies.md │ └── list-languages.md │ ├── messaging │ ├── create-subscriber.md │ └── delete-subscriber.md │ ├── storage │ ├── create-file.md │ ├── delete-file.md │ ├── get-file-download.md │ ├── get-file-preview.md │ ├── get-file-view.md │ ├── get-file.md │ ├── list-files.md │ └── update-file.md │ └── teams │ ├── create-membership.md │ ├── create.md │ ├── delete-membership.md │ ├── delete.md │ ├── get-membership.md │ ├── get-prefs.md │ ├── get.md │ ├── list-memberships.md │ ├── list.md │ ├── update-membership-status.md │ ├── update-membership.md │ ├── update-name.md │ └── update-prefs.md ├── package.json ├── rollup.config.js ├── src ├── client.ts ├── enums │ ├── authentication-factor.ts │ ├── authenticator-type.ts │ ├── browser.ts │ ├── credit-card.ts │ ├── execution-method.ts │ ├── flag.ts │ ├── image-format.ts │ ├── image-gravity.ts │ └── o-auth-provider.ts ├── id.ts ├── index.ts ├── models.ts ├── permission.ts ├── query.ts ├── role.ts ├── service.ts └── services │ ├── account.ts │ ├── avatars.ts │ ├── databases.ts │ ├── functions.ts │ ├── graphql.ts │ ├── locale.ts │ ├── messaging.ts │ ├── storage.ts │ └── teams.ts └── tsconfig.json /.github/ISSUE_TEMPLATE/bug.yaml: -------------------------------------------------------------------------------- 1 | name: "🐛 Bug Report" 2 | description: "Submit a bug report to help us improve" 3 | title: "🐛 Bug Report: " 4 | labels: [bug] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to fill out our bug report form 🙏 10 | - type: textarea 11 | id: steps-to-reproduce 12 | validations: 13 | required: true 14 | attributes: 15 | label: "👟 Reproduction steps" 16 | description: "How do you trigger this bug? Please walk us through it step by step." 17 | placeholder: "When I ..." 18 | - type: textarea 19 | id: expected-behavior 20 | validations: 21 | required: true 22 | attributes: 23 | label: "👍 Expected behavior" 24 | description: "What did you think would happen?" 25 | placeholder: "It should ..." 26 | - type: textarea 27 | id: actual-behavior 28 | validations: 29 | required: true 30 | attributes: 31 | label: "👎 Actual Behavior" 32 | description: "What did actually happen? Add screenshots, if applicable." 33 | placeholder: "It actually ..." 34 | - type: dropdown 35 | id: appwrite-version 36 | attributes: 37 | label: "🎲 Appwrite version" 38 | description: "What version of Appwrite are you running?" 39 | options: 40 | - Version 0.10.x 41 | - Version 0.9.x 42 | - Version 0.8.x 43 | - Version 0.7.x 44 | - Version 0.6.x 45 | - Different version (specify in environment) 46 | validations: 47 | required: true 48 | - type: dropdown 49 | id: operating-system 50 | attributes: 51 | label: "💻 Operating system" 52 | description: "What OS is your server / device running on?" 53 | options: 54 | - Linux 55 | - MacOS 56 | - Windows 57 | - Something else 58 | validations: 59 | required: true 60 | - type: textarea 61 | id: enviromnemt 62 | validations: 63 | required: false 64 | attributes: 65 | label: "🧱 Your Environment" 66 | description: "Is your environment customized in any way?" 67 | placeholder: "I use Cloudflare for ..." 68 | - type: checkboxes 69 | id: no-duplicate-issues 70 | attributes: 71 | label: "👀 Have you spent some time to check if this issue has been raised before?" 72 | description: "Have you Googled for a similar issue or checked our older issues for a similar bug?" 73 | options: 74 | - label: "I checked and didn't find similar issue" 75 | required: true 76 | - type: checkboxes 77 | id: read-code-of-conduct 78 | attributes: 79 | label: "🏢 Have you read the Code of Conduct?" 80 | options: 81 | - label: "I have read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/HEAD/CODE_OF_CONDUCT.md)" 82 | required: true -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.yaml: -------------------------------------------------------------------------------- 1 | name: "📚 Documentation" 2 | description: "Report an issue related to documentation" 3 | title: "📚 Documentation: " 4 | labels: [documentation] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to make our documentation better 🙏 10 | - type: textarea 11 | id: issue-description 12 | validations: 13 | required: true 14 | attributes: 15 | label: "💭 Description" 16 | description: "A clear and concise description of what the issue is." 17 | placeholder: "Documentation should not ..." 18 | - type: checkboxes 19 | id: no-duplicate-issues 20 | attributes: 21 | label: "👀 Have you spent some time to check if this issue has been raised before?" 22 | description: "Have you Googled for a similar issue or checked our older issues for a similar bug?" 23 | options: 24 | - label: "I checked and didn't find similar issue" 25 | required: true 26 | - type: checkboxes 27 | id: read-code-of-conduct 28 | attributes: 29 | label: "🏢 Have you read the Code of Conduct?" 30 | options: 31 | - label: "I have read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/HEAD/CODE_OF_CONDUCT.md)" 32 | required: true -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature.yaml: -------------------------------------------------------------------------------- 1 | name: 🚀 Feature 2 | description: "Submit a proposal for a new feature" 3 | title: "🚀 Feature: " 4 | labels: [feature] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to fill out our feature request form 🙏 10 | - type: textarea 11 | id: feature-description 12 | validations: 13 | required: true 14 | attributes: 15 | label: "🔖 Feature description" 16 | description: "A clear and concise description of what the feature is." 17 | placeholder: "You should add ..." 18 | - type: textarea 19 | id: pitch 20 | validations: 21 | required: true 22 | attributes: 23 | label: "🎤 Pitch" 24 | description: "Please explain why this feature should be implemented and how it would be used. Add examples, if applicable." 25 | placeholder: "In my use-case, ..." 26 | - type: checkboxes 27 | id: no-duplicate-issues 28 | attributes: 29 | label: "👀 Have you spent some time to check if this issue has been raised before?" 30 | description: "Have you Googled for a similar issue or checked our older issues for a similar bug?" 31 | options: 32 | - label: "I checked and didn't find similar issue" 33 | required: true 34 | - type: checkboxes 35 | id: read-code-of-conduct 36 | attributes: 37 | label: "🏢 Have you read the Code of Conduct?" 38 | options: 39 | - label: "I have read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/HEAD/CODE_OF_CONDUCT.md)" 40 | required: true -------------------------------------------------------------------------------- /.github/workflows/autoclose.yml: -------------------------------------------------------------------------------- 1 | name: Auto-close External Pull Requests 2 | 3 | on: 4 | pull_request_target: 5 | types: [opened, reopened] 6 | 7 | jobs: 8 | auto_close: 9 | uses: appwrite/.github/.github/workflows/autoclose.yml@main 10 | secrets: 11 | GH_AUTO_CLOSE_PR_TOKEN: ${{ secrets.GH_AUTO_CLOSE_PR_TOKEN }} 12 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to NPM 2 | 3 | on: 4 | release: 5 | types: [published] 6 | workflow_dispatch: 7 | 8 | jobs: 9 | publish: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v4 14 | 15 | # Setup Node.js environment 16 | - name: Use Node.js 17 | uses: actions/setup-node@v4 18 | with: 19 | node-version: '20.x' 20 | registry-url: 'https://registry.npmjs.org' 21 | 22 | # Determine release tag based on the tag name 23 | - name: Determine release tag 24 | id: release_tag 25 | run: | 26 | if [[ "${{ github.ref }}" == *"-rc"* ]] || [[ "${{ github.ref }}" == *"-RC"* ]]; then 27 | echo "tag=next" >> "$GITHUB_OUTPUT" 28 | else 29 | echo "tag=latest" >> "$GITHUB_OUTPUT" 30 | fi 31 | 32 | # Install dependencies (if any) and build your project (if necessary) 33 | - name: Install dependencies and build 34 | run: | 35 | npm install 36 | npm run build 37 | 38 | # Publish to NPM with the appropriate tag 39 | - name: Publish 40 | run: npm publish --tag ${{ steps.release_tag.outputs.tag }} 41 | env: 42 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 43 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## 18.0.0 4 | 5 | * Add `<REGION>` to doc examples due to the new multi region endpoints 6 | * Remove `Gif` from ImageFormat enum 7 | * Remove `search` param from `listExecutions` method 8 | * Add `token` param to `getFilePreview` and `getFileView` for File tokens usage 9 | * Improve CORS error catching in `client.call` method -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Appwrite Web SDK 2 | 3 | ![License](https://img.shields.io/github/license/appwrite/sdk-for-web.svg?style=flat-square) 4 | ![Version](https://img.shields.io/badge/api%20version-1.7.0-blue.svg?style=flat-square) 5 | [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) 6 | [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) 7 | [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) 8 | 9 | **This SDK is compatible with Appwrite server version 1.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-web/releases).** 10 | 11 | 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 Web 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) 12 | 13 | ![Appwrite](https://github.com/appwrite/appwrite/raw/main/public/images/github.png) 14 | 15 | ## Installation 16 | 17 | ### NPM 18 | 19 | To install via [NPM](https://www.npmjs.com/): 20 | 21 | ```bash 22 | npm install appwrite --save 23 | ``` 24 | 25 | If you're using a bundler (like [Rollup](https://rollupjs.org/) or [webpack](https://webpack.js.org/)), you can import the Appwrite module when you need it: 26 | 27 | ```js 28 | import { Client, Account } from "appwrite"; 29 | ``` 30 | 31 | ### CDN 32 | 33 | To install with a CDN (content delivery network) add the following scripts to the bottom of your tag, but before you use any Appwrite services: 34 | 35 | ```html 36 | 37 | ``` 38 | 39 | 40 | ## Getting Started 41 | 42 | ### Add your Web Platform 43 | For you to init your SDK and interact with Appwrite services you need to add a web platform to your project. To add a new platform, go to your Appwrite console, choose the project you created in the step before and click the 'Add Platform' button. 44 | 45 | From the options, choose to add a **Web** platform and add your client app hostname. By adding your hostname to your project platform you are allowing cross-domain communication between your project and the Appwrite API. 46 | 47 | ### Init your SDK 48 | Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page. 49 | 50 | ```js 51 | // Init your Web SDK 52 | const client = new Client(); 53 | 54 | client 55 | .setEndpoint('http://localhost/v1') // Your Appwrite Endpoint 56 | .setProject('455x34dfkj') // Your project ID 57 | ; 58 | ``` 59 | 60 | ### Make Your First Request 61 | Once your SDK object is set, access any of the Appwrite services and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section. 62 | 63 | ```js 64 | const account = new Account(client); 65 | 66 | // Register User 67 | account.create(ID.unique(), "email@example.com", "password", "Walter O'Brien") 68 | .then(function (response) { 69 | console.log(response); 70 | }, function (error) { 71 | console.log(error); 72 | }); 73 | 74 | ``` 75 | 76 | ### Full Example 77 | ```js 78 | // Init your Web SDK 79 | const client = new Client(); 80 | 81 | client 82 | .setEndpoint('http://localhost/v1') // Your Appwrite Endpoint 83 | .setProject('455x34dfkj') 84 | ; 85 | 86 | const account = new Account(client); 87 | 88 | // Register User 89 | account.create(ID.unique(), "email@example.com", "password", "Walter O'Brien") 90 | .then(function (response) { 91 | console.log(response); 92 | }, function (error) { 93 | console.log(error); 94 | }); 95 | ``` 96 | 97 | ### Learn more 98 | You can use the following resources to learn more and get help 99 | - 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-web) 100 | - 📜 [Appwrite Docs](https://appwrite.io/docs) 101 | - 💬 [Discord Community](https://appwrite.io/discord) 102 | - 🚂 [Appwrite Web Playground](https://github.com/appwrite/playground-for-web) 103 | 104 | 105 | ## Contribution 106 | 107 | This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request. 108 | 109 | ## License 110 | 111 | Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information. -------------------------------------------------------------------------------- /dist/cjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "commonjs" 3 | } -------------------------------------------------------------------------------- /dist/esm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } -------------------------------------------------------------------------------- /docs/examples/account/create-anonymous-session.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createAnonymousSession(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/account/create-email-password-session.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createEmailPasswordSession( 10 | 'email@example.com', // email 11 | 'password' // password 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/create-email-token.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createEmailToken( 10 | '', // userId 11 | 'email@example.com', // email 12 | false // phrase (optional) 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/account/create-j-w-t.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createJWT(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/account/create-magic-u-r-l-token.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createMagicURLToken( 10 | '', // userId 11 | 'email@example.com', // email 12 | 'https://example.com', // url (optional) 13 | false // phrase (optional) 14 | ); 15 | 16 | console.log(result); 17 | -------------------------------------------------------------------------------- /docs/examples/account/create-mfa-authenticator.md: -------------------------------------------------------------------------------- 1 | import { Client, Account, AuthenticatorType } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createMfaAuthenticator( 10 | AuthenticatorType.Totp // type 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/create-mfa-challenge.md: -------------------------------------------------------------------------------- 1 | import { Client, Account, AuthenticationFactor } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createMfaChallenge( 10 | AuthenticationFactor.Email // factor 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/create-mfa-recovery-codes.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createMfaRecoveryCodes(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/account/create-o-auth2session.md: -------------------------------------------------------------------------------- 1 | import { Client, Account, OAuthProvider } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | account.createOAuth2Session( 10 | OAuthProvider.Amazon, // provider 11 | 'https://example.com', // success (optional) 12 | 'https://example.com', // failure (optional) 13 | [] // scopes (optional) 14 | ); 15 | 16 | -------------------------------------------------------------------------------- /docs/examples/account/create-o-auth2token.md: -------------------------------------------------------------------------------- 1 | import { Client, Account, OAuthProvider } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | account.createOAuth2Token( 10 | OAuthProvider.Amazon, // provider 11 | 'https://example.com', // success (optional) 12 | 'https://example.com', // failure (optional) 13 | [] // scopes (optional) 14 | ); 15 | 16 | -------------------------------------------------------------------------------- /docs/examples/account/create-phone-token.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createPhoneToken( 10 | '', // userId 11 | '+12065550100' // phone 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/create-phone-verification.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createPhoneVerification(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/account/create-push-target.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createPushTarget( 10 | '', // targetId 11 | '', // identifier 12 | '' // providerId (optional) 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/account/create-recovery.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createRecovery( 10 | 'email@example.com', // email 11 | 'https://example.com' // url 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/create-session.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createSession( 10 | '', // userId 11 | '' // secret 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/create-verification.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.createVerification( 10 | 'https://example.com' // url 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/create.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.create( 10 | '', // userId 11 | 'email@example.com', // email 12 | '', // password 13 | '' // name (optional) 14 | ); 15 | 16 | console.log(result); 17 | -------------------------------------------------------------------------------- /docs/examples/account/delete-identity.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.deleteIdentity( 10 | '' // identityId 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/delete-mfa-authenticator.md: -------------------------------------------------------------------------------- 1 | import { Client, Account, AuthenticatorType } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.deleteMfaAuthenticator( 10 | AuthenticatorType.Totp // type 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/delete-push-target.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.deletePushTarget( 10 | '' // targetId 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/delete-session.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.deleteSession( 10 | '' // sessionId 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/delete-sessions.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.deleteSessions(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/account/get-mfa-recovery-codes.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.getMfaRecoveryCodes(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/account/get-prefs.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.getPrefs(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/account/get-session.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.getSession( 10 | '' // sessionId 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/get.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.get(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/account/list-identities.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.listIdentities( 10 | [] // queries (optional) 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/list-logs.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.listLogs( 10 | [] // queries (optional) 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/list-mfa-factors.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.listMfaFactors(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/account/list-sessions.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.listSessions(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/account/update-email.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updateEmail( 10 | 'email@example.com', // email 11 | 'password' // password 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/update-m-f-a.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updateMFA( 10 | false // mfa 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/update-magic-u-r-l-session.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updateMagicURLSession( 10 | '', // userId 11 | '' // secret 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/update-mfa-authenticator.md: -------------------------------------------------------------------------------- 1 | import { Client, Account, AuthenticatorType } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updateMfaAuthenticator( 10 | AuthenticatorType.Totp, // type 11 | '' // otp 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/update-mfa-challenge.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updateMfaChallenge( 10 | '', // challengeId 11 | '' // otp 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/update-mfa-recovery-codes.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updateMfaRecoveryCodes(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/account/update-name.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updateName( 10 | '' // name 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/update-password.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updatePassword( 10 | '', // password 11 | 'password' // oldPassword (optional) 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/update-phone-session.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updatePhoneSession( 10 | '', // userId 11 | '' // secret 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/update-phone-verification.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updatePhoneVerification( 10 | '', // userId 11 | '' // secret 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/update-phone.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updatePhone( 10 | '+12065550100', // phone 11 | 'password' // password 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/update-prefs.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updatePrefs( 10 | {} // prefs 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/update-push-target.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updatePushTarget( 10 | '', // targetId 11 | '' // identifier 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/account/update-recovery.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updateRecovery( 10 | '', // userId 11 | '', // secret 12 | '' // password 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/account/update-session.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updateSession( 10 | '' // sessionId 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/account/update-status.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updateStatus(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/account/update-verification.md: -------------------------------------------------------------------------------- 1 | import { Client, Account } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const account = new Account(client); 8 | 9 | const result = await account.updateVerification( 10 | '', // userId 11 | '' // secret 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/avatars/get-browser.md: -------------------------------------------------------------------------------- 1 | import { Client, Avatars, Browser } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const avatars = new Avatars(client); 8 | 9 | const result = avatars.getBrowser( 10 | Browser.AvantBrowser, // code 11 | 0, // width (optional) 12 | 0, // height (optional) 13 | -1 // quality (optional) 14 | ); 15 | 16 | console.log(result); 17 | -------------------------------------------------------------------------------- /docs/examples/avatars/get-credit-card.md: -------------------------------------------------------------------------------- 1 | import { Client, Avatars, CreditCard } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const avatars = new Avatars(client); 8 | 9 | const result = avatars.getCreditCard( 10 | CreditCard.AmericanExpress, // code 11 | 0, // width (optional) 12 | 0, // height (optional) 13 | -1 // quality (optional) 14 | ); 15 | 16 | console.log(result); 17 | -------------------------------------------------------------------------------- /docs/examples/avatars/get-favicon.md: -------------------------------------------------------------------------------- 1 | import { Client, Avatars } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const avatars = new Avatars(client); 8 | 9 | const result = avatars.getFavicon( 10 | 'https://example.com' // url 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/avatars/get-flag.md: -------------------------------------------------------------------------------- 1 | import { Client, Avatars, Flag } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const avatars = new Avatars(client); 8 | 9 | const result = avatars.getFlag( 10 | Flag.Afghanistan, // code 11 | 0, // width (optional) 12 | 0, // height (optional) 13 | -1 // quality (optional) 14 | ); 15 | 16 | console.log(result); 17 | -------------------------------------------------------------------------------- /docs/examples/avatars/get-image.md: -------------------------------------------------------------------------------- 1 | import { Client, Avatars } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const avatars = new Avatars(client); 8 | 9 | const result = avatars.getImage( 10 | 'https://example.com', // url 11 | 0, // width (optional) 12 | 0 // height (optional) 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/avatars/get-initials.md: -------------------------------------------------------------------------------- 1 | import { Client, Avatars } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const avatars = new Avatars(client); 8 | 9 | const result = avatars.getInitials( 10 | '', // name (optional) 11 | 0, // width (optional) 12 | 0, // height (optional) 13 | '' // background (optional) 14 | ); 15 | 16 | console.log(result); 17 | -------------------------------------------------------------------------------- /docs/examples/avatars/get-q-r.md: -------------------------------------------------------------------------------- 1 | import { Client, Avatars } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const avatars = new Avatars(client); 8 | 9 | const result = avatars.getQR( 10 | '', // text 11 | 1, // size (optional) 12 | 0, // margin (optional) 13 | false // download (optional) 14 | ); 15 | 16 | console.log(result); 17 | -------------------------------------------------------------------------------- /docs/examples/databases/create-document.md: -------------------------------------------------------------------------------- 1 | import { Client, Databases } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setSession('') // The user session to authenticate with 6 | .setKey('') // 7 | .setJWT(''); // Your secret JSON Web Token 8 | 9 | const databases = new Databases(client); 10 | 11 | const result = await databases.createDocument( 12 | '', // databaseId 13 | '', // collectionId 14 | '', // documentId 15 | {}, // data 16 | ["read("any")"] // permissions (optional) 17 | ); 18 | 19 | console.log(result); 20 | -------------------------------------------------------------------------------- /docs/examples/databases/delete-document.md: -------------------------------------------------------------------------------- 1 | import { Client, Databases } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const databases = new Databases(client); 8 | 9 | const result = await databases.deleteDocument( 10 | '', // databaseId 11 | '', // collectionId 12 | '' // documentId 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/databases/get-document.md: -------------------------------------------------------------------------------- 1 | import { Client, Databases } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const databases = new Databases(client); 8 | 9 | const result = await databases.getDocument( 10 | '', // databaseId 11 | '', // collectionId 12 | '', // documentId 13 | [] // queries (optional) 14 | ); 15 | 16 | console.log(result); 17 | -------------------------------------------------------------------------------- /docs/examples/databases/list-documents.md: -------------------------------------------------------------------------------- 1 | import { Client, Databases } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const databases = new Databases(client); 8 | 9 | const result = await databases.listDocuments( 10 | '', // databaseId 11 | '', // collectionId 12 | [] // queries (optional) 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/databases/update-document.md: -------------------------------------------------------------------------------- 1 | import { Client, Databases } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const databases = new Databases(client); 8 | 9 | const result = await databases.updateDocument( 10 | '', // databaseId 11 | '', // collectionId 12 | '', // documentId 13 | {}, // data (optional) 14 | ["read("any")"] // permissions (optional) 15 | ); 16 | 17 | console.log(result); 18 | -------------------------------------------------------------------------------- /docs/examples/databases/upsert-document.md: -------------------------------------------------------------------------------- 1 | import { Client, Databases } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const databases = new Databases(client); 8 | 9 | const result = await databases.upsertDocument( 10 | '', // databaseId 11 | '', // collectionId 12 | '', // documentId 13 | {}, // data 14 | ["read("any")"] // permissions (optional) 15 | ); 16 | 17 | console.log(result); 18 | -------------------------------------------------------------------------------- /docs/examples/functions/create-execution.md: -------------------------------------------------------------------------------- 1 | import { Client, Functions, ExecutionMethod } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const functions = new Functions(client); 8 | 9 | const result = await functions.createExecution( 10 | '', // functionId 11 | '', // body (optional) 12 | false, // async (optional) 13 | '', // path (optional) 14 | ExecutionMethod.GET, // method (optional) 15 | {}, // headers (optional) 16 | '' // scheduledAt (optional) 17 | ); 18 | 19 | console.log(result); 20 | -------------------------------------------------------------------------------- /docs/examples/functions/get-execution.md: -------------------------------------------------------------------------------- 1 | import { Client, Functions } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const functions = new Functions(client); 8 | 9 | const result = await functions.getExecution( 10 | '', // functionId 11 | '' // executionId 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/functions/list-executions.md: -------------------------------------------------------------------------------- 1 | import { Client, Functions } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const functions = new Functions(client); 8 | 9 | const result = await functions.listExecutions( 10 | '', // functionId 11 | [] // queries (optional) 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/graphql/mutation.md: -------------------------------------------------------------------------------- 1 | import { Client, Graphql } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const graphql = new Graphql(client); 8 | 9 | const result = await graphql.mutation( 10 | {} // query 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/graphql/query.md: -------------------------------------------------------------------------------- 1 | import { Client, Graphql } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const graphql = new Graphql(client); 8 | 9 | const result = await graphql.query( 10 | {} // query 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/locale/get.md: -------------------------------------------------------------------------------- 1 | import { Client, Locale } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const locale = new Locale(client); 8 | 9 | const result = await locale.get(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/locale/list-codes.md: -------------------------------------------------------------------------------- 1 | import { Client, Locale } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const locale = new Locale(client); 8 | 9 | const result = await locale.listCodes(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/locale/list-continents.md: -------------------------------------------------------------------------------- 1 | import { Client, Locale } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const locale = new Locale(client); 8 | 9 | const result = await locale.listContinents(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/locale/list-countries-e-u.md: -------------------------------------------------------------------------------- 1 | import { Client, Locale } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const locale = new Locale(client); 8 | 9 | const result = await locale.listCountriesEU(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/locale/list-countries-phones.md: -------------------------------------------------------------------------------- 1 | import { Client, Locale } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const locale = new Locale(client); 8 | 9 | const result = await locale.listCountriesPhones(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/locale/list-countries.md: -------------------------------------------------------------------------------- 1 | import { Client, Locale } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const locale = new Locale(client); 8 | 9 | const result = await locale.listCountries(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/locale/list-currencies.md: -------------------------------------------------------------------------------- 1 | import { Client, Locale } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const locale = new Locale(client); 8 | 9 | const result = await locale.listCurrencies(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/locale/list-languages.md: -------------------------------------------------------------------------------- 1 | import { Client, Locale } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const locale = new Locale(client); 8 | 9 | const result = await locale.listLanguages(); 10 | 11 | console.log(result); 12 | -------------------------------------------------------------------------------- /docs/examples/messaging/create-subscriber.md: -------------------------------------------------------------------------------- 1 | import { Client, Messaging } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const messaging = new Messaging(client); 8 | 9 | const result = await messaging.createSubscriber( 10 | '', // topicId 11 | '', // subscriberId 12 | '' // targetId 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/messaging/delete-subscriber.md: -------------------------------------------------------------------------------- 1 | import { Client, Messaging } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const messaging = new Messaging(client); 8 | 9 | const result = await messaging.deleteSubscriber( 10 | '', // topicId 11 | '' // subscriberId 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/storage/create-file.md: -------------------------------------------------------------------------------- 1 | import { Client, Storage } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const storage = new Storage(client); 8 | 9 | const result = await storage.createFile( 10 | '', // bucketId 11 | '', // fileId 12 | document.getElementById('uploader').files[0], // file 13 | ["read("any")"] // permissions (optional) 14 | ); 15 | 16 | console.log(result); 17 | -------------------------------------------------------------------------------- /docs/examples/storage/delete-file.md: -------------------------------------------------------------------------------- 1 | import { Client, Storage } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const storage = new Storage(client); 8 | 9 | const result = await storage.deleteFile( 10 | '', // bucketId 11 | '' // fileId 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/storage/get-file-download.md: -------------------------------------------------------------------------------- 1 | import { Client, Storage } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const storage = new Storage(client); 8 | 9 | const result = storage.getFileDownload( 10 | '', // bucketId 11 | '', // fileId 12 | '' // token (optional) 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/storage/get-file-preview.md: -------------------------------------------------------------------------------- 1 | import { Client, Storage, ImageGravity, ImageFormat } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const storage = new Storage(client); 8 | 9 | const result = storage.getFilePreview( 10 | '', // bucketId 11 | '', // fileId 12 | 0, // width (optional) 13 | 0, // height (optional) 14 | ImageGravity.Center, // gravity (optional) 15 | -1, // quality (optional) 16 | 0, // borderWidth (optional) 17 | '', // borderColor (optional) 18 | 0, // borderRadius (optional) 19 | 0, // opacity (optional) 20 | -360, // rotation (optional) 21 | '', // background (optional) 22 | ImageFormat.Jpg, // output (optional) 23 | '' // token (optional) 24 | ); 25 | 26 | console.log(result); 27 | -------------------------------------------------------------------------------- /docs/examples/storage/get-file-view.md: -------------------------------------------------------------------------------- 1 | import { Client, Storage } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const storage = new Storage(client); 8 | 9 | const result = storage.getFileView( 10 | '', // bucketId 11 | '', // fileId 12 | '' // token (optional) 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/storage/get-file.md: -------------------------------------------------------------------------------- 1 | import { Client, Storage } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const storage = new Storage(client); 8 | 9 | const result = await storage.getFile( 10 | '', // bucketId 11 | '' // fileId 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/storage/list-files.md: -------------------------------------------------------------------------------- 1 | import { Client, Storage } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const storage = new Storage(client); 8 | 9 | const result = await storage.listFiles( 10 | '', // bucketId 11 | [], // queries (optional) 12 | '' // search (optional) 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/storage/update-file.md: -------------------------------------------------------------------------------- 1 | import { Client, Storage } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const storage = new Storage(client); 8 | 9 | const result = await storage.updateFile( 10 | '', // bucketId 11 | '', // fileId 12 | '', // name (optional) 13 | ["read("any")"] // permissions (optional) 14 | ); 15 | 16 | console.log(result); 17 | -------------------------------------------------------------------------------- /docs/examples/teams/create-membership.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.createMembership( 10 | '', // teamId 11 | [], // roles 12 | 'email@example.com', // email (optional) 13 | '', // userId (optional) 14 | '+12065550100', // phone (optional) 15 | 'https://example.com', // url (optional) 16 | '' // name (optional) 17 | ); 18 | 19 | console.log(result); 20 | -------------------------------------------------------------------------------- /docs/examples/teams/create.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.create( 10 | '', // teamId 11 | '', // name 12 | [] // roles (optional) 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/teams/delete-membership.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.deleteMembership( 10 | '', // teamId 11 | '' // membershipId 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/teams/delete.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.delete( 10 | '' // teamId 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/teams/get-membership.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.getMembership( 10 | '', // teamId 11 | '' // membershipId 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/teams/get-prefs.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.getPrefs( 10 | '' // teamId 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/teams/get.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.get( 10 | '' // teamId 11 | ); 12 | 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /docs/examples/teams/list-memberships.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.listMemberships( 10 | '', // teamId 11 | [], // queries (optional) 12 | '' // search (optional) 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/teams/list.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.list( 10 | [], // queries (optional) 11 | '' // search (optional) 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/teams/update-membership-status.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.updateMembershipStatus( 10 | '', // teamId 11 | '', // membershipId 12 | '', // userId 13 | '' // secret 14 | ); 15 | 16 | console.log(result); 17 | -------------------------------------------------------------------------------- /docs/examples/teams/update-membership.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.updateMembership( 10 | '', // teamId 11 | '', // membershipId 12 | [] // roles 13 | ); 14 | 15 | console.log(result); 16 | -------------------------------------------------------------------------------- /docs/examples/teams/update-name.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.updateName( 10 | '', // teamId 11 | '' // name 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /docs/examples/teams/update-prefs.md: -------------------------------------------------------------------------------- 1 | import { Client, Teams } from "appwrite"; 2 | 3 | const client = new Client() 4 | .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint 5 | .setProject(''); // Your project ID 6 | 7 | const teams = new Teams(client); 8 | 9 | const result = await teams.updatePrefs( 10 | '', // teamId 11 | {} // prefs 12 | ); 13 | 14 | console.log(result); 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "appwrite", 3 | "homepage": "https://appwrite.io/support", 4 | "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", 5 | "version": "18.1.1", 6 | "license": "BSD-3-Clause", 7 | "main": "dist/cjs/sdk.js", 8 | "exports": { 9 | ".": { 10 | "import": "./dist/esm/sdk.js", 11 | "require": "./dist/cjs/sdk.js", 12 | "types": "./types/index.d.ts" 13 | }, 14 | "./package.json": "./package.json" 15 | }, 16 | "module": "dist/esm/sdk.js", 17 | "types": "types/index.d.ts", 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/appwrite/sdk-for-web" 21 | }, 22 | "scripts": { 23 | "build": "npm run build:types && npm run build:libs", 24 | "build:types": "tsc --declaration --emitDeclarationOnly --outDir types", 25 | "build:libs": "rollup -c" 26 | }, 27 | "devDependencies": { 28 | "@rollup/plugin-typescript": "8.3.2", 29 | "playwright": "1.15.0", 30 | "rollup": "2.75.4", 31 | "serve-handler": "6.1.0", 32 | "tslib": "2.4.0", 33 | "typescript": "4.7.2" 34 | }, 35 | "jsdelivr": "dist/iife/sdk.js", 36 | "unpkg": "dist/iife/sdk.js" 37 | } 38 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import pkg from "./package.json"; 2 | import typescript from "@rollup/plugin-typescript"; 3 | 4 | export default { 5 | external: Object.keys(pkg.dependencies ?? {}), 6 | input: "src/index.ts", 7 | plugins: [typescript()], 8 | output: [ 9 | { 10 | format: "cjs", 11 | file: pkg.main, 12 | esModule: false, 13 | sourcemap: true, 14 | }, 15 | { 16 | format: "es", 17 | file: pkg.module, 18 | sourcemap: true, 19 | }, 20 | { 21 | format: "iife", 22 | file: pkg.jsdelivr, 23 | name: "Appwrite", 24 | extend: true, 25 | }, 26 | ], 27 | }; 28 | -------------------------------------------------------------------------------- /src/client.ts: -------------------------------------------------------------------------------- 1 | import { Models } from './models'; 2 | 3 | /** 4 | * Payload type representing a key-value pair with string keys and any values. 5 | */ 6 | type Payload = { 7 | [key: string]: any; 8 | } 9 | 10 | /** 11 | * Headers type representing a key-value pair with string keys and string values. 12 | */ 13 | type Headers = { 14 | [key: string]: string; 15 | } 16 | 17 | /** 18 | * Realtime response structure with different types. 19 | */ 20 | type RealtimeResponse = { 21 | /** 22 | * Type of the response: 'error', 'event', 'connected', 'response' or 'pong'. 23 | */ 24 | type: 'error' | 'event' | 'connected' | 'response' | 'pong'; 25 | 26 | /** 27 | * Data associated with the response based on the response type. 28 | */ 29 | data: RealtimeResponseAuthenticated | RealtimeResponseConnected | RealtimeResponseError | RealtimeResponseEvent | undefined; 30 | } 31 | 32 | /** 33 | * Realtime request structure for authentication. 34 | */ 35 | type RealtimeRequest = { 36 | /** 37 | * Type of the request: 'authentication'. 38 | */ 39 | type: 'authentication'; 40 | 41 | /** 42 | * Data required for authentication. 43 | */ 44 | data: RealtimeRequestAuthenticate; 45 | } 46 | 47 | /** 48 | * Realtime event response structure with generic payload type. 49 | */ 50 | type RealtimeResponseEvent = { 51 | /** 52 | * List of event names associated with the response. 53 | */ 54 | events: string[]; 55 | 56 | /** 57 | * List of channel names associated with the response. 58 | */ 59 | channels: string[]; 60 | 61 | /** 62 | * Timestamp indicating the time of the event. 63 | */ 64 | timestamp: number; 65 | 66 | /** 67 | * Payload containing event-specific data. 68 | */ 69 | payload: T; 70 | } 71 | 72 | /** 73 | * Realtime response structure for errors. 74 | */ 75 | type RealtimeResponseError = { 76 | /** 77 | * Numeric error code indicating the type of error. 78 | */ 79 | code: number; 80 | 81 | /** 82 | * Error message describing the encountered error. 83 | */ 84 | message: string; 85 | } 86 | 87 | /** 88 | * Realtime response structure for a successful connection. 89 | */ 90 | type RealtimeResponseConnected = { 91 | /** 92 | * List of channels the user is connected to. 93 | */ 94 | channels: string[]; 95 | 96 | /** 97 | * User object representing the connected user (optional). 98 | */ 99 | user?: object; 100 | } 101 | 102 | /** 103 | * Realtime response structure for authenticated connections. 104 | */ 105 | type RealtimeResponseAuthenticated = { 106 | /** 107 | * Destination channel for the response. 108 | */ 109 | to: string; 110 | 111 | /** 112 | * Boolean indicating the success of the authentication process. 113 | */ 114 | success: boolean; 115 | 116 | /** 117 | * User object representing the authenticated user. 118 | */ 119 | user: object; 120 | } 121 | 122 | /** 123 | * Realtime request structure for authentication. 124 | */ 125 | type RealtimeRequestAuthenticate = { 126 | /** 127 | * Session identifier for authentication. 128 | */ 129 | session: string; 130 | } 131 | 132 | type TimeoutHandle = ReturnType | number; 133 | 134 | /** 135 | * Realtime interface representing the structure of a realtime communication object. 136 | */ 137 | type Realtime = { 138 | /** 139 | * WebSocket instance for realtime communication. 140 | */ 141 | socket?: WebSocket; 142 | 143 | /** 144 | * Timeout for reconnect operations. 145 | */ 146 | timeout?: TimeoutHandle; 147 | 148 | /** 149 | * Heartbeat interval for the realtime connection. 150 | */ 151 | heartbeat?: TimeoutHandle; 152 | 153 | /** 154 | * URL for establishing the WebSocket connection. 155 | */ 156 | url?: string; 157 | 158 | /** 159 | * Last received message from the realtime server. 160 | */ 161 | lastMessage?: RealtimeResponse; 162 | 163 | /** 164 | * Set of channel names the client is subscribed to. 165 | */ 166 | channels: Set; 167 | 168 | /** 169 | * Map of subscriptions containing channel names and corresponding callback functions. 170 | */ 171 | subscriptions: Map) => void 174 | }>; 175 | 176 | /** 177 | * Counter for managing subscriptions. 178 | */ 179 | subscriptionsCounter: number; 180 | 181 | /** 182 | * Boolean indicating whether automatic reconnection is enabled. 183 | */ 184 | reconnect: boolean; 185 | 186 | /** 187 | * Number of reconnection attempts made. 188 | */ 189 | reconnectAttempts: number; 190 | 191 | /** 192 | * Function to get the timeout duration for communication operations. 193 | */ 194 | getTimeout: () => number; 195 | 196 | /** 197 | * Function to establish a WebSocket connection. 198 | */ 199 | connect: () => void; 200 | 201 | /** 202 | * Function to create a new WebSocket instance. 203 | */ 204 | createSocket: () => void; 205 | 206 | /** 207 | * Function to create a new heartbeat interval. 208 | */ 209 | createHeartbeat: () => void; 210 | 211 | /** 212 | * Function to clean up resources associated with specified channels. 213 | * 214 | * @param {string[]} channels - List of channel names to clean up. 215 | */ 216 | cleanUp: (channels: string[]) => void; 217 | 218 | /** 219 | * Function to handle incoming messages from the WebSocket connection. 220 | * 221 | * @param {MessageEvent} event - Event containing the received message. 222 | */ 223 | onMessage: (event: MessageEvent) => void; 224 | } 225 | 226 | /** 227 | * Type representing upload progress information. 228 | */ 229 | type UploadProgress = { 230 | /** 231 | * Identifier for the upload progress. 232 | */ 233 | $id: string; 234 | 235 | /** 236 | * Current progress of the upload (in percentage). 237 | */ 238 | progress: number; 239 | 240 | /** 241 | * Total size uploaded (in bytes) during the upload process. 242 | */ 243 | sizeUploaded: number; 244 | 245 | /** 246 | * Total number of chunks that need to be uploaded. 247 | */ 248 | chunksTotal: number; 249 | 250 | /** 251 | * Number of chunks that have been successfully uploaded. 252 | */ 253 | chunksUploaded: number; 254 | } 255 | 256 | /** 257 | * Exception thrown by the package 258 | */ 259 | class AppwriteException extends Error { 260 | /** 261 | * The error code associated with the exception. 262 | */ 263 | code: number; 264 | 265 | /** 266 | * The response string associated with the exception. 267 | */ 268 | response: string; 269 | 270 | /** 271 | * Error type. 272 | * See [Error Types](https://appwrite.io/docs/response-codes#errorTypes) for more information. 273 | */ 274 | type: string; 275 | 276 | /** 277 | * Initializes a Appwrite Exception. 278 | * 279 | * @param {string} message - The error message. 280 | * @param {number} code - The error code. Default is 0. 281 | * @param {string} type - The error type. Default is an empty string. 282 | * @param {string} response - The response string. Default is an empty string. 283 | */ 284 | constructor(message: string, code: number = 0, type: string = '', response: string = '') { 285 | super(message); 286 | this.name = 'AppwriteException'; 287 | this.message = message; 288 | this.code = code; 289 | this.type = type; 290 | this.response = response; 291 | } 292 | } 293 | 294 | /** 295 | * Client that handles requests to Appwrite 296 | */ 297 | class Client { 298 | static CHUNK_SIZE = 1024 * 1024 * 5; 299 | 300 | /** 301 | * Holds configuration such as project. 302 | */ 303 | config = { 304 | endpoint: 'https://cloud.appwrite.io/v1', 305 | endpointRealtime: '', 306 | project: '', 307 | jwt: '', 308 | locale: '', 309 | session: '', 310 | devkey: '', 311 | }; 312 | /** 313 | * Custom headers for API requests. 314 | */ 315 | headers: Headers = { 316 | 'x-sdk-name': 'Web', 317 | 'x-sdk-platform': 'client', 318 | 'x-sdk-language': 'web', 319 | 'x-sdk-version': '18.1.1', 320 | 'X-Appwrite-Response-Format': '1.7.0', 321 | }; 322 | 323 | /** 324 | * Set Endpoint 325 | * 326 | * Your project endpoint 327 | * 328 | * @param {string} endpoint 329 | * 330 | * @returns {this} 331 | */ 332 | setEndpoint(endpoint: string): this { 333 | if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) { 334 | throw new AppwriteException('Invalid endpoint URL: ' + endpoint); 335 | } 336 | 337 | this.config.endpoint = endpoint; 338 | this.config.endpointRealtime = endpoint.replace('https://', 'wss://').replace('http://', 'ws://'); 339 | 340 | return this; 341 | } 342 | 343 | /** 344 | * Set Realtime Endpoint 345 | * 346 | * @param {string} endpointRealtime 347 | * 348 | * @returns {this} 349 | */ 350 | setEndpointRealtime(endpointRealtime: string): this { 351 | if (!endpointRealtime.startsWith('ws://') && !endpointRealtime.startsWith('wss://')) { 352 | throw new AppwriteException('Invalid realtime endpoint URL: ' + endpointRealtime); 353 | } 354 | 355 | this.config.endpointRealtime = endpointRealtime; 356 | return this; 357 | } 358 | 359 | /** 360 | * Set Project 361 | * 362 | * Your project ID 363 | * 364 | * @param value string 365 | * 366 | * @return {this} 367 | */ 368 | setProject(value: string): this { 369 | this.headers['X-Appwrite-Project'] = value; 370 | this.config.project = value; 371 | return this; 372 | } 373 | /** 374 | * Set JWT 375 | * 376 | * Your secret JSON Web Token 377 | * 378 | * @param value string 379 | * 380 | * @return {this} 381 | */ 382 | setJWT(value: string): this { 383 | this.headers['X-Appwrite-JWT'] = value; 384 | this.config.jwt = value; 385 | return this; 386 | } 387 | /** 388 | * Set Locale 389 | * 390 | * @param value string 391 | * 392 | * @return {this} 393 | */ 394 | setLocale(value: string): this { 395 | this.headers['X-Appwrite-Locale'] = value; 396 | this.config.locale = value; 397 | return this; 398 | } 399 | /** 400 | * Set Session 401 | * 402 | * The user session to authenticate with 403 | * 404 | * @param value string 405 | * 406 | * @return {this} 407 | */ 408 | setSession(value: string): this { 409 | this.headers['X-Appwrite-Session'] = value; 410 | this.config.session = value; 411 | return this; 412 | } 413 | /** 414 | * Set DevKey 415 | * 416 | * Your secret dev API key 417 | * 418 | * @param value string 419 | * 420 | * @return {this} 421 | */ 422 | setDevKey(value: string): this { 423 | this.headers['X-Appwrite-Dev-Key'] = value; 424 | this.config.devkey = value; 425 | return this; 426 | } 427 | 428 | private realtime: Realtime = { 429 | socket: undefined, 430 | timeout: undefined, 431 | heartbeat: undefined, 432 | url: '', 433 | channels: new Set(), 434 | subscriptions: new Map(), 435 | subscriptionsCounter: 0, 436 | reconnect: true, 437 | reconnectAttempts: 0, 438 | lastMessage: undefined, 439 | connect: () => { 440 | clearTimeout(this.realtime.timeout); 441 | this.realtime.timeout = window?.setTimeout(() => { 442 | this.realtime.createSocket(); 443 | }, 50); 444 | }, 445 | getTimeout: () => { 446 | switch (true) { 447 | case this.realtime.reconnectAttempts < 5: 448 | return 1000; 449 | case this.realtime.reconnectAttempts < 15: 450 | return 5000; 451 | case this.realtime.reconnectAttempts < 100: 452 | return 10_000; 453 | default: 454 | return 60_000; 455 | } 456 | }, 457 | createHeartbeat: () => { 458 | if (this.realtime.heartbeat) { 459 | clearTimeout(this.realtime.heartbeat); 460 | } 461 | 462 | this.realtime.heartbeat = window?.setInterval(() => { 463 | this.realtime.socket?.send(JSON.stringify({ 464 | type: 'ping' 465 | })); 466 | }, 20_000); 467 | }, 468 | createSocket: () => { 469 | if (this.realtime.channels.size < 1) { 470 | this.realtime.reconnect = false; 471 | this.realtime.socket?.close(); 472 | return; 473 | } 474 | 475 | const channels = new URLSearchParams(); 476 | channels.set('project', this.config.project); 477 | this.realtime.channels.forEach(channel => { 478 | channels.append('channels[]', channel); 479 | }); 480 | 481 | const url = this.config.endpointRealtime + '/realtime?' + channels.toString(); 482 | 483 | if ( 484 | url !== this.realtime.url || // Check if URL is present 485 | !this.realtime.socket || // Check if WebSocket has not been created 486 | this.realtime.socket?.readyState > WebSocket.OPEN // Check if WebSocket is CLOSING (3) or CLOSED (4) 487 | ) { 488 | if ( 489 | this.realtime.socket && 490 | this.realtime.socket?.readyState < WebSocket.CLOSING // Close WebSocket if it is CONNECTING (0) or OPEN (1) 491 | ) { 492 | this.realtime.reconnect = false; 493 | this.realtime.socket.close(); 494 | } 495 | 496 | this.realtime.url = url; 497 | this.realtime.socket = new WebSocket(url); 498 | this.realtime.socket.addEventListener('message', this.realtime.onMessage); 499 | this.realtime.socket.addEventListener('open', _event => { 500 | this.realtime.reconnectAttempts = 0; 501 | this.realtime.createHeartbeat(); 502 | }); 503 | this.realtime.socket.addEventListener('close', event => { 504 | if ( 505 | !this.realtime.reconnect || 506 | ( 507 | this.realtime?.lastMessage?.type === 'error' && // Check if last message was of type error 508 | (this.realtime?.lastMessage.data).code === 1008 // Check for policy violation 1008 509 | ) 510 | ) { 511 | this.realtime.reconnect = true; 512 | return; 513 | } 514 | 515 | const timeout = this.realtime.getTimeout(); 516 | console.error(`Realtime got disconnected. Reconnect will be attempted in ${timeout / 1000} seconds.`, event.reason); 517 | 518 | setTimeout(() => { 519 | this.realtime.reconnectAttempts++; 520 | this.realtime.createSocket(); 521 | }, timeout); 522 | }) 523 | } 524 | }, 525 | onMessage: (event) => { 526 | try { 527 | const message: RealtimeResponse = JSON.parse(event.data); 528 | this.realtime.lastMessage = message; 529 | switch (message.type) { 530 | case 'connected': 531 | const cookie = JSON.parse(window.localStorage.getItem('cookieFallback') ?? '{}'); 532 | const session = cookie?.[`a_session_${this.config.project}`]; 533 | const messageData = message.data; 534 | 535 | if (session && !messageData.user) { 536 | this.realtime.socket?.send(JSON.stringify({ 537 | type: 'authentication', 538 | data: { 539 | session 540 | } 541 | })); 542 | } 543 | break; 544 | case 'event': 545 | let data = >message.data; 546 | if (data?.channels) { 547 | const isSubscribed = data.channels.some(channel => this.realtime.channels.has(channel)); 548 | if (!isSubscribed) return; 549 | this.realtime.subscriptions.forEach(subscription => { 550 | if (data.channels.some(channel => subscription.channels.includes(channel))) { 551 | setTimeout(() => subscription.callback(data)); 552 | } 553 | }) 554 | } 555 | break; 556 | case 'pong': 557 | break; // Handle pong response if needed 558 | case 'error': 559 | throw message.data; 560 | default: 561 | break; 562 | } 563 | } catch (e) { 564 | console.error(e); 565 | } 566 | }, 567 | cleanUp: channels => { 568 | this.realtime.channels.forEach(channel => { 569 | if (channels.includes(channel)) { 570 | let found = Array.from(this.realtime.subscriptions).some(([_key, subscription] )=> { 571 | return subscription.channels.includes(channel); 572 | }) 573 | 574 | if (!found) { 575 | this.realtime.channels.delete(channel); 576 | } 577 | } 578 | }) 579 | } 580 | } 581 | 582 | /** 583 | * Subscribes to Appwrite events and passes you the payload in realtime. 584 | * 585 | * @param {string|string[]} channels 586 | * Channel to subscribe - pass a single channel as a string or multiple with an array of strings. 587 | * 588 | * Possible channels are: 589 | * - account 590 | * - collections 591 | * - collections.[ID] 592 | * - collections.[ID].documents 593 | * - documents 594 | * - documents.[ID] 595 | * - files 596 | * - files.[ID] 597 | * - executions 598 | * - executions.[ID] 599 | * - functions.[ID] 600 | * - teams 601 | * - teams.[ID] 602 | * - memberships 603 | * - memberships.[ID] 604 | * @param {(payload: RealtimeMessage) => void} callback Is called on every realtime update. 605 | * @returns {() => void} Unsubscribes from events. 606 | */ 607 | subscribe(channels: string | string[], callback: (payload: RealtimeResponseEvent) => void): () => void { 608 | let channelArray = typeof channels === 'string' ? [channels] : channels; 609 | channelArray.forEach(channel => this.realtime.channels.add(channel)); 610 | 611 | const counter = this.realtime.subscriptionsCounter++; 612 | this.realtime.subscriptions.set(counter, { 613 | channels: channelArray, 614 | callback 615 | }); 616 | 617 | this.realtime.connect(); 618 | 619 | return () => { 620 | this.realtime.subscriptions.delete(counter); 621 | this.realtime.cleanUp(channelArray); 622 | this.realtime.connect(); 623 | } 624 | } 625 | 626 | prepareRequest(method: string, url: URL, headers: Headers = {}, params: Payload = {}): { uri: string, options: RequestInit } { 627 | method = method.toUpperCase(); 628 | 629 | headers = Object.assign({}, this.headers, headers); 630 | 631 | if (typeof window !== 'undefined' && window.localStorage) { 632 | const cookieFallback = window.localStorage.getItem('cookieFallback'); 633 | if (cookieFallback) { 634 | headers['X-Fallback-Cookies'] = cookieFallback; 635 | } 636 | } 637 | 638 | let options: RequestInit = { 639 | method, 640 | headers, 641 | }; 642 | 643 | if (headers['X-Appwrite-Dev-Key'] === undefined) { 644 | options.credentials = 'include'; 645 | } 646 | 647 | if (method === 'GET') { 648 | for (const [key, value] of Object.entries(Client.flatten(params))) { 649 | url.searchParams.append(key, value); 650 | } 651 | } else { 652 | switch (headers['content-type']) { 653 | case 'application/json': 654 | options.body = JSON.stringify(params); 655 | break; 656 | 657 | case 'multipart/form-data': 658 | const formData = new FormData(); 659 | 660 | for (const [key, value] of Object.entries(params)) { 661 | if (value instanceof File) { 662 | formData.append(key, value, value.name); 663 | } else if (Array.isArray(value)) { 664 | for (const nestedValue of value) { 665 | formData.append(`${key}[]`, nestedValue); 666 | } 667 | } else { 668 | formData.append(key, value); 669 | } 670 | } 671 | 672 | options.body = formData; 673 | delete headers['content-type']; 674 | break; 675 | } 676 | } 677 | 678 | return { uri: url.toString(), options }; 679 | } 680 | 681 | async chunkedUpload(method: string, url: URL, headers: Headers = {}, originalPayload: Payload = {}, onProgress: (progress: UploadProgress) => void) { 682 | const file = Object.values(originalPayload).find((value) => value instanceof File); 683 | 684 | if (!file) { 685 | throw new Error('File not found in payload'); 686 | } 687 | 688 | if (file.size <= Client.CHUNK_SIZE) { 689 | return await this.call(method, url, headers, originalPayload); 690 | } 691 | 692 | let start = 0; 693 | let response = null; 694 | 695 | while (start < file.size) { 696 | let end = start + Client.CHUNK_SIZE; // Prepare end for the next chunk 697 | if (end >= file.size) { 698 | end = file.size; // Adjust for the last chunk to include the last byte 699 | } 700 | 701 | headers['content-range'] = `bytes ${start}-${end-1}/${file.size}`; 702 | const chunk = file.slice(start, end); 703 | 704 | let payload = { ...originalPayload, file: new File([chunk], file.name)}; 705 | 706 | response = await this.call(method, url, headers, payload); 707 | 708 | if (onProgress && typeof onProgress === 'function') { 709 | onProgress({ 710 | $id: response.$id, 711 | progress: Math.round((end / file.size) * 100), 712 | sizeUploaded: end, 713 | chunksTotal: Math.ceil(file.size / Client.CHUNK_SIZE), 714 | chunksUploaded: Math.ceil(end / Client.CHUNK_SIZE) 715 | }); 716 | } 717 | 718 | if (response && response.$id) { 719 | headers['x-appwrite-id'] = response.$id; 720 | } 721 | 722 | start = end; 723 | } 724 | 725 | return response; 726 | } 727 | 728 | async ping(): Promise { 729 | return this.call('GET', new URL(this.config.endpoint + '/ping')); 730 | } 731 | 732 | async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json'): Promise { 733 | const { uri, options } = this.prepareRequest(method, url, headers, params); 734 | 735 | let data: any = null; 736 | 737 | const response = await fetch(uri, options); 738 | 739 | // type opaque: No-CORS, different-origin response (CORS-issue) 740 | if (response.type === 'opaque') { 741 | throw new AppwriteException( 742 | `Invalid Origin. Register your new client (${window.location.host}) as a new Web platform on your project console dashboard`, 743 | 403, 744 | "forbidden", 745 | "" 746 | ); 747 | } 748 | 749 | const warnings = response.headers.get('x-appwrite-warning'); 750 | if (warnings) { 751 | warnings.split(';').forEach((warning: string) => console.warn('Warning: ' + warning)); 752 | } 753 | 754 | if (response.headers.get('content-type')?.includes('application/json')) { 755 | data = await response.json(); 756 | } else if (responseType === 'arrayBuffer') { 757 | data = await response.arrayBuffer(); 758 | } else { 759 | data = { 760 | message: await response.text() 761 | }; 762 | } 763 | 764 | if (400 <= response.status) { 765 | let responseText = ''; 766 | if (response.headers.get('content-type')?.includes('application/json') || responseType === 'arrayBuffer') { 767 | responseText = JSON.stringify(data); 768 | } else { 769 | responseText = data?.message; 770 | } 771 | throw new AppwriteException(data?.message, response.status, data?.type, responseText); 772 | } 773 | 774 | const cookieFallback = response.headers.get('X-Fallback-Cookies'); 775 | 776 | if (typeof window !== 'undefined' && window.localStorage && cookieFallback) { 777 | window.console.warn('Appwrite is using localStorage for session management. Increase your security by adding a custom domain as your API endpoint.'); 778 | window.localStorage.setItem('cookieFallback', cookieFallback); 779 | } 780 | 781 | return data; 782 | } 783 | 784 | static flatten(data: Payload, prefix = ''): Payload { 785 | let output: Payload = {}; 786 | 787 | for (const [key, value] of Object.entries(data)) { 788 | let finalKey = prefix ? prefix + '[' + key +']' : key; 789 | if (Array.isArray(value)) { 790 | output = { ...output, ...Client.flatten(value, finalKey) }; 791 | } else { 792 | output[finalKey] = value; 793 | } 794 | } 795 | 796 | return output; 797 | } 798 | } 799 | 800 | export { Client, AppwriteException }; 801 | export { Query } from './query'; 802 | export type { Models, Payload, UploadProgress }; 803 | export type { RealtimeResponseEvent }; 804 | export type { QueryTypes, QueryTypesList } from './query'; 805 | -------------------------------------------------------------------------------- /src/enums/authentication-factor.ts: -------------------------------------------------------------------------------- 1 | export enum AuthenticationFactor { 2 | Email = 'email', 3 | Phone = 'phone', 4 | Totp = 'totp', 5 | Recoverycode = 'recoverycode', 6 | } -------------------------------------------------------------------------------- /src/enums/authenticator-type.ts: -------------------------------------------------------------------------------- 1 | export enum AuthenticatorType { 2 | Totp = 'totp', 3 | } -------------------------------------------------------------------------------- /src/enums/browser.ts: -------------------------------------------------------------------------------- 1 | export enum Browser { 2 | AvantBrowser = 'aa', 3 | AndroidWebViewBeta = 'an', 4 | GoogleChrome = 'ch', 5 | GoogleChromeIOS = 'ci', 6 | GoogleChromeMobile = 'cm', 7 | Chromium = 'cr', 8 | MozillaFirefox = 'ff', 9 | Safari = 'sf', 10 | MobileSafari = 'mf', 11 | MicrosoftEdge = 'ps', 12 | MicrosoftEdgeIOS = 'oi', 13 | OperaMini = 'om', 14 | Opera = 'op', 15 | OperaNext = 'on', 16 | } -------------------------------------------------------------------------------- /src/enums/credit-card.ts: -------------------------------------------------------------------------------- 1 | export enum CreditCard { 2 | AmericanExpress = 'amex', 3 | Argencard = 'argencard', 4 | Cabal = 'cabal', 5 | Cencosud = 'cencosud', 6 | DinersClub = 'diners', 7 | Discover = 'discover', 8 | Elo = 'elo', 9 | Hipercard = 'hipercard', 10 | JCB = 'jcb', 11 | Mastercard = 'mastercard', 12 | Naranja = 'naranja', 13 | TarjetaShopping = 'targeta-shopping', 14 | UnionChinaPay = 'union-china-pay', 15 | Visa = 'visa', 16 | MIR = 'mir', 17 | Maestro = 'maestro', 18 | Rupay = 'rupay', 19 | } -------------------------------------------------------------------------------- /src/enums/execution-method.ts: -------------------------------------------------------------------------------- 1 | export enum ExecutionMethod { 2 | GET = 'GET', 3 | POST = 'POST', 4 | PUT = 'PUT', 5 | PATCH = 'PATCH', 6 | DELETE = 'DELETE', 7 | OPTIONS = 'OPTIONS', 8 | } -------------------------------------------------------------------------------- /src/enums/flag.ts: -------------------------------------------------------------------------------- 1 | export enum Flag { 2 | Afghanistan = 'af', 3 | Angola = 'ao', 4 | Albania = 'al', 5 | Andorra = 'ad', 6 | UnitedArabEmirates = 'ae', 7 | Argentina = 'ar', 8 | Armenia = 'am', 9 | AntiguaAndBarbuda = 'ag', 10 | Australia = 'au', 11 | Austria = 'at', 12 | Azerbaijan = 'az', 13 | Burundi = 'bi', 14 | Belgium = 'be', 15 | Benin = 'bj', 16 | BurkinaFaso = 'bf', 17 | Bangladesh = 'bd', 18 | Bulgaria = 'bg', 19 | Bahrain = 'bh', 20 | Bahamas = 'bs', 21 | BosniaAndHerzegovina = 'ba', 22 | Belarus = 'by', 23 | Belize = 'bz', 24 | Bolivia = 'bo', 25 | Brazil = 'br', 26 | Barbados = 'bb', 27 | BruneiDarussalam = 'bn', 28 | Bhutan = 'bt', 29 | Botswana = 'bw', 30 | CentralAfricanRepublic = 'cf', 31 | Canada = 'ca', 32 | Switzerland = 'ch', 33 | Chile = 'cl', 34 | China = 'cn', 35 | CoteDIvoire = 'ci', 36 | Cameroon = 'cm', 37 | DemocraticRepublicOfTheCongo = 'cd', 38 | RepublicOfTheCongo = 'cg', 39 | Colombia = 'co', 40 | Comoros = 'km', 41 | CapeVerde = 'cv', 42 | CostaRica = 'cr', 43 | Cuba = 'cu', 44 | Cyprus = 'cy', 45 | CzechRepublic = 'cz', 46 | Germany = 'de', 47 | Djibouti = 'dj', 48 | Dominica = 'dm', 49 | Denmark = 'dk', 50 | DominicanRepublic = 'do', 51 | Algeria = 'dz', 52 | Ecuador = 'ec', 53 | Egypt = 'eg', 54 | Eritrea = 'er', 55 | Spain = 'es', 56 | Estonia = 'ee', 57 | Ethiopia = 'et', 58 | Finland = 'fi', 59 | Fiji = 'fj', 60 | France = 'fr', 61 | MicronesiaFederatedStatesOf = 'fm', 62 | Gabon = 'ga', 63 | UnitedKingdom = 'gb', 64 | Georgia = 'ge', 65 | Ghana = 'gh', 66 | Guinea = 'gn', 67 | Gambia = 'gm', 68 | GuineaBissau = 'gw', 69 | EquatorialGuinea = 'gq', 70 | Greece = 'gr', 71 | Grenada = 'gd', 72 | Guatemala = 'gt', 73 | Guyana = 'gy', 74 | Honduras = 'hn', 75 | Croatia = 'hr', 76 | Haiti = 'ht', 77 | Hungary = 'hu', 78 | Indonesia = 'id', 79 | India = 'in', 80 | Ireland = 'ie', 81 | IranIslamicRepublicOf = 'ir', 82 | Iraq = 'iq', 83 | Iceland = 'is', 84 | Israel = 'il', 85 | Italy = 'it', 86 | Jamaica = 'jm', 87 | Jordan = 'jo', 88 | Japan = 'jp', 89 | Kazakhstan = 'kz', 90 | Kenya = 'ke', 91 | Kyrgyzstan = 'kg', 92 | Cambodia = 'kh', 93 | Kiribati = 'ki', 94 | SaintKittsAndNevis = 'kn', 95 | SouthKorea = 'kr', 96 | Kuwait = 'kw', 97 | LaoPeopleSDemocraticRepublic = 'la', 98 | Lebanon = 'lb', 99 | Liberia = 'lr', 100 | Libya = 'ly', 101 | SaintLucia = 'lc', 102 | Liechtenstein = 'li', 103 | SriLanka = 'lk', 104 | Lesotho = 'ls', 105 | Lithuania = 'lt', 106 | Luxembourg = 'lu', 107 | Latvia = 'lv', 108 | Morocco = 'ma', 109 | Monaco = 'mc', 110 | Moldova = 'md', 111 | Madagascar = 'mg', 112 | Maldives = 'mv', 113 | Mexico = 'mx', 114 | MarshallIslands = 'mh', 115 | NorthMacedonia = 'mk', 116 | Mali = 'ml', 117 | Malta = 'mt', 118 | Myanmar = 'mm', 119 | Montenegro = 'me', 120 | Mongolia = 'mn', 121 | Mozambique = 'mz', 122 | Mauritania = 'mr', 123 | Mauritius = 'mu', 124 | Malawi = 'mw', 125 | Malaysia = 'my', 126 | Namibia = 'na', 127 | Niger = 'ne', 128 | Nigeria = 'ng', 129 | Nicaragua = 'ni', 130 | Netherlands = 'nl', 131 | Norway = 'no', 132 | Nepal = 'np', 133 | Nauru = 'nr', 134 | NewZealand = 'nz', 135 | Oman = 'om', 136 | Pakistan = 'pk', 137 | Panama = 'pa', 138 | Peru = 'pe', 139 | Philippines = 'ph', 140 | Palau = 'pw', 141 | PapuaNewGuinea = 'pg', 142 | Poland = 'pl', 143 | FrenchPolynesia = 'pf', 144 | NorthKorea = 'kp', 145 | Portugal = 'pt', 146 | Paraguay = 'py', 147 | Qatar = 'qa', 148 | Romania = 'ro', 149 | Russia = 'ru', 150 | Rwanda = 'rw', 151 | SaudiArabia = 'sa', 152 | Sudan = 'sd', 153 | Senegal = 'sn', 154 | Singapore = 'sg', 155 | SolomonIslands = 'sb', 156 | SierraLeone = 'sl', 157 | ElSalvador = 'sv', 158 | SanMarino = 'sm', 159 | Somalia = 'so', 160 | Serbia = 'rs', 161 | SouthSudan = 'ss', 162 | SaoTomeAndPrincipe = 'st', 163 | Suriname = 'sr', 164 | Slovakia = 'sk', 165 | Slovenia = 'si', 166 | Sweden = 'se', 167 | Eswatini = 'sz', 168 | Seychelles = 'sc', 169 | Syria = 'sy', 170 | Chad = 'td', 171 | Togo = 'tg', 172 | Thailand = 'th', 173 | Tajikistan = 'tj', 174 | Turkmenistan = 'tm', 175 | TimorLeste = 'tl', 176 | Tonga = 'to', 177 | TrinidadAndTobago = 'tt', 178 | Tunisia = 'tn', 179 | Turkey = 'tr', 180 | Tuvalu = 'tv', 181 | Tanzania = 'tz', 182 | Uganda = 'ug', 183 | Ukraine = 'ua', 184 | Uruguay = 'uy', 185 | UnitedStates = 'us', 186 | Uzbekistan = 'uz', 187 | VaticanCity = 'va', 188 | SaintVincentAndTheGrenadines = 'vc', 189 | Venezuela = 've', 190 | Vietnam = 'vn', 191 | Vanuatu = 'vu', 192 | Samoa = 'ws', 193 | Yemen = 'ye', 194 | SouthAfrica = 'za', 195 | Zambia = 'zm', 196 | Zimbabwe = 'zw', 197 | } -------------------------------------------------------------------------------- /src/enums/image-format.ts: -------------------------------------------------------------------------------- 1 | export enum ImageFormat { 2 | Jpg = 'jpg', 3 | Jpeg = 'jpeg', 4 | Png = 'png', 5 | Webp = 'webp', 6 | Heic = 'heic', 7 | Avif = 'avif', 8 | } -------------------------------------------------------------------------------- /src/enums/image-gravity.ts: -------------------------------------------------------------------------------- 1 | export enum ImageGravity { 2 | Center = 'center', 3 | Topleft = 'top-left', 4 | Top = 'top', 5 | Topright = 'top-right', 6 | Left = 'left', 7 | Right = 'right', 8 | Bottomleft = 'bottom-left', 9 | Bottom = 'bottom', 10 | Bottomright = 'bottom-right', 11 | } -------------------------------------------------------------------------------- /src/enums/o-auth-provider.ts: -------------------------------------------------------------------------------- 1 | export enum OAuthProvider { 2 | Amazon = 'amazon', 3 | Apple = 'apple', 4 | Auth0 = 'auth0', 5 | Authentik = 'authentik', 6 | Autodesk = 'autodesk', 7 | Bitbucket = 'bitbucket', 8 | Bitly = 'bitly', 9 | Box = 'box', 10 | Dailymotion = 'dailymotion', 11 | Discord = 'discord', 12 | Disqus = 'disqus', 13 | Dropbox = 'dropbox', 14 | Etsy = 'etsy', 15 | Facebook = 'facebook', 16 | Figma = 'figma', 17 | Github = 'github', 18 | Gitlab = 'gitlab', 19 | Google = 'google', 20 | Linkedin = 'linkedin', 21 | Microsoft = 'microsoft', 22 | Notion = 'notion', 23 | Oidc = 'oidc', 24 | Okta = 'okta', 25 | Paypal = 'paypal', 26 | PaypalSandbox = 'paypalSandbox', 27 | Podio = 'podio', 28 | Salesforce = 'salesforce', 29 | Slack = 'slack', 30 | Spotify = 'spotify', 31 | Stripe = 'stripe', 32 | Tradeshift = 'tradeshift', 33 | TradeshiftBox = 'tradeshiftBox', 34 | Twitch = 'twitch', 35 | Wordpress = 'wordpress', 36 | Yahoo = 'yahoo', 37 | Yammer = 'yammer', 38 | Yandex = 'yandex', 39 | Zoho = 'zoho', 40 | Zoom = 'zoom', 41 | Mock = 'mock', 42 | } -------------------------------------------------------------------------------- /src/id.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Helper class to generate ID strings for resources. 3 | */ 4 | export class ID { 5 | /** 6 | * Generate an hex ID based on timestamp. 7 | * Recreated from https://www.php.net/manual/en/function.uniqid.php 8 | * 9 | * @returns {string} 10 | */ 11 | static #hexTimestamp(): string { 12 | const now = new Date(); 13 | const sec = Math.floor(now.getTime() / 1000); 14 | const msec = now.getMilliseconds(); 15 | 16 | // Convert to hexadecimal 17 | const hexTimestamp = sec.toString(16) + msec.toString(16).padStart(5, '0'); 18 | return hexTimestamp; 19 | } 20 | 21 | /** 22 | * Uses the provided ID as the ID for the resource. 23 | * 24 | * @param {string} id 25 | * @returns {string} 26 | */ 27 | public static custom(id: string): string { 28 | return id 29 | } 30 | 31 | /** 32 | * Have Appwrite generate a unique ID for you. 33 | * 34 | * @param {number} padding. Default is 7. 35 | * @returns {string} 36 | */ 37 | public static unique(padding: number = 7): string { 38 | // Generate a unique ID with padding to have a longer ID 39 | const baseId = ID.#hexTimestamp(); 40 | let randomPadding = ''; 41 | for (let i = 0; i < padding; i++) { 42 | const randomHexDigit = Math.floor(Math.random() * 16).toString(16); 43 | randomPadding += randomHexDigit; 44 | } 45 | return baseId + randomPadding; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Appwrite Web SDK 3 | * 4 | * This SDK is compatible with Appwrite server version 1.7.x. 5 | * For older versions, please check 6 | * [previous releases](https://github.com/appwrite/sdk-for-web/releases). 7 | */ 8 | export { Client, Query, AppwriteException } from './client'; 9 | export { Account } from './services/account'; 10 | export { Avatars } from './services/avatars'; 11 | export { Databases } from './services/databases'; 12 | export { Functions } from './services/functions'; 13 | export { Graphql } from './services/graphql'; 14 | export { Locale } from './services/locale'; 15 | export { Messaging } from './services/messaging'; 16 | export { Storage } from './services/storage'; 17 | export { Teams } from './services/teams'; 18 | export type { Models, Payload, RealtimeResponseEvent, UploadProgress } from './client'; 19 | export type { QueryTypes, QueryTypesList } from './query'; 20 | export { Permission } from './permission'; 21 | export { Role } from './role'; 22 | export { ID } from './id'; 23 | export { AuthenticatorType } from './enums/authenticator-type'; 24 | export { AuthenticationFactor } from './enums/authentication-factor'; 25 | export { OAuthProvider } from './enums/o-auth-provider'; 26 | export { Browser } from './enums/browser'; 27 | export { CreditCard } from './enums/credit-card'; 28 | export { Flag } from './enums/flag'; 29 | export { ExecutionMethod } from './enums/execution-method'; 30 | export { ImageGravity } from './enums/image-gravity'; 31 | export { ImageFormat } from './enums/image-format'; 32 | -------------------------------------------------------------------------------- /src/permission.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Helper class to generate permission strings for resources. 3 | */ 4 | export class Permission { 5 | /** 6 | * Generate read permission string for the provided role. 7 | * 8 | * @param {string} role 9 | * @returns {string} 10 | */ 11 | static read = (role: string): string => { 12 | return `read("${role}")`; 13 | } 14 | 15 | /** 16 | * Generate write permission string for the provided role. 17 | * 18 | * This is an alias of update, delete, and possibly create. 19 | * Don't use write in combination with update, delete, or create. 20 | * 21 | * @param {string} role 22 | * @returns {string} 23 | */ 24 | static write = (role: string): string => { 25 | return `write("${role}")`; 26 | } 27 | 28 | /** 29 | * Generate create permission string for the provided role. 30 | * 31 | * @param {string} role 32 | * @returns {string} 33 | */ 34 | static create = (role: string): string => { 35 | return `create("${role}")`; 36 | } 37 | 38 | /** 39 | * Generate update permission string for the provided role. 40 | * 41 | * @param {string} role 42 | * @returns {string} 43 | */ 44 | static update = (role: string): string => { 45 | return `update("${role}")`; 46 | } 47 | 48 | /** 49 | * Generate delete permission string for the provided role. 50 | * 51 | * @param {string} role 52 | * @returns {string} 53 | */ 54 | static delete = (role: string): string => { 55 | return `delete("${role}")`; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/query.ts: -------------------------------------------------------------------------------- 1 | type QueryTypesSingle = string | number | boolean; 2 | export type QueryTypesList = string[] | number[] | boolean[] | Query[]; 3 | export type QueryTypes = QueryTypesSingle | QueryTypesList; 4 | type AttributesTypes = string | string[]; 5 | 6 | /** 7 | * Helper class to generate query strings. 8 | */ 9 | export class Query { 10 | method: string; 11 | attribute: AttributesTypes | undefined; 12 | values: QueryTypesList | undefined; 13 | 14 | /** 15 | * Constructor for Query class. 16 | * 17 | * @param {string} method 18 | * @param {AttributesTypes} attribute 19 | * @param {QueryTypes} values 20 | */ 21 | constructor( 22 | method: string, 23 | attribute?: AttributesTypes, 24 | values?: QueryTypes 25 | ) { 26 | this.method = method; 27 | this.attribute = attribute; 28 | 29 | if (values !== undefined) { 30 | if (Array.isArray(values)) { 31 | this.values = values; 32 | } else { 33 | this.values = [values] as QueryTypesList; 34 | } 35 | } 36 | } 37 | 38 | /** 39 | * Convert the query object to a JSON string. 40 | * 41 | * @returns {string} 42 | */ 43 | toString(): string { 44 | return JSON.stringify({ 45 | method: this.method, 46 | attribute: this.attribute, 47 | values: this.values, 48 | }); 49 | } 50 | 51 | /** 52 | * Filter resources where attribute is equal to value. 53 | * 54 | * @param {string} attribute 55 | * @param {QueryTypes} value 56 | * @returns {string} 57 | */ 58 | static equal = (attribute: string, value: QueryTypes): string => 59 | new Query("equal", attribute, value).toString(); 60 | 61 | /** 62 | * Filter resources where attribute is not equal to value. 63 | * 64 | * @param {string} attribute 65 | * @param {QueryTypes} value 66 | * @returns {string} 67 | */ 68 | static notEqual = (attribute: string, value: QueryTypes): string => 69 | new Query("notEqual", attribute, value).toString(); 70 | 71 | /** 72 | * Filter resources where attribute is less than value. 73 | * 74 | * @param {string} attribute 75 | * @param {QueryTypes} value 76 | * @returns {string} 77 | */ 78 | static lessThan = (attribute: string, value: QueryTypes): string => 79 | new Query("lessThan", attribute, value).toString(); 80 | 81 | /** 82 | * Filter resources where attribute is less than or equal to value. 83 | * 84 | * @param {string} attribute 85 | * @param {QueryTypes} value 86 | * @returns {string} 87 | */ 88 | static lessThanEqual = (attribute: string, value: QueryTypes): string => 89 | new Query("lessThanEqual", attribute, value).toString(); 90 | 91 | /** 92 | * Filter resources where attribute is greater than value. 93 | * 94 | * @param {string} attribute 95 | * @param {QueryTypes} value 96 | * @returns {string} 97 | */ 98 | static greaterThan = (attribute: string, value: QueryTypes): string => 99 | new Query("greaterThan", attribute, value).toString(); 100 | 101 | /** 102 | * Filter resources where attribute is greater than or equal to value. 103 | * 104 | * @param {string} attribute 105 | * @param {QueryTypes} value 106 | * @returns {string} 107 | */ 108 | static greaterThanEqual = (attribute: string, value: QueryTypes): string => 109 | new Query("greaterThanEqual", attribute, value).toString(); 110 | 111 | /** 112 | * Filter resources where attribute is null. 113 | * 114 | * @param {string} attribute 115 | * @returns {string} 116 | */ 117 | static isNull = (attribute: string): string => 118 | new Query("isNull", attribute).toString(); 119 | 120 | /** 121 | * Filter resources where attribute is not null. 122 | * 123 | * @param {string} attribute 124 | * @returns {string} 125 | */ 126 | static isNotNull = (attribute: string): string => 127 | new Query("isNotNull", attribute).toString(); 128 | 129 | /** 130 | * Filter resources where attribute is between start and end (inclusive). 131 | * 132 | * @param {string} attribute 133 | * @param {string | number} start 134 | * @param {string | number} end 135 | * @returns {string} 136 | */ 137 | static between = (attribute: string, start: string | number, end: string | number): string => 138 | new Query("between", attribute, [start, end] as QueryTypesList).toString(); 139 | 140 | /** 141 | * Filter resources where attribute starts with value. 142 | * 143 | * @param {string} attribute 144 | * @param {string} value 145 | * @returns {string} 146 | */ 147 | static startsWith = (attribute: string, value: string): string => 148 | new Query("startsWith", attribute, value).toString(); 149 | 150 | /** 151 | * Filter resources where attribute ends with value. 152 | * 153 | * @param {string} attribute 154 | * @param {string} value 155 | * @returns {string} 156 | */ 157 | static endsWith = (attribute: string, value: string): string => 158 | new Query("endsWith", attribute, value).toString(); 159 | 160 | /** 161 | * Specify which attributes should be returned by the API call. 162 | * 163 | * @param {string[]} attributes 164 | * @returns {string} 165 | */ 166 | static select = (attributes: string[]): string => 167 | new Query("select", undefined, attributes).toString(); 168 | 169 | /** 170 | * Filter resources by searching attribute for value. 171 | * A fulltext index on attribute is required for this query to work. 172 | * 173 | * @param {string} attribute 174 | * @param {string} value 175 | * @returns {string} 176 | */ 177 | static search = (attribute: string, value: string): string => 178 | new Query("search", attribute, value).toString(); 179 | 180 | /** 181 | * Sort results by attribute descending. 182 | * 183 | * @param {string} attribute 184 | * @returns {string} 185 | */ 186 | static orderDesc = (attribute: string): string => 187 | new Query("orderDesc", attribute).toString(); 188 | 189 | /** 190 | * Sort results by attribute ascending. 191 | * 192 | * @param {string} attribute 193 | * @returns {string} 194 | */ 195 | static orderAsc = (attribute: string): string => 196 | new Query("orderAsc", attribute).toString(); 197 | 198 | /** 199 | * Return results after documentId. 200 | * 201 | * @param {string} documentId 202 | * @returns {string} 203 | */ 204 | static cursorAfter = (documentId: string): string => 205 | new Query("cursorAfter", undefined, documentId).toString(); 206 | 207 | /** 208 | * Return results before documentId. 209 | * 210 | * @param {string} documentId 211 | * @returns {string} 212 | */ 213 | static cursorBefore = (documentId: string): string => 214 | new Query("cursorBefore", undefined, documentId).toString(); 215 | 216 | /** 217 | * Return only limit results. 218 | * 219 | * @param {number} limit 220 | * @returns {string} 221 | */ 222 | static limit = (limit: number): string => 223 | new Query("limit", undefined, limit).toString(); 224 | 225 | /** 226 | * Filter resources by skipping the first offset results. 227 | * 228 | * @param {number} offset 229 | * @returns {string} 230 | */ 231 | static offset = (offset: number): string => 232 | new Query("offset", undefined, offset).toString(); 233 | 234 | /** 235 | * Filter resources where attribute contains the specified value. 236 | * 237 | * @param {string} attribute 238 | * @param {string | string[]} value 239 | * @returns {string} 240 | */ 241 | static contains = (attribute: string, value: string | string[]): string => 242 | new Query("contains", attribute, value).toString(); 243 | 244 | /** 245 | * Combine multiple queries using logical OR operator. 246 | * 247 | * @param {string[]} queries 248 | * @returns {string} 249 | */ 250 | static or = (queries: string[]) => 251 | new Query("or", undefined, queries.map((query) => JSON.parse(query))).toString(); 252 | 253 | /** 254 | * Combine multiple queries using logical AND operator. 255 | * 256 | * @param {string[]} queries 257 | * @returns {string} 258 | */ 259 | static and = (queries: string[]) => 260 | new Query("and", undefined, queries.map((query) => JSON.parse(query))).toString(); 261 | } 262 | -------------------------------------------------------------------------------- /src/role.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Helper class to generate role strings for `Permission`. 3 | */ 4 | export class Role { 5 | 6 | /** 7 | * Grants access to anyone. 8 | * 9 | * This includes authenticated and unauthenticated users. 10 | * 11 | * @returns {string} 12 | */ 13 | public static any(): string { 14 | return 'any' 15 | } 16 | 17 | /** 18 | * Grants access to a specific user by user ID. 19 | * 20 | * You can optionally pass verified or unverified for 21 | * `status` to target specific types of users. 22 | * 23 | * @param {string} id 24 | * @param {string} status 25 | * @returns {string} 26 | */ 27 | public static user(id: string, status: string = ''): string { 28 | if (status === '') { 29 | return `user:${id}` 30 | } 31 | return `user:${id}/${status}` 32 | } 33 | 34 | /** 35 | * Grants access to any authenticated or anonymous user. 36 | * 37 | * You can optionally pass verified or unverified for 38 | * `status` to target specific types of users. 39 | * 40 | * @param {string} status 41 | * @returns {string} 42 | */ 43 | public static users(status: string = ''): string { 44 | if (status === '') { 45 | return 'users' 46 | } 47 | return `users/${status}` 48 | } 49 | 50 | /** 51 | * Grants access to any guest user without a session. 52 | * 53 | * Authenticated users don't have access to this role. 54 | * 55 | * @returns {string} 56 | */ 57 | public static guests(): string { 58 | return 'guests' 59 | } 60 | 61 | /** 62 | * Grants access to a team by team ID. 63 | * 64 | * You can optionally pass a role for `role` to target 65 | * team members with the specified role. 66 | * 67 | * @param {string} id 68 | * @param {string} role 69 | * @returns {string} 70 | */ 71 | public static team(id: string, role: string = ''): string { 72 | if (role === '') { 73 | return `team:${id}` 74 | } 75 | return `team:${id}/${role}` 76 | } 77 | 78 | /** 79 | * Grants access to a specific member of a team. 80 | * 81 | * When the member is removed from the team, they will 82 | * no longer have access. 83 | * 84 | * @param {string} id 85 | * @returns {string} 86 | */ 87 | public static member(id: string): string { 88 | return `member:${id}` 89 | } 90 | 91 | /** 92 | * Grants access to a user with the specified label. 93 | * 94 | * @param {string} name 95 | * @returns {string} 96 | */ 97 | public static label(name: string): string { 98 | return `label:${name}` 99 | } 100 | } -------------------------------------------------------------------------------- /src/service.ts: -------------------------------------------------------------------------------- 1 | import { Client } from './client'; 2 | import type { Payload } from './client'; 3 | 4 | export class Service { 5 | /** 6 | * The size for chunked uploads in bytes. 7 | */ 8 | static CHUNK_SIZE = 5*1024*1024; // 5MB 9 | 10 | client: Client; 11 | 12 | constructor(client: Client) { 13 | this.client = client; 14 | } 15 | 16 | static flatten(data: Payload, prefix = ''): Payload { 17 | let output: Payload = {}; 18 | 19 | for (const [key, value] of Object.entries(data)) { 20 | let finalKey = prefix ? prefix + '[' + key +']' : key; 21 | if (Array.isArray(value)) { 22 | output = { ...output, ...Service.flatten(value, finalKey) }; 23 | } else { 24 | output[finalKey] = value; 25 | } 26 | } 27 | 28 | return output; 29 | } 30 | } -------------------------------------------------------------------------------- /src/services/avatars.ts: -------------------------------------------------------------------------------- 1 | import { Service } from '../service'; 2 | import { AppwriteException, Client, type Payload, UploadProgress } from '../client'; 3 | import type { Models } from '../models'; 4 | import { Browser } from '../enums/browser'; 5 | import { CreditCard } from '../enums/credit-card'; 6 | import { Flag } from '../enums/flag'; 7 | 8 | export class Avatars { 9 | client: Client; 10 | 11 | constructor(client: Client) { 12 | this.client = client; 13 | } 14 | 15 | /** 16 | * You can use this endpoint to show different browser icons to your users. The code argument receives the browser code as it appears in your user [GET /account/sessions](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) endpoint. Use width, height and quality arguments to change the output settings. 17 | 18 | When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px. 19 | * 20 | * @param {Browser} code 21 | * @param {number} width 22 | * @param {number} height 23 | * @param {number} quality 24 | * @throws {AppwriteException} 25 | * @returns {string} 26 | */ 27 | getBrowser(code: Browser, width?: number, height?: number, quality?: number): string { 28 | if (typeof code === 'undefined') { 29 | throw new AppwriteException('Missing required parameter: "code"'); 30 | } 31 | const apiPath = '/avatars/browsers/{code}'.replace('{code}', code); 32 | const payload: Payload = {}; 33 | if (typeof width !== 'undefined') { 34 | payload['width'] = width; 35 | } 36 | if (typeof height !== 'undefined') { 37 | payload['height'] = height; 38 | } 39 | if (typeof quality !== 'undefined') { 40 | payload['quality'] = quality; 41 | } 42 | const uri = new URL(this.client.config.endpoint + apiPath); 43 | 44 | const apiHeaders: { [header: string]: string } = { 45 | } 46 | 47 | payload['project'] = this.client.config.project; 48 | 49 | for (const [key, value] of Object.entries(Service.flatten(payload))) { 50 | uri.searchParams.append(key, value); 51 | } 52 | 53 | return uri.toString(); 54 | } 55 | /** 56 | * The credit card endpoint will return you the icon of the credit card provider you need. Use width, height and quality arguments to change the output settings. 57 | 58 | When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px. 59 | 60 | * 61 | * @param {CreditCard} code 62 | * @param {number} width 63 | * @param {number} height 64 | * @param {number} quality 65 | * @throws {AppwriteException} 66 | * @returns {string} 67 | */ 68 | getCreditCard(code: CreditCard, width?: number, height?: number, quality?: number): string { 69 | if (typeof code === 'undefined') { 70 | throw new AppwriteException('Missing required parameter: "code"'); 71 | } 72 | const apiPath = '/avatars/credit-cards/{code}'.replace('{code}', code); 73 | const payload: Payload = {}; 74 | if (typeof width !== 'undefined') { 75 | payload['width'] = width; 76 | } 77 | if (typeof height !== 'undefined') { 78 | payload['height'] = height; 79 | } 80 | if (typeof quality !== 'undefined') { 81 | payload['quality'] = quality; 82 | } 83 | const uri = new URL(this.client.config.endpoint + apiPath); 84 | 85 | const apiHeaders: { [header: string]: string } = { 86 | } 87 | 88 | payload['project'] = this.client.config.project; 89 | 90 | for (const [key, value] of Object.entries(Service.flatten(payload))) { 91 | uri.searchParams.append(key, value); 92 | } 93 | 94 | return uri.toString(); 95 | } 96 | /** 97 | * Use this endpoint to fetch the favorite icon (AKA favicon) of any remote website URL. 98 | 99 | This endpoint does not follow HTTP redirects. 100 | * 101 | * @param {string} url 102 | * @throws {AppwriteException} 103 | * @returns {string} 104 | */ 105 | getFavicon(url: string): string { 106 | if (typeof url === 'undefined') { 107 | throw new AppwriteException('Missing required parameter: "url"'); 108 | } 109 | const apiPath = '/avatars/favicon'; 110 | const payload: Payload = {}; 111 | if (typeof url !== 'undefined') { 112 | payload['url'] = url; 113 | } 114 | const uri = new URL(this.client.config.endpoint + apiPath); 115 | 116 | const apiHeaders: { [header: string]: string } = { 117 | } 118 | 119 | payload['project'] = this.client.config.project; 120 | 121 | for (const [key, value] of Object.entries(Service.flatten(payload))) { 122 | uri.searchParams.append(key, value); 123 | } 124 | 125 | return uri.toString(); 126 | } 127 | /** 128 | * You can use this endpoint to show different country flags icons to your users. The code argument receives the 2 letter country code. Use width, height and quality arguments to change the output settings. Country codes follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard. 129 | 130 | When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px. 131 | 132 | * 133 | * @param {Flag} code 134 | * @param {number} width 135 | * @param {number} height 136 | * @param {number} quality 137 | * @throws {AppwriteException} 138 | * @returns {string} 139 | */ 140 | getFlag(code: Flag, width?: number, height?: number, quality?: number): string { 141 | if (typeof code === 'undefined') { 142 | throw new AppwriteException('Missing required parameter: "code"'); 143 | } 144 | const apiPath = '/avatars/flags/{code}'.replace('{code}', code); 145 | const payload: Payload = {}; 146 | if (typeof width !== 'undefined') { 147 | payload['width'] = width; 148 | } 149 | if (typeof height !== 'undefined') { 150 | payload['height'] = height; 151 | } 152 | if (typeof quality !== 'undefined') { 153 | payload['quality'] = quality; 154 | } 155 | const uri = new URL(this.client.config.endpoint + apiPath); 156 | 157 | const apiHeaders: { [header: string]: string } = { 158 | } 159 | 160 | payload['project'] = this.client.config.project; 161 | 162 | for (const [key, value] of Object.entries(Service.flatten(payload))) { 163 | uri.searchParams.append(key, value); 164 | } 165 | 166 | return uri.toString(); 167 | } 168 | /** 169 | * Use this endpoint to fetch a remote image URL and crop it to any image size you want. This endpoint is very useful if you need to crop and display remote images in your app or in case you want to make sure a 3rd party image is properly served using a TLS protocol. 170 | 171 | When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 400x400px. 172 | 173 | This endpoint does not follow HTTP redirects. 174 | * 175 | * @param {string} url 176 | * @param {number} width 177 | * @param {number} height 178 | * @throws {AppwriteException} 179 | * @returns {string} 180 | */ 181 | getImage(url: string, width?: number, height?: number): string { 182 | if (typeof url === 'undefined') { 183 | throw new AppwriteException('Missing required parameter: "url"'); 184 | } 185 | const apiPath = '/avatars/image'; 186 | const payload: Payload = {}; 187 | if (typeof url !== 'undefined') { 188 | payload['url'] = url; 189 | } 190 | if (typeof width !== 'undefined') { 191 | payload['width'] = width; 192 | } 193 | if (typeof height !== 'undefined') { 194 | payload['height'] = height; 195 | } 196 | const uri = new URL(this.client.config.endpoint + apiPath); 197 | 198 | const apiHeaders: { [header: string]: string } = { 199 | } 200 | 201 | payload['project'] = this.client.config.project; 202 | 203 | for (const [key, value] of Object.entries(Service.flatten(payload))) { 204 | uri.searchParams.append(key, value); 205 | } 206 | 207 | return uri.toString(); 208 | } 209 | /** 210 | * Use this endpoint to show your user initials avatar icon on your website or app. By default, this route will try to print your logged-in user name or email initials. You can also overwrite the user name if you pass the 'name' parameter. If no name is given and no user is logged, an empty avatar will be returned. 211 | 212 | You can use the color and background params to change the avatar colors. By default, a random theme will be selected. The random theme will persist for the user's initials when reloading the same theme will always return for the same initials. 213 | 214 | When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px. 215 | 216 | * 217 | * @param {string} name 218 | * @param {number} width 219 | * @param {number} height 220 | * @param {string} background 221 | * @throws {AppwriteException} 222 | * @returns {string} 223 | */ 224 | getInitials(name?: string, width?: number, height?: number, background?: string): string { 225 | const apiPath = '/avatars/initials'; 226 | const payload: Payload = {}; 227 | if (typeof name !== 'undefined') { 228 | payload['name'] = name; 229 | } 230 | if (typeof width !== 'undefined') { 231 | payload['width'] = width; 232 | } 233 | if (typeof height !== 'undefined') { 234 | payload['height'] = height; 235 | } 236 | if (typeof background !== 'undefined') { 237 | payload['background'] = background; 238 | } 239 | const uri = new URL(this.client.config.endpoint + apiPath); 240 | 241 | const apiHeaders: { [header: string]: string } = { 242 | } 243 | 244 | payload['project'] = this.client.config.project; 245 | 246 | for (const [key, value] of Object.entries(Service.flatten(payload))) { 247 | uri.searchParams.append(key, value); 248 | } 249 | 250 | return uri.toString(); 251 | } 252 | /** 253 | * Converts a given plain text to a QR code image. You can use the query parameters to change the size and style of the resulting image. 254 | 255 | * 256 | * @param {string} text 257 | * @param {number} size 258 | * @param {number} margin 259 | * @param {boolean} download 260 | * @throws {AppwriteException} 261 | * @returns {string} 262 | */ 263 | getQR(text: string, size?: number, margin?: number, download?: boolean): string { 264 | if (typeof text === 'undefined') { 265 | throw new AppwriteException('Missing required parameter: "text"'); 266 | } 267 | const apiPath = '/avatars/qr'; 268 | const payload: Payload = {}; 269 | if (typeof text !== 'undefined') { 270 | payload['text'] = text; 271 | } 272 | if (typeof size !== 'undefined') { 273 | payload['size'] = size; 274 | } 275 | if (typeof margin !== 'undefined') { 276 | payload['margin'] = margin; 277 | } 278 | if (typeof download !== 'undefined') { 279 | payload['download'] = download; 280 | } 281 | const uri = new URL(this.client.config.endpoint + apiPath); 282 | 283 | const apiHeaders: { [header: string]: string } = { 284 | } 285 | 286 | payload['project'] = this.client.config.project; 287 | 288 | for (const [key, value] of Object.entries(Service.flatten(payload))) { 289 | uri.searchParams.append(key, value); 290 | } 291 | 292 | return uri.toString(); 293 | } 294 | } 295 | -------------------------------------------------------------------------------- /src/services/databases.ts: -------------------------------------------------------------------------------- 1 | import { Service } from '../service'; 2 | import { AppwriteException, Client, type Payload, UploadProgress } from '../client'; 3 | import type { Models } from '../models'; 4 | 5 | export class Databases { 6 | client: Client; 7 | 8 | constructor(client: Client) { 9 | this.client = client; 10 | } 11 | 12 | /** 13 | * Get a list of all the user's documents in a given collection. You can use the query params to filter your results. 14 | * 15 | * @param {string} databaseId 16 | * @param {string} collectionId 17 | * @param {string[]} queries 18 | * @throws {AppwriteException} 19 | * @returns {Promise>} 20 | */ 21 | listDocuments(databaseId: string, collectionId: string, queries?: string[]): Promise> { 22 | if (typeof databaseId === 'undefined') { 23 | throw new AppwriteException('Missing required parameter: "databaseId"'); 24 | } 25 | if (typeof collectionId === 'undefined') { 26 | throw new AppwriteException('Missing required parameter: "collectionId"'); 27 | } 28 | const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); 29 | const payload: Payload = {}; 30 | if (typeof queries !== 'undefined') { 31 | payload['queries'] = queries; 32 | } 33 | const uri = new URL(this.client.config.endpoint + apiPath); 34 | 35 | const apiHeaders: { [header: string]: string } = { 36 | } 37 | 38 | return this.client.call( 39 | 'get', 40 | uri, 41 | apiHeaders, 42 | payload 43 | ); 44 | } 45 | /** 46 | * Create a new Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. 47 | * 48 | * @param {string} databaseId 49 | * @param {string} collectionId 50 | * @param {string} documentId 51 | * @param {Omit} data 52 | * @param {string[]} permissions 53 | * @throws {AppwriteException} 54 | * @returns {Promise} 55 | */ 56 | createDocument(databaseId: string, collectionId: string, documentId: string, data: Omit, permissions?: string[]): Promise { 57 | if (typeof databaseId === 'undefined') { 58 | throw new AppwriteException('Missing required parameter: "databaseId"'); 59 | } 60 | if (typeof collectionId === 'undefined') { 61 | throw new AppwriteException('Missing required parameter: "collectionId"'); 62 | } 63 | if (typeof documentId === 'undefined') { 64 | throw new AppwriteException('Missing required parameter: "documentId"'); 65 | } 66 | if (typeof data === 'undefined') { 67 | throw new AppwriteException('Missing required parameter: "data"'); 68 | } 69 | const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); 70 | const payload: Payload = {}; 71 | if (typeof documentId !== 'undefined') { 72 | payload['documentId'] = documentId; 73 | } 74 | if (typeof data !== 'undefined') { 75 | payload['data'] = data; 76 | } 77 | if (typeof permissions !== 'undefined') { 78 | payload['permissions'] = permissions; 79 | } 80 | const uri = new URL(this.client.config.endpoint + apiPath); 81 | 82 | const apiHeaders: { [header: string]: string } = { 83 | 'content-type': 'application/json', 84 | } 85 | 86 | return this.client.call( 87 | 'post', 88 | uri, 89 | apiHeaders, 90 | payload 91 | ); 92 | } 93 | /** 94 | * Get a document by its unique ID. This endpoint response returns a JSON object with the document data. 95 | * 96 | * @param {string} databaseId 97 | * @param {string} collectionId 98 | * @param {string} documentId 99 | * @param {string[]} queries 100 | * @throws {AppwriteException} 101 | * @returns {Promise} 102 | */ 103 | getDocument(databaseId: string, collectionId: string, documentId: string, queries?: string[]): Promise { 104 | if (typeof databaseId === 'undefined') { 105 | throw new AppwriteException('Missing required parameter: "databaseId"'); 106 | } 107 | if (typeof collectionId === 'undefined') { 108 | throw new AppwriteException('Missing required parameter: "collectionId"'); 109 | } 110 | if (typeof documentId === 'undefined') { 111 | throw new AppwriteException('Missing required parameter: "documentId"'); 112 | } 113 | const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); 114 | const payload: Payload = {}; 115 | if (typeof queries !== 'undefined') { 116 | payload['queries'] = queries; 117 | } 118 | const uri = new URL(this.client.config.endpoint + apiPath); 119 | 120 | const apiHeaders: { [header: string]: string } = { 121 | } 122 | 123 | return this.client.call( 124 | 'get', 125 | uri, 126 | apiHeaders, 127 | payload 128 | ); 129 | } 130 | /** 131 | * Create or update a Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. 132 | * 133 | * @param {string} databaseId 134 | * @param {string} collectionId 135 | * @param {string} documentId 136 | * @param {object} data 137 | * @param {string[]} permissions 138 | * @throws {AppwriteException} 139 | * @returns {Promise} 140 | */ 141 | upsertDocument(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: string[]): Promise { 142 | if (typeof databaseId === 'undefined') { 143 | throw new AppwriteException('Missing required parameter: "databaseId"'); 144 | } 145 | if (typeof collectionId === 'undefined') { 146 | throw new AppwriteException('Missing required parameter: "collectionId"'); 147 | } 148 | if (typeof documentId === 'undefined') { 149 | throw new AppwriteException('Missing required parameter: "documentId"'); 150 | } 151 | if (typeof data === 'undefined') { 152 | throw new AppwriteException('Missing required parameter: "data"'); 153 | } 154 | const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); 155 | const payload: Payload = {}; 156 | if (typeof data !== 'undefined') { 157 | payload['data'] = data; 158 | } 159 | if (typeof permissions !== 'undefined') { 160 | payload['permissions'] = permissions; 161 | } 162 | const uri = new URL(this.client.config.endpoint + apiPath); 163 | 164 | const apiHeaders: { [header: string]: string } = { 165 | 'content-type': 'application/json', 166 | } 167 | 168 | return this.client.call( 169 | 'put', 170 | uri, 171 | apiHeaders, 172 | payload 173 | ); 174 | } 175 | /** 176 | * Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated. 177 | * 178 | * @param {string} databaseId 179 | * @param {string} collectionId 180 | * @param {string} documentId 181 | * @param {Partial>} data 182 | * @param {string[]} permissions 183 | * @throws {AppwriteException} 184 | * @returns {Promise} 185 | */ 186 | updateDocument(databaseId: string, collectionId: string, documentId: string, data?: Partial>, permissions?: string[]): Promise { 187 | if (typeof databaseId === 'undefined') { 188 | throw new AppwriteException('Missing required parameter: "databaseId"'); 189 | } 190 | if (typeof collectionId === 'undefined') { 191 | throw new AppwriteException('Missing required parameter: "collectionId"'); 192 | } 193 | if (typeof documentId === 'undefined') { 194 | throw new AppwriteException('Missing required parameter: "documentId"'); 195 | } 196 | const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); 197 | const payload: Payload = {}; 198 | if (typeof data !== 'undefined') { 199 | payload['data'] = data; 200 | } 201 | if (typeof permissions !== 'undefined') { 202 | payload['permissions'] = permissions; 203 | } 204 | const uri = new URL(this.client.config.endpoint + apiPath); 205 | 206 | const apiHeaders: { [header: string]: string } = { 207 | 'content-type': 'application/json', 208 | } 209 | 210 | return this.client.call( 211 | 'patch', 212 | uri, 213 | apiHeaders, 214 | payload 215 | ); 216 | } 217 | /** 218 | * Delete a document by its unique ID. 219 | * 220 | * @param {string} databaseId 221 | * @param {string} collectionId 222 | * @param {string} documentId 223 | * @throws {AppwriteException} 224 | * @returns {Promise<{}>} 225 | */ 226 | deleteDocument(databaseId: string, collectionId: string, documentId: string): Promise<{}> { 227 | if (typeof databaseId === 'undefined') { 228 | throw new AppwriteException('Missing required parameter: "databaseId"'); 229 | } 230 | if (typeof collectionId === 'undefined') { 231 | throw new AppwriteException('Missing required parameter: "collectionId"'); 232 | } 233 | if (typeof documentId === 'undefined') { 234 | throw new AppwriteException('Missing required parameter: "documentId"'); 235 | } 236 | const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); 237 | const payload: Payload = {}; 238 | const uri = new URL(this.client.config.endpoint + apiPath); 239 | 240 | const apiHeaders: { [header: string]: string } = { 241 | 'content-type': 'application/json', 242 | } 243 | 244 | return this.client.call( 245 | 'delete', 246 | uri, 247 | apiHeaders, 248 | payload 249 | ); 250 | } 251 | } 252 | -------------------------------------------------------------------------------- /src/services/functions.ts: -------------------------------------------------------------------------------- 1 | import { Service } from '../service'; 2 | import { AppwriteException, Client, type Payload, UploadProgress } from '../client'; 3 | import type { Models } from '../models'; 4 | import { ExecutionMethod } from '../enums/execution-method'; 5 | 6 | export class Functions { 7 | client: Client; 8 | 9 | constructor(client: Client) { 10 | this.client = client; 11 | } 12 | 13 | /** 14 | * Get a list of all the current user function execution logs. You can use the query params to filter your results. 15 | * 16 | * @param {string} functionId 17 | * @param {string[]} queries 18 | * @throws {AppwriteException} 19 | * @returns {Promise} 20 | */ 21 | listExecutions(functionId: string, queries?: string[]): Promise { 22 | if (typeof functionId === 'undefined') { 23 | throw new AppwriteException('Missing required parameter: "functionId"'); 24 | } 25 | const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId); 26 | const payload: Payload = {}; 27 | if (typeof queries !== 'undefined') { 28 | payload['queries'] = queries; 29 | } 30 | const uri = new URL(this.client.config.endpoint + apiPath); 31 | 32 | const apiHeaders: { [header: string]: string } = { 33 | } 34 | 35 | return this.client.call( 36 | 'get', 37 | uri, 38 | apiHeaders, 39 | payload 40 | ); 41 | } 42 | /** 43 | * Trigger a function execution. The returned object will return you the current execution status. You can ping the `Get Execution` endpoint to get updates on the current execution status. Once this endpoint is called, your function execution process will start asynchronously. 44 | * 45 | * @param {string} functionId 46 | * @param {string} body 47 | * @param {boolean} async 48 | * @param {string} xpath 49 | * @param {ExecutionMethod} method 50 | * @param {object} headers 51 | * @param {string} scheduledAt 52 | * @throws {AppwriteException} 53 | * @returns {Promise} 54 | */ 55 | createExecution(functionId: string, body?: string, async?: boolean, xpath?: string, method?: ExecutionMethod, headers?: object, scheduledAt?: string): Promise { 56 | if (typeof functionId === 'undefined') { 57 | throw new AppwriteException('Missing required parameter: "functionId"'); 58 | } 59 | const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId); 60 | const payload: Payload = {}; 61 | if (typeof body !== 'undefined') { 62 | payload['body'] = body; 63 | } 64 | if (typeof async !== 'undefined') { 65 | payload['async'] = async; 66 | } 67 | if (typeof xpath !== 'undefined') { 68 | payload['path'] = xpath; 69 | } 70 | if (typeof method !== 'undefined') { 71 | payload['method'] = method; 72 | } 73 | if (typeof headers !== 'undefined') { 74 | payload['headers'] = headers; 75 | } 76 | if (typeof scheduledAt !== 'undefined') { 77 | payload['scheduledAt'] = scheduledAt; 78 | } 79 | const uri = new URL(this.client.config.endpoint + apiPath); 80 | 81 | const apiHeaders: { [header: string]: string } = { 82 | 'content-type': 'application/json', 83 | } 84 | 85 | return this.client.call( 86 | 'post', 87 | uri, 88 | apiHeaders, 89 | payload 90 | ); 91 | } 92 | /** 93 | * Get a function execution log by its unique ID. 94 | * 95 | * @param {string} functionId 96 | * @param {string} executionId 97 | * @throws {AppwriteException} 98 | * @returns {Promise} 99 | */ 100 | getExecution(functionId: string, executionId: string): Promise { 101 | if (typeof functionId === 'undefined') { 102 | throw new AppwriteException('Missing required parameter: "functionId"'); 103 | } 104 | if (typeof executionId === 'undefined') { 105 | throw new AppwriteException('Missing required parameter: "executionId"'); 106 | } 107 | const apiPath = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId); 108 | const payload: Payload = {}; 109 | const uri = new URL(this.client.config.endpoint + apiPath); 110 | 111 | const apiHeaders: { [header: string]: string } = { 112 | } 113 | 114 | return this.client.call( 115 | 'get', 116 | uri, 117 | apiHeaders, 118 | payload 119 | ); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/services/graphql.ts: -------------------------------------------------------------------------------- 1 | import { Service } from '../service'; 2 | import { AppwriteException, Client, type Payload, UploadProgress } from '../client'; 3 | import type { Models } from '../models'; 4 | 5 | export class Graphql { 6 | client: Client; 7 | 8 | constructor(client: Client) { 9 | this.client = client; 10 | } 11 | 12 | /** 13 | * Execute a GraphQL mutation. 14 | * 15 | * @param {object} query 16 | * @throws {AppwriteException} 17 | * @returns {Promise<{}>} 18 | */ 19 | query(query: object): Promise<{}> { 20 | if (typeof query === 'undefined') { 21 | throw new AppwriteException('Missing required parameter: "query"'); 22 | } 23 | const apiPath = '/graphql'; 24 | const payload: Payload = {}; 25 | if (typeof query !== 'undefined') { 26 | payload['query'] = query; 27 | } 28 | const uri = new URL(this.client.config.endpoint + apiPath); 29 | 30 | const apiHeaders: { [header: string]: string } = { 31 | 'x-sdk-graphql': 'true', 32 | 'content-type': 'application/json', 33 | } 34 | 35 | return this.client.call( 36 | 'post', 37 | uri, 38 | apiHeaders, 39 | payload 40 | ); 41 | } 42 | /** 43 | * Execute a GraphQL mutation. 44 | * 45 | * @param {object} query 46 | * @throws {AppwriteException} 47 | * @returns {Promise<{}>} 48 | */ 49 | mutation(query: object): Promise<{}> { 50 | if (typeof query === 'undefined') { 51 | throw new AppwriteException('Missing required parameter: "query"'); 52 | } 53 | const apiPath = '/graphql/mutation'; 54 | const payload: Payload = {}; 55 | if (typeof query !== 'undefined') { 56 | payload['query'] = query; 57 | } 58 | const uri = new URL(this.client.config.endpoint + apiPath); 59 | 60 | const apiHeaders: { [header: string]: string } = { 61 | 'x-sdk-graphql': 'true', 62 | 'content-type': 'application/json', 63 | } 64 | 65 | return this.client.call( 66 | 'post', 67 | uri, 68 | apiHeaders, 69 | payload 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/services/locale.ts: -------------------------------------------------------------------------------- 1 | import { Service } from '../service'; 2 | import { AppwriteException, Client, type Payload, UploadProgress } from '../client'; 3 | import type { Models } from '../models'; 4 | 5 | export class Locale { 6 | client: Client; 7 | 8 | constructor(client: Client) { 9 | this.client = client; 10 | } 11 | 12 | /** 13 | * Get the current user location based on IP. Returns an object with user country code, country name, continent name, continent code, ip address and suggested currency. You can use the locale header to get the data in a supported language. 14 | 15 | ([IP Geolocation by DB-IP](https://db-ip.com)) 16 | * 17 | * @throws {AppwriteException} 18 | * @returns {Promise} 19 | */ 20 | get(): Promise { 21 | const apiPath = '/locale'; 22 | const payload: Payload = {}; 23 | const uri = new URL(this.client.config.endpoint + apiPath); 24 | 25 | const apiHeaders: { [header: string]: string } = { 26 | } 27 | 28 | return this.client.call( 29 | 'get', 30 | uri, 31 | apiHeaders, 32 | payload 33 | ); 34 | } 35 | /** 36 | * List of all locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). 37 | * 38 | * @throws {AppwriteException} 39 | * @returns {Promise} 40 | */ 41 | listCodes(): Promise { 42 | const apiPath = '/locale/codes'; 43 | const payload: Payload = {}; 44 | const uri = new URL(this.client.config.endpoint + apiPath); 45 | 46 | const apiHeaders: { [header: string]: string } = { 47 | } 48 | 49 | return this.client.call( 50 | 'get', 51 | uri, 52 | apiHeaders, 53 | payload 54 | ); 55 | } 56 | /** 57 | * List of all continents. You can use the locale header to get the data in a supported language. 58 | * 59 | * @throws {AppwriteException} 60 | * @returns {Promise} 61 | */ 62 | listContinents(): Promise { 63 | const apiPath = '/locale/continents'; 64 | const payload: Payload = {}; 65 | const uri = new URL(this.client.config.endpoint + apiPath); 66 | 67 | const apiHeaders: { [header: string]: string } = { 68 | } 69 | 70 | return this.client.call( 71 | 'get', 72 | uri, 73 | apiHeaders, 74 | payload 75 | ); 76 | } 77 | /** 78 | * List of all countries. You can use the locale header to get the data in a supported language. 79 | * 80 | * @throws {AppwriteException} 81 | * @returns {Promise} 82 | */ 83 | listCountries(): Promise { 84 | const apiPath = '/locale/countries'; 85 | const payload: Payload = {}; 86 | const uri = new URL(this.client.config.endpoint + apiPath); 87 | 88 | const apiHeaders: { [header: string]: string } = { 89 | } 90 | 91 | return this.client.call( 92 | 'get', 93 | uri, 94 | apiHeaders, 95 | payload 96 | ); 97 | } 98 | /** 99 | * List of all countries that are currently members of the EU. You can use the locale header to get the data in a supported language. 100 | * 101 | * @throws {AppwriteException} 102 | * @returns {Promise} 103 | */ 104 | listCountriesEU(): Promise { 105 | const apiPath = '/locale/countries/eu'; 106 | const payload: Payload = {}; 107 | const uri = new URL(this.client.config.endpoint + apiPath); 108 | 109 | const apiHeaders: { [header: string]: string } = { 110 | } 111 | 112 | return this.client.call( 113 | 'get', 114 | uri, 115 | apiHeaders, 116 | payload 117 | ); 118 | } 119 | /** 120 | * List of all countries phone codes. You can use the locale header to get the data in a supported language. 121 | * 122 | * @throws {AppwriteException} 123 | * @returns {Promise} 124 | */ 125 | listCountriesPhones(): Promise { 126 | const apiPath = '/locale/countries/phones'; 127 | const payload: Payload = {}; 128 | const uri = new URL(this.client.config.endpoint + apiPath); 129 | 130 | const apiHeaders: { [header: string]: string } = { 131 | } 132 | 133 | return this.client.call( 134 | 'get', 135 | uri, 136 | apiHeaders, 137 | payload 138 | ); 139 | } 140 | /** 141 | * List of all currencies, including currency symbol, name, plural, and decimal digits for all major and minor currencies. You can use the locale header to get the data in a supported language. 142 | * 143 | * @throws {AppwriteException} 144 | * @returns {Promise} 145 | */ 146 | listCurrencies(): Promise { 147 | const apiPath = '/locale/currencies'; 148 | const payload: Payload = {}; 149 | const uri = new URL(this.client.config.endpoint + apiPath); 150 | 151 | const apiHeaders: { [header: string]: string } = { 152 | } 153 | 154 | return this.client.call( 155 | 'get', 156 | uri, 157 | apiHeaders, 158 | payload 159 | ); 160 | } 161 | /** 162 | * List of all languages classified by ISO 639-1 including 2-letter code, name in English, and name in the respective language. 163 | * 164 | * @throws {AppwriteException} 165 | * @returns {Promise} 166 | */ 167 | listLanguages(): Promise { 168 | const apiPath = '/locale/languages'; 169 | const payload: Payload = {}; 170 | const uri = new URL(this.client.config.endpoint + apiPath); 171 | 172 | const apiHeaders: { [header: string]: string } = { 173 | } 174 | 175 | return this.client.call( 176 | 'get', 177 | uri, 178 | apiHeaders, 179 | payload 180 | ); 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /src/services/messaging.ts: -------------------------------------------------------------------------------- 1 | import { Service } from '../service'; 2 | import { AppwriteException, Client, type Payload, UploadProgress } from '../client'; 3 | import type { Models } from '../models'; 4 | 5 | export class Messaging { 6 | client: Client; 7 | 8 | constructor(client: Client) { 9 | this.client = client; 10 | } 11 | 12 | /** 13 | * Create a new subscriber. 14 | * 15 | * @param {string} topicId 16 | * @param {string} subscriberId 17 | * @param {string} targetId 18 | * @throws {AppwriteException} 19 | * @returns {Promise} 20 | */ 21 | createSubscriber(topicId: string, subscriberId: string, targetId: string): Promise { 22 | if (typeof topicId === 'undefined') { 23 | throw new AppwriteException('Missing required parameter: "topicId"'); 24 | } 25 | if (typeof subscriberId === 'undefined') { 26 | throw new AppwriteException('Missing required parameter: "subscriberId"'); 27 | } 28 | if (typeof targetId === 'undefined') { 29 | throw new AppwriteException('Missing required parameter: "targetId"'); 30 | } 31 | const apiPath = '/messaging/topics/{topicId}/subscribers'.replace('{topicId}', topicId); 32 | const payload: Payload = {}; 33 | if (typeof subscriberId !== 'undefined') { 34 | payload['subscriberId'] = subscriberId; 35 | } 36 | if (typeof targetId !== 'undefined') { 37 | payload['targetId'] = targetId; 38 | } 39 | const uri = new URL(this.client.config.endpoint + apiPath); 40 | 41 | const apiHeaders: { [header: string]: string } = { 42 | 'content-type': 'application/json', 43 | } 44 | 45 | return this.client.call( 46 | 'post', 47 | uri, 48 | apiHeaders, 49 | payload 50 | ); 51 | } 52 | /** 53 | * Delete a subscriber by its unique ID. 54 | * 55 | * @param {string} topicId 56 | * @param {string} subscriberId 57 | * @throws {AppwriteException} 58 | * @returns {Promise<{}>} 59 | */ 60 | deleteSubscriber(topicId: string, subscriberId: string): Promise<{}> { 61 | if (typeof topicId === 'undefined') { 62 | throw new AppwriteException('Missing required parameter: "topicId"'); 63 | } 64 | if (typeof subscriberId === 'undefined') { 65 | throw new AppwriteException('Missing required parameter: "subscriberId"'); 66 | } 67 | const apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replace('{topicId}', topicId).replace('{subscriberId}', subscriberId); 68 | const payload: Payload = {}; 69 | const uri = new URL(this.client.config.endpoint + apiPath); 70 | 71 | const apiHeaders: { [header: string]: string } = { 72 | 'content-type': 'application/json', 73 | } 74 | 75 | return this.client.call( 76 | 'delete', 77 | uri, 78 | apiHeaders, 79 | payload 80 | ); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/services/storage.ts: -------------------------------------------------------------------------------- 1 | import { Service } from '../service'; 2 | import { AppwriteException, Client, type Payload, UploadProgress } from '../client'; 3 | import type { Models } from '../models'; 4 | import { ImageGravity } from '../enums/image-gravity'; 5 | import { ImageFormat } from '../enums/image-format'; 6 | 7 | export class Storage { 8 | client: Client; 9 | 10 | constructor(client: Client) { 11 | this.client = client; 12 | } 13 | 14 | /** 15 | * Get a list of all the user files. You can use the query params to filter your results. 16 | * 17 | * @param {string} bucketId 18 | * @param {string[]} queries 19 | * @param {string} search 20 | * @throws {AppwriteException} 21 | * @returns {Promise} 22 | */ 23 | listFiles(bucketId: string, queries?: string[], search?: string): Promise { 24 | if (typeof bucketId === 'undefined') { 25 | throw new AppwriteException('Missing required parameter: "bucketId"'); 26 | } 27 | const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); 28 | const payload: Payload = {}; 29 | if (typeof queries !== 'undefined') { 30 | payload['queries'] = queries; 31 | } 32 | if (typeof search !== 'undefined') { 33 | payload['search'] = search; 34 | } 35 | const uri = new URL(this.client.config.endpoint + apiPath); 36 | 37 | const apiHeaders: { [header: string]: string } = { 38 | } 39 | 40 | return this.client.call( 41 | 'get', 42 | uri, 43 | apiHeaders, 44 | payload 45 | ); 46 | } 47 | /** 48 | * Create a new file. Before using this route, you should create a new bucket resource using either a [server integration](https://appwrite.io/docs/server/storage#storageCreateBucket) API or directly from your Appwrite console. 49 | 50 | Larger files should be uploaded using multiple requests with the [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range) header to send a partial request with a maximum supported chunk of `5MB`. The `content-range` header values should always be in bytes. 51 | 52 | When the first request is sent, the server will return the **File** object, and the subsequent part request must include the file's **id** in `x-appwrite-id` header to allow the server to know that the partial upload is for the existing file and not for a new one. 53 | 54 | If you're creating a new file using one of the Appwrite SDKs, all the chunking logic will be managed by the SDK internally. 55 | 56 | * 57 | * @param {string} bucketId 58 | * @param {string} fileId 59 | * @param {File} file 60 | * @param {string[]} permissions 61 | * @throws {AppwriteException} 62 | * @returns {Promise} 63 | */ 64 | createFile(bucketId: string, fileId: string, file: File, permissions?: string[], onProgress = (progress: UploadProgress) => {}): Promise { 65 | if (typeof bucketId === 'undefined') { 66 | throw new AppwriteException('Missing required parameter: "bucketId"'); 67 | } 68 | if (typeof fileId === 'undefined') { 69 | throw new AppwriteException('Missing required parameter: "fileId"'); 70 | } 71 | if (typeof file === 'undefined') { 72 | throw new AppwriteException('Missing required parameter: "file"'); 73 | } 74 | const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); 75 | const payload: Payload = {}; 76 | if (typeof fileId !== 'undefined') { 77 | payload['fileId'] = fileId; 78 | } 79 | if (typeof file !== 'undefined') { 80 | payload['file'] = file; 81 | } 82 | if (typeof permissions !== 'undefined') { 83 | payload['permissions'] = permissions; 84 | } 85 | const uri = new URL(this.client.config.endpoint + apiPath); 86 | 87 | const apiHeaders: { [header: string]: string } = { 88 | 'content-type': 'multipart/form-data', 89 | } 90 | 91 | return this.client.chunkedUpload( 92 | 'post', 93 | uri, 94 | apiHeaders, 95 | payload, 96 | onProgress 97 | ); 98 | } 99 | /** 100 | * Get a file by its unique ID. This endpoint response returns a JSON object with the file metadata. 101 | * 102 | * @param {string} bucketId 103 | * @param {string} fileId 104 | * @throws {AppwriteException} 105 | * @returns {Promise} 106 | */ 107 | getFile(bucketId: string, fileId: string): Promise { 108 | if (typeof bucketId === 'undefined') { 109 | throw new AppwriteException('Missing required parameter: "bucketId"'); 110 | } 111 | if (typeof fileId === 'undefined') { 112 | throw new AppwriteException('Missing required parameter: "fileId"'); 113 | } 114 | const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); 115 | const payload: Payload = {}; 116 | const uri = new URL(this.client.config.endpoint + apiPath); 117 | 118 | const apiHeaders: { [header: string]: string } = { 119 | } 120 | 121 | return this.client.call( 122 | 'get', 123 | uri, 124 | apiHeaders, 125 | payload 126 | ); 127 | } 128 | /** 129 | * Update a file by its unique ID. Only users with write permissions have access to update this resource. 130 | * 131 | * @param {string} bucketId 132 | * @param {string} fileId 133 | * @param {string} name 134 | * @param {string[]} permissions 135 | * @throws {AppwriteException} 136 | * @returns {Promise} 137 | */ 138 | updateFile(bucketId: string, fileId: string, name?: string, permissions?: string[]): Promise { 139 | if (typeof bucketId === 'undefined') { 140 | throw new AppwriteException('Missing required parameter: "bucketId"'); 141 | } 142 | if (typeof fileId === 'undefined') { 143 | throw new AppwriteException('Missing required parameter: "fileId"'); 144 | } 145 | const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); 146 | const payload: Payload = {}; 147 | if (typeof name !== 'undefined') { 148 | payload['name'] = name; 149 | } 150 | if (typeof permissions !== 'undefined') { 151 | payload['permissions'] = permissions; 152 | } 153 | const uri = new URL(this.client.config.endpoint + apiPath); 154 | 155 | const apiHeaders: { [header: string]: string } = { 156 | 'content-type': 'application/json', 157 | } 158 | 159 | return this.client.call( 160 | 'put', 161 | uri, 162 | apiHeaders, 163 | payload 164 | ); 165 | } 166 | /** 167 | * Delete a file by its unique ID. Only users with write permissions have access to delete this resource. 168 | * 169 | * @param {string} bucketId 170 | * @param {string} fileId 171 | * @throws {AppwriteException} 172 | * @returns {Promise<{}>} 173 | */ 174 | deleteFile(bucketId: string, fileId: string): Promise<{}> { 175 | if (typeof bucketId === 'undefined') { 176 | throw new AppwriteException('Missing required parameter: "bucketId"'); 177 | } 178 | if (typeof fileId === 'undefined') { 179 | throw new AppwriteException('Missing required parameter: "fileId"'); 180 | } 181 | const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); 182 | const payload: Payload = {}; 183 | const uri = new URL(this.client.config.endpoint + apiPath); 184 | 185 | const apiHeaders: { [header: string]: string } = { 186 | 'content-type': 'application/json', 187 | } 188 | 189 | return this.client.call( 190 | 'delete', 191 | uri, 192 | apiHeaders, 193 | payload 194 | ); 195 | } 196 | /** 197 | * Get a file content by its unique ID. The endpoint response return with a 'Content-Disposition: attachment' header that tells the browser to start downloading the file to user downloads directory. 198 | * 199 | * @param {string} bucketId 200 | * @param {string} fileId 201 | * @param {string} token 202 | * @throws {AppwriteException} 203 | * @returns {string} 204 | */ 205 | getFileDownload(bucketId: string, fileId: string, token?: string): string { 206 | if (typeof bucketId === 'undefined') { 207 | throw new AppwriteException('Missing required parameter: "bucketId"'); 208 | } 209 | if (typeof fileId === 'undefined') { 210 | throw new AppwriteException('Missing required parameter: "fileId"'); 211 | } 212 | const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); 213 | const payload: Payload = {}; 214 | if (typeof token !== 'undefined') { 215 | payload['token'] = token; 216 | } 217 | const uri = new URL(this.client.config.endpoint + apiPath); 218 | 219 | const apiHeaders: { [header: string]: string } = { 220 | } 221 | 222 | payload['project'] = this.client.config.project; 223 | 224 | for (const [key, value] of Object.entries(Service.flatten(payload))) { 225 | uri.searchParams.append(key, value); 226 | } 227 | 228 | return uri.toString(); 229 | } 230 | /** 231 | * Get a file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets, will return the file icon image. You can also pass query string arguments for cutting and resizing your preview image. Preview is supported only for image files smaller than 10MB. 232 | * 233 | * @param {string} bucketId 234 | * @param {string} fileId 235 | * @param {number} width 236 | * @param {number} height 237 | * @param {ImageGravity} gravity 238 | * @param {number} quality 239 | * @param {number} borderWidth 240 | * @param {string} borderColor 241 | * @param {number} borderRadius 242 | * @param {number} opacity 243 | * @param {number} rotation 244 | * @param {string} background 245 | * @param {ImageFormat} output 246 | * @param {string} token 247 | * @throws {AppwriteException} 248 | * @returns {string} 249 | */ 250 | 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, token?: string): string { 251 | if (typeof bucketId === 'undefined') { 252 | throw new AppwriteException('Missing required parameter: "bucketId"'); 253 | } 254 | if (typeof fileId === 'undefined') { 255 | throw new AppwriteException('Missing required parameter: "fileId"'); 256 | } 257 | const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); 258 | const payload: Payload = {}; 259 | if (typeof width !== 'undefined') { 260 | payload['width'] = width; 261 | } 262 | if (typeof height !== 'undefined') { 263 | payload['height'] = height; 264 | } 265 | if (typeof gravity !== 'undefined') { 266 | payload['gravity'] = gravity; 267 | } 268 | if (typeof quality !== 'undefined') { 269 | payload['quality'] = quality; 270 | } 271 | if (typeof borderWidth !== 'undefined') { 272 | payload['borderWidth'] = borderWidth; 273 | } 274 | if (typeof borderColor !== 'undefined') { 275 | payload['borderColor'] = borderColor; 276 | } 277 | if (typeof borderRadius !== 'undefined') { 278 | payload['borderRadius'] = borderRadius; 279 | } 280 | if (typeof opacity !== 'undefined') { 281 | payload['opacity'] = opacity; 282 | } 283 | if (typeof rotation !== 'undefined') { 284 | payload['rotation'] = rotation; 285 | } 286 | if (typeof background !== 'undefined') { 287 | payload['background'] = background; 288 | } 289 | if (typeof output !== 'undefined') { 290 | payload['output'] = output; 291 | } 292 | if (typeof token !== 'undefined') { 293 | payload['token'] = token; 294 | } 295 | const uri = new URL(this.client.config.endpoint + apiPath); 296 | 297 | const apiHeaders: { [header: string]: string } = { 298 | } 299 | 300 | payload['project'] = this.client.config.project; 301 | 302 | for (const [key, value] of Object.entries(Service.flatten(payload))) { 303 | uri.searchParams.append(key, value); 304 | } 305 | 306 | return uri.toString(); 307 | } 308 | /** 309 | * Get a file content by its unique ID. This endpoint is similar to the download method but returns with no 'Content-Disposition: attachment' header. 310 | * 311 | * @param {string} bucketId 312 | * @param {string} fileId 313 | * @param {string} token 314 | * @throws {AppwriteException} 315 | * @returns {string} 316 | */ 317 | getFileView(bucketId: string, fileId: string, token?: string): string { 318 | if (typeof bucketId === 'undefined') { 319 | throw new AppwriteException('Missing required parameter: "bucketId"'); 320 | } 321 | if (typeof fileId === 'undefined') { 322 | throw new AppwriteException('Missing required parameter: "fileId"'); 323 | } 324 | const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); 325 | const payload: Payload = {}; 326 | if (typeof token !== 'undefined') { 327 | payload['token'] = token; 328 | } 329 | const uri = new URL(this.client.config.endpoint + apiPath); 330 | 331 | const apiHeaders: { [header: string]: string } = { 332 | } 333 | 334 | payload['project'] = this.client.config.project; 335 | 336 | for (const [key, value] of Object.entries(Service.flatten(payload))) { 337 | uri.searchParams.append(key, value); 338 | } 339 | 340 | return uri.toString(); 341 | } 342 | } 343 | -------------------------------------------------------------------------------- /src/services/teams.ts: -------------------------------------------------------------------------------- 1 | import { Service } from '../service'; 2 | import { AppwriteException, Client, type Payload, UploadProgress } from '../client'; 3 | import type { Models } from '../models'; 4 | 5 | export class Teams { 6 | client: Client; 7 | 8 | constructor(client: Client) { 9 | this.client = client; 10 | } 11 | 12 | /** 13 | * Get a list of all the teams in which the current user is a member. You can use the parameters to filter your results. 14 | * 15 | * @param {string[]} queries 16 | * @param {string} search 17 | * @throws {AppwriteException} 18 | * @returns {Promise>} 19 | */ 20 | list(queries?: string[], search?: string): Promise> { 21 | const apiPath = '/teams'; 22 | const payload: Payload = {}; 23 | if (typeof queries !== 'undefined') { 24 | payload['queries'] = queries; 25 | } 26 | if (typeof search !== 'undefined') { 27 | payload['search'] = search; 28 | } 29 | const uri = new URL(this.client.config.endpoint + apiPath); 30 | 31 | const apiHeaders: { [header: string]: string } = { 32 | } 33 | 34 | return this.client.call( 35 | 'get', 36 | uri, 37 | apiHeaders, 38 | payload 39 | ); 40 | } 41 | /** 42 | * Create a new team. The user who creates the team will automatically be assigned as the owner of the team. Only the users with the owner role can invite new members, add new owners and delete or update the team. 43 | * 44 | * @param {string} teamId 45 | * @param {string} name 46 | * @param {string[]} roles 47 | * @throws {AppwriteException} 48 | * @returns {Promise>} 49 | */ 50 | create(teamId: string, name: string, roles?: string[]): Promise> { 51 | if (typeof teamId === 'undefined') { 52 | throw new AppwriteException('Missing required parameter: "teamId"'); 53 | } 54 | if (typeof name === 'undefined') { 55 | throw new AppwriteException('Missing required parameter: "name"'); 56 | } 57 | const apiPath = '/teams'; 58 | const payload: Payload = {}; 59 | if (typeof teamId !== 'undefined') { 60 | payload['teamId'] = teamId; 61 | } 62 | if (typeof name !== 'undefined') { 63 | payload['name'] = name; 64 | } 65 | if (typeof roles !== 'undefined') { 66 | payload['roles'] = roles; 67 | } 68 | const uri = new URL(this.client.config.endpoint + apiPath); 69 | 70 | const apiHeaders: { [header: string]: string } = { 71 | 'content-type': 'application/json', 72 | } 73 | 74 | return this.client.call( 75 | 'post', 76 | uri, 77 | apiHeaders, 78 | payload 79 | ); 80 | } 81 | /** 82 | * Get a team by its ID. All team members have read access for this resource. 83 | * 84 | * @param {string} teamId 85 | * @throws {AppwriteException} 86 | * @returns {Promise>} 87 | */ 88 | get(teamId: string): Promise> { 89 | if (typeof teamId === 'undefined') { 90 | throw new AppwriteException('Missing required parameter: "teamId"'); 91 | } 92 | const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); 93 | const payload: Payload = {}; 94 | const uri = new URL(this.client.config.endpoint + apiPath); 95 | 96 | const apiHeaders: { [header: string]: string } = { 97 | } 98 | 99 | return this.client.call( 100 | 'get', 101 | uri, 102 | apiHeaders, 103 | payload 104 | ); 105 | } 106 | /** 107 | * Update the team's name by its unique ID. 108 | * 109 | * @param {string} teamId 110 | * @param {string} name 111 | * @throws {AppwriteException} 112 | * @returns {Promise>} 113 | */ 114 | updateName(teamId: string, name: string): Promise> { 115 | if (typeof teamId === 'undefined') { 116 | throw new AppwriteException('Missing required parameter: "teamId"'); 117 | } 118 | if (typeof name === 'undefined') { 119 | throw new AppwriteException('Missing required parameter: "name"'); 120 | } 121 | const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); 122 | const payload: Payload = {}; 123 | if (typeof name !== 'undefined') { 124 | payload['name'] = name; 125 | } 126 | const uri = new URL(this.client.config.endpoint + apiPath); 127 | 128 | const apiHeaders: { [header: string]: string } = { 129 | 'content-type': 'application/json', 130 | } 131 | 132 | return this.client.call( 133 | 'put', 134 | uri, 135 | apiHeaders, 136 | payload 137 | ); 138 | } 139 | /** 140 | * Delete a team using its ID. Only team members with the owner role can delete the team. 141 | * 142 | * @param {string} teamId 143 | * @throws {AppwriteException} 144 | * @returns {Promise<{}>} 145 | */ 146 | delete(teamId: string): Promise<{}> { 147 | if (typeof teamId === 'undefined') { 148 | throw new AppwriteException('Missing required parameter: "teamId"'); 149 | } 150 | const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); 151 | const payload: Payload = {}; 152 | const uri = new URL(this.client.config.endpoint + apiPath); 153 | 154 | const apiHeaders: { [header: string]: string } = { 155 | 'content-type': 'application/json', 156 | } 157 | 158 | return this.client.call( 159 | 'delete', 160 | uri, 161 | apiHeaders, 162 | payload 163 | ); 164 | } 165 | /** 166 | * Use this endpoint to list a team's members using the team's ID. All team members have read access to this endpoint. Hide sensitive attributes from the response by toggling membership privacy in the Console. 167 | * 168 | * @param {string} teamId 169 | * @param {string[]} queries 170 | * @param {string} search 171 | * @throws {AppwriteException} 172 | * @returns {Promise} 173 | */ 174 | listMemberships(teamId: string, queries?: string[], search?: string): Promise { 175 | if (typeof teamId === 'undefined') { 176 | throw new AppwriteException('Missing required parameter: "teamId"'); 177 | } 178 | const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); 179 | const payload: Payload = {}; 180 | if (typeof queries !== 'undefined') { 181 | payload['queries'] = queries; 182 | } 183 | if (typeof search !== 'undefined') { 184 | payload['search'] = search; 185 | } 186 | const uri = new URL(this.client.config.endpoint + apiPath); 187 | 188 | const apiHeaders: { [header: string]: string } = { 189 | } 190 | 191 | return this.client.call( 192 | 'get', 193 | uri, 194 | apiHeaders, 195 | payload 196 | ); 197 | } 198 | /** 199 | * Invite a new member to join your team. Provide an ID for existing users, or invite unregistered users using an email or phone number. If initiated from a Client SDK, Appwrite will send an email or sms with a link to join the team to the invited user, and an account will be created for them if one doesn't exist. If initiated from a Server SDK, the new member will be added automatically to the team. 200 | 201 | You only need to provide one of a user ID, email, or phone number. Appwrite will prioritize accepting the user ID > email > phone number if you provide more than one of these parameters. 202 | 203 | Use the `url` parameter to redirect the user from the invitation email to your app. After the user is redirected, use the [Update Team Membership Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) endpoint to allow the user to accept the invitation to the team. 204 | 205 | Please note that to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) Appwrite will accept the only redirect URLs under the domains you have added as a platform on the Appwrite Console. 206 | 207 | * 208 | * @param {string} teamId 209 | * @param {string[]} roles 210 | * @param {string} email 211 | * @param {string} userId 212 | * @param {string} phone 213 | * @param {string} url 214 | * @param {string} name 215 | * @throws {AppwriteException} 216 | * @returns {Promise} 217 | */ 218 | createMembership(teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string): Promise { 219 | if (typeof teamId === 'undefined') { 220 | throw new AppwriteException('Missing required parameter: "teamId"'); 221 | } 222 | if (typeof roles === 'undefined') { 223 | throw new AppwriteException('Missing required parameter: "roles"'); 224 | } 225 | const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); 226 | const payload: Payload = {}; 227 | if (typeof email !== 'undefined') { 228 | payload['email'] = email; 229 | } 230 | if (typeof userId !== 'undefined') { 231 | payload['userId'] = userId; 232 | } 233 | if (typeof phone !== 'undefined') { 234 | payload['phone'] = phone; 235 | } 236 | if (typeof roles !== 'undefined') { 237 | payload['roles'] = roles; 238 | } 239 | if (typeof url !== 'undefined') { 240 | payload['url'] = url; 241 | } 242 | if (typeof name !== 'undefined') { 243 | payload['name'] = name; 244 | } 245 | const uri = new URL(this.client.config.endpoint + apiPath); 246 | 247 | const apiHeaders: { [header: string]: string } = { 248 | 'content-type': 'application/json', 249 | } 250 | 251 | return this.client.call( 252 | 'post', 253 | uri, 254 | apiHeaders, 255 | payload 256 | ); 257 | } 258 | /** 259 | * Get a team member by the membership unique id. All team members have read access for this resource. Hide sensitive attributes from the response by toggling membership privacy in the Console. 260 | * 261 | * @param {string} teamId 262 | * @param {string} membershipId 263 | * @throws {AppwriteException} 264 | * @returns {Promise} 265 | */ 266 | getMembership(teamId: string, membershipId: string): Promise { 267 | if (typeof teamId === 'undefined') { 268 | throw new AppwriteException('Missing required parameter: "teamId"'); 269 | } 270 | if (typeof membershipId === 'undefined') { 271 | throw new AppwriteException('Missing required parameter: "membershipId"'); 272 | } 273 | const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); 274 | const payload: Payload = {}; 275 | const uri = new URL(this.client.config.endpoint + apiPath); 276 | 277 | const apiHeaders: { [header: string]: string } = { 278 | } 279 | 280 | return this.client.call( 281 | 'get', 282 | uri, 283 | apiHeaders, 284 | payload 285 | ); 286 | } 287 | /** 288 | * Modify the roles of a team member. Only team members with the owner role have access to this endpoint. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). 289 | 290 | * 291 | * @param {string} teamId 292 | * @param {string} membershipId 293 | * @param {string[]} roles 294 | * @throws {AppwriteException} 295 | * @returns {Promise} 296 | */ 297 | updateMembership(teamId: string, membershipId: string, roles: string[]): Promise { 298 | if (typeof teamId === 'undefined') { 299 | throw new AppwriteException('Missing required parameter: "teamId"'); 300 | } 301 | if (typeof membershipId === 'undefined') { 302 | throw new AppwriteException('Missing required parameter: "membershipId"'); 303 | } 304 | if (typeof roles === 'undefined') { 305 | throw new AppwriteException('Missing required parameter: "roles"'); 306 | } 307 | const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); 308 | const payload: Payload = {}; 309 | if (typeof roles !== 'undefined') { 310 | payload['roles'] = roles; 311 | } 312 | const uri = new URL(this.client.config.endpoint + apiPath); 313 | 314 | const apiHeaders: { [header: string]: string } = { 315 | 'content-type': 'application/json', 316 | } 317 | 318 | return this.client.call( 319 | 'patch', 320 | uri, 321 | apiHeaders, 322 | payload 323 | ); 324 | } 325 | /** 326 | * This endpoint allows a user to leave a team or for a team owner to delete the membership of any other team member. You can also use this endpoint to delete a user membership even if it is not accepted. 327 | * 328 | * @param {string} teamId 329 | * @param {string} membershipId 330 | * @throws {AppwriteException} 331 | * @returns {Promise<{}>} 332 | */ 333 | deleteMembership(teamId: string, membershipId: string): Promise<{}> { 334 | if (typeof teamId === 'undefined') { 335 | throw new AppwriteException('Missing required parameter: "teamId"'); 336 | } 337 | if (typeof membershipId === 'undefined') { 338 | throw new AppwriteException('Missing required parameter: "membershipId"'); 339 | } 340 | const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); 341 | const payload: Payload = {}; 342 | const uri = new URL(this.client.config.endpoint + apiPath); 343 | 344 | const apiHeaders: { [header: string]: string } = { 345 | 'content-type': 'application/json', 346 | } 347 | 348 | return this.client.call( 349 | 'delete', 350 | uri, 351 | apiHeaders, 352 | payload 353 | ); 354 | } 355 | /** 356 | * Use this endpoint to allow a user to accept an invitation to join a team after being redirected back to your app from the invitation email received by the user. 357 | 358 | If the request is successful, a session for the user is automatically created. 359 | 360 | * 361 | * @param {string} teamId 362 | * @param {string} membershipId 363 | * @param {string} userId 364 | * @param {string} secret 365 | * @throws {AppwriteException} 366 | * @returns {Promise} 367 | */ 368 | updateMembershipStatus(teamId: string, membershipId: string, userId: string, secret: string): Promise { 369 | if (typeof teamId === 'undefined') { 370 | throw new AppwriteException('Missing required parameter: "teamId"'); 371 | } 372 | if (typeof membershipId === 'undefined') { 373 | throw new AppwriteException('Missing required parameter: "membershipId"'); 374 | } 375 | if (typeof userId === 'undefined') { 376 | throw new AppwriteException('Missing required parameter: "userId"'); 377 | } 378 | if (typeof secret === 'undefined') { 379 | throw new AppwriteException('Missing required parameter: "secret"'); 380 | } 381 | const apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); 382 | const payload: Payload = {}; 383 | if (typeof userId !== 'undefined') { 384 | payload['userId'] = userId; 385 | } 386 | if (typeof secret !== 'undefined') { 387 | payload['secret'] = secret; 388 | } 389 | const uri = new URL(this.client.config.endpoint + apiPath); 390 | 391 | const apiHeaders: { [header: string]: string } = { 392 | 'content-type': 'application/json', 393 | } 394 | 395 | return this.client.call( 396 | 'patch', 397 | uri, 398 | apiHeaders, 399 | payload 400 | ); 401 | } 402 | /** 403 | * Get the team's shared preferences by its unique ID. If a preference doesn't need to be shared by all team members, prefer storing them in [user preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). 404 | * 405 | * @param {string} teamId 406 | * @throws {AppwriteException} 407 | * @returns {Promise} 408 | */ 409 | getPrefs(teamId: string): Promise { 410 | if (typeof teamId === 'undefined') { 411 | throw new AppwriteException('Missing required parameter: "teamId"'); 412 | } 413 | const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); 414 | const payload: Payload = {}; 415 | const uri = new URL(this.client.config.endpoint + apiPath); 416 | 417 | const apiHeaders: { [header: string]: string } = { 418 | } 419 | 420 | return this.client.call( 421 | 'get', 422 | uri, 423 | apiHeaders, 424 | payload 425 | ); 426 | } 427 | /** 428 | * Update the team's preferences by its unique ID. The object you pass is stored as is and replaces any previous value. The maximum allowed prefs size is 64kB and throws an error if exceeded. 429 | * 430 | * @param {string} teamId 431 | * @param {object} prefs 432 | * @throws {AppwriteException} 433 | * @returns {Promise} 434 | */ 435 | updatePrefs(teamId: string, prefs: object): Promise { 436 | if (typeof teamId === 'undefined') { 437 | throw new AppwriteException('Missing required parameter: "teamId"'); 438 | } 439 | if (typeof prefs === 'undefined') { 440 | throw new AppwriteException('Missing required parameter: "prefs"'); 441 | } 442 | const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); 443 | const payload: Payload = {}; 444 | if (typeof prefs !== 'undefined') { 445 | payload['prefs'] = prefs; 446 | } 447 | const uri = new URL(this.client.config.endpoint + apiPath); 448 | 449 | const apiHeaders: { [header: string]: string } = { 450 | 'content-type': 'application/json', 451 | } 452 | 453 | return this.client.call( 454 | 'put', 455 | uri, 456 | apiHeaders, 457 | payload 458 | ); 459 | } 460 | } 461 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": true, 4 | "allowSyntheticDefaultImports": true, 5 | "baseUrl": "src", 6 | "declaration": false, 7 | "esModuleInterop": true, 8 | "inlineSourceMap": false, 9 | "lib": ["ESNext", "DOM"], 10 | "listEmittedFiles": false, 11 | "listFiles": false, 12 | "moduleResolution": "node", 13 | "noFallthroughCasesInSwitch": true, 14 | "pretty": true, 15 | "rootDir": "src", 16 | "skipLibCheck": true, 17 | "strict": true, 18 | "target": "ES6", 19 | "traceResolution": false, 20 | }, 21 | "compileOnSave": false, 22 | "exclude": ["node_modules", "dist"], 23 | "include": ["src"] 24 | } --------------------------------------------------------------------------------