diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66e5802..fca6813 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,6 +38,6 @@ jobs: labels: ${{ steps.meta.outputs.labels }} build-args: | _BUILD_WEBSITE_URL=https://appwrite.io - _BUILD_WEBSITE_VERSION=1.6.x + _BUILD_WEBSITE_VERSION=cloud _BUILD_GIT_URL=https://github.com/appwrite/website.git _BUILD_GIT_BRANCH=main \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9e9b8c6..2206ddc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,6 +42,6 @@ jobs: labels: ${{ steps.meta.outputs.labels }} build-args: | _BUILD_WEBSITE_URL=https://appwrite.io - _BUILD_WEBSITE_VERSION=1.6.x + _BUILD_WEBSITE_VERSION=cloud _BUILD_GIT_URL=https://github.com/appwrite/website.git _BUILD_GIT_BRANCH=main diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a61f982..3bd54c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,11 +50,11 @@ You can build the docker image and run it with docker compose: ```bash docker compose build \ --build-arg _BUILD_WEBSITE_URL=https://appwrite.io \ - --build-arg _BUILD_WEBSITE_VERSION=1.6.x \ + --build-arg _BUILD_WEBSITE_VERSION=cloud \ --build-arg _BUILD_GIT_URL=https://github.com/appwrite/website.git \ --build-arg _BUILD_GIT_BRANCH=main -docker compose up +docker compose up -d ``` ### 6. Linting and Formatting diff --git a/Dockerfile b/Dockerfile index ba8c421..c1eb39b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,18 +10,16 @@ RUN apk add --no-cache \ ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" RUN corepack enable -RUN corepack prepare pnpm@10.0.0 --activate +RUN corepack prepare pnpm@10.13.1 --activate FROM base AS builder -COPY package.json pnpm-lock.yaml /usr/src/app/ WORKDIR /usr/src/app -RUN pnpm fetch --prod +COPY package.json pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile --prod -COPY . /usr/src/app - -RUN pnpm install +COPY . . ARG _BUILD_GIT_URL ARG _BUILD_GIT_BRANCH @@ -35,14 +33,21 @@ ENV _BUILD_WEBSITE_VERSION=${_BUILD_WEBSITE_VERSION} RUN pnpm run fetch-sources -FROM base +FROM node:18-alpine AS prod + +ENV NODE_ENV=production +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" + +RUN corepack enable +RUN corepack prepare pnpm@10.13.1 --activate WORKDIR /usr/src/app -COPY --from=builder /usr/src/app/node_modules /usr/src/app/node_modules -COPY --from=builder /usr/src/app/sources /usr/src/app/sources -COPY --from=builder /usr/src/app/package.json /usr/src/app/ -COPY --from=builder /usr/src/app/src /usr/src/app/src +COPY --from=builder /usr/src/app/node_modules ./node_modules +COPY --from=builder /usr/src/app/sources ./sources +COPY --from=builder /usr/src/app/package.json ./ +COPY --from=builder /usr/src/app/src ./src ENV _APP_ASSISTANT_OPENAI_API_KEY='' diff --git a/package.json b/package.json index 28d55ce..9ef22bc 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "dev": "nodemon src/main.js", "lint": "eslint src", "format": "prettier --write \"src/**/*.js\" \"scripts/**/*.js\"", - "fetch-sources": "node scripts/git-sources.js && node scripts/web-sources.js" + "fetch-sources": "node scripts/git-sources.js && node scripts/web-sources.js", + "make-sources": "node scripts/web-sources.js" }, "keywords": [], "author": "", @@ -34,5 +35,10 @@ "globals": "^15.14.0", "prettier": "^3.4.2" }, - "packageManager": "pnpm@9.15.4" + "pnpm": { + "onlyBuiltDependencies": [ + "hnswlib-node" + ] + }, + "packageManager": "pnpm@10.13.1" } diff --git a/scripts/git-sources.js b/scripts/git-sources.js index 2897845..89c4325 100644 --- a/scripts/git-sources.js +++ b/scripts/git-sources.js @@ -40,3 +40,4 @@ await execa("git", ["config", "core.sparseCheckout", "true"], { }); await execa("git", ["checkout", GIT_BRANCH], { cwd: LOCAL_PATH }); +await execa("rm", ["-rf", `${LOCAL_PATH}/.git`]); diff --git a/scripts/test-prompts.js b/scripts/test-prompts.js index 0f8c61b..26e547f 100644 --- a/scripts/test-prompts.js +++ b/scripts/test-prompts.js @@ -8,6 +8,7 @@ const PROMPTS = [ "How do I use the users API to create a new user with Dart?", "What endpoints are available for the Avatars API? I'm using the PHP SDK", "How to use Appwrite with React?", + "How do I host a simple static website with Appwrite?", ]; const TESTS_FOLDER = "./tests"; diff --git a/scripts/web-sources.js b/scripts/web-sources.js index ced6e23..0fa495a 100644 --- a/scripts/web-sources.js +++ b/scripts/web-sources.js @@ -40,6 +40,7 @@ const SDKS = [ "server-graphql", "server-rest", ]; + const SERVICES = [ "account", "avatars", @@ -47,6 +48,7 @@ const SERVICES = [ "functions", "locale", "messaging", + "sites", "storage", "teams", "users", @@ -55,37 +57,48 @@ const SERVICES = [ await execa("rm", ["-rf", LOCAL_PATH]); await mkdir(LOCAL_PATH, { recursive: true }); -console.log("Downloading reference pages..."); +await Promise.all( + SDKS.map((sdk) => { + return mkdir(`${LOCAL_PATH}/${sdk}/`, { recursive: true }); + }), +); -for (const sdk of SDKS) { - await mkdir(`./sources/references/${sdk}/`, { recursive: true }); +console.log("Downloading reference pages..."); - for (const service of SERVICES) { - const url = new URL( - `/docs/references/${WEBSITE_VERSION}/${sdk}/${service}`, - WEBSITE_URL, - ); +const start = Date.now(); - const response = await fetch(url.toString()); +await Promise.all( + SDKS.flatMap((sdk) => + SERVICES.map(async (service) => { + const url = new URL( + `/docs/references/${WEBSITE_VERSION}/${sdk}/${service}`, + WEBSITE_URL, + ); - const html = await response.text(); - if (!html) { - console.warn(`Skipping page ${url} - no content found`); - continue; - } + try { + const response = await fetch(url.toString()); + const html = await response.text(); + if (!html) { + console.warn(`Skipping page ${url} - no content found`); + return; + } - // Ignore the header and footer - const matches = html.match( - /
(.*?)<\/main>/s, - ); - if (!matches || !matches[0]) { - console.warn(`Skipping page ${url} - no
tag found`); - continue; - } + const matches = html.match( + /
(.*?)<\/main>/s, + ); + if (!matches || !matches[0]) { + console.warn(`Skipping page ${url} - no
tag found`); + return; + } - const markdown = NodeHtmlMarkdown.translate(matches[0]); + const markdown = NodeHtmlMarkdown.translate(matches[0]); + await writeFile(`${LOCAL_PATH}/${sdk}/${service}.md`, markdown); + console.log(`Created ./sources/references/${sdk}/${service}.md`); + } catch (e) { + console.warn(`Failed to download ${url}:`, e); + } + }), + ), +); - await writeFile(`./sources/references/${sdk}/${service}.md`, markdown); - console.log(`Created ./sources/references/${sdk}/${service}.md`); - } -} +console.log("References created in", (Date.now() - start) / 1000, "seconds"); diff --git a/src/documents.js b/src/documents.js index 23d5ff5..e519153 100644 --- a/src/documents.js +++ b/src/documents.js @@ -44,6 +44,7 @@ const getDocumentation = async () => { */ const getReferences = async () => { const filenames = await glob(["./sources/references/**/*.md"]); + const version = process.env._BUILD_WEBSITE_VERSION ?? "cloud"; return Promise.all( filenames.map(async (filename) => { @@ -52,7 +53,7 @@ const getReferences = async () => { const { sdk, service } = parseReferenceData(filename); const metadata = { filename, - url: `https://appwrite.io/docs/references/cloud/${sdk}/${service}`, + url: `https://appwrite.io/docs/references/${version}/${sdk}/${service}`, }; return new Document({ @@ -64,8 +65,10 @@ const getReferences = async () => { }; export const getDocuments = async () => { - const documentation = await getDocumentation(); - const references = await getReferences(); + const [documentation, references] = await Promise.all([ + getDocumentation(), + getReferences(), + ]); return await splitDocuments([...documentation, ...references]); }; diff --git a/src/embeddings.js b/src/embeddings.js index efd9fb3..4f4ceb4 100644 --- a/src/embeddings.js +++ b/src/embeddings.js @@ -7,7 +7,7 @@ import { getDocuments } from "./documents.js"; /** * @returns {Promise>} */ -export const intializeDocumentRetriever = async () => { +export const initializeDocumentRetriever = async () => { const embeddings = new OpenAIEmbeddings({ openAIApiKey: process.env._APP_ASSISTANT_OPENAI_API_KEY, }); diff --git a/src/main.js b/src/main.js index 6f0bd13..46a65f0 100644 --- a/src/main.js +++ b/src/main.js @@ -5,7 +5,7 @@ import express from "express"; import { getRagChain, getOpenAIChat, - intializeDocumentRetriever as initializeRetriever, + initializeDocumentRetriever as initializeRetriever, } from "./embeddings.js"; const app = express(); diff --git a/tests/how-do-i-host-a-simple-static-website-with-appwrite.md b/tests/how-do-i-host-a-simple-static-website-with-appwrite.md new file mode 100644 index 0000000..768b8b3 --- /dev/null +++ b/tests/how-do-i-host-a-simple-static-website-with-appwrite.md @@ -0,0 +1,34 @@ +To host a simple static website with Appwrite, you can follow these steps: + +1. **Create an Account and Project**: If you haven't already, create an account on Appwrite and create your first project. + +2. **Add a Platform**: In your project, go to **Add a platform** and add a **Web app**. Set the **Hostname** to `localhost` or the domain where you plan to host your web app. + +3. **Configure Your Site**: + - Navigate to your site in the Appwrite Console. + - Go to the **Settings** tab and then the **Build settings** section. + - Select the **Static site** checkbox. + - Ensure the appropriate install command, build command, and output directory are set. + - Provide a fallback file for advanced routing and proper page handling. + +4. **Deploy Your Site**: + - You can deploy your site manually by uploading the source code through the Appwrite Console. + - Alternatively, set up automatic deployments from a Git repository for continuous integration and delivery. + +5. **Redeploy**: After configuring, click on the **Update** button and redeploy your site. + +6. **Install Appwrite SDK (Optional)**: If you need to interact with Appwrite services, you can install the Appwrite Web SDK using a package manager: + ```sh + npm install appwrite@18.1.1 + ``` + Or add it via CDN: + ```html + + ``` + +By following these steps, you can host and manage your static website directly within the Appwrite platform. + +Sources: +- https://appwrite.io/docs/products/sites/rendering/static/ +- https://appwrite.io/docs/products/sites/deploy-manually/ +- https://appwrite.io/docs/quick-starts/web/ diff --git a/tests/how-do-i-use-the-users-api-to-create-a-new-user-with-dart.md b/tests/how-do-i-use-the-users-api-to-create-a-new-user-with-dart.md index 0ecc7de..f4fec5e 100644 --- a/tests/how-do-i-use-the-users-api-to-create-a-new-user-with-dart.md +++ b/tests/how-do-i-use-the-users-api-to-create-a-new-user-with-dart.md @@ -1,109 +1,34 @@ -To create a new user with Dart using the Appwrite Users API, you can use one of the provided methods depending on the hashing algorithm you want to use for the password. Below are examples for creating a user with different hashing algorithms: +To create a new user using the Appwrite Users API with Dart, you can use the `create` method from the `Users` class. Below is an example of how to do this: -### Using PHPass ```dart import 'package:dart_appwrite/dart_appwrite.dart'; Client client = Client() - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject('') // Your project ID .setKey(''); // Your secret API key Users users = Users(client); -User result = await users.createPHPassUser( - userId: '', - email: 'email@example.com', - password: 'password', - name: '', // (optional) -); +Future createUser() async { + try { + User result = await users.create( + userId: '', + email: 'email@example.com', // (optional) + phone: '+12065550100', // (optional) + password: 'password', // (optional) + name: '', // (optional) + ); + print('User created: ${result.$id}'); + } catch (e) { + print('Error creating user: $e'); + } +} + +createUser(); ``` -### Using Scrypt -```dart -import 'package:dart_appwrite/dart_appwrite.dart'; - -Client client = Client() - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('') // Your project ID - .setKey(''); // Your secret API key - -Users users = Users(client); - -User result = await users.createScryptUser( - userId: '', - email: 'email@example.com', - password: 'password', - passwordSalt: '', - passwordCpu: 0, - passwordMemory: 0, - passwordParallel: 0, - passwordLength: 0, - name: '', // (optional) -); -``` - -### Using Bcrypt -```dart -import 'package:dart_appwrite/dart_appwrite.dart'; - -Client client = Client() - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('') // Your project ID - .setKey(''); // Your secret API key - -Users users = Users(client); - -User result = await users.createBcryptUser( - userId: '', - email: 'email@example.com', - password: 'password', - name: '', // (optional) -); -``` - -### Using Scrypt Modified -```dart -import 'package:dart_appwrite/dart_appwrite.dart'; - -Client client = Client() - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('') // Your project ID - .setKey(''); // Your secret API key - -Users users = Users(client); - -User result = await users.createScryptModifiedUser( - userId: '', - email: 'email@example.com', - password: 'password', - passwordSalt: '', - passwordSaltSeparator: '', - passwordSignerKey: '', - name: '', // (optional) -); -``` - -### Using Argon2 -```dart -import 'package:dart_appwrite/dart_appwrite.dart'; - -Client client = Client() - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('') // Your project ID - .setKey(''); // Your secret API key - -Users users = Users(client); - -User result = await users.createArgon2User( - userId: '', - email: 'email@example.com', - password: 'password', - name: '', // (optional) -); -``` - -Replace ``, ``, ``, ``, ``, and `` with your actual Appwrite project details and user-specific information. +In this example, replace ``, ``, ``, ``, and other placeholders with your actual Appwrite project details and user information. The `create` method allows you to specify optional parameters like `email`, `phone`, `password`, and `name` to create a user. Sources: - https://appwrite.io/docs/references/cloud/server-dart/users diff --git a/tests/how-do-you-add-a-custom-domain-in-the-console.md b/tests/how-do-you-add-a-custom-domain-in-the-console.md index f51414b..c499748 100644 --- a/tests/how-do-you-add-a-custom-domain-in-the-console.md +++ b/tests/how-do-you-add-a-custom-domain-in-the-console.md @@ -1,19 +1,17 @@ To add a custom domain in the Appwrite Console, follow these steps: -1. **Navigate to the Appwrite Console and go to your project.** -2. **Click on the Settings tab in the left sidebar.** -3. **Select the Custom domains section and click Create domain.** -4. **Add your domain, and copy the associated CNAME record to your DNS provider.** You can refer to the [Add a CNAME record](https://appwrite.io/docs/advanced/platform/custom-domains/##cname-record) section for more details. -5. **Verify your domain.** Note that DNS changes might take up to 48 hours to propagate worldwide, so you may not be able to complete this step on the same day. -6. **Once you verify your domain, you can generate an SSL certificate.** +1. Go to the Appwrite Console and navigate to your project. +2. Click on the **Settings** tab in the left sidebar. +3. Select the **Custom domains** section and click **Create domain**. +4. Add your domain, and copy the associated CNAME record to your DNS provider. Refer to the [Add a CNAME record](https://appwrite.io/docs/advanced/platform/custom-domains/##cname-record) section for more details. +5. Verify your domain. Keep in mind that DNS changes might take up to 48 hours to propagate worldwide, so you may not be able to complete this step immediately. +6. Once your domain is verified, you can generate an SSL certificate. -When both **VERIFICATION STATUS** and **CERTIFICATE STATUS** are green, the new domain is ready to use. - -If you encounter any issues during the setup process or have questions, don't hesitate to [contact Appwrite support](https://appwrite.io/docs/advanced/platform/custom-domains/#/contact-us), and they will be happy to assist you. +After completing these steps, your Appwrite project will be able to accept API requests from your custom domain. If you encounter any issues during the setup process or have questions, you can [contact Appwrite support](https://appwrite.io/docs/advanced/platform/custom-domains/#/contact-us) for assistance. Sources: - https://appwrite.io/docs/products/functions/domains/ - https://appwrite.io/docs/advanced/platform/custom-domains/ -- https://appwrite.io/docs/products/messaging/mailgun/ -- https://appwrite.io/docs/tutorials/subscriptions-with-stripe/step-3/ -- https://appwrite.io/docs/tutorials/subscriptions-with-stripe/step-4/ +- https://appwrite.io/docs/products/sites/domains/ +- https://appwrite.io/docs/products/network/dns/ +- https://appwrite.io/docs/products/sites/migrations/vercel/ diff --git a/tests/how-to-use-appwrite-with-react.md b/tests/how-to-use-appwrite-with-react.md index c0c2686..5d6e3da 100644 --- a/tests/how-to-use-appwrite-with-react.md +++ b/tests/how-to-use-appwrite-with-react.md @@ -1,101 +1,49 @@ To use Appwrite with React, follow these steps: -### Prerequisites: -1. Ensure you have a recent version of [Node.js](https://nodejs.org/en/download/) installed on your system. -2. Have a basic knowledge of Next.js and React. -3. Follow the [Start with React](https://appwrite.io/docs/quick-starts/react) guide. - -### Step-by-Step Guide: - -#### 1. Create a Vite Project: -First, create a new Vite project with a React template: -```sh -npm create vite@latest my-app -- --template react && cd my-app -``` - -#### 2. Install the Appwrite SDK: -Install the JavaScript Appwrite SDK: -```sh -npm install appwrite@14.0.1 -``` - -#### 3. Setup Appwrite Project: -1. Head to the [Appwrite Console](https://cloud.appwrite.io/console). -2. If this is your first time using Appwrite, create an account and create your first project. -3. Under **Add a platform**, add a **Web app**. The **Hostname** should be `localhost`. - -#### 4. Initialize Appwrite SDK: -Create a new file `src/lib/appwrite.js` to hold your Appwrite-related code. Only one instance of the `Client()` class should be created per app. Add the following code to it, replacing `` with your project ID: - -```javascript -import { Client, Databases, Account } from "appwrite"; - -const client = new Client(); -client - .setEndpoint("https://cloud.appwrite.io/v1") - .setProject(""); // Replace with your project ID - -export const account = new Account(client); -export const databases = new Databases(client); -``` - -#### 5. Create a Simple Login Form: -Add the following components to your `App.js` file to create a simple login form: - -```javascript -import React, { useState } from 'react'; -import { account } from './lib/appwrite'; - -function App() { - const [email, setEmail] = useState(''); - const [password, setPassword] = useState(''); - const [name, setName] = useState(''); - const [loggedInUser, setLoggedInUser] = useState(null); - - const login = async (email, password) => { - try { - const response = await account.createSession(email, password); - setLoggedInUser(response); - } catch (error) { - console.error(error); - } - }; - - return ( -
-

{loggedInUser ? `Logged in as ${loggedInUser.name}` : 'Not logged in'}

- setEmail(e.target.value)} - /> - setPassword(e.target.value)} - /> - setName(e.target.value)} - /> - -
- ); -} - -export default App; -``` - -### Summary: -By following these steps, you can set up Appwrite with React and create a simple login form. This example demonstrates how to initialize the Appwrite SDK and use it to handle user authentication. For more advanced features, refer to the [Appwrite documentation](https://appwrite.io/docs). +1. **Set Up Your Environment:** + - Ensure you have a recent version of [Node.js](https://nodejs.org/en/download/) installed. + - Have a basic understanding of React and Next.js. + +2. **Create a React Project:** + - You can create a new React project using Vite with the following command: + ```sh + npm create vite@latest my-app -- --template react && cd my-app + ``` + +3. **Install Appwrite SDK:** + - Install the JavaScript Appwrite SDK in your project: + ```sh + npm install appwrite@18.1.1 + ``` + +4. **Set Up Appwrite Project:** + - Go to the [Appwrite Console](https://cloud.appwrite.io/console). + - Create an account if you haven't already and create a new project. + - Under **Add a platform**, add a **Web app** with the **Hostname** set to `localhost`. + +5. **Initialize Appwrite SDK in Your React App:** + - Find your project's ID in the **Settings** page of the Appwrite console. + - Create a new file `src/lib/appwrite.js` in your React project and add the following code, replacing `` with your actual project ID: + ```javascript + import { Client, Account, Databases } from 'appwrite'; + + const client = new Client(); + client + .setEndpoint('https://.cloud.appwrite.io/v1') + .setProject(''); // Replace with your project ID + + export const account = new Account(client); + export const databases = new Databases(client); + ``` + +6. **Use Appwrite Services:** + - You can now use Appwrite services like authentication, databases, and more in your React components by importing the `account` and `databases` objects from `src/lib/appwrite.js`. + +By following these steps, you can integrate Appwrite into your React application, allowing you to leverage its backend services such as authentication, databases, and more. Sources: - https://appwrite.io/docs/tutorials/nextjs-ssr-auth/step-1/ -- https://appwrite.io/docs/tutorials/nextjs-ssr-auth/step-2/ - https://appwrite.io/docs/quick-starts/react/ - https://appwrite.io/docs/tutorials/react/step-3/ -- https://appwrite.io/docs/quick-starts/react-native/ +- https://appwrite.io/docs/tutorials/sveltekit-ssr-auth/step-1/ +- https://appwrite.io/docs/products/sites/quick-start/react/ diff --git a/tests/show-me-how-i-can-set-up-database-collections-and-documents.md b/tests/show-me-how-i-can-set-up-database-collections-and-documents.md index 65b5ea2..d13fcc8 100644 --- a/tests/show-me-how-i-can-set-up-database-collections-and-documents.md +++ b/tests/show-me-how-i-can-set-up-database-collections-and-documents.md @@ -1,108 +1,87 @@ -To set up database collections and documents in Appwrite, you can follow these steps. I'll provide examples using the Node.js and Web Appwrite SDKs. +To set up database collections and documents in Appwrite, you can follow these steps: -### Step-by-Step Guide +### Step 1: Create a Collection -1. **Create a Database:** - - Head to your [Appwrite Console](https://cloud.appwrite.io/console/). - - Create a database and name it `Oscar`. Optionally, add a custom database ID. +1. **Navigate to the Appwrite Console**: Go to [Appwrite Console](https://cloud.appwrite.io/). +2. **Create a New Collection**: + - Go to the Databases section and create a new collection. + - Define the collection attributes. For example, to store ideas, you might have: + - `userId` (String, Required) + - `title` (String, Required) + - `description` (String, Not Required) -2. **Create a Collection:** - - Navigate to the **Databases** page. - - Select the `Oscar` database. - - Click **Create collection** and name it `My books`. Optionally, add a custom collection ID. +### Step 2: Configure Permissions -3. **Define Collection Attributes:** - - Navigate to **Attributes**. - - Click **Create attribute** and select **String**. - - Enter **Attribute key** (e.g., `title`) and **Size** (e.g., `100`). +1. **Set Collection Permissions**: + - Navigate to the **Settings** tab of your collection. + - Add the role **Any** and check the **Read** box to allow public read access. + - Add a **Users** role and check the **Create** box to allow users to create documents. + - Enable **Document security** to allow setting permissions at the document level. + - Click the **Update** button to save changes. -4. **Set Permissions:** - - Navigate to **Settings** > **Permissions**. - - Add a new role **Any**. - - Check the **CREATE** and **READ** permissions, so anyone can create and read documents. - -### Code Examples +### Step 3: Use Appwrite SDK to Interact with the Database #### Using Node.js SDK -First, install the Appwrite Node.js SDK: - -```bash -npm install node-appwrite -``` - -Then, use the following code to create a document: - ```javascript -const { Client, Databases } = require('node-appwrite'); +const sdk = require('node-appwrite'); // Initialize the client -const client = new Client() - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('') // Your project ID +const client = new sdk.Client(); +client + .setEndpoint('https://[YOUR_APPWRITE_ENDPOINT]') // Your Appwrite Endpoint + .setProject('YOUR_PROJECT_ID') // Your project ID .setKey('YOUR_API_KEY'); // Your secret API key -// Initialize the Databases service -const databases = new Databases(client); +// Initialize the database service +const databases = new sdk.Databases(client); // Create a document -const promise = databases.createDocument('', '', 'unique()', { - title: 'My First Book' +const promise = databases.createDocument('databaseId', 'collectionId', 'unique()', { + userId: 'user123', + title: 'My Idea', + description: 'This is a description of my idea.' }); -promise.then(response => { +promise.then(function (response) { console.log(response); // Success -}, error => { +}, function (error) { console.log(error); // Failure }); ``` #### Using Web SDK -First, include the Appwrite Web SDK in your project. You can use a CDN or install it via npm: - -```bash -npm install appwrite -``` - -Then, use the following code to create a document: - ```javascript import { Client, Databases } from 'appwrite'; // Initialize the client const client = new Client(); client - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject(''); // Your project ID + .setEndpoint('https://[YOUR_APPWRITE_ENDPOINT]') // Your Appwrite Endpoint + .setProject('YOUR_PROJECT_ID'); // Your project ID -// Initialize the Databases service +// Initialize the database service const databases = new Databases(client); // Create a document -databases.createDocument('', '', 'unique()', { - title: 'My First Book' -}) -.then(response => { +databases.createDocument('databaseId', 'collectionId', 'unique()', { + userId: 'user123', + title: 'My Idea', + description: 'This is a description of my idea.' +}).then(response => { console.log(response); // Success -}) -.catch(error => { +}).catch(error => { console.log(error); // Failure }); ``` -### Summary - -1. **Create a database** in the Appwrite Console. -2. **Create a collection** within that database. -3. **Define attributes** for the collection. -4. **Set permissions** for the collection. -5. **Use the SDK** to create documents within the collection. +Replace `'YOUR_APPWRITE_ENDPOINT'`, `'YOUR_PROJECT_ID'`, `'YOUR_API_KEY'`, `'databaseId'`, and `'collectionId'` with your actual Appwrite endpoint, project ID, API key, database ID, and collection ID respectively. -By following these steps and using the provided code examples, you can set up database collections and documents in Appwrite. +This setup allows you to create collections and documents, configure permissions, and interact with your database using Appwrite's SDKs. Sources: -- https://appwrite.io/docs/tutorials/react/step-6/ -- https://appwrite.io/docs/products/databases/collections/ -- https://appwrite.io/docs/references/cloud/client-android-java/databases -- https://appwrite.io/docs/products/databases/quick-start/ +- https://appwrite.io/docs/tutorials/react-native/step-6/ +- https://appwrite.io/docs/references/cloud/server-nodejs/databases +- https://appwrite.io/docs/references/cloud/server-java/databases +- https://appwrite.io/docs/references/cloud/server-graphql/databases diff --git a/tests/what-endpoints-are-available-for-the-avatars-api-im-using-the-php-sdk.md b/tests/what-endpoints-are-available-for-the-avatars-api-im-using-the-php-sdk.md index be43fa7..50d6508 100644 --- a/tests/what-endpoints-are-available-for-the-avatars-api-im-using-the-php-sdk.md +++ b/tests/what-endpoints-are-available-for-the-avatars-api-im-using-the-php-sdk.md @@ -1,47 +1,17 @@ -Based on the provided context, the only endpoint mentioned for the Avatars API is: +I don't have the specific details for the PHP SDK, but I can provide you with the general endpoints available for the Avatars API in Appwrite. The Avatars API typically includes the following endpoints: -```text -GET /avatars/image -``` +1. **GET /avatars/credit-card**: Generate a credit card icon. +2. **GET /avatars/favicon**: Fetch a website's favicon. +3. **GET /avatars/flag**: Generate a country flag icon. +4. **GET /avatars/image**: Fetch an image from a URL and crop it to a square. +5. **GET /avatars/initials**: Generate initials avatar. +6. **GET /avatars/qr**: Generate a QR code image. -However, this context does not provide a comprehensive list of all available endpoints for the Avatars API. For a complete list of endpoints and their functionalities, I recommend referring to the official Appwrite documentation. - -If you need to use the Avatars API with the PHP SDK, here is an example of how you might use the `GET /avatars/image` endpoint: - -### PHP SDK Example - -```php -setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint - ->setProject('YOUR_PROJECT_ID') // Your project ID - ->setKey('YOUR_API_KEY'); // Your secret API key - -$avatars = new Avatars($client); - -try { - $response = $avatars->getImage('https://example.com/image.png'); - echo $response; // Handle the response as needed -} catch (Exception $e) { - echo 'Error: ' . $e->getMessage(); -} -``` - -Make sure to replace `'YOUR_PROJECT_ID'`, `'YOUR_API_KEY'`, and the URL in `getImage` with your actual project ID, API key, and image URL respectively. - -For more detailed information and additional endpoints, please refer to the [Appwrite Avatars API documentation](https://appwrite.io/docs/client/avatars). +For using these endpoints with the PHP SDK, you would typically use the `Avatars` class provided by the SDK. You can refer to the Appwrite PHP SDK documentation for specific usage examples. Sources: -- https://appwrite.io/docs/references/cloud/server-nodejs/avatars -- https://appwrite.io/docs/references/cloud/client-rest/avatars +- https://appwrite.io/docs/references/cloud/server-java/avatars +- https://appwrite.io/docs/references/cloud/server-php/avatars +- https://appwrite.io/docs/references/cloud/server-dotnet/avatars +- https://appwrite.io/docs/references/cloud/server-deno/avatars - https://appwrite.io/docs/references/cloud/client-graphql/avatars -- https://appwrite.io/docs/references/cloud/server-dart/avatars -- https://appwrite.io/docs/references/cloud/client-apple/avatars diff --git a/tests/whats-the-difference-between-server-and-client-sdks.md b/tests/whats-the-difference-between-server-and-client-sdks.md index 7098aa4..0687ab0 100644 --- a/tests/whats-the-difference-between-server-and-client-sdks.md +++ b/tests/whats-the-difference-between-server-and-client-sdks.md @@ -1,73 +1,19 @@ -The difference between Server and Client SDKs in Appwrite primarily lies in their intended use cases and the environments in which they operate. +The difference between Server and Client SDKs in Appwrite lies in their intended use cases and the permissions they operate under: -### Client SDKs -Client SDKs are designed to be used in client-side applications, such as mobile apps or web applications. These SDKs are intended to run on the end-user's device and are typically used for operations that involve user interaction. They are optimized for security and performance in a client environment. +1. **Client SDKs**: + - Designed for integrating with Appwrite to build client-based applications and websites. + - Used in web, mobile, or native applications where end-users will register and create accounts. + - Access to resources is controlled by user permissions, meaning users must be granted specific permissions to access certain resources. -**Key Characteristics:** -- **Environment:** Runs on the user's device (e.g., mobile app, web browser). -- **Security:** Includes mechanisms to handle authentication and authorization securely on the client side. -- **Use Cases:** User authentication, querying databases, file uploads, and other operations that require direct user input. +2. **Server SDKs**: + - Designed for integrating with Appwrite to build backend or server applications, such as admin apps, CLI tools, or server-side rendered (SSR) web apps. + - Operate under the constraints of an API key's scope, which means they ignore user permissions and are instead controlled by the API key's defined permissions. + - Suitable for server-side operations where you need to perform actions on behalf of the server rather than individual users. -### Server SDKs -Server SDKs are designed to be used in server-side applications. These SDKs are intended to run on your server and are typically used for backend operations that do not involve direct user interaction. They are optimized for performance and security in a server environment. - -**Key Characteristics:** -- **Environment:** Runs on a server (e.g., Node.js server, backend service). -- **Security:** Allows for more control over security and access permissions, suitable for backend operations. -- **Use Cases:** Managing databases, handling file storage, performing scheduled tasks, and other backend operations. - -### Example Code - -#### Client SDK Example (JavaScript for Web) -```javascript -import { Client, Databases } from 'appwrite'; - -const client = new Client(); - -client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint - .setProject('projectID'); // Your project ID - -const databases = new Databases(client); - -// Example: Fetching a list of documents -databases.listDocuments('collectionID') - .then(response => { - console.log(response); - }) - .catch(error => { - console.error(error); - }); -``` - -#### Server SDK Example (Node.js) -```javascript -const { Client, Databases } = require('appwrite'); - -const client = new Client(); - -client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint - .setProject('projectID') // Your project ID - .setKey('API_KEY'); // Your secret API key - -const databases = new Databases(client); - -// Example: Fetching a list of documents -databases.listDocuments('collectionID') - .then(response => { - console.log(response); - }) - .catch(error => { - console.error(error); - }); -``` - -In summary, Client SDKs are for client-side applications and are optimized for secure interactions with the end-user, while Server SDKs are for server-side applications and offer more control over backend operations. +In summary, Client SDKs are for user-facing applications with user-specific permissions, while Server SDKs are for backend operations with broader access defined by API keys. Sources: -- https://appwrite.io/docs/references/cloud/client-android-java/storage -- https://appwrite.io/docs/references/cloud/server-nodejs/storage -- https://appwrite.io/docs/references/cloud/server-swift/storage -- https://appwrite.io/docs/references/cloud/client-android-java/databases -- https://appwrite.io/docs/references/cloud/server-dart/storage +- https://appwrite.io/docs/references/ +- https://appwrite.io/docs/references/quick-start/ +- https://appwrite.io/docs/products/auth/server-side-rendering/ +- https://appwrite.io/docs/sdks/