Merge branch 'main' of github.com:appwrite/console into feat-custom-smtp

This commit is contained in:
Arman committed 2023-05-31 16:10:32 +02:00
commit ac1307236d
25 files changed
+700 -578

No files matched your search

+2 -2
View File
@@ -22,11 +22,11 @@ jobs:
# run: npm audit --audit-level low
- name: Install dependencies
run: npm ci
- name: Build Console
run: npm run build
- name: Svelte Diagnostics
run: npm run check
- name: Linter
run: npm run lint
- name: Unit Tests
run: npm test
- name: Build Console
run: npm run build
+24 -19
View File
@@ -10,25 +10,30 @@ If you are worried about or don’t know where to start, check out the next sect
```
├── src
│ ├── lib // All non-route components, accessible over "import ... from '$lib'"
│ │ ├── components // Re-usable components
│ │ ├── elements // Re-usable elements
│ │ ├── layout // Global components for the layout (Nav/Content/Container)
│ │ └── stores // Global stores (state management)
│ └─── routes
│ ├── console // Routes that need authentication
│ │ ├──[project]
│ │ │ ├── database // Database Service
│ │ │ │ ├── [collection] // Nested Route for the collection "/console/[PROJECT_ID]/database/[COLLECTION_ID]"
│ │ │ │ ├── _create.svelte // Component to Create collections
│ │ │ │ └── index.svelte // Entrypoint for "/console/[PROJECT_ID]/database"
│ │ │ ├── storage // Storage Service "/console/[PROJECT]/storage"
│ │ │ └── auth // Users Service "/console/[PROJECT]/auth"
│ │ └──...
│ ├── login.svelte // Component for Login "/console/login"
│ └── register.svelte // Component for Register "/console/register"
├── build // Compiled application
└── static // Static assets
│ ├── lib // Reusable logic (accessible with '$lib')
│ │ ├── actions // Svelte actions
│ │ ├── charts // Chart components
│ │ ├── components // Re-usable components
│ │ ├── elements // Re-usable elements
│ │ ├── helpers // Small functions used through out the console
│ │ ├── images // Images used in the console
│ │ ├── layout // Global components for the layout (Nav/Content/Container)
│ │ ├── mock // Mock components used for testing
│ │ └── stores // Global stores (state management)
│ └── routes
│ └── console // Routes that need authentication
│ │ └── project-[project]
│ │ │ └── database // Database Service
│ │ │ │ ├── +layout.svelte // Layout head and other logic like realtime events is set here
│ │ │ │ ├── +layout.ts // Layout data is set here (Header, Breadcrumbs, ...)
│ │ │ │ ├── +page.svelte // Page displayed on "/console/project-[PROJECT_ID]/database"
│ │ │ │ ├── +page.ts // Necessary data for the page is fetched here
│ │ │ │ └── create.svelte // Component to create databases
│ │ │ └── ... // Other services
│ │ └── ...
│ └── ... // Routes that don't need authentication
├── build // Compiled application
└── static // Static assets
```
## Development
+17 -15
View File
@@ -3,6 +3,7 @@
export let value: string;
export let event: string = null;
export let isCentered = true;
function truncateText(node: HTMLElement) {
const MAX_TRIES = 100;
@@ -46,22 +47,23 @@
}
</script>
<div
class="interactive-text-output is-buttons-on-top u-text-center"
style:min-inline-size="0"
style:display="inline-flex">
<span
style:white-space="nowrap"
class="text u-line-height-1-5"
style:overflow="hidden"
use:truncateText>
<slot />
</span>
<div class="interactive-text-output-buttons">
<Copy {value} {event}>
<Copy {value} {event}>
<div
class="interactive-text-output is-buttons-on-top"
class:u-text-center={isCentered}
style:min-inline-size="0"
style:display="inline-flex">
<span
style:white-space="nowrap"
class="text u-line-height-1-5"
style:overflow="hidden"
use:truncateText>
<slot />
</span>
<div class="interactive-text-output-buttons">
<button class="interactive-text-output-button is-hidden" aria-label="copy text">
<span class="icon-duplicate" aria-hidden="true" />
</button>
</Copy>
</div>
</div>
</div>
</Copy>
+20 -5
View File
@@ -2,11 +2,28 @@
import type { Action } from 'svelte/action';
export let isSticky = false;
let isOverflowing = false;
const hasOverflow: Action<HTMLDivElement, (value: boolean) => void> = (node, callback) => {
const hasOverflow: Action<HTMLDivElement> = (node) => {
const observer = new ResizeObserver((entries) => {
for (const entry of entries) {
callback(entry.contentRect.width < entry.target.scrollWidth);
let overflowing = false;
if (entry.contentRect.width < entry.target.scrollWidth) {
overflowing = true;
}
const cols = entry.target.querySelectorAll('.table-thead-col');
for (let i = 0; i < cols.length; i++) {
const col = cols[i];
const cs = getComputedStyle(col);
const innerWidth =
col.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight);
if (innerWidth < 32) {
overflowing = true;
}
}
isOverflowing = overflowing;
}
});
@@ -18,12 +35,10 @@
}
};
};
let isOverflowing = false;
</script>
<div class="table-with-scroll u-margin-block-start-32" data-private>
<div class="table-wrapper" use:hasOverflow={(v) => (isOverflowing = v)}>
<div class="table-wrapper" use:hasOverflow>
<table class="table" class:is-sticky-scroll={isSticky && isOverflowing}>
<slot />
</table>
@@ -81,7 +81,7 @@
disabled={(secret === provider.secret &&
enabled === provider.enabled &&
appId === provider.appId) ||
!(appId && clientSecret && endpoint)}
!(appId && clientSecret)}
submit>Update</Button>
</svelte:fragment>
</Modal>
@@ -15,6 +15,7 @@
try {
await sdk.forProject.users.deleteSession($page.params.user, selectedSessionId);
await invalidate(Dependencies.SESSIONS);
showDelete = false;
addNotification({
type: 'success',
message: 'Session has been deleted'
@@ -19,7 +19,7 @@
await invalidate(Dependencies.USER);
addNotification({
message: `${$user.name || $user.email || $user.phone || 'The account'} has been ${
$user.emailVerification ? 'unverified' : 'verified'
!$user.emailVerification ? 'unverified' : 'verified'
}`,
type: 'success'
});
@@ -3,13 +3,13 @@
import { page } from '$app/stores';
import { Id } from '$lib/components';
import {
Table,
TableBody,
TableCell,
TableCellHead,
TableCellText,
TableHeader,
TableRowLink
TableRowLink,
TableScroll
} from '$lib/elements/table';
import { toLocaleDateTime } from '$lib/helpers/date';
import type { PageData } from './$types';
@@ -20,7 +20,7 @@
const databaseId = $page.params.database;
</script>
<Table>
<TableScroll>
<TableHeader>
{#each $columns as column}
{#if column.show}
@@ -54,4 +54,4 @@
</TableRowLink>
{/each}
</TableBody>
</Table>
</TableScroll>
@@ -3,13 +3,13 @@
import { page } from '$app/stores';
import { Id } from '$lib/components';
import {
Table,
TableBody,
TableCell,
TableCellHead,
TableCellText,
TableHeader,
TableRowLink
TableRowLink,
TableScroll
} from '$lib/elements/table';
import { toLocaleDateTime } from '$lib/helpers/date';
import type { PageData } from './$types';
@@ -19,7 +19,7 @@
const projectId = $page.params.project;
</script>
<Table>
<TableScroll>
<TableHeader>
{#each $columns as column}
{#if column.show}
@@ -55,4 +55,4 @@
</TableRowLink>
{/each}
</TableBody>
</Table>
</TableScroll>
@@ -62,10 +62,10 @@
function setCodeSnippets(lang: string) {
return {
Unix: {
code: `appwrite functions createDeployment \\
--functionId=${functionId} \\
--entrypoint='index.${lang}' \\
--code="." \\
code: `appwrite functions createDeployment \\
--functionId=${functionId} \\
--entrypoint='index.${lang}' \\
--code="." \\
--activate=true`,
language: 'bash'
},
@@ -40,7 +40,9 @@
<CoverTitle href={`/console/project-${projectId}/functions`}>
{$func?.name}
</CoverTitle>
<Id value={$func?.$id} event="function">Function ID</Id>
{#if $func?.$id}
<Id value={$func.$id} event="function">{$func.$id}</Id>
{/if}
</svelte:fragment>
<Tabs>
@@ -1,520 +1,25 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import {
Box,
CardGrid,
DropList,
DropListItem,
Empty,
Output,
PaginationInline,
Secret
} from '$lib/components';
import Heading from '$lib/components/heading.svelte';
import { Roles } from '$lib/components/permissions';
import { Dependencies } from '$lib/constants';
import { Button, Form, FormList, InputCron, InputNumber, InputText } from '$lib/elements/forms';
import { symmetricDifference } from '$lib/helpers/array';
import { toLocaleDateTime } from '$lib/helpers/date';
import { Container } from '$lib/layout';
import { app } from '$lib/stores/app';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { onMount } from 'svelte';
import Variable from '../../createVariable.svelte';
import { execute, func } from '../store';
import UploadVariables from './uploadVariables.svelte';
import {
Table,
TableBody,
TableCell,
TableCellHead,
TableHeader,
TableRow
} from '$lib/elements/table';
import type { PageData } from './$types';
import Delete from './delete.svelte';
import UpdateEvents from './updateEvents.svelte';
import ExecuteFunction from './executeFunction.svelte';
import UpdateName from './updateName.svelte';
import UpdatePermissions from './updatePermissions.svelte';
import UpdateSchedule from './updateSchedule.svelte';
import UpdateVariables from './updateVariables.svelte';
import UpdateTimeout from './updateTimeout.svelte';
import DangerZone from './dangerZone.svelte';
export let data: PageData;
const functionId = $page.params.function;
let showDelete = false;
let selectedVar: Models.Variable = null;
let showVariablesUpload = false;
let showVariablesModal = false;
let showVariablesDropdown = [];
let timeout: number = null;
let functionName: string = null;
let functionSchedule: string = null;
let permissions: string[] = [];
let arePermsDisabled = true;
let offset = 0;
onMount(async () => {
timeout ??= $func.timeout;
functionName ??= $func.name;
functionSchedule ??= $func.schedule;
permissions = $func.execute;
});
async function updateName() {
try {
await sdk.forProject.functions.update(
functionId,
functionName,
$func.execute || undefined,
$func.events || undefined,
$func.schedule || undefined,
$func.timeout || undefined,
$func.enabled
);
await invalidate(Dependencies.FUNCTION);
addNotification({
message: 'Name has been updated',
type: 'success'
});
trackEvent(Submit.FunctionUpdateName);
} catch (error) {
addNotification({
message: error.message,
type: 'error'
});
trackError(error, Submit.FunctionUpdateName);
}
}
async function updatePermissions() {
try {
await sdk.forProject.functions.update(
functionId,
$func.name,
permissions,
$func.events || undefined,
$func.schedule || undefined,
$func.timeout || undefined,
$func.enabled
);
await invalidate(Dependencies.FUNCTION);
addNotification({
message: 'Permissions have been updated',
type: 'success'
});
trackEvent(Submit.FunctionUpdatePermissions);
} catch (error) {
addNotification({
message: error.message,
type: 'error'
});
trackError(error, Submit.FunctionUpdatePermissions);
}
}
async function updateSchedule() {
try {
await sdk.forProject.functions.update(
functionId,
$func.name,
$func.execute || undefined,
$func.events || undefined,
functionSchedule,
$func.timeout || undefined,
$func.enabled
);
await invalidate(Dependencies.FUNCTION);
addNotification({
type: 'success',
message: 'Cron Schedule has been updated'
});
trackEvent(Submit.FunctionUpdateSchedule);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.FunctionUpdateSchedule);
}
}
async function updateTimeout() {
try {
await sdk.forProject.functions.update(
functionId,
$func.name,
$func.execute || undefined,
$func.events || undefined,
$func.schedule || undefined,
timeout,
$func.enabled
);
await invalidate(Dependencies.FUNCTION);
addNotification({
type: 'success',
message: 'Timeout has been updated'
});
trackEvent(Submit.FunctionUpdateTimeout);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.FunctionUpdateTimeout);
}
}
async function handleVariableCreated(event: CustomEvent<Models.Variable>) {
const variable = event.detail;
try {
await sdk.forProject.functions.createVariable(functionId, variable.key, variable.value);
await invalidate(Dependencies.VARIABLES);
showVariablesModal = false;
addNotification({
type: 'success',
message: `${$func.name} variables have been updated`
});
trackEvent(Submit.VariableCreate);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.VariableCreate);
}
}
async function handleVariableUpdated(event: CustomEvent<Models.Variable>) {
const variable = event.detail;
try {
await sdk.forProject.functions.updateVariable(
functionId,
variable.$id,
variable.key,
variable.value
);
await invalidate(Dependencies.VARIABLES);
selectedVar = null;
showVariablesModal = false;
addNotification({
type: 'success',
message: `${$func.name} variables have been updated`
});
trackEvent(Submit.VariableUpdate);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.VariableUpdate);
}
}
async function handleVariableDeleted(variable: Models.Variable) {
try {
await sdk.forProject.functions.deleteVariable(variable.functionId, variable.$id);
await invalidate(Dependencies.VARIABLES);
addNotification({
type: 'success',
message: `Variable has been deleted`
});
trackEvent(Submit.VariableDelete);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.VariableDelete);
}
}
function downloadVariables() {
if (data.variables.total) {
let content = data.variables.variables
.map((variable) => `${variable.key}=${variable.value}`)
.join('\n');
const file = new File([content], '.env', {
type: 'application/x-envoy'
});
const link = document.createElement('a');
const url = URL.createObjectURL(file);
link.href = url;
link.download = file.name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
}
}
$: if (permissions) {
if (symmetricDifference(permissions, $func.execute).length) {
arePermsDisabled = false;
} else arePermsDisabled = true;
}
export let data;
</script>
<Container>
<CardGrid>
<div class="grid-1-2-col-1 u-flex u-cross-center u-gap-16">
<div class="avatar is-medium">
<img
src={`${base}/icons/${$app.themeInUse}/color/${
$func.runtime.split('-')[0]
}.svg`}
alt="technology" />
</div>
<div>
<Heading tag="h6" size="7">{$func.name}</Heading>
<p class="text u-capitalize">{$func.runtime}</p>
</div>
</div>
<svelte:fragment slot="aside">
<div class="u-flex u-main-space-between">
<div>
<p>Function ID: {$func.$id}</p>
<p>Created at: {toLocaleDateTime($func.$createdAt)}</p>
<p>Updated at: {toLocaleDateTime($func.$updatedAt)}</p>
</div>
</div>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button secondary on:click={() => ($execute = $func)}>Execute now</Button>
</svelte:fragment>
</CardGrid>
<Form onSubmit={updateName}>
<CardGrid>
<Heading tag="h6" size="7">Name</Heading>
<svelte:fragment slot="aside">
<ul>
<InputText
id="name"
label="Name"
placeholder="Enter name"
autocomplete={false}
bind:value={functionName} />
</ul>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button disabled={functionName === $func.name || !functionName} submit>
Update
</Button>
</svelte:fragment>
</CardGrid>
</Form>
<Form onSubmit={updatePermissions}>
<CardGrid>
<Heading tag="h6" size="7">Execute Access</Heading>
<p>
Choose who can execute this function using the client API. For more information,
check out the <a
href="https://appwrite.io/docs/permissions"
target="_blank"
rel="noopener noreferrer"
class="link">
Permissions Guide
</a>.
</p>
<svelte:fragment slot="aside">
<Roles bind:roles={permissions} />
</svelte:fragment>
<svelte:fragment slot="actions">
<Button disabled={arePermsDisabled} submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>
<ExecuteFunction />
<UpdateName />
<UpdatePermissions />
<UpdateEvents />
<Form onSubmit={updateSchedule}>
<CardGrid>
<Heading tag="h6" size="7">Schedule</Heading>
<p>
Set a Cron schedule to trigger your function. Leave blank for no schedule. <a
href="https://en.wikipedia.org/wiki/Cron"
target="_blank"
rel="noopener noreferrer"
class="link">
More details on Cron syntax here.</a>
</p>
<svelte:fragment slot="aside">
<FormList>
<InputCron
bind:value={functionSchedule}
label="Schedule (Cron Syntax)"
id="schedule" />
</FormList>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button disabled={$func.schedule === functionSchedule} submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>
<CardGrid>
<Heading tag="h6" size="7">Variables</Heading>
<p>Set the variables (or secret keys) that will be passed to your function at runtime.</p>
<svelte:fragment slot="aside">
<div class="u-flex u-margin-inline-start-auto u-gap-16">
<Button
secondary
event="download_env"
disabled={!data.variables.total}
on:click={downloadVariables}>
<span class="icon-download" />
<span class="text">Download .env file</span>
</Button>
<Button secondary on:click={() => (showVariablesUpload = true)}>
<span class="icon-upload" />
<span class="text">Import .env file</span>
</Button>
</div>
{@const limit = 10}
{@const sum = data.variables.total}
{#if sum}
<div class="u-flex u-flex-vertical u-gap-16">
<Table noMargin noStyles>
<TableHeader>
<TableCellHead>Key</TableCellHead>
<TableCellHead width={180}>Value</TableCellHead>
<TableCellHead width={30} />
</TableHeader>
<TableBody>
{#each data.variables.variables.slice(offset, offset + limit) as variable, i}
<TableRow>
<TableCell title="key">
<Output value={variable.key} hideCopyIcon>
{variable.key}
</Output>
</TableCell>
<TableCell showOverflow title="value">
<Secret copyEvent="variable" value={variable.value} />
</TableCell>
<TableCell showOverflow title="options">
<DropList
bind:show={showVariablesDropdown[i]}
placement="bottom-start"
noArrow>
<Button
text
round
ariaLabel="more options"
on:click={() =>
(showVariablesDropdown[i] =
!showVariablesDropdown[i])}>
<span
class="icon-dots-horizontal"
aria-hidden="true" />
</Button>
<svelte:fragment slot="list">
<DropListItem
icon="pencil"
on:click={() => {
selectedVar = variable;
showVariablesDropdown[i] = false;
showVariablesModal = true;
}}>
Edit
</DropListItem>
<DropListItem
icon="trash"
on:click={async () => {
handleVariableDeleted(variable);
showVariablesDropdown[i] = false;
}}>
Delete
</DropListItem>
</svelte:fragment>
</DropList>
</TableCell>
</TableRow>
{/each}
</TableBody>
</Table>
<Button text noMargin on:click={() => (showVariablesModal = true)}>
<span class="icon-plus" aria-hidden="true" />
<span class="text">Create variable</span>
</Button>
<div class="u-flex u-main-space-between">
<p class="text">Total variables: {sum}</p>
<PaginationInline {sum} {limit} bind:offset hidePages />
</div>
</div>
{:else}
<Empty on:click={() => (showVariablesModal = !showVariablesModal)}>
Create a variable to get started
</Empty>
{/if}
</svelte:fragment>
</CardGrid>
<Form onSubmit={updateTimeout}>
<CardGrid>
<Heading tag="h6" size="7">Timeout</Heading>
<p>
Limit the execution time of your function. Maximum value is 900 seconds (15
minutes).
</p>
<svelte:fragment slot="aside">
<FormList>
<InputNumber
min={1}
max={900}
id="time"
label="Time (in seconds)"
bind:value={timeout} />
</FormList>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button disabled={$func.timeout === timeout || timeout < 1} submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>
<CardGrid danger>
<Heading tag="h6" size="7">Delete Function</Heading>
<p>
The function will be permanently deleted, including all deployments associated with it.
This action is irreversible.
</p>
<svelte:fragment slot="aside">
<Box>
<svelte:fragment slot="title">
<h6 class="u-bold u-trim-1">{$func.name}</h6>
</svelte:fragment>
<p>Last Updated: {toLocaleDateTime($func.$updatedAt)}</p>
</Box>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button secondary on:click={() => (showDelete = true)}>Delete</Button>
</svelte:fragment>
</CardGrid>
<UpdateSchedule />
<UpdateVariables variableList={data.variables} />
<UpdateTimeout />
<DangerZone />
</Container>
<Delete bind:showDelete />
{#if showVariablesModal}
<Variable
bind:selectedVar
bind:showCreate={showVariablesModal}
on:created={handleVariableCreated}
on:updated={handleVariableUpdated} />
{/if}
{#if showVariablesUpload}
<UploadVariables bind:show={showVariablesUpload} />
{/if}
@@ -0,0 +1,33 @@
<script lang="ts">
import { Box, CardGrid } from '$lib/components';
import Heading from '$lib/components/heading.svelte';
import { Button } from '$lib/elements/forms';
import { toLocaleDateTime } from '$lib/helpers/date';
import Delete from './deleteModal.svelte';
import { func } from '../store';
let showDelete = false;
</script>
<CardGrid danger>
<Heading tag="h6" size="7">Delete Function</Heading>
<p>
The function will be permanently deleted, including all deployments associated with it. This
action is irreversible.
</p>
<svelte:fragment slot="aside">
<Box>
<svelte:fragment slot="title">
<h6 class="u-bold u-trim-1">{$func.name}</h6>
</svelte:fragment>
<p>Last Updated: {toLocaleDateTime($func.$updatedAt)}</p>
</Box>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button secondary on:click={() => (showDelete = true)}>Delete</Button>
</svelte:fragment>
</CardGrid>
<Delete bind:showDelete />
@@ -0,0 +1,36 @@
<script lang="ts">
import { base } from '$app/paths';
import { CardGrid, Heading } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { toLocaleDateTime } from '$lib/helpers/date';
import { app } from '$lib/stores/app';
import { execute, func } from '../store';
</script>
<CardGrid>
<div class="grid-1-2-col-1 u-flex u-cross-center u-gap-16">
<div class="avatar is-medium">
<img
src={`${base}/icons/${$app.themeInUse}/color/${$func.runtime.split('-')[0]}.svg`}
alt="technology" />
</div>
<div>
<Heading tag="h6" size="7">{$func.name}</Heading>
<p class="text u-capitalize">{$func.runtime}</p>
</div>
</div>
<svelte:fragment slot="aside">
<div class="u-flex u-main-space-between">
<div>
<p>Function ID: {$func.$id}</p>
<p>Created at: {toLocaleDateTime($func.$createdAt)}</p>
<p>Updated at: {toLocaleDateTime($func.$updatedAt)}</p>
</div>
</div>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button secondary on:click={() => ($execute = $func)}>Execute now</Button>
</svelte:fragment>
</CardGrid>
@@ -0,0 +1,66 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { page } from '$app/stores';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { CardGrid, Heading } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { Button, Form, InputText } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { func } from '../store';
const functionId = $page.params.function;
let functionName: string = null;
onMount(async () => {
functionName ??= $func.name;
});
async function updateName() {
try {
await sdk.forProject.functions.update(
functionId,
functionName,
$func.execute || undefined,
$func.events || undefined,
$func.schedule || undefined,
$func.timeout || undefined,
$func.enabled
);
await invalidate(Dependencies.FUNCTION);
addNotification({
message: 'Name has been updated',
type: 'success'
});
trackEvent(Submit.FunctionUpdateName);
} catch (error) {
addNotification({
message: error.message,
type: 'error'
});
trackError(error, Submit.FunctionUpdateName);
}
}
</script>
<Form onSubmit={updateName}>
<CardGrid>
<Heading tag="h6" size="7">Name</Heading>
<svelte:fragment slot="aside">
<ul>
<InputText
id="name"
label="Name"
placeholder="Enter name"
autocomplete={false}
bind:value={functionName} />
</ul>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button disabled={functionName === $func.name || !functionName} submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>
@@ -0,0 +1,78 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { page } from '$app/stores';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { CardGrid, Heading } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { Button, Form } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { func } from '../store';
import { Roles } from '$lib/components/permissions';
import { symmetricDifference } from '$lib/helpers/array';
const functionId = $page.params.function;
let arePermsDisabled = true;
let permissions: string[] = [];
onMount(async () => {
permissions = $func.execute;
});
async function updatePermissions() {
try {
await sdk.forProject.functions.update(
functionId,
$func.name,
permissions,
$func.events || undefined,
$func.schedule || undefined,
$func.timeout || undefined,
$func.enabled
);
await invalidate(Dependencies.FUNCTION);
addNotification({
message: 'Permissions have been updated',
type: 'success'
});
trackEvent(Submit.FunctionUpdatePermissions);
} catch (error) {
addNotification({
message: error.message,
type: 'error'
});
trackError(error, Submit.FunctionUpdatePermissions);
}
}
$: if (permissions) {
if (symmetricDifference(permissions, $func.execute).length) {
arePermsDisabled = false;
} else arePermsDisabled = true;
}
</script>
<Form onSubmit={updatePermissions}>
<CardGrid>
<Heading tag="h6" size="7">Execute Access</Heading>
<p>
Choose who can execute this function using the client API. For more information, check
out the <a
href="https://appwrite.io/docs/permissions"
target="_blank"
rel="noopener noreferrer"
class="link">
Permissions Guide
</a>.
</p>
<svelte:fragment slot="aside">
<Roles bind:roles={permissions} />
</svelte:fragment>
<svelte:fragment slot="actions">
<Button disabled={arePermsDisabled} submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>
@@ -0,0 +1,71 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { page } from '$app/stores';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { CardGrid, Heading } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { Button, Form, FormList, InputCron } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { func } from '../store';
const functionId = $page.params.function;
let functionSchedule: string = null;
onMount(async () => {
functionSchedule ??= $func.schedule;
});
async function updateSchedule() {
try {
await sdk.forProject.functions.update(
functionId,
$func.name,
$func.execute || undefined,
$func.events || undefined,
functionSchedule,
$func.timeout || undefined,
$func.enabled
);
await invalidate(Dependencies.FUNCTION);
addNotification({
type: 'success',
message: 'Cron Schedule has been updated'
});
trackEvent(Submit.FunctionUpdateSchedule);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.FunctionUpdateSchedule);
}
}
</script>
<Form onSubmit={updateSchedule}>
<CardGrid>
<Heading tag="h6" size="7">Schedule</Heading>
<p>
Set a Cron schedule to trigger your function. Leave blank for no schedule. <a
href="https://en.wikipedia.org/wiki/Cron"
target="_blank"
rel="noopener noreferrer"
class="link">
More details on Cron syntax here.</a>
</p>
<svelte:fragment slot="aside">
<FormList>
<InputCron
bind:value={functionSchedule}
label="Schedule (Cron Syntax)"
id="schedule" />
</FormList>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button disabled={$func.schedule === functionSchedule} submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>
@@ -0,0 +1,66 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { page } from '$app/stores';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { CardGrid, Heading } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { Button, Form, FormList, InputNumber } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { func } from '../store';
const functionId = $page.params.function;
let timeout: number = null;
onMount(async () => {
timeout ??= $func.timeout;
});
async function updateTimeout() {
try {
await sdk.forProject.functions.update(
functionId,
$func.name,
$func.execute || undefined,
$func.events || undefined,
$func.schedule || undefined,
timeout,
$func.enabled
);
await invalidate(Dependencies.FUNCTION);
addNotification({
type: 'success',
message: 'Timeout has been updated'
});
trackEvent(Submit.FunctionUpdateTimeout);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.FunctionUpdateTimeout);
}
}
</script>
<Form onSubmit={updateTimeout}>
<CardGrid>
<Heading tag="h6" size="7">Timeout</Heading>
<p>Limit the execution time of your function. Maximum value is 900 seconds (15 minutes).</p>
<svelte:fragment slot="aside">
<FormList>
<InputNumber
min={1}
max={900}
id="time"
label="Time (in seconds)"
bind:value={timeout} />
</FormList>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button disabled={$func.timeout === timeout || timeout < 1} submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>
@@ -0,0 +1,233 @@
<script lang="ts">
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import {
Table,
TableBody,
TableCell,
TableCellHead,
TableHeader,
TableRow
} from '$lib/elements/table';
import { Button } from '$lib/elements/forms';
import {
CardGrid,
Heading,
DropList,
DropListItem,
Empty,
Output,
PaginationInline,
Secret
} from '$lib/components';
import Variable from '../../createVariable.svelte';
import UploadVariables from './uploadVariablesModal.svelte';
import { invalidate } from '$app/navigation';
import { page } from '$app/stores';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { Dependencies } from '$lib/constants';
import { addNotification } from '$lib/stores/notifications';
import { func } from '../store';
export let variableList: Models.VariableList;
const functionId = $page.params.function;
let showVariablesDropdown = [];
let selectedVar: Models.Variable = null;
let showVariablesUpload = false;
let showVariablesModal = false;
let offset = 0;
async function handleVariableCreated(event: CustomEvent<Models.Variable>) {
const variable = event.detail;
try {
await sdk.forProject.functions.createVariable(functionId, variable.key, variable.value);
await invalidate(Dependencies.VARIABLES);
showVariablesModal = false;
addNotification({
type: 'success',
message: `${$func.name} variables have been updated`
});
trackEvent(Submit.VariableCreate);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.VariableCreate);
}
}
async function handleVariableUpdated(event: CustomEvent<Models.Variable>) {
const variable = event.detail;
try {
await sdk.forProject.functions.updateVariable(
functionId,
variable.$id,
variable.key,
variable.value
);
await invalidate(Dependencies.VARIABLES);
selectedVar = null;
showVariablesModal = false;
addNotification({
type: 'success',
message: `${$func.name} variables have been updated`
});
trackEvent(Submit.VariableUpdate);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.VariableUpdate);
}
}
async function handleVariableDeleted(variable: Models.Variable) {
try {
await sdk.forProject.functions.deleteVariable(variable.functionId, variable.$id);
await invalidate(Dependencies.VARIABLES);
addNotification({
type: 'success',
message: `Variable has been deleted`
});
trackEvent(Submit.VariableDelete);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.VariableDelete);
}
}
function downloadVariables() {
if (variableList.total) {
let content = variableList.variables
.map((variable) => `${variable.key}=${variable.value}`)
.join('\n');
const file = new File([content], '.env', {
type: 'application/x-envoy'
});
const link = document.createElement('a');
const url = URL.createObjectURL(file);
link.href = url;
link.download = file.name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
}
}
</script>
<CardGrid>
<Heading tag="h6" size="7">Variables</Heading>
<p>Set the variables (or secret keys) that will be passed to your function at runtime.</p>
<svelte:fragment slot="aside">
<div class="u-flex u-margin-inline-start-auto u-gap-16">
<Button
secondary
event="download_env"
disabled={!variableList.total}
on:click={downloadVariables}>
<span class="icon-download" />
<span class="text">Download .env file</span>
</Button>
<Button secondary on:click={() => (showVariablesUpload = true)}>
<span class="icon-upload" />
<span class="text">Import .env file</span>
</Button>
</div>
{@const limit = 10}
{@const sum = variableList.total}
{#if sum}
<div class="u-flex u-flex-vertical u-gap-16">
<Table noMargin noStyles>
<TableHeader>
<TableCellHead>Key</TableCellHead>
<TableCellHead width={180}>Value</TableCellHead>
<TableCellHead width={30} />
</TableHeader>
<TableBody>
{#each variableList.variables.slice(offset, offset + limit) as variable, i}
<TableRow>
<TableCell title="key">
<Output value={variable.key} hideCopyIcon>
{variable.key}
</Output>
</TableCell>
<TableCell showOverflow title="value">
<Secret copyEvent="variable" value={variable.value} />
</TableCell>
<TableCell showOverflow title="options">
<DropList
bind:show={showVariablesDropdown[i]}
placement="bottom-start"
noArrow>
<Button
text
round
ariaLabel="more options"
on:click={() =>
(showVariablesDropdown[i] =
!showVariablesDropdown[i])}>
<span class="icon-dots-horizontal" aria-hidden="true" />
</Button>
<svelte:fragment slot="list">
<DropListItem
icon="pencil"
on:click={() => {
selectedVar = variable;
showVariablesDropdown[i] = false;
showVariablesModal = true;
}}>
Edit
</DropListItem>
<DropListItem
icon="trash"
on:click={async () => {
handleVariableDeleted(variable);
showVariablesDropdown[i] = false;
}}>
Delete
</DropListItem>
</svelte:fragment>
</DropList>
</TableCell>
</TableRow>
{/each}
</TableBody>
</Table>
<Button text noMargin on:click={() => (showVariablesModal = true)}>
<span class="icon-plus" aria-hidden="true" />
<span class="text">Create variable</span>
</Button>
<div class="u-flex u-main-space-between">
<p class="text">Total variables: {sum}</p>
<PaginationInline {sum} {limit} bind:offset hidePages />
</div>
</div>
{:else}
<Empty on:click={() => (showVariablesModal = !showVariablesModal)}>
Create a variable to get started
</Empty>
{/if}
</svelte:fragment>
</CardGrid>
{#if showVariablesModal}
<Variable
bind:selectedVar
bind:showCreate={showVariablesModal}
on:created={handleVariableCreated}
on:updated={handleVariableUpdated} />
{/if}
{#if showVariablesUpload}
<UploadVariables bind:show={showVariablesUpload} />
{/if}
@@ -35,8 +35,12 @@
</svelte:fragment>
{#if method === Method.NPM}
<p>
Use <a href="https://npmjs.org" target="_blank" rel="noopener noreferrer" class="link"
>NPM (node package manager)</a> from your command line to add Appwrite SDK to your project.
Use <a
href="https://npmjs.com/package/appwrite"
target="_blank"
rel="noopener noreferrer"
class="link">NPM (node package manager)</a> from your command line to add Appwrite SDK
to your project.
</p>
<Code label="Bash" language="sh" code="npm install appwrite" withCopy />
<p class="common-section">
@@ -115,7 +115,10 @@
<CardGrid>
<Heading tag="h6" size="7">Services</Heading>
<p class="text">Choose services you wish to enable or disable.</p>
<p class="text">
Choose services you wish to enable or disable for the client API. When disabled, the
services are not accessible to client SDKs but remain accessible to server SDKs.
</p>
<svelte:fragment slot="aside">
<FormList>
<form class="form">
@@ -6,13 +6,13 @@
import { Button } from '$lib/elements/forms';
import { Pill } from '$lib/elements';
import {
Table,
TableBody,
TableRowLink,
TableCellHead,
TableCell,
TableCellText,
TableHeader
TableHeader,
TableScroll
} from '$lib/elements/table';
import { Container } from '$lib/layout';
import { wizard } from '$lib/stores/wizard';
@@ -46,10 +46,10 @@
</div>
{#if data.webhooks.total}
<Table>
<TableScroll>
<TableHeader>
<TableCellHead>Name</TableCellHead>
<TableCellHead>POST URL</TableCellHead>
<TableCellHead width={200}>Name</TableCellHead>
<TableCellHead width={180}>POST URL</TableCellHead>
<TableCellHead width={80}>Events</TableCellHead>
</TableHeader>
<TableBody>
@@ -57,7 +57,7 @@
<TableRowLink
href={`${base}/console/project-${projectId}/settings/webhooks/${webhook.$id}`}>
<TableCell title="Name">
<div class="u-flex u-main-space-between">
<div class="u-flex u-main-space-between u-cross-center">
{webhook.name}
{#if webhook.security === false}
<Pill>SLL/TLS disabled</Pill>
@@ -69,7 +69,7 @@
</TableRowLink>
{/each}
</TableBody>
</Table>
</TableScroll>
{:else}
<Empty
single
@@ -34,7 +34,9 @@
<CoverTitle href={`/console/project-${projectId}/storage`}>
{$bucket?.name}
</CoverTitle>
<Id value={$bucket?.$id} event="bucket">Bucket ID</Id>
{#if $bucket?.$id}
<Id value={$bucket.$id} event="bucket">{$bucket.$id}</Id>
{/if}
</svelte:fragment>
<Tabs>