Skip to content

Commit

Permalink
feat: new console sdk and typings
Browse files Browse the repository at this point in the history
# Conflicts:
#	package-lock.json
#	package.json
  • Loading branch information
abnegate committed Feb 19, 2024
1 parent 006dd3b commit 44edd46
Show file tree
Hide file tree
Showing 28 changed files with 109 additions and 85 deletions.
4 changes: 2 additions & 2 deletions src/routes/console/account/deleteMfa.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import InputDigits from '$lib/elements/forms/inputDigits.svelte';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { AuthenticatorProvider } from '@appwrite.io/console';
import { AuthenticatorType } from '@appwrite.io/console';
export let showDelete = false;
Expand All @@ -17,7 +17,7 @@
async function deleteProvider() {
try {
await sdk.forConsole.account.deleteAuthenticator(AuthenticatorProvider.Totp, code);
await sdk.forConsole.account.deleteAuthenticator(AuthenticatorType.Totp, code);
await invalidate(Dependencies.ACCOUNT);
await invalidate(Dependencies.FACTORS);
showDelete = false;
Expand Down
16 changes: 8 additions & 8 deletions src/routes/console/account/mfa.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
import { Table, TableBody, TableCell, TableRow } from '$lib/elements/table';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { AuthenticatorFactor, type Models } from '@appwrite.io/console';
import { AuthenticatorType, type Models } from '@appwrite.io/console';
export let showSetup = false;
export let showRecoveryCodes = false;
let code: string;
let provider: Models.MfaProvider = null;
let type: Models.MfaType = null;
async function addAuthenticator(): Promise<URL> {
provider = await sdk.forConsole.account.addAuthenticator(AuthenticatorFactor.Totp);
type = await sdk.forConsole.account.addAuthenticator(AuthenticatorType.Totp);
return sdk.forConsole.avatars.getQR(provider.uri, 192 * 2);
return sdk.forConsole.avatars.getQR(type.uri, 192 * 2);
}
async function verifyAuthenticator() {
try {
await sdk.forConsole.account.verifyAuthenticator(AuthenticatorFactor.Totp, code);
await sdk.forConsole.account.verifyAuthenticator(AuthenticatorType.Totp, code);
await invalidate(Dependencies.ACCOUNT);
await invalidate(Dependencies.FACTORS);
showSetup = false;
Expand Down Expand Up @@ -72,8 +72,8 @@
description="Learn more about multi-factor authentication in our documentation."
bind:show={showRecoveryCodes}
onSubmit={verifyAuthenticator}>
{#if provider}
{@const formattedBackupCodes = provider.backups.join('\n')}
{#if type}
{@const formattedBackupCodes = type.backups.join('\n')}
<Alert type="info">
<span slot="title">
It is highly recommended to securely store your recovery codes
Expand Down Expand Up @@ -109,7 +109,7 @@
</div>
<Table noMargin noStyles>
<TableBody>
{#each provider.backups as code}
{#each type.backups as code}
<TableRow>
<TableCell title="code">
<Output value={code} hideCopyIcon>{code}</Output>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/console/account/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { page } from '$app/stores';
import { derived } from 'svelte/store';
import type { Models } from '@appwrite.io/console';

export const factors = derived(page, ($page) => $page.data.factors as Models.MfaProviders);
export const factors = derived(page, ($page) => $page.data.factors as Models.MfaFactors);
15 changes: 10 additions & 5 deletions src/routes/console/project-[project]/auth/templates/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// TODO: fix TemplateType and TemplateLocale typing once SDK is updated
return await sdk.forConsole.projects.getEmailTemplate(
projectId,
type as TemplateType,
locale as TemplateLocale
type as EmailTemplateType,
locale as EmailTemplateLocale
);
} catch (e) {
addNotification({
Expand All @@ -19,8 +19,8 @@
// TODO: fix TemplateType and TemplateLocale typing once SDK is updated
return await sdk.forConsole.projects.getSmsTemplate(
projectId,
type as TemplateType,
locale as TemplateLocale
type as SMSTemplateType,
locale as SMSTemplateLocale
);
} catch (e) {
addNotification({
Expand Down Expand Up @@ -54,7 +54,12 @@
import ChangeOrganizationTierCloud from '$routes/console/changeOrganizationTierCloud.svelte';
import { wizard } from '$lib/stores/wizard';
import { BillingPlan } from '$lib/constants';
import type { TemplateLocale, TemplateType } from '@appwrite.io/console';
import type {
SMSTemplateLocale,
SMSTemplateType,
EmailTemplateType,
EmailTemplateLocale
} from '@appwrite.io/console';
const projectId = $page.params.project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import deepEqual from 'deep-equal';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { Box } from '$lib/components';
import type { TemplateLocale, TemplateType } from '@appwrite.io/console';
import type { EmailTemplateLocale, EmailTemplateType } from '@appwrite.io/console';
export let loading = false;
let openResetModal = false;
Expand Down Expand Up @@ -56,8 +56,8 @@
// TODO: fix TemplateType and TemplateLocale typing once SDK is updated
await sdk.forConsole.projects.updateEmailTemplate(
$project.$id,
$emailTemplate.type ? ($emailTemplate.type as TemplateType) : undefined,
$emailTemplate.locale ? ($emailTemplate.locale as TemplateLocale) : undefined,
$emailTemplate.type ? ($emailTemplate.type as EmailTemplateType) : undefined,
$emailTemplate.locale ? ($emailTemplate.locale as EmailTemplateLocale) : undefined,
$emailTemplate.subject ? $emailTemplate.subject : undefined,
$emailTemplate.message ? $emailTemplate.message : undefined,
$emailTemplate.senderName ? $emailTemplate.senderName : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { Button } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import type { TemplateLocale, TemplateType } from '@appwrite.io/console';
import type { EmailTemplateLocale, EmailTemplateType } from '@appwrite.io/console';
import { project } from '../../store';
import { loadEmailTemplate } from './+page.svelte';
import { baseEmailTemplate, emailTemplate } from './store';
Expand All @@ -18,8 +18,8 @@
// TODO: fix TemplateType and TemplateLocale typing once SDK is updated
await sdk.forConsole.projects.deleteEmailTemplate(
$project.$id,
$emailTemplate.type as TemplateType,
$emailTemplate.locale as TemplateLocale
$emailTemplate.type as EmailTemplateType,
$emailTemplate.locale as EmailTemplateLocale
);
$emailTemplate = await loadEmailTemplate(
$project.$id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Modal } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { sdk } from '$lib/stores/sdk';
import type { TemplateLocale, TemplateType } from '@appwrite.io/console';
import type { SMSTemplateLocale, SMSTemplateType } from '@appwrite.io/console';
import { project } from '../../store';
import { loadSmsTemplate } from './+page.svelte';
import { baseSmsTemplate, smsTemplate } from './store';
Expand All @@ -17,8 +17,8 @@
// TODO: fix TemplateType and TemplateLocale typing once SDK is updated
await sdk.forConsole.projects.deleteSmsTemplate(
$project.$id,
$smsTemplate.type as TemplateType,
$smsTemplate.locale as TemplateLocale
$smsTemplate.type as SMSTemplateType,
$smsTemplate.locale as SMSTemplateLocale
);
$smsTemplate = await loadSmsTemplate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import deepEqual from 'deep-equal';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { Box } from '$lib/components';
import type { TemplateLocale, TemplateType } from '@appwrite.io/console';
import type { SMSTemplateLocale, SMSTemplateType } from '@appwrite.io/console';
export let loading = false;
const projectId = $page.params.project;
Expand Down Expand Up @@ -39,8 +39,8 @@
// TODO: fix TemplateType and TemplateLocale typing once SDK is updated
await sdk.forConsole.projects.updateSmsTemplate(
projectId,
$smsTemplate.type as TemplateType,
$smsTemplate.locale as TemplateLocale,
$smsTemplate.type as SMSTemplateType,
$smsTemplate.locale as SMSTemplateLocale,
$smsTemplate.message
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const load: LayoutLoad = async ({ params, depends }) => {
header: Header,
breadcrumbs: Breadcrumbs,
user: await sdk.forProject.users.get(params.user),
userFactors: await sdk.forProject.users.listProviders(params.user)
userFactors: await sdk.forProject.users.listFactors(params.user)
};
} catch (e) {
error(e.code, e.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import InputDigits from '$lib/elements/forms/inputDigits.svelte';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { AuthenticatorProvider } from '@appwrite.io/console';
import { AuthenticatorType } from '@appwrite.io/console';
import { user } from './store';
export let showDelete = false;
Expand All @@ -18,11 +18,7 @@
async function deleteProvider() {
try {
await sdk.forConsole.users.deleteAuthenticator(
$user.$id,
AuthenticatorProvider.Totp,
''
);
await sdk.forConsole.users.deleteAuthenticator($user.$id, AuthenticatorType.Totp, '');
await invalidate(Dependencies.ACCOUNT);
await invalidate(Dependencies.FACTORS);
showDelete = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export const user = derived(
page,
($page) => $page.data.user as Models.User<Record<string, string>>
);
export const userFactors = derived(page, ($page) => $page.data.userFactors as Models.MfaProviders);
export const userFactors = derived(page, ($page) => $page.data.userFactors as Models.MfaFactors);
4 changes: 2 additions & 2 deletions src/routes/console/project-[project]/messaging/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
} from '$lib/elements/table';
import { toLocaleDateTime } from '$lib/helpers/date';
import { Container } from '$lib/layout';
import { MessageType, MessagingProviderType } from '@appwrite.io/console';
import { MessageStatus, MessagingProviderType } from '@appwrite.io/console';
import type { PageData } from './$types';
import CreateMessageDropdown from './createMessageDropdown.svelte';
import FailedModal from './failedModal.svelte';
Expand Down Expand Up @@ -141,7 +141,7 @@
<TableCellCheck
bind:selectedIds={selected}
id={message.$id}
disabled={message.status === MessageType.Processing} />
disabled={message.status === MessageStatus.Processing} />

{#each $columns as column (column.id)}
{#if column.show}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import Wizard from '../wizard.svelte';
import type { PageData } from './$types';
import { isValueOfStringEnum } from '$lib/helpers/types';
import { MessageType, MessagingProviderType } from '@appwrite.io/console';
import { MessageStatus, MessagingProviderType } from '@appwrite.io/console';
import Topics from './topics.svelte';
import Targets from './targets.svelte';
Expand All @@ -35,7 +35,7 @@
topics: $message.topics,
users: $message.users,
targets: $message.targets,
status: MessageType.Draft,
status: MessageStatus.Draft,
scheduledAt: $message.scheduledAt
};
Expand Down Expand Up @@ -100,19 +100,19 @@
{#if $message.providerType === MessagingProviderType.Email}
<EmailPreview
message={$message}
onEdit={$message.status === MessageType.Draft ? onEdit : null} />
onEdit={$message.status === MessageStatus.Draft ? onEdit : null} />
{:else if $message.providerType === MessagingProviderType.Sms}
<SMSPreview
message={$message}
onEdit={$message.status === MessageType.Draft ? onEdit : null} />
onEdit={$message.status === MessageStatus.Draft ? onEdit : null} />
{:else if $message.providerType === MessagingProviderType.Push}
<PushPreview
message={$message}
onEdit={$message.status === MessageType.Draft ? onEdit : null} />
onEdit={$message.status === MessageStatus.Draft ? onEdit : null} />
{/if}
<Topics topics={Object.values(data.topicsById)} />
<Targets targets={Object.values(data.targetsById)} usersById={data.usersById} />
{#if $message.status !== MessageType.Processing}
{#if $message.status !== MessageStatus.Processing}
<Delete message={$message} />
{/if}
</Container>
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</TableCellText>

<TableCellText title="subscribers">
{topic.total}
{topic.smsTotal + topic.emailTotal + topic.pushTotal}
</TableCellText>
</TableRow>
{/each}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
undefined,
undefined,
undefined,
undefined,
enabled
);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
$providerParams[$provider].password || undefined,
$providerParams[$provider].encryption,
$providerParams[$provider].autoTLS,
$providerParams[$provider].mailer || undefined,
$providerParams[$provider].fromName || undefined,
$providerParams[$provider].fromEmail,
$providerParams[$provider].replyToName || undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { CardGrid, BoxAvatar, Heading } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { writable } from 'svelte/store';
import { topic } from './store';
import { topic, topicTotal } from './store';
import { goto } from '$app/navigation';
import { project } from '$routes/console/project-[project]/store';
import DeleteTopic from './deleteTopic.svelte';
Expand All @@ -31,7 +31,7 @@
<h6 class="u-bold u-trim-1">{$topic.name}</h6>
</svelte:fragment>
<p>
{$topic.total} subscriber{$topic.total === 1 ? '' : 's'}
{$topicTotal} subscriber{$topicTotal === 1 ? '' : 's'}
</p>
</BoxAvatar>
</svelte:fragment>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { CardGrid, Heading } from '$lib/components';
import { toLocaleDateTime } from '$lib/helpers/date';
import { topic } from './store';
import { topic, topicTotal } from './store';
</script>

<CardGrid>
Expand All @@ -11,7 +11,7 @@
<svelte:fragment slot="aside">
<div class="u-flex u-main-space-between">
<div data-private>
<p class="title">{$topic.total} subscriber{$topic.total === 1 ? '' : 's'}</p>
<p class="title">{$topicTotal} subscriber{$topicTotal === 1 ? '' : 's'}</p>
<p>Created: {toLocaleDateTime($topic.$createdAt)}</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ export const topic = derived(
// TODO: Set actual type
($page) => $page.data.topic as Models.Topic
);
export const topicTotal = derived(
topic,
($topic) => $topic.emailTotal + $topic.smsTotal + $topic.pushTotal
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { sdk } from '$lib/stores/sdk';
import { Query, type Models } from '@appwrite.io/console';
import { createEventDispatcher } from 'svelte';
import { providerType } from './wizard/store';
import { providerType, getTotal } from './wizard/store';
export let show: boolean;
export let topicsById: Record<string, Models.Topic>;
Expand Down Expand Up @@ -98,12 +98,14 @@
checked={!!selected[topicId]}
on:change={(event) => onTopicSelection(event, topic)}>
<svelte:fragment slot="description">
<span class="title"
><span class="u-line-height-1-5">
<span class="title">
<span class="u-line-height-1-5">
<span class="body-text-2 u-bold" data-private>
{topic.name}
</span><span class="collapsible-button-optional"
>({topic.total} subscribers)</span>
</span>
<span class="collapsible-button-optional">
({getTotal(topic)} subscribers)
</span>
</span></span>
</svelte:fragment>
</InputCheckbox>
Expand Down
Loading

0 comments on commit 44edd46

Please sign in to comment.