diff --git a/bun/sync-with-meilisearch/README.md b/bun/sync-with-meilisearch/README.md index 45b71dae..e6d17f8d 100644 --- a/bun/sync-with-meilisearch/README.md +++ b/bun/sync-with-meilisearch/README.md @@ -28,16 +28,6 @@ Sample `204` Response: No content. ## 🔒 Environment Variables -### APPWRITE_API_KEY - -API Key to talk to Appwrite backend APIs. - -| Question | Answer | -| ------------- | ------------------------------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `d1efb...aec35` | -| Documentation | [Appwrite: Getting Started for Server](https://appwrite.io/docs/advanced/platform/api-keys) | - ### APPWRITE_DATABASE_ID The ID of the Appwrite database that contains the collection to sync. @@ -58,15 +48,6 @@ The ID of the collection in the Appwrite database to sync. | Sample Value | `7c3e8...2a9f1` | | Documentation | [Appwrite: Collections](https://appwrite.io/docs/products/databases/collections) | -### APPWRITE_ENDPOINT - -The URL endpoint of the Appwrite server. If not provided, it defaults to the Appwrite Cloud server: `https://cloud.appwrite.io/v1`. - -| Question | Answer | -| ------------ | ------------------------------ | -| Required | No | -| Sample Value | `https://cloud.appwrite.io/v1` | - ### MEILISEARCH_ENDPOINT The host URL of the Meilisearch server. diff --git a/bun/sync-with-meilisearch/env.d.ts b/bun/sync-with-meilisearch/env.d.ts index c06173fd..9715e207 100644 --- a/bun/sync-with-meilisearch/env.d.ts +++ b/bun/sync-with-meilisearch/env.d.ts @@ -1,7 +1,6 @@ declare module "bun" { interface Env { - APPWRITE_ENDPOINT?: string; - APPWRITE_API_KEY: string; + APPWRITE_FUNCTION_API_ENDPOINT: string; APPWRITE_FUNCTION_PROJECT_ID: string; APPWRITE_DATABASE_ID: string; APPWRITE_COLLECTION_ID: string; diff --git a/bun/sync-with-meilisearch/src/main.ts b/bun/sync-with-meilisearch/src/main.ts index 6a28bf04..d7bd307c 100644 --- a/bun/sync-with-meilisearch/src/main.ts +++ b/bun/sync-with-meilisearch/src/main.ts @@ -4,7 +4,6 @@ import { MeiliSearch } from "meilisearch"; export default async ({ req, res, log }) => { throwIfMissing(Bun.env, [ - "APPWRITE_API_KEY", "APPWRITE_DATABASE_ID", "APPWRITE_COLLECTION_ID", "MEILISEARCH_ENDPOINT", @@ -24,9 +23,9 @@ export default async ({ req, res, log }) => { } const client = new Client() - .setEndpoint(Bun.env.APPWRITE_ENDPOINT ?? "https://cloud.appwrite.io/v1") + .setEndpoint(Bun.env.APPWRITE_FUNCTION_API_ENDPOINT) .setProject(Bun.env.APPWRITE_FUNCTION_PROJECT_ID) - .setKey(Bun.env.APPWRITE_API_KEY); + .setKey(req.headers['x-appwrite-key'] ?? ''); const databases = new Databases(client); diff --git a/bun/sync-with-qdrant/README.md b/bun/sync-with-qdrant/README.md index 2af3e7ea..5cbc75b2 100644 --- a/bun/sync-with-qdrant/README.md +++ b/bun/sync-with-qdrant/README.md @@ -24,16 +24,6 @@ Triggers sync of the Appwrite database collection to Qdrant. ## 🔒 Environment Variables -### APPWRITE_API_KEY - -API Key to talk to Appwrite backend APIs. - -| Question | Answer | -| ------------- | -------------------------------------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `d1efb...aec35` | -| Documentation | [Appwrite: Getting Started for Server](https://appwrite.io/docs/getting-started-for-server#apiKey) | - ### APPWRITE_DATABASE_ID The ID of the Appwrite database that contains the collection to sync. @@ -54,15 +44,6 @@ The ID of the collection in the Appwrite database to sync. | Sample Value | `7c3e8...2a9f1` | | Documentation | [Appwrite: Collections](https://appwrite.io/docs/databases#collection) | -### APPWRITE_ENDPOINT - -The URL endpoint of the Appwrite server. If not provided, it defaults to the Appwrite Cloud server: `https://cloud.appwrite.io/v1`. - -| Question | Answer | -| ------------ | ------------------------------ | -| Required | No | -| Sample Value | `https://cloud.appwrite.io/v1` | - ### QDRANT_URL The URL of the Qdrant server. diff --git a/bun/sync-with-qdrant/env.d.ts b/bun/sync-with-qdrant/env.d.ts index c06173fd..9715e207 100644 --- a/bun/sync-with-qdrant/env.d.ts +++ b/bun/sync-with-qdrant/env.d.ts @@ -1,7 +1,6 @@ declare module "bun" { interface Env { - APPWRITE_ENDPOINT?: string; - APPWRITE_API_KEY: string; + APPWRITE_FUNCTION_API_ENDPOINT: string; APPWRITE_FUNCTION_PROJECT_ID: string; APPWRITE_DATABASE_ID: string; APPWRITE_COLLECTION_ID: string; diff --git a/bun/sync-with-qdrant/src/appwrite.ts b/bun/sync-with-qdrant/src/appwrite.ts index 7bcf718e..40aa4b28 100644 --- a/bun/sync-with-qdrant/src/appwrite.ts +++ b/bun/sync-with-qdrant/src/appwrite.ts @@ -3,14 +3,12 @@ import { Client, Databases, Query } from 'node-appwrite'; class AppwriteService { databases: Databases; - constructor() { + constructor(apiKey: string) { const client = new Client(); client - .setEndpoint( - process.env.APPWRITE_ENDPOINT ?? 'https://cloud.appwrite.io/v1' - ) + .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) - .setKey(process.env.APPWRITE_API_KEY); + .setKey(apiKey); this.databases = new Databases(client); } diff --git a/bun/sync-with-qdrant/src/main.ts b/bun/sync-with-qdrant/src/main.ts index c950b86f..63f27e7c 100644 --- a/bun/sync-with-qdrant/src/main.ts +++ b/bun/sync-with-qdrant/src/main.ts @@ -5,7 +5,6 @@ import AppwriteService from './appwrite.js'; export default async ({ req, res, log }: Context) => { throwIfMissing(process.env, [ - 'APPWRITE_API_KEY', 'APPWRITE_DATABASE_ID', 'APPWRITE_COLLECTION_ID', 'QDRANT_URL', @@ -51,7 +50,7 @@ export default async ({ req, res, log }: Context) => { } log('Fetching documents from Appwrite...'); - const appwrite = new AppwriteService(); + const appwrite = new AppwriteService(req.headers['x-appwrite-key'] ?? ''); const documents = await appwrite.getAllDocuments( process.env.APPWRITE_DATABASE_ID, process.env.APPWRITE_COLLECTION_ID diff --git a/deno/sync-with-meilisearch/README.md b/deno/sync-with-meilisearch/README.md index f874c6c6..f8886c9d 100644 --- a/deno/sync-with-meilisearch/README.md +++ b/deno/sync-with-meilisearch/README.md @@ -28,16 +28,6 @@ Sample `204` Response: No content. ## 🔒 Environment Variables -### APPWRITE_API_KEY - -API Key to talk to Appwrite backend APIs. - -| Question | Answer | -| ------------- | ------------------------------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `d1efb...aec35` | -| Documentation | [Appwrite: Getting Started for Server](https://appwrite.io/docs/advanced/platform/api-keys) | - ### APPWRITE_DATABASE_ID The ID of the Appwrite database that contains the collection to sync. @@ -58,15 +48,6 @@ The ID of the collection in the Appwrite database to sync. | Sample Value | `7c3e8...2a9f1` | | Documentation | [Appwrite: Collections](https://appwrite.io/docs/products/databases/collections) | -### APPWRITE_ENDPOINT - -The URL endpoint of the Appwrite server. If not provided, it defaults to the Appwrite Cloud server: `https://cloud.appwrite.io/v1`. - -| Question | Answer | -| ------------ | ------------------------------ | -| Required | No | -| Sample Value | `https://cloud.appwrite.io/v1` | - ### MEILISEARCH_ENDPOINT The host URL of the Meilisearch server. diff --git a/deno/sync-with-meilisearch/src/main.ts b/deno/sync-with-meilisearch/src/main.ts index 07287711..e5952ba9 100644 --- a/deno/sync-with-meilisearch/src/main.ts +++ b/deno/sync-with-meilisearch/src/main.ts @@ -8,7 +8,6 @@ import { MeiliSearch } from "https://esm.sh/meilisearch@0.35.0"; export default async ({ req, res, log, error }: any) => { throwIfMissing(Deno.env.toObject(), [ - "APPWRITE_API_KEY", "APPWRITE_DATABASE_ID", "APPWRITE_COLLECTION_ID", "MEILISEARCH_ENDPOINT", @@ -30,11 +29,9 @@ export default async ({ req, res, log, error }: any) => { } const client = new Client() - .setEndpoint( - Deno.env.get("APPWRITE_ENDPOINT") ?? "https://cloud.appwrite.io/v1", - ) + .setEndpoint(Deno.env.get("APPWRITE_FUNCTION_API_ENDPOINT") ?? "") .setProject(Deno.env.get("APPWRITE_FUNCTION_PROJECT_ID") ?? "") - .setKey(Deno.env.get("APPWRITE_API_KEY") ?? ""); + .setKey(req.headers['x-appwrite-key'] ?? ""); const databases = new Databases(client); diff --git a/kotlin/sync-with-meilisearch/README.md b/kotlin/sync-with-meilisearch/README.md index 622eae45..17013f2b 100644 --- a/kotlin/sync-with-meilisearch/README.md +++ b/kotlin/sync-with-meilisearch/README.md @@ -27,16 +27,6 @@ Sample `204` Response: No content. ## 🔒 Environment Variables -### APPWRITE_API_KEY - -API Key to talk to Appwrite backend APIs. - -| Question | Answer | -| ------------- | ------------------------------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `d1efb...aec35` | -| Documentation | [Appwrite: Getting Started for Server](https://appwrite.io/docs/advanced/platform/api-keys) | - ### APPWRITE_DATABASE_ID The ID of the Appwrite database that contains the collection to sync. @@ -57,15 +47,6 @@ The ID of the collection in the Appwrite database to sync. | Sample Value | `7c3e8...2a9f1` | | Documentation | [Appwrite: Collections](https://appwrite.io/docs/products/databases/collections) | -### APPWRITE_ENDPOINT - -The URL endpoint of the Appwrite server. If not provided, it defaults to the Appwrite Cloud server: `https://cloud.appwrite.io/v1`. - -| Question | Answer | -| ------------ | ------------------------------ | -| Required | No | -| Sample Value | `https://cloud.appwrite.io/v1` | - ### MEILISEARCH_ENDPOINT The host URL of the Meilisearch server. diff --git a/kotlin/sync-with-meilisearch/src/Main.kt b/kotlin/sync-with-meilisearch/src/Main.kt index 745c7ac7..486656aa 100644 --- a/kotlin/sync-with-meilisearch/src/Main.kt +++ b/kotlin/sync-with-meilisearch/src/Main.kt @@ -15,7 +15,6 @@ class Main { suspend fun main(context: RuntimeContext): RuntimeOutput { Utils.throwIfMissing(System.getenv(), listOf( - "APPWRITE_API_KEY", "APPWRITE_DATABASE_ID", "APPWRITE_COLLECTION_ID", "MEILISEARCH_ENDPOINT", @@ -35,9 +34,9 @@ class Main { } val client = AppwriteClient().apply { - setEndpoint(System.getenv("APPWRITE_ENDPOINT") ?: "https://cloud.appwrite.io/v1") + setEndpoint(System.getenv("APPWRITE_FUNCTION_API_ENDPOINT")) setProject(System.getenv("APPWRITE_FUNCTION_PROJECT_ID")) - setKey(System.getenv("APPWRITE_API_KEY")) + setKey(context.res.headers["x-appwrite-key"]) } val databases = Databases(client) diff --git a/node-typescript/sync-with-meilisearch/README.md b/node-typescript/sync-with-meilisearch/README.md index 9ecfbf47..cba1b7a0 100644 --- a/node-typescript/sync-with-meilisearch/README.md +++ b/node-typescript/sync-with-meilisearch/README.md @@ -28,16 +28,6 @@ Sample `204` Response: No content. ## 🔒 Environment Variables -### APPWRITE_API_KEY - -API Key to talk to Appwrite backend APIs. - -| Question | Answer | -| ------------- | ------------------------------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `d1efb...aec35` | -| Documentation | [Appwrite: Getting Started for Server](https://appwrite.io/docs/advanced/platform/api-keys) | - ### APPWRITE_DATABASE_ID The ID of the Appwrite database that contains the collection to sync. @@ -58,15 +48,6 @@ The ID of the collection in the Appwrite database to sync. | Sample Value | `7c3e8...2a9f1` | | Documentation | [Appwrite: Collections](https://appwrite.io/docs/products/databases/collections) | -### APPWRITE_ENDPOINT - -The URL endpoint of the Appwrite server. If not provided, it defaults to the Appwrite Cloud server: `https://cloud.appwrite.io/v1`. - -| Question | Answer | -| ------------ | ------------------------------ | -| Required | No | -| Sample Value | `https://cloud.appwrite.io/v1` | - ### MEILISEARCH_ENDPOINT The host URL of the Meilisearch server. diff --git a/node-typescript/sync-with-meilisearch/env.d.ts b/node-typescript/sync-with-meilisearch/env.d.ts index 53708b23..7e061527 100644 --- a/node-typescript/sync-with-meilisearch/env.d.ts +++ b/node-typescript/sync-with-meilisearch/env.d.ts @@ -1,8 +1,7 @@ declare global { namespace NodeJS { interface ProcessEnv { - APPWRITE_ENDPOINT?: string; - APPWRITE_API_KEY: string; + APPWRITE_FUNCTION_API_ENDPOINT: string; APPWRITE_FUNCTION_PROJECT_ID: string; APPWRITE_DATABASE_ID: string; APPWRITE_COLLECTION_ID: string; diff --git a/node-typescript/sync-with-meilisearch/src/main.ts b/node-typescript/sync-with-meilisearch/src/main.ts index 9e8e1322..6c79d288 100644 --- a/node-typescript/sync-with-meilisearch/src/main.ts +++ b/node-typescript/sync-with-meilisearch/src/main.ts @@ -11,7 +11,6 @@ type Context = { export default async ({ req, res, log }: Context) => { throwIfMissing(process.env, [ - 'APPWRITE_API_KEY', 'APPWRITE_DATABASE_ID', 'APPWRITE_COLLECTION_ID', 'MEILISEARCH_ENDPOINT', @@ -31,11 +30,9 @@ export default async ({ req, res, log }: Context) => { } const client = new Client() - .setEndpoint( - process.env.APPWRITE_ENDPOINT ?? 'https://cloud.appwrite.io/v1' - ) + .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) - .setKey(process.env.APPWRITE_API_KEY); + .setKey(req.headers['x-appwrite-key'] ?? ''); const databases = new Databases(client); diff --git a/node-typescript/sync-with-qdrant/README.md b/node-typescript/sync-with-qdrant/README.md index da7d8fed..7ce2e8b2 100644 --- a/node-typescript/sync-with-qdrant/README.md +++ b/node-typescript/sync-with-qdrant/README.md @@ -24,16 +24,6 @@ Triggers sync of the Appwrite database collection to Qdrant. ## 🔒 Environment Variables -### APPWRITE_API_KEY - -API Key to talk to Appwrite backend APIs. - -| Question | Answer | -| ------------- | -------------------------------------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `d1efb...aec35` | -| Documentation | [Appwrite: Getting Started for Server](https://appwrite.io/docs/getting-started-for-server#apiKey) | - ### APPWRITE_DATABASE_ID The ID of the Appwrite database that contains the collection to sync. @@ -54,15 +44,6 @@ The ID of the collection in the Appwrite database to sync. | Sample Value | `7c3e8...2a9f1` | | Documentation | [Appwrite: Collections](https://appwrite.io/docs/databases#collection) | -### APPWRITE_ENDPOINT - -The URL endpoint of the Appwrite server. If not provided, it defaults to the Appwrite Cloud server: `https://cloud.appwrite.io/v1`. - -| Question | Answer | -| ------------ | ------------------------------ | -| Required | No | -| Sample Value | `https://cloud.appwrite.io/v1` | - ### QDRANT_URL The URL of the Qdrant server. diff --git a/node-typescript/sync-with-qdrant/env.d.ts b/node-typescript/sync-with-qdrant/env.d.ts index e0c5f3ce..d43d184d 100644 --- a/node-typescript/sync-with-qdrant/env.d.ts +++ b/node-typescript/sync-with-qdrant/env.d.ts @@ -1,8 +1,7 @@ declare global { namespace NodeJS { interface ProcessEnv { - APPWRITE_ENDPOINT?: string; - APPWRITE_API_KEY: string; + APPWRITE_FUNCTION_API_ENDPOINT: string; APPWRITE_FUNCTION_PROJECT_ID: string; APPWRITE_DATABASE_ID: string; APPWRITE_COLLECTION_ID: string; diff --git a/node-typescript/sync-with-qdrant/src/appwrite.ts b/node-typescript/sync-with-qdrant/src/appwrite.ts index 1f48f1be..d113caf2 100644 --- a/node-typescript/sync-with-qdrant/src/appwrite.ts +++ b/node-typescript/sync-with-qdrant/src/appwrite.ts @@ -3,14 +3,12 @@ import { Client, Databases, Query } from 'node-appwrite'; class AppwriteService { databases: Databases; - constructor() { + constructor(apiKey) { const client = new Client(); client - .setEndpoint( - process.env.APPWRITE_ENDPOINT ?? 'https://cloud.appwrite.io/v1' - ) + .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) - .setKey(process.env.APPWRITE_API_KEY); + .setKey(apiKey); this.databases = new Databases(client); } diff --git a/node-typescript/sync-with-qdrant/src/main.ts b/node-typescript/sync-with-qdrant/src/main.ts index b5f164fb..aa9be75d 100644 --- a/node-typescript/sync-with-qdrant/src/main.ts +++ b/node-typescript/sync-with-qdrant/src/main.ts @@ -5,7 +5,6 @@ import AppwriteService from './appwrite.js'; export default async ({ req, res, log }: Context) => { throwIfMissing(process.env, [ - 'APPWRITE_API_KEY', 'APPWRITE_DATABASE_ID', 'APPWRITE_COLLECTION_ID', 'QDRANT_URL', @@ -51,7 +50,7 @@ export default async ({ req, res, log }: Context) => { } log('Fetching documents from Appwrite...'); - const appwrite = new AppwriteService(); + const appwrite = new AppwriteService(req.headers['x-appwrite-key'] ?? ''); const documents = await appwrite.getAllDocuments( process.env.APPWRITE_DATABASE_ID, process.env.APPWRITE_COLLECTION_ID diff --git a/node/database-cleaner/README.md b/node/database-cleaner/README.md index 60cd4116..14bf603d 100644 --- a/node/database-cleaner/README.md +++ b/node/database-cleaner/README.md @@ -24,25 +24,6 @@ Sample `200` Response: Cleaning Finished. ## 🔒 Environment Variables -### APPWRITE_API_KEY - -Your Appwrite project's API key. - -| Question | Answer | -| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `083d341ee48...` | -| Documentation | [Appwrite: Create an API key](https://appwrite.io/docs/keys#:~:text=To%20create%20a%20new%20API,scope%20to%20grant%20your%20application.) | - -### APPWRITE_ENDPOINT - -The endpoint where your Appwrite server is located. If not provided, it defaults to the Appwrite Cloud server: `https://cloud.appwrite.io/v1`. - -| Question | Answer | -| ------------ | ------------------------------ | -| Required | No | -| Sample Value | `https://cloud.appwrite.io/v1` | - ### APPWRITE_DATABASE_ID The ID of the database to wipe documents from. diff --git a/node/database-cleaner/src/appwrite.js b/node/database-cleaner/src/appwrite.js index 0c516614..77d6ecca 100644 --- a/node/database-cleaner/src/appwrite.js +++ b/node/database-cleaner/src/appwrite.js @@ -2,14 +2,12 @@ import { Client, Databases, Query } from 'node-appwrite'; import { getExpiryDate } from './utils.js'; class AppwriteService { - constructor() { + constructor(apiKey) { const client = new Client(); client - .setEndpoint( - process.env.APPWRITE_ENDPOINT ?? 'https://cloud.appwrite.io/v1' - ) + .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) - .setKey(process.env.APPWRITE_API_KEY); + .setKey(apikey); this.databases = new Databases(client); } diff --git a/node/database-cleaner/src/main.js b/node/database-cleaner/src/main.js index daa1161d..137c8e50 100644 --- a/node/database-cleaner/src/main.js +++ b/node/database-cleaner/src/main.js @@ -5,11 +5,10 @@ export default async ({ req, res, log, error }) => { throwIfMissing(process.env, [ 'APPWRITE_DATABASE_ID', 'APPWRITE_COLLECTION_ID', - 'APPWRITE_API_KEY', 'RETENTION_PERIOD_DAYS', ]); - const appwrite = new AppwriteService(); + const appwrite = new AppwriteService(req.headers['x-appwrite-key'] ?? ''); await appwrite.cleanCollection( process.env.APPWRITE_DATABASE_ID, diff --git a/node/generate-with-together-ai/README.md b/node/generate-with-together-ai/README.md index d92c9a5e..45f7ed7c 100644 --- a/node/generate-with-together-ai/README.md +++ b/node/generate-with-together-ai/README.md @@ -86,25 +86,6 @@ A unique key used to authenticate with the Together AI API. Please note that thi | Sample Value | `r8_......` | | Documentation | [Together AI Docs](https://docs.together.ai/docs/quickstart) | -### APPWRITE_ENDPOINT - -The endpoint of the Appwrite API. - -| Question | Answer | -| ------------- | ------------------------------ | -| Required | No | -| Default Value | `https://cloud.appwrite.io/v1` | - -### APPWRITE_API_KEY - -A unique key used to authenticate with the Appwrite API. You can generate your API key in the Appwrite dashboard. It must have the `files.read` and `files.write` permissions. - -| Question | Answer | -| ------------- | -------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `631xxxxxxxx8a` | -| Documentation | [Appwrite Docs](https://appwrite.io/docs/advanced/platform/api-keys) | - ### APPWRITE_BUCKET_ID The ID of the Appwrite storage bucket where the image files will be saved. It must have permissions set for `any` read access for the front-end to work. diff --git a/node/generate-with-together-ai/src/main.js b/node/generate-with-together-ai/src/main.js index 6707ecd7..1b0b1b91 100644 --- a/node/generate-with-together-ai/src/main.js +++ b/node/generate-with-together-ai/src/main.js @@ -5,7 +5,6 @@ import { fetch } from 'undici'; export default async ({ req, res, error }) => { throwIfMissing(process.env, [ 'TOGETHER_API_KEY', - 'APPWRITE_API_KEY', 'APPWRITE_FUNCTION_PROJECT_ID', 'APPWRITE_BUCKET_ID', ]); @@ -92,13 +91,12 @@ export default async ({ req, res, error }) => { // Upload image to Appwrite Storage and return URL if (req.bodyJson.type === 'image') { - const endpoint = - process.env.APPWRITE_ENDPOINT || 'https://cloud.appwrite.io/v1'; + const endpoint = process.env.APPWRITE_FUNCTION_API_ENDPOINT; const client = new Client() .setEndpoint(endpoint) - .setKey(process.env.APPWRITE_API_KEY) - .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID); + .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) + .setKey(req.headers['x-appwrite-key']); const storage = new Storage(client); diff --git a/node/image-classification-with-huggingface/README.md b/node/image-classification-with-huggingface/README.md index 5a44881e..df732d06 100644 --- a/node/image-classification-with-huggingface/README.md +++ b/node/image-classification-with-huggingface/README.md @@ -65,27 +65,6 @@ Sample `404` Response: ## 🔒 Environment Variables -### APPWRITE_API_KEY - -Your Appwrite project's API key. - -| Question | Answer | -| ------------- | ------------------------------------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `083d341ee48...` | -| Documentation | [Appwrite: Create an API key](https://appwrite.io/docs/advanced/platform/api-keys#create-api-key) | - -This key should have all permissions in the `Databases` scope aswell as all permissions in the `Storage` scope. - -### APPWRITE_ENDPOINT - -The endpoint where your Appwrite server is located. If not provided, it defaults to the Appwrite Cloud server: `https://cloud.appwrite.io/v1`. - -| Question | Answer | -| ------------ | ------------------------------ | -| Required | No | -| Sample Value | `https://cloud.appwrite.io/v1` | - ### APPWRITE_BUCKET_ID The ID of the storage bucket where the images are stored. diff --git a/node/image-classification-with-huggingface/src/appwrite.js b/node/image-classification-with-huggingface/src/appwrite.js index 3f9aeca4..87debb7d 100644 --- a/node/image-classification-with-huggingface/src/appwrite.js +++ b/node/image-classification-with-huggingface/src/appwrite.js @@ -1,14 +1,12 @@ import { Client, Databases, ID, Storage } from 'node-appwrite'; class AppwriteService { - constructor() { + constructor(apiKey) { const client = new Client(); client - .setEndpoint( - process.env.APPWRITE_ENDPOINT ?? 'https://cloud.appwrite.io/v1' - ) + .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) - .setKey(process.env.APPWRITE_API_KEY); + .setKey(apiKey); this.databases = new Databases(client); this.storage = new Storage(client); diff --git a/node/image-classification-with-huggingface/src/main.js b/node/image-classification-with-huggingface/src/main.js index 67221c5b..9f138290 100644 --- a/node/image-classification-with-huggingface/src/main.js +++ b/node/image-classification-with-huggingface/src/main.js @@ -3,7 +3,7 @@ import { throwIfMissing } from './utils.js'; import AppwriteService from './appwrite.js'; export default async ({ req, res, log, error }) => { - throwIfMissing(process.env, ['HUGGINGFACE_ACCESS_TOKEN', 'APPWRITE_API_KEY']); + throwIfMissing(process.env, ['HUGGINGFACE_ACCESS_TOKEN']); const databaseId = process.env.APPWRITE_DATABASE_ID ?? 'ai'; const collectionId = @@ -25,7 +25,7 @@ export default async ({ req, res, log, error }) => { return res.json({ ok: false, error: 'Bad request' }, 400); } - const appwrite = new AppwriteService(); + const appwrite = new AppwriteService(req.headers['x-appwrite-key']); let file; try { diff --git a/node/image-classification-with-huggingface/src/setup.js b/node/image-classification-with-huggingface/src/setup.js index 105ca760..2214915b 100644 --- a/node/image-classification-with-huggingface/src/setup.js +++ b/node/image-classification-with-huggingface/src/setup.js @@ -2,8 +2,6 @@ import AppwriteService from './appwrite.js'; import { throwIfMissing } from './utils.js'; async function setup() { - throwIfMissing(process.env, ['APPWRITE_API_KEY']); - const databaseId = process.env.APPWRITE_DATABASE_ID ?? 'ai'; const collectionId = process.env.APPWRITE_COLLECTION_ID ?? 'image_classification'; @@ -11,7 +9,7 @@ async function setup() { console.log('Executing setup script...'); - const appwrite = new AppwriteService(); + const appwrite = new AppwriteService(process.env.APPWRITE_FUNCTION_API_KEY); if (await appwrite.doesAIDataExist(databaseId, collectionId)) { console.log(`Database exists.`); diff --git a/node/music-generation-with-huggingface/README.md b/node/music-generation-with-huggingface/README.md index 2796be3d..a759a5ac 100644 --- a/node/music-generation-with-huggingface/README.md +++ b/node/music-generation-with-huggingface/README.md @@ -36,27 +36,6 @@ Sample `200` Response: ## 🔒 Environment Variables -### APPWRITE_API_KEY - -Your Appwrite project's API key. - -| Question | Answer | -| ------------- | ------------------------------------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `083d341ee48...` | -| Documentation | [Appwrite: Create an API key](https://appwrite.io/docs/advanced/platform/api-keys#create-api-key) | - -This key should have all permissions in the `Storage` scope. - -### APPWRITE_ENDPOINT - -The endpoint where your Appwrite server is located. If not provided, it defaults to the Appwrite Cloud server: `https://cloud.appwrite.io/v1`. - -| Question | Answer | -| ------------ | ------------------------------ | -| Required | No | -| Sample Value | `https://cloud.appwrite.io/v1` | - ### APPWRITE_BUCKET_ID The ID of the storage bucket where the music files will be stored. diff --git a/node/music-generation-with-huggingface/env.d.ts b/node/music-generation-with-huggingface/env.d.ts index 374958d5..95a22b89 100644 --- a/node/music-generation-with-huggingface/env.d.ts +++ b/node/music-generation-with-huggingface/env.d.ts @@ -2,9 +2,8 @@ declare global { namespace NodeJS { interface ProcessEnv { HUGGINGFACE_ACCESS_TOKEN: string; - APPWRITE_ENDPOINT: string; + APPWRITE_FUNCTION_API_ENDPOINT: string; APPWRITE_FUNCTION_PROJECT_ID: string; - APPWRITE_API_KEY: string; APPWRITE_BUCKET_ID: string; } } diff --git a/node/music-generation-with-huggingface/src/appwrite.js b/node/music-generation-with-huggingface/src/appwrite.js index 31366ca2..05334978 100644 --- a/node/music-generation-with-huggingface/src/appwrite.js +++ b/node/music-generation-with-huggingface/src/appwrite.js @@ -1,14 +1,12 @@ import { Client, Databases, ID, InputFile, Storage } from 'node-appwrite'; class AppwriteService { - constructor() { + constructor(apiKey) { const client = new Client(); client - .setEndpoint( - process.env.APPWRITE_ENDPOINT ?? 'https://cloud.appwrite.io/v1' - ) + .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) - .setKey(process.env.APPWRITE_API_KEY); + .setKey(apiKey); this.databases = new Databases(client); this.storage = new Storage(client); diff --git a/node/music-generation-with-huggingface/src/main.js b/node/music-generation-with-huggingface/src/main.js index 66edf3bc..e754b02d 100644 --- a/node/music-generation-with-huggingface/src/main.js +++ b/node/music-generation-with-huggingface/src/main.js @@ -39,7 +39,7 @@ export default async ({ req, res }) => { const blob = await response.blob(); - const appwrite = new AppwriteService(); + const appwrite = new AppwriteService(req.headers['x-appwrite-key']); // @ts-ignore const file = await appwrite.createFile(bucketId, blob); diff --git a/node/music-generation-with-huggingface/src/setup.js b/node/music-generation-with-huggingface/src/setup.js index d4238cf3..db5a3eec 100644 --- a/node/music-generation-with-huggingface/src/setup.js +++ b/node/music-generation-with-huggingface/src/setup.js @@ -4,10 +4,9 @@ import { throwIfMissing } from './utils.js'; async function setup() { console.log('Executing setup script...'); - throwIfMissing(process.env, ['APPWRITE_API_KEY']); const bucketId = process.env.APPWRITE_BUCKET_ID ?? 'generated_music'; - const appwrite = new AppwriteService(); + const appwrite = new AppwriteService(process.env.APPWRITE_FUNCTION_API_KEY); if (await appwrite.doesGeneratedMusicBucketExist(bucketId)) { console.log(`Bucket exists.`); diff --git a/node/object-detection-with-huggingface/README.md b/node/object-detection-with-huggingface/README.md index 4e43eb55..affc68ca 100644 --- a/node/object-detection-with-huggingface/README.md +++ b/node/object-detection-with-huggingface/README.md @@ -125,27 +125,6 @@ Sample `404` Response: ## 🔒 Environment Variables -### APPWRITE_API_KEY - -Your Appwrite project's API key. - -| Question | Answer | -| ------------- | ------------------------------------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `083d341ee48...` | -| Documentation | [Appwrite: Create an API key](https://appwrite.io/docs/advanced/platform/api-keys#create-api-key) | - -This key should have all permissions in the `Databases` scope aswell as all permissions in the `Storage` scope. - -### APPWRITE_ENDPOINT - -The endpoint where your Appwrite server is located. If not provided, it defaults to the Appwrite Cloud server: `https://cloud.appwrite.io/v1`. - -| Question | Answer | -| ------------ | ------------------------------ | -| Required | No | -| Sample Value | `https://cloud.appwrite.io/v1` | - ### APPWRITE_BUCKET_ID The ID of the storage bucket where the images are stored. diff --git a/node/object-detection-with-huggingface/src/appwrite.js b/node/object-detection-with-huggingface/src/appwrite.js index 3f9aeca4..87debb7d 100644 --- a/node/object-detection-with-huggingface/src/appwrite.js +++ b/node/object-detection-with-huggingface/src/appwrite.js @@ -1,14 +1,12 @@ import { Client, Databases, ID, Storage } from 'node-appwrite'; class AppwriteService { - constructor() { + constructor(apiKey) { const client = new Client(); client - .setEndpoint( - process.env.APPWRITE_ENDPOINT ?? 'https://cloud.appwrite.io/v1' - ) + .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) - .setKey(process.env.APPWRITE_API_KEY); + .setKey(apiKey); this.databases = new Databases(client); this.storage = new Storage(client); diff --git a/node/object-detection-with-huggingface/src/main.js b/node/object-detection-with-huggingface/src/main.js index 67221c5b..9f138290 100644 --- a/node/object-detection-with-huggingface/src/main.js +++ b/node/object-detection-with-huggingface/src/main.js @@ -3,7 +3,7 @@ import { throwIfMissing } from './utils.js'; import AppwriteService from './appwrite.js'; export default async ({ req, res, log, error }) => { - throwIfMissing(process.env, ['HUGGINGFACE_ACCESS_TOKEN', 'APPWRITE_API_KEY']); + throwIfMissing(process.env, ['HUGGINGFACE_ACCESS_TOKEN']); const databaseId = process.env.APPWRITE_DATABASE_ID ?? 'ai'; const collectionId = @@ -25,7 +25,7 @@ export default async ({ req, res, log, error }) => { return res.json({ ok: false, error: 'Bad request' }, 400); } - const appwrite = new AppwriteService(); + const appwrite = new AppwriteService(req.headers['x-appwrite-key']); let file; try { diff --git a/node/object-detection-with-huggingface/src/setup.js b/node/object-detection-with-huggingface/src/setup.js index 96bc3938..15d5bf88 100644 --- a/node/object-detection-with-huggingface/src/setup.js +++ b/node/object-detection-with-huggingface/src/setup.js @@ -2,15 +2,13 @@ import AppwriteService from './appwrite.js'; import { throwIfMissing } from './utils.js'; async function setup() { - throwIfMissing(process.env, ['APPWRITE_API_KEY']); - const databaseId = process.env.APPWRITE_DATABASE_ID ?? 'ai'; const collectionId = process.env.APPWRITE_COLLECTION_ID ?? 'object_detection'; const bucketId = process.env.APPWRITE_BUCKET_ID ?? 'object_detection'; console.log('Executing setup script...'); - const appwrite = new AppwriteService(); + const appwrite = new AppwriteService(process.env.APPWRITE_FUNCTION_API_KEY); if (await appwrite.doesAIDataExist(databaseId, collectionId)) { console.log(`Database exists.`); diff --git a/node/password-expiry/README.md b/node/password-expiry/README.md index 9852f443..6c56a5de 100644 --- a/node/password-expiry/README.md +++ b/node/password-expiry/README.md @@ -41,25 +41,6 @@ You can set CRON to control how often the function is executed. For example, `0 ## 🔒 Environment Variables -### APPWRITE_API_KEY - -The API Key to talk to Appwrite backend APIs. - -| Question | Answer | -| ------------- | -------------------------------------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `d1efb...aec35` | -| Documentation | [Appwrite: Getting Started for Server](https://appwrite.io/docs/getting-started-for-server#apiKey) | - -### APPWRITE_ENDPOINT - -The URL endpoint of the Appwrite server. If not provided, it defaults to the Appwrite Cloud server: `https://cloud.appwrite.io/v1`. - -| Question | Answer | -| ------------ | ------------------------------ | -| Required | No | -| Sample Value | `https://cloud.appwrite.io/v1` | - ### MAX_PASSWORD_AGE The maximum number of days a password can be used before the user is forced to change it. diff --git a/node/password-expiry/env.d.ts b/node/password-expiry/env.d.ts index f1545b55..9e3b13a8 100644 --- a/node/password-expiry/env.d.ts +++ b/node/password-expiry/env.d.ts @@ -1,9 +1,8 @@ declare global { namespace NodeJS { interface ProcessEnv { - APPWRITE_ENDPOINT?: string; + APPWRITE_FUNCTION_API_ENDPOINT: string; APPWRITE_FUNCTION_PROJECT_ID: string; - APPWRITE_API_KEY?: string; STMP_DSN?: string; RESET_PASSWORD_URL?: string; MAX_PASSWORD_AGE?: string; diff --git a/node/password-expiry/src/main.js b/node/password-expiry/src/main.js index bdbcbf07..72e903c0 100644 --- a/node/password-expiry/src/main.js +++ b/node/password-expiry/src/main.js @@ -2,10 +2,9 @@ import { throwIfMissing } from './utils.js'; import { Client, Users, Query } from 'node-appwrite'; import nodemailer from 'nodemailer'; -export default async ({ res, log, error }) => { +export default async ({ req, res, log, error }) => { throwIfMissing(process.env, [ 'APPWRITE_FUNCTION_PROJECT_ID', - 'APPWRITE_API_KEY', 'MAX_PASSWORD_AGE', 'RESET_PASSWORD_URL', 'STMP_DSN', @@ -13,11 +12,9 @@ export default async ({ res, log, error }) => { const client = new Client(); client - .setEndpoint( - process.env.APPWRITE_ENDPOINT ?? 'https://cloud.appwrite.io/v1' - ) + .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) - .setKey(process.env.APPWRITE_API_KEY); + .setKey(req.headers['x-appwrite-key']); const users = new Users(client); diff --git a/node/payments-with-lemon-squeezy/README.md b/node/payments-with-lemon-squeezy/README.md index c3b92cea..8f0796c1 100644 --- a/node/payments-with-lemon-squeezy/README.md +++ b/node/payments-with-lemon-squeezy/README.md @@ -71,25 +71,6 @@ Sample `401` Response: ## 🔒 Environment Variables -### APPWRITE_API_KEY - -Your Appwrite project's API key. - -| Question | Answer | -| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Required | Yes | -| Sample Value | `083d341ee48...` | -| Documentation | [Appwrite: Create an API key](https://appwrite.io/docs/advanced/platform/api-keys#:~:text=To%20create%20a%20new%20API,scope%20to%20grant%20your%20application.) | - -### APPWRITE_ENDPOINT - -The endpoint where your Appwrite server is located. If not provided, it defaults to the Appwrite Cloud server: `https://cloud.appwrite.io/v1`. - -| Question | Answer | -| ------------ | ------------------------------ | -| Required | No | -| Sample Value | `https://cloud.appwrite.io/v1` | - ### APPWRITE_DATABASE_ID The ID of the database to store the orders. diff --git a/node/payments-with-lemon-squeezy/src/appwrite.js b/node/payments-with-lemon-squeezy/src/appwrite.js index 519f76b9..1ae7cbcf 100644 --- a/node/payments-with-lemon-squeezy/src/appwrite.js +++ b/node/payments-with-lemon-squeezy/src/appwrite.js @@ -1,14 +1,12 @@ import { Client, Databases, ID, Permission, Role } from 'node-appwrite'; class AppwriteService { - constructor() { + constructor(apiKey) { const client = new Client(); client - .setEndpoint( - process.env.APPWRITE_ENDPOINT ?? 'https://cloud.appwrite.io/v1' - ) + .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) - .setKey(process.env.APPWRITE_API_KEY); + .setKey(apiKey); this.databases = new Databases(client); diff --git a/node/payments-with-lemon-squeezy/src/main.js b/node/payments-with-lemon-squeezy/src/main.js index 5c35bc0c..d17466d4 100644 --- a/node/payments-with-lemon-squeezy/src/main.js +++ b/node/payments-with-lemon-squeezy/src/main.js @@ -8,7 +8,6 @@ export default async (context) => { throwIfMissing(process.env, [ 'LEMON_SQUEEZY_API_KEY', 'LEMON_SQUEEZY_WEBHOOK_SECRET', - 'APPWRITE_API_KEY', 'LEMON_SQUEEZY_STORE_ID', 'LEMON_SQUEEZY_VARIANT_ID', ]); @@ -18,8 +17,7 @@ export default async (context) => { if (req.method === 'GET') { const html = interpolate(getStaticFile('index.html'), { - APPWRITE_ENDPOINT: - process.env.APPWRITE_ENDPOINT ?? 'https://cloud.appwrite.io/v1', + APPWRITE_FUNCTION_API_ENDPOINT: process.env.APPWRITE_FUNCTION_API_ENDPOINT, APPWRITE_FUNCTION_PROJECT_ID: process.env.APPWRITE_FUNCTION_PROJECT_ID, APPWRITE_FUNCTION_ID: process.env.APPWRITE_FUNCTION_ID, APPWRITE_DATABASE_ID: databaseId, @@ -29,7 +27,7 @@ export default async (context) => { return res.text(html, 200, { 'Content-Type': 'text/html; charset=utf-8' }); } - const appwrite = new AppwriteService(); + const appwrite = new AppwriteService(context.req.headers['x-appwrite-key']); const lemonsqueezy = new LemonSqueezyService(); switch (req.path) { diff --git a/node/payments-with-lemon-squeezy/static/index.html b/node/payments-with-lemon-squeezy/static/index.html index 31caa70d..f671456d 100644 --- a/node/payments-with-lemon-squeezy/static/index.html +++ b/node/payments-with-lemon-squeezy/static/index.html @@ -141,7 +141,7 @@