mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
Merge remote-tracking branch 'origin/main' into feat-documentsdb
# Conflicts: # bun.lock # package.json # src/lib/stores/project-services.ts # src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/regenerate.svelte # src/routes/(console)/project-[region]-[project]/settings/webhooks/[webhook]/updateSignature.svelte
This commit is contained in:
commit
a52569f6a9
13 files changed
+500
-76
No files matched your search
@@ -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=="],
|
||||
|
||||
|
||||
@@ -143,6 +143,8 @@
|
||||
Since <Badge variant="secondary" size="s" content={domain} /> is an apex domain, CNAME
|
||||
record is only supported by certain providers. If yours doesn't, please verify using
|
||||
<Link variant="muted" on:click={onNavigateToNameservers}>nameservers</Link> 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.
|
||||
</Alert.Inline>
|
||||
{:else if aTabVisible || aaaaTabVisible}
|
||||
<Alert.Inline>
|
||||
@@ -155,7 +157,9 @@
|
||||
>{/if}
|
||||
{:else if aaaaTabVisible}
|
||||
<Link variant="muted" on:click={onNavigateToAAAA}>AAAA record</Link>
|
||||
{/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.
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
{:else}
|
||||
|
||||
@@ -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`;
|
||||
}
|
||||
@@ -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();
|
||||
@@ -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,
|
||||
|
||||
+2
-42
@@ -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,
|
||||
|
||||
@@ -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}
|
||||
<UpdateName />
|
||||
<UpdateLabels />
|
||||
<UpdateProtocols />
|
||||
<UpdateServices />
|
||||
<UpdateInstallations {...data.installations} limit={data.limit} offset={data.offset} />
|
||||
<UpdateVariables
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
<script lang="ts">
|
||||
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<boolean | null>(null);
|
||||
let apiProtocolUpdates = new SvelteSet<ProtocolId>();
|
||||
const protocolDescriptions: Record<ProtocolId, string> = {
|
||||
[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));
|
||||
</script>
|
||||
|
||||
<CardGrid>
|
||||
<svelte:fragment slot="title">Protocols</svelte:fragment>
|
||||
Choose which protocols clients can use to access your project. Disabled protocols remain unavailable
|
||||
until re-enabled.
|
||||
<svelte:fragment slot="aside">
|
||||
<div class="protocols-list">
|
||||
<div class="protocol-toolbar">
|
||||
<Layout.Stack direction="row" alignItems="center" gap="s">
|
||||
<Button
|
||||
extraCompact
|
||||
on:click={() => {
|
||||
showUpdateProtocolDialog = true;
|
||||
updateProtocolsEnabledMode = true;
|
||||
}}
|
||||
disabled={shouldDisableEnableAllButton}>Enable all</Button>
|
||||
<span style:height="20px">
|
||||
<Divider vertical />
|
||||
</span>
|
||||
<Button
|
||||
extraCompact
|
||||
on:click={() => {
|
||||
showUpdateProtocolDialog = true;
|
||||
updateProtocolsEnabledMode = false;
|
||||
}}
|
||||
disabled={shouldDisableDisableAllButton}>Disable all</Button>
|
||||
</Layout.Stack>
|
||||
</div>
|
||||
<Divider />
|
||||
<div class="protocol-list-content">
|
||||
<Layout.Stack gap="xs">
|
||||
{#each $protocols.list as protocol, index}
|
||||
<div class="protocol-row">
|
||||
<div class="protocol-control">
|
||||
<InputSwitch
|
||||
id={protocol.method}
|
||||
label={protocol.label}
|
||||
description={protocolDescriptions[protocol.method]}
|
||||
bind:value={protocol.value}
|
||||
on:change={() => protocolUpdate(protocol)}
|
||||
disabled={apiProtocolUpdates.has(protocol.method)} />
|
||||
|
||||
{#if apiProtocolUpdates.has(protocol.method)}
|
||||
<span class="protocol-spinner">
|
||||
<Spinner size="s" />
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if index < $protocols.list.length - 1}
|
||||
<Divider />
|
||||
{/if}
|
||||
{/each}
|
||||
</Layout.Stack>
|
||||
</div>
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
|
||||
<Dialog title={dialogDetails.title} bind:open={showUpdateProtocolDialog}>
|
||||
<p class="text" data-private>{dialogDetails.message}</p>
|
||||
<svelte:fragment slot="footer">
|
||||
<Layout.Stack direction="row" gap="s" justifyContent="flex-end">
|
||||
<Button text on:click={() => (showUpdateProtocolDialog = false)}>Cancel</Button>
|
||||
|
||||
<Button
|
||||
secondary
|
||||
submissionLoader
|
||||
disabled={isUpdatingAllProtocols}
|
||||
forceShowLoader={isUpdatingAllProtocols}
|
||||
on:click={() => toggleAllProtocols(updateProtocolsEnabledMode)}>
|
||||
{dialogDetails.actionButton}
|
||||
</Button>
|
||||
</Layout.Stack>
|
||||
</svelte:fragment>
|
||||
</Dialog>
|
||||
|
||||
<style>
|
||||
.protocols-list {
|
||||
max-width: 36rem;
|
||||
}
|
||||
|
||||
.protocol-toolbar {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding-bottom: var(--space-6);
|
||||
}
|
||||
|
||||
.protocol-row {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.protocol-list-content {
|
||||
padding-top: var(--space-6);
|
||||
}
|
||||
|
||||
.protocol-control {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-4);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.protocol-control :global(label) {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.protocol-spinner {
|
||||
opacity: 0.75;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
+63
-10
@@ -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<Models.Webhook>;
|
||||
};
|
||||
|
||||
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 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<Confirm title="Regenerate Key" bind:open={show} onSubmit={regenerate} action="Regenerate">
|
||||
Are you sure you want to generate a new Signature key?
|
||||
<b>You will not be able to recover the current key.</b>
|
||||
</Confirm>
|
||||
<Modal title="Rotate Webhook Secret" bind:show onSubmit={regenerate}>
|
||||
<Layout.Stack gap="l">
|
||||
{#if revealedSecret}
|
||||
<Typography.Text>
|
||||
This secret is only shown once after webhook creation or secret rotation. Copy it
|
||||
now.
|
||||
</Typography.Text>
|
||||
<Secret label="Secret" copyEvent="signature" bind:value={revealedSecret} />
|
||||
{:else}
|
||||
<Typography.Text>
|
||||
Leave this empty to rotate the webhook secret automatically, or enter a value to set
|
||||
a custom secret.
|
||||
</Typography.Text>
|
||||
<Typography.Text variant="m-400">
|
||||
Used to validate incoming webhook payloads.
|
||||
</Typography.Text>
|
||||
<InputPassword
|
||||
id="webhook-secret"
|
||||
label="Secret"
|
||||
placeholder="Leave empty to auto-generate"
|
||||
minlength={0}
|
||||
autocomplete
|
||||
bind:value={secret} />
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
{#if revealedSecret}
|
||||
<Button on:click={() => (show = false)}>Done</Button>
|
||||
{:else}
|
||||
<Button text on:click={() => (show = false)}>Cancel</Button>
|
||||
<Button submit>{secret.trim() ? 'Set custom secret' : 'Rotate secret'}</Button>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
+1
-1
@@ -73,7 +73,7 @@
|
||||
bind:value={authPassword} />
|
||||
|
||||
<Selector.Checkbox
|
||||
id="security"
|
||||
id="tls"
|
||||
label="Certificate verification (SSL/TLS)"
|
||||
bind:checked={tls}
|
||||
description="Placeholder" />
|
||||
|
||||
+8
-9
@@ -1,26 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { CardGrid, Secret } from '$lib/components';
|
||||
import { CardGrid } from '$lib/components';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { Link } from '@appwrite.io/pink-svelte';
|
||||
import { Alert, Link } from '@appwrite.io/pink-svelte';
|
||||
import Regenerate from './regenerate.svelte';
|
||||
import { webhook } from './store';
|
||||
import { Click, trackEvent } from '$lib/actions/analytics';
|
||||
|
||||
let showRegenerate = false;
|
||||
</script>
|
||||
|
||||
<CardGrid>
|
||||
<svelte:fragment slot="title">Signature key</svelte:fragment>
|
||||
Add the Signature Key to the X-Appwrite-Webhook-Signature header to validate your webhooks.
|
||||
<svelte:fragment slot="title">Webhook secret</svelte:fragment>
|
||||
Used to validate incoming webhook payloads with the `X-Appwrite-Webhook-Signature` header.
|
||||
<Link.Anchor
|
||||
href="https://appwrite.io/docs/advanced/platform/webhooks#verification"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="link">Learn more</Link.Anchor>
|
||||
<svelte:fragment slot="aside">
|
||||
<div>
|
||||
<Secret label="Key" copyEvent="signature" bind:value={$webhook.secret} />
|
||||
</div>
|
||||
<Alert.Inline status="info">
|
||||
This secret is only shown once after webhook creation or secret rotation.
|
||||
</Alert.Inline>
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="actions">
|
||||
<Button
|
||||
@@ -29,7 +28,7 @@
|
||||
trackEvent(Click.SettingsWebhookUpdateSignatureClick);
|
||||
}}
|
||||
secondary
|
||||
submit>Regenerate key</Button>
|
||||
submit>Rotate secret</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
|
||||
|
||||
+40
-5
@@ -1,8 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/state';
|
||||
import Modal from '$lib/components/modal.svelte';
|
||||
import { Secret } from '$lib/components';
|
||||
import { Wizard } from '$lib/layout';
|
||||
import { Layout } from '@appwrite.io/pink-svelte';
|
||||
import { Layout, Typography } from '@appwrite.io/pink-svelte';
|
||||
import Form from '$lib/elements/forms/form.svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { ID } from '@appwrite.io/console';
|
||||
@@ -15,6 +17,9 @@
|
||||
import Button from '$lib/elements/forms/button.svelte';
|
||||
|
||||
let showExitModal = false;
|
||||
let showSecretModal = false;
|
||||
let createdWebhookId = '';
|
||||
let createdSecret = '';
|
||||
|
||||
let name = '',
|
||||
events: string[] = [],
|
||||
@@ -24,6 +29,16 @@
|
||||
authPassword = '';
|
||||
|
||||
export let data;
|
||||
|
||||
async function openWebhook() {
|
||||
showSecretModal = false;
|
||||
if (!createdWebhookId) return;
|
||||
|
||||
await goto(
|
||||
`${base}/project-${page.params.region}-${page.params.project}/settings/webhooks/${createdWebhookId}`
|
||||
);
|
||||
}
|
||||
|
||||
async function create() {
|
||||
try {
|
||||
const webhook = await sdk
|
||||
@@ -39,15 +54,22 @@
|
||||
authPassword: authPassword || undefined
|
||||
});
|
||||
addNotification({
|
||||
message: 'Webhook has been created',
|
||||
message: 'Webhook created. Secret ready to copy.',
|
||||
type: 'success'
|
||||
});
|
||||
trackEvent(Submit.WebhookCreate, {
|
||||
events: events
|
||||
});
|
||||
goto(
|
||||
`${base}/project-${page.params.region}-${page.params.project}/settings/webhooks/${webhook.$id}`
|
||||
);
|
||||
|
||||
createdWebhookId = webhook.$id;
|
||||
createdSecret = webhook.secret;
|
||||
|
||||
if (createdSecret) {
|
||||
showSecretModal = true;
|
||||
return;
|
||||
}
|
||||
|
||||
await openWebhook();
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
@@ -76,3 +98,16 @@
|
||||
</svelte:fragment>
|
||||
</Wizard>
|
||||
</Form>
|
||||
|
||||
<Modal title="Webhook Created" bind:show={showSecretModal} onSubmit={openWebhook}>
|
||||
<Layout.Stack gap="l">
|
||||
<Typography.Text>
|
||||
This secret is only shown once after webhook creation or secret rotation. Copy it now.
|
||||
</Typography.Text>
|
||||
<Secret label="Secret" copyEvent="signature" bind:value={createdSecret} />
|
||||
</Layout.Stack>
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<Button submit>Continue</Button>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
<Layout.Stack gap="s">
|
||||
<InputChoice
|
||||
type="switchbox"
|
||||
id="Security"
|
||||
id="tls"
|
||||
label="Certificate verification (SSL/TLS)"
|
||||
bind:value={tls} />
|
||||
{#if !tls}
|
||||
|
||||
Reference in new issue
Block a user