diff --git a/bun.lock b/bun.lock index 5e313fc46..657ad22a9 100644 --- a/bun.lock +++ b/bun.lock @@ -188,7 +188,7 @@ "@codemirror/state": ["@codemirror/state@6.6.0", "", { "dependencies": { "@marijn/find-cluster-break": "^1.0.0" } }, "sha512-4nbvra5R5EtiCzr9BTHiTLc+MLXK2QGiAVYMyi8PkQd3SR+6ixar/Q/01Fa21TBIDOZXgeWV4WppsQolSreAPQ=="], - "@codemirror/view": ["@codemirror/view@6.41.0", "", { "dependencies": { "@codemirror/state": "^6.6.0", "crelt": "^1.0.6", "style-mod": "^4.1.0", "w3c-keyname": "^2.2.4" } }, "sha512-6H/qadXsVuDY219Yljhohglve8xf4B8xJkVOEWfA5uiYKiTFppjqsvsfR5iPA0RbvRBoOyTZpbLIxe9+0UR8xA=="], + "@codemirror/view": ["@codemirror/view@6.41.1", "", { "dependencies": { "@codemirror/state": "^6.6.0", "crelt": "^1.0.6", "style-mod": "^4.1.0", "w3c-keyname": "^2.2.4" } }, "sha512-ToDnWKbBnke+ZLrP6vgTTDScGi5H37YYuZGniQaBzxMVdtCxMrslsmtnOvbPZk4RX9bvkQqnWR/WS/35tJA0qg=="], "@csstools/color-helpers": ["@csstools/color-helpers@5.1.0", "", {}, "sha512-S11EXWJyy0Mz5SYvRmY8nJYTFFd1LCNV+7cXyAgQtOOuzb4EsgfqDufL+9esx72/eLhsRdGZwaldu/h+E4t4BA=="], @@ -264,7 +264,7 @@ "@lezer/json": ["@lezer/json@1.0.3", "", { "dependencies": { "@lezer/common": "^1.2.0", "@lezer/highlight": "^1.0.0", "@lezer/lr": "^1.0.0" } }, "sha512-BP9KzdF9Y35PDpv04r0VeSTKDeox5vVr3efE7eBbx3r4s3oNLfunchejZhjArmeieBH+nVOpgIiBJpEAv8ilqQ=="], - "@lezer/lr": ["@lezer/lr@1.4.8", "", { "dependencies": { "@lezer/common": "^1.0.0" } }, "sha512-bPWa0Pgx69ylNlMlPvBPryqeLYQjyJjqPx+Aupm5zydLIF3NE+6MMLT8Yi23Bd9cif9VS00aUebn+6fDIGBcDA=="], + "@lezer/lr": ["@lezer/lr@1.4.10", "", { "dependencies": { "@lezer/common": "^1.0.0" } }, "sha512-rnCpTIBafOx4mRp43xOxDJbFipJm/c0cia/V5TiGlhmMa+wsSdoGmUN3w5Bqrks/09Q/D4tNAmWaT8p6NRi77A=="], "@marijn/find-cluster-break": ["@marijn/find-cluster-break@1.0.2", "", {}, "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g=="], diff --git a/src/lib/components/domains/recordTable.svelte b/src/lib/components/domains/recordTable.svelte index 118b8149a..c385ec573 100644 --- a/src/lib/components/domains/recordTable.svelte +++ b/src/lib/components/domains/recordTable.svelte @@ -143,6 +143,8 @@ Since is an apex domain, CNAME record is only supported by certain providers. If yours doesn't, please verify using nameservers instead. + If you're using Cloudflare or another CDN, make sure the proxy is disabled (set to + DNS only) for this record, since Appwrite serves your domain through its own CDN. {:else if aTabVisible || aaaaTabVisible} @@ -155,7 +157,9 @@ >{/if} {:else if aaaaTabVisible} AAAA record - {/if} instead. + {/if} instead. If you're using Cloudflare or another CDN, make sure the proxy is disabled + (set to DNS only) for this record, since Appwrite serves your domain through its own + CDN. {/if} {:else} diff --git a/src/lib/helpers/apiEndpoint.ts b/src/lib/helpers/apiEndpoint.ts new file mode 100644 index 000000000..1bcc1bf3b --- /dev/null +++ b/src/lib/helpers/apiEndpoint.ts @@ -0,0 +1,90 @@ +import { + REGION_FRA, + REGION_NYC, + REGION_SFO, + REGION_SGP, + REGION_SYD, + REGION_TOR, + SUBDOMAIN_FRA, + SUBDOMAIN_NYC, + SUBDOMAIN_SFO, + SUBDOMAIN_SGP, + SUBDOMAIN_SYD, + SUBDOMAIN_TOR +} from '$lib/constants'; + +/** Ordered list of region DNS prefixes (e.g. `fra.`) for stripping from API hostnames. */ +const REGION_SUBDOMAIN_PREFIXES: readonly string[] = [ + SUBDOMAIN_FRA, + SUBDOMAIN_NYC, + SUBDOMAIN_SYD, + SUBDOMAIN_SFO, + SUBDOMAIN_SGP, + SUBDOMAIN_TOR +]; + +/** + * Removes leading Appwrite Cloud region label(s) from `hostname` (e.g. `fra.`). + * Strips repeatedly so a doubled prefix (`fra.fra.cloud...`) does not become + * `nyc.fra.cloud...` after prepending another region. + */ +export function stripLeadingRegionSubdomain(hostname: string): string { + let host = hostname; + let changed = true; + while (changed) { + changed = false; + for (const prefix of REGION_SUBDOMAIN_PREFIXES) { + if (host.startsWith(prefix)) { + host = host.slice(prefix.length); + changed = true; + break; + } + } + } + return host; +} + +/** Region prefix (e.g. `fra.`) used before the API hostname when multi-region is enabled. */ +export function getRegionSubdomain(region?: string): string { + switch (region) { + case REGION_FRA: + return SUBDOMAIN_FRA; + case REGION_SYD: + return SUBDOMAIN_SYD; + case REGION_NYC: + return SUBDOMAIN_NYC; + case REGION_SFO: + return SUBDOMAIN_SFO; + case REGION_SGP: + return SUBDOMAIN_SGP; + case REGION_TOR: + return SUBDOMAIN_TOR; + default: + return ''; + } +} + +/** + * Builds the `/v1` API base URL (protocol + host + `/v1`). + * When `isMultiRegion` is true and a region is selected, strips any known region prefix from the host, + * then prepends that region. If multi-region is on but no region is requested (`region` missing or + * unknown), the hostname is left unchanged so a default region baked into `APPWRITE_ENDPOINT` is kept. + */ +export function buildRegionalV1Endpoint( + protocol: string, + hostname: string, + region: string | undefined, + isMultiRegion: boolean +): string { + if (!isMultiRegion) { + return `${protocol}//${hostname}/v1`; + } + + const subdomain = getRegionSubdomain(region); + if (!subdomain) { + return `${protocol}//${hostname}/v1`; + } + + const hostWithoutRegion = stripLeadingRegionSubdomain(hostname); + return `${protocol}//${subdomain}${hostWithoutRegion}/v1`; +} diff --git a/src/lib/stores/project-protocols.ts b/src/lib/stores/project-protocols.ts new file mode 100644 index 000000000..072c3c522 --- /dev/null +++ b/src/lib/stores/project-protocols.ts @@ -0,0 +1,44 @@ +import { writable } from 'svelte/store'; +import { ProtocolId, type Models } from '@appwrite.io/console'; + +export type Protocol = { + label: string; + method: ProtocolId; + value: boolean | null; +}; + +function projectProtocolRows(project: Models.Project | null): Protocol[] { + return [ + { + label: 'REST', + method: ProtocolId.Rest, + value: project?.protocolStatusForRest ?? null + }, + { + label: 'GraphQL', + method: ProtocolId.Graphql, + value: project?.protocolStatusForGraphql ?? null + }, + { + label: 'WebSocket', + method: ProtocolId.Websocket, + value: project?.protocolStatusForWebsocket ?? null + } + ]; +} + +function createProtocols() { + const { subscribe, set } = writable({ + list: projectProtocolRows(null) + }); + + return { + subscribe, + set, + load: (project: Models.Project) => { + set({ list: projectProtocolRows(project) }); + } + }; +} + +export const protocols = createProtocols(); diff --git a/src/lib/stores/project-services.ts b/src/lib/stores/project-services.ts index 7f835c7f9..cb8866f04 100644 --- a/src/lib/stores/project-services.ts +++ b/src/lib/stores/project-services.ts @@ -34,11 +34,6 @@ function projectServiceRows(project: Models.Project | null): Service[] { method: ServiceId.Graphql, value: project?.serviceStatusForGraphql ?? null }, - { - label: 'Health', - method: ServiceId.Health, - value: project?.serviceStatusForHealth ?? null - }, { label: 'Locale', method: ServiceId.Locale, diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index e0c36ce5d..b94d1782f 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -29,21 +29,8 @@ import { Organizations, VectorsDB } from '@appwrite.io/console'; +import { buildRegionalV1Endpoint } from '$lib/helpers/apiEndpoint'; import { Sources } from '$lib/sdk/sources'; -import { - REGION_FRA, - REGION_NYC, - REGION_SYD, - REGION_SFO, - REGION_SGP, - REGION_TOR, - SUBDOMAIN_FRA, - SUBDOMAIN_NYC, - SUBDOMAIN_SFO, - SUBDOMAIN_SYD, - SUBDOMAIN_SGP, - SUBDOMAIN_TOR -} from '$lib/constants'; import { building } from '$app/environment'; export function getApiEndpoint(region?: string): string { @@ -51,37 +38,10 @@ export function getApiEndpoint(region?: string): string { const url = new URL( VARS.APPWRITE_ENDPOINT ? VARS.APPWRITE_ENDPOINT : globalThis?.location?.toString() ); - const protocol = url.protocol; - const hostname = url.host; // "hostname:port" (or just "hostname" if no port) - // If instance supports multi-region, add the region subdomain. - let subdomain = isMultiRegionSupported(url) ? getSubdomain(region) : ''; - if (subdomain && hostname.startsWith(subdomain)) { - subdomain = ''; - } - - return `${protocol}//${subdomain}${hostname}/v1`; + return buildRegionalV1Endpoint(url.protocol, url.host, region, isMultiRegionSupported(url)); } -const getSubdomain = (region?: string) => { - switch (region) { - case REGION_FRA: - return SUBDOMAIN_FRA; - case REGION_SYD: - return SUBDOMAIN_SYD; - case REGION_NYC: - return SUBDOMAIN_NYC; - case REGION_SFO: - return SUBDOMAIN_SFO; - case REGION_SGP: - return SUBDOMAIN_SGP; - case REGION_TOR: - return SUBDOMAIN_TOR; - default: - return ''; - } -}; - function createConsoleSdk(client: Client) { return { client, diff --git a/src/routes/(console)/project-[region]-[project]/settings/+page.svelte b/src/routes/(console)/project-[region]-[project]/settings/+page.svelte index 8c8781b3b..7e63a523b 100644 --- a/src/routes/(console)/project-[region]-[project]/settings/+page.svelte +++ b/src/routes/(console)/project-[region]-[project]/settings/+page.svelte @@ -8,6 +8,7 @@ import { invalidate } from '$app/navigation'; import { Dependencies } from '$lib/constants'; import UpdateName from './updateName.svelte'; + import UpdateProtocols from './updateProtocols.svelte'; import UpdateServices from './updateServices.svelte'; import UpdateInstallations from './updateInstallations.svelte'; import DeleteProject from './deleteProject.svelte'; @@ -89,6 +90,7 @@ {#if $canWriteProjects} + + import { invalidate } from '$app/navigation'; + import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; + import { CardGrid } from '$lib/components'; + import { Dependencies } from '$lib/constants'; + import { InputSwitch } from '$lib/elements/forms'; + import { addNotification } from '$lib/stores/notifications'; + import { protocols, type Protocol } from '$lib/stores/project-protocols'; + import { sdk } from '$lib/stores/sdk'; + import { project } from '../store'; + import Button from '$lib/elements/forms/button.svelte'; + import { Dialog, Divider, Layout, Spinner } from '@appwrite.io/pink-svelte'; + import { SvelteSet } from 'svelte/reactivity'; + import { ProtocolId } from '@appwrite.io/console'; + import { get } from 'svelte/store'; + + let isUpdatingAllProtocols = $state(false); + let showUpdateProtocolDialog = $state(false); + let updateProtocolsEnabledMode = $state(null); + let apiProtocolUpdates = new SvelteSet(); + const protocolDescriptions: Record = { + [ProtocolId.Rest]: 'Standard HTTP API requests from client SDKs.', + [ProtocolId.Graphql]: 'GraphQL API access for queries and mutations.', + [ProtocolId.Websocket]: 'Realtime subscriptions over WebSocket connections.' + }; + const isAnyProtocolUpdating = $derived(apiProtocolUpdates.size > 0); + const isAnyUpdateInProgress = $derived(isUpdatingAllProtocols || isAnyProtocolUpdating); + + const allProtocolsEnabled = $derived.by(() => { + if (isAnyUpdateInProgress) return false; + return $protocols.list.every((protocol) => protocol.value); + }); + + const allProtocolsDisabled = $derived.by(() => { + if (isAnyUpdateInProgress) return false; + return $protocols.list.every((protocol) => !protocol.value); + }); + + const shouldDisableEnableAllButton = $derived(isAnyUpdateInProgress || allProtocolsEnabled); + const shouldDisableDisableAllButton = $derived(isAnyUpdateInProgress || allProtocolsDisabled); + + async function protocolUpdate(protocol: Protocol) { + apiProtocolUpdates.add(protocol.method); + + try { + await sdk.forProject($project.region, $project.$id).project.updateProtocolStatus({ + protocolId: protocol.method, + enabled: protocol.value + }); + + await invalidate(Dependencies.PROJECT); + + addNotification({ + type: 'success', + message: `${protocol.label} protocol has been ${ + protocol.value ? 'enabled' : 'disabled' + }` + }); + trackEvent(Submit.ProjectService, { + method: protocol.method, + value: protocol.value + }); + } catch (error) { + addNotification({ + type: 'error', + message: error.message + }); + trackError(error, Submit.ProjectService); + } finally { + apiProtocolUpdates.delete(protocol.method); + } + } + + async function toggleAllProtocols(status: boolean) { + isUpdatingAllProtocols = true; + + try { + const projectSdk = sdk.forProject($project.region, $project.$id); + for (const protocol of get(protocols).list) { + if (protocol.value === status) continue; + await projectSdk.project.updateProtocolStatus({ + protocolId: protocol.method, + enabled: status + }); + } + + await invalidate(Dependencies.PROJECT); + + addNotification({ + type: 'success', + message: + 'All protocols for ' + + $project.name + + ' have been ' + + (status ? 'enabled.' : 'disabled.') + }); + trackEvent(Submit.ProjectService); + } catch (error) { + addNotification({ + type: 'error', + message: error.message + }); + trackError(error, Submit.ProjectService); + } finally { + isUpdatingAllProtocols = false; + showUpdateProtocolDialog = false; + updateProtocolsEnabledMode = null; + } + } + + const dialogDetails = $derived.by(() => { + if (updateProtocolsEnabledMode) { + return { + title: 'Enable all protocols', + message: 'All project protocols will be enabled.', + actionButton: 'Enable all' + }; + } else { + return { + title: 'Disable all protocols', + message: + 'Are you sure you want to disable all protocols? This will disable client access over those protocols until they are re-enabled.', + actionButton: 'Disable all' + }; + } + }); + + $effect(() => protocols.load($project)); + + + + Protocols + Choose which protocols clients can use to access your project. Disabled protocols remain unavailable + until re-enabled. + +
+
+ + + + + + + +
+ +
+ + {#each $protocols.list as protocol, index} +
+
+ protocolUpdate(protocol)} + disabled={apiProtocolUpdates.has(protocol.method)} /> + + {#if apiProtocolUpdates.has(protocol.method)} + + + + {/if} +
+
+ + {#if index < $protocols.list.length - 1} + + {/if} + {/each} +
+
+
+
+
+ + +

{dialogDetails.message}

+ + + + + + + +
+ + diff --git a/src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/regenerate.svelte b/src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/regenerate.svelte index 93a7e6e8b..be924894d 100644 --- a/src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/regenerate.svelte +++ b/src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/regenerate.svelte @@ -2,25 +2,47 @@ import { invalidate } from '$app/navigation'; import { page } from '$app/state'; import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; - import Confirm from '$lib/components/confirm.svelte'; + import Modal from '$lib/components/modal.svelte'; + import { Secret } from '$lib/components'; import { Dependencies } from '$lib/constants'; + import { Button, InputPassword } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; import { sdk } from '$lib/stores/sdk'; - import { webhook } from './store'; + import { Layout, Typography } from '@appwrite.io/pink-svelte'; + import type { Models } from '@appwrite.io/console'; + import { get } from 'svelte/store'; + import { webhook as webhookStore } from './store'; + + type WebhooksWithCustomSecret = { + updateSecret(params: { webhookId: string; secret?: string }): Promise; + }; export let show = false; + const projectId = page.params.project; + let secret = ''; + let revealedSecret = ''; + + $: if (!show) { + secret = ''; + revealedSecret = ''; + } async function regenerate() { try { - await sdk.forProject(page.params.region, projectId).webhooks.updateSecret({ - webhookId: $webhook.$id + const currentWebhook = get(webhookStore); + const customSecret = secret.trim(); + const updatedWebhook = await ( + sdk.forProject(page.params.region, projectId).webhooks as WebhooksWithCustomSecret + ).updateSecret({ + webhookId: currentWebhook.$id, + secret: customSecret || undefined }); await invalidate(Dependencies.WEBHOOK); - show = false; + revealedSecret = customSecret || updatedWebhook.secret; addNotification({ type: 'success', - message: 'Key has been regenerated' + message: customSecret ? 'Webhook secret updated.' : 'Webhook secret rotated.' }); trackEvent(Submit.WebhookUpdateSignature); } catch (error) { @@ -33,7 +55,38 @@ } - - Are you sure you want to generate a new Signature key? - You will not be able to recover the current key. - + + + {#if revealedSecret} + + This secret is only shown once after webhook creation or secret rotation. Copy it + now. + + + {:else} + + Leave this empty to rotate the webhook secret automatically, or enter a value to set + a custom secret. + + + Used to validate incoming webhook payloads. + + + {/if} + + + + {#if revealedSecret} + + {:else} + + + {/if} + + diff --git a/src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/updateSecurity.svelte b/src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/updateSecurity.svelte index 18d72cd8b..6cd871088 100644 --- a/src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/updateSecurity.svelte +++ b/src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/updateSecurity.svelte @@ -73,7 +73,7 @@ bind:value={authPassword} /> diff --git a/src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/updateSignature.svelte b/src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/updateSignature.svelte index a229bd487..fac14e8e7 100644 --- a/src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/updateSignature.svelte +++ b/src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/updateSignature.svelte @@ -1,26 +1,25 @@ - Signature key - Add the Signature Key to the X-Appwrite-Webhook-Signature header to validate your webhooks. + Webhook secret + Used to validate incoming webhook payloads with the `X-Appwrite-Webhook-Signature` header. Learn more -
- -
+ + This secret is only shown once after webhook creation or secret rotation. +
+ submit>Rotate secret
diff --git a/src/routes/(console)/project-[region]-[project]/settings/webhooks/create/+page.svelte b/src/routes/(console)/project-[region]-[project]/settings/webhooks/create/+page.svelte index 03d80aadb..10158b62c 100644 --- a/src/routes/(console)/project-[region]-[project]/settings/webhooks/create/+page.svelte +++ b/src/routes/(console)/project-[region]-[project]/settings/webhooks/create/+page.svelte @@ -1,8 +1,10 @@