Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions src/lib/stores/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@ export const createMigrationFormStore = () => {
};
};

const resources = [
'user',
'team',
'membership',
'file',
'bucket',
'function',
'envVar',
'deployment',
'database',
'collection',
'index',
'attribute',
'document'
] as const;
export const ResourcesFriendly = {
user: { singular: 'User', plural: 'Users' },
team: { singular: 'Team', plural: 'Teams' },
membership: { singular: 'Membership', plural: 'Memberships' },
file: { singular: 'File', plural: 'Files' },
bucket: { singular: 'Bucket', plural: 'Buckets' },
function: { singular: 'Function', plural: 'Functions' },
'environment variable': { singular: 'Environment Variable', plural: 'Environment Variables' },
deployment: { singular: 'Deployment', plural: 'Deployments' },
database: { singular: 'Database', plural: 'Databases' },
collection: { singular: 'Collection', plural: 'Collections' },
index: { singular: 'Index', plural: 'Indexes' },
attribute: { singular: 'Attribute', plural: 'Attributes' },
document: { singular: 'Document', plural: 'Documents' }
};

const resources = Object.keys(ResourcesFriendly);

type Resource = (typeof resources)[number];

Expand Down Expand Up @@ -101,7 +103,7 @@ export const migrationFormToResources = (
addResource('function');
}
if (formData.functions.env) {
addResource('envVar');
addResource('environment variable');
}
if (formData.functions.inactive) {
addResource('deployment');
Expand Down Expand Up @@ -155,7 +157,7 @@ export const resourcesToMigrationForm = (
if (resources.includes('function') && isVersionAtLeast(version, '1.4.0')) {
formData.functions.root = true;
}
if (resources.includes('envVar') && isVersionAtLeast(version, '1.4.0')) {
if (resources.includes('environment variable') && isVersionAtLeast(version, '1.4.0')) {
formData.functions.env = true;
}
if (resources.includes('deployment') && isVersionAtLeast(version, '1.4.0')) {
Expand Down
21 changes: 6 additions & 15 deletions src/routes/console/(migration-wizard)/resource-form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Button } from '$lib/elements/forms';
import { deepMap } from '$lib/helpers/object';
import type { WritableValue } from '$lib/helpers/types';
import { sdk, type getSdkForProject } from '$lib/stores/sdk';
import { type getSdkForProject } from '$lib/stores/sdk';

import { onMount } from 'svelte';

Expand Down Expand Up @@ -107,19 +107,10 @@
);
break;
case 'firebase':
if ($provider.projectId) {
// OAuth
report = await sdk.forProject.migrations.getFirebaseReportOAuth(
providerResources.firebase,
$provider.projectId
);
} else if ($provider.serviceAccount) {
// Manual auth
report = await projectSdk.migrations.getFirebaseReport(
providerResources.firebase,
$provider.serviceAccount
);
}
report = await projectSdk.migrations.getFirebaseReport(
providerResources.firebase,
$provider.serviceAccount
);

break;
case 'nhost':
Expand Down Expand Up @@ -353,7 +344,7 @@
<div />
<span>Import all functions and their active deployment</span>
<ul>
{#if resources?.includes('envVar')}
{#if resources?.includes('environment variable')}
<li class="checkbox-field">
<input
type="checkbox"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { page } from '$app/stores';
import { Dependencies } from '$lib/constants';
import {
FormList,
InputNumber,
InputPassword,
InputSelect,
InputText,
InputTextarea
} from '$lib/elements/forms';
import { WizardStep } from '$lib/layout';
import type { Provider } from '$lib/stores/migration';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { provider } from '.';

const providers: Record<Provider, string> = {
Expand All @@ -22,34 +16,6 @@
supabase: 'Supabase',
nhost: 'NHost'
};

// function connectGoogle() {
// const redirect = new URL($page.url);
// const target = new URL(
// `${sdk.forProject.client.config.endpoint}/migrations/firebase/connect`
// );
// target.searchParams.set('redirect', redirect.toString());
// target.searchParams.set('project', $page.params.project);
// target.searchParams.set('mode', 'admin');
// return target;
// }

function deauthorizeGoogle() {
sdk.forProject.migrations.deleteFirebaseAuth().then(() => {
firebaseProjects = [];
});

addNotification({
type: 'success',
message: 'Signed out of Google successfully'
});

invalidate(Dependencies.MIGRATIONS);
}

$: firebaseProjects = $page.data.firebaseProjects;

// let showAuth = false;
</script>

<WizardStep>
Expand Down Expand Up @@ -102,24 +68,7 @@
bind:value={$provider.apiKey} />
</FormList>
{:else if $provider.provider === 'firebase'}
{#if !firebaseProjects?.length}
<!-- <div class="box u-flex u-flex-vertical u-gap-16 u-cross-center u-margin-block-start-24">
<p class="u-text-center u-bold">Sign in with Google to get started</p>
<Button secondary href={connectGoogle().toString()}>
<SvgIcon name="google" />Sign in
</Button>
</div> -->

<!-- <button
class="tag u-margin-block-start-16"
type="button"
on:click={() => (showAuth = !showAuth)}
class:is-selected={showAuth}>
<span class="icon-lock-closed" aria-hidden="true" />
<span class="text">Manual authentication</span>
</button> -->

<!-- {#if showAuth} -->
<FormList class="u-margin-block-start-24">
<div class="u-margin-block-start-16">
<InputTextarea
id="credentials"
Expand All @@ -128,23 +77,7 @@
bind:value={$provider.serviceAccount}
placeholder="Enter account credentials" />
</div>
<!-- {/if} -->
{:else}
<FormList class="u-margin-block-start-24">
<InputSelect
id="firebase-project"
label="Firebase project"
required
bind:value={$provider.projectId}
options={firebaseProjects.map((project) => ({
label: project.displayName,
value: project.projectId
}))} />
</FormList>
<p class="u-text-center u-margin-block-start-24">
<button class="u-bold" on:click|preventDefault={deauthorizeGoogle}>Sign out</button>
</p>
{/if}
</FormList>
{:else if $provider.provider === 'supabase'}
<FormList class="u-margin-block-start-24">
<p class="body-text-1 u-bold">Postgres credentials</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,10 @@
break;
}
case 'firebase': {
if ($provider.projectId) {
// OAuth
await sdk.forProject.migrations.createFirebaseOAuthMigration(
resources,
$provider.projectId
);
} else if ($provider.serviceAccount) {
// Manual auth
await sdk.forProject.migrations.createFirebaseMigration(
resources,
$provider.serviceAccount
);
}
await sdk.forProject.migrations.createFirebaseMigration(
resources,
$provider.serviceAccount
);
invalidate(Dependencies.MIGRATIONS);
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import { Dependencies } from '$lib/constants.js';
import { sdk } from '$lib/stores/sdk';

async function getFirebaseProjects() {
try {
const res = await sdk.forProject.migrations.listFirebaseProjects();
return res.projects;
} catch (e) {
if (e.type === 'user_identity_not_found') {
return [];
} else {
throw e;
}
}
}

export async function load({ depends }) {
depends(Dependencies.MIGRATIONS);

try {
const { migrations } = await sdk.forProject.migrations.list();

return {
migrations,
firebaseProjects: getFirebaseProjects()
migrations
};
} catch {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { parseIfString } from '$lib/helpers/object';
import { formatNum } from '$lib/helpers/string';
import type { Models } from '@appwrite.io/console';
import { ResourcesFriendly } from '$lib/stores/migration';

export let migrations: Models.Migration[] = [];
export let migrationId: string = null;
Expand Down Expand Up @@ -106,7 +107,10 @@
</div>

<div>
<span class="u-capitalize">{entity + 's'}</span>
<span class="u-capitalize"
>{total(Object.values(entityCounter)) > 1
? ResourcesFriendly[entity].plural
: ResourcesFriendly[entity].singular}</span>
<span class="inline-tag">{totalItems(entityCounter)}</span>
</div>
</div>
Expand Down