diff --git a/src/lib/commandCenter/commands.ts b/src/lib/commandCenter/commands.ts index ba033b1c5..a28d32625 100644 --- a/src/lib/commandCenter/commands.ts +++ b/src/lib/commandCenter/commands.ts @@ -17,7 +17,8 @@ export type CommandGroup = | 'storage' | 'domains' | 'webhooks' - | 'integrations'; + | 'integrations' + | 'migrations'; type BaseCommand = { callback: () => void; @@ -264,6 +265,7 @@ export const commandGroupRanks = derived(groupRankTransformations, ($groupRankTr functions: 0, storage: 0, integrations: 0, + migrations: 0, help: -1 }; diff --git a/src/lib/commandCenter/panels/ai.svelte b/src/lib/commandCenter/panels/ai.svelte index 88f1818d7..48c557326 100644 --- a/src/lib/commandCenter/panels/ai.svelte +++ b/src/lib/commandCenter/panels/ai.svelte @@ -15,12 +15,10 @@ }); const examples = [ - 'How can I integrate Appwrite with my frontend application?', 'How to add platform in the console?', 'How can I manage users, permissions, and access control in Appwrite?', 'How can I set up database collections and documents in Appwrite?', 'How do I configure and manage server-side functions in Appwrite?', - 'How can I access the audit logs in the console?', 'How to add custom domain in the console?' ]; diff --git a/src/lib/stores/migration.ts b/src/lib/stores/migration.ts index aa2daa1b0..b4e8046da 100644 --- a/src/lib/stores/migration.ts +++ b/src/lib/stores/migration.ts @@ -1,8 +1,5 @@ -import { excludeArray } from '$lib/helpers/array'; import { writable } from 'svelte/store'; -export type Provider = 'appwrite' | 'nhost' | 'supabase' | 'firebase'; - const initialFormData = { users: { root: false, @@ -103,3 +100,87 @@ export const migrationFormToResources = (formData: MigrationFormData): Resource[ return resources; }; + +import { + PUBLIC_NHOST_TEST_DATABASE, + PUBLIC_NHOST_TEST_PASSWORD, + PUBLIC_NHOST_TEST_REGION, + PUBLIC_NHOST_TEST_SECRET, + PUBLIC_NHOST_TEST_SUBDOMAIN, + PUBLIC_NHOST_TEST_USERNAME +} from '$env/static/public'; + +type AppwriteInput = { + provider: 'appwrite'; + endpoint?: string; + projectID?: string; + apiKey?: string; +}; + +type FirebaseInput = { + provider: 'firebase'; + serviceAccount?: string; +}; + +type SupabaseInput = { + provider: 'supabase'; + host?: string; + username?: string; + password?: string; + endpoint?: string; + apiKey?: string; + port?: number; +}; + +type NhostInput = { + provider: 'nhost'; + region?: string; + subdomain?: string; + database?: string; + username?: string; + password?: string; + adminSecret?: string; +}; + +export type ProviderInput = AppwriteInput | NhostInput | SupabaseInput | FirebaseInput; +export type Provider = ProviderInput['provider']; + +// const mockProvider: ProviderInput = { +// provider: 'appwrite', +// endpoint: PUBLIC_MOCK_ENDPOINT, +// apiKey: PUBLIC_MOCK_APIKEY, +// projectID: PUBLIC_MOCK_PROJECTID +// }; +// const mockProvider: ProviderInput = { +// provider: 'supabase', +// endpoint: PUBLIC_SUPABASE_TEST_ENDPOINT, +// apiKey: PUBLIC_SUPABASE_TEST_KEY, +// host: PUBLIC_SUPABASE_TEST_HOST, +// port: Number(PUBLIC_SUPABASE_TEST_PORT), +// username: PUBLIC_SUPABASE_TEST_USERNAME, +// password: PUBLIC_SUPABASE_TEST_PASSWORD +// }; +const mockProvider: ProviderInput = { + provider: 'nhost', + subdomain: PUBLIC_NHOST_TEST_SUBDOMAIN, + region: PUBLIC_NHOST_TEST_REGION, + adminSecret: PUBLIC_NHOST_TEST_SECRET, + database: PUBLIC_NHOST_TEST_DATABASE, + username: PUBLIC_NHOST_TEST_USERNAME, + password: PUBLIC_NHOST_TEST_PASSWORD +}; + +const initialProvider: ProviderInput = { provider: 'appwrite' }; +export const createMigrationProviderStore = () => { + const store = writable({ ...mockProvider }); + + const changeProvider = (provider: Provider) => { + const newProvider: ProviderInput = { provider }; + store.set(newProvider); + }; + + return { + ...store, + changeProvider + }; +}; diff --git a/src/lib/stores/migrator.ts b/src/lib/stores/migrator.ts deleted file mode 100644 index ae17cb355..000000000 --- a/src/lib/stores/migrator.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { writable } from 'svelte/store'; - -const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); -const randRange = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min; - -type Status = 'idle' | 'running' | 'error' | 'success'; - -type State = { - items: { - databases?: Status; - documents?: Status; - users?: Status; - storage?: Status; - }; - status: Status; -}; - -function createMigrator() { - const { subscribe, update, set } = writable({ - items: { databases: 'idle', documents: 'running', users: 'error', storage: 'success' }, - status: 'running' - }); - - const startMigration = async () => { - set({ - items: { - databases: 'idle', - documents: 'idle', - users: 'idle', - storage: 'idle' - }, - status: 'running' - }); - - const keys = ['databases', 'documents', 'users', 'storage']; - - for (const key of keys) { - sleep(randRange(1000, 5000)).then(() => { - update((state) => ({ - ...state, - items: { ...state.items, [key]: 'running' } - })); - - sleep(randRange(1000, 5000)).then(() => { - update((state) => ({ - ...state, - items: { ...state.items, [key]: 'success' } - })); - }); - }); - } - }; - - return { - subscribe, - startMigration - }; -} - -export const migrator = createMigrator(); diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index a50dd02f7..72d334535 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -10,13 +10,12 @@ import { user } from '$lib/stores/user'; import { ENV, isCloud } from '$lib/system'; import * as Sentry from '@sentry/svelte'; - import LogRocket from 'logrocket'; import { BrowserTracing } from '@sentry/tracing'; + import LogRocket from 'logrocket'; import { onMount } from 'svelte'; import { onCLS, onFCP, onFID, onINP, onLCP, onTTFB } from 'web-vitals'; import Loading from './loading.svelte'; - import { loading, requestedMigration } from './store'; - import { openMigrationWizard } from './console/organization-[organization]/(migration-wizard)'; + import { loading } from './store'; if (browser) { window.VERCEL_ANALYTICS_ID = import.meta.env.VERCEL_ANALYTICS_ID?.toString() ?? false; diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index e2dc890a3..e27abf83e 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -7,6 +7,7 @@ import { redirect } from '@sveltejs/kit'; import { Dependencies } from '$lib/constants'; import type { LayoutLoad } from './$types'; import { requestedMigration } from './store'; +import { parseIfString } from '$lib/helpers/object'; export const ssr = false; @@ -14,7 +15,8 @@ export const load: LayoutLoad = async ({ depends, url }) => { depends(Dependencies.ACCOUNT); if (url.searchParams.has('migrate')) { - requestedMigration.set(url.searchParams.get('migrate')); + const migrateData = url.searchParams.get('migrate'); + requestedMigration.set(parseIfString(migrateData)); } try { diff --git a/src/routes/console/(migration-wizard)/index.ts b/src/routes/console/(migration-wizard)/index.ts new file mode 100644 index 000000000..a9b23e663 --- /dev/null +++ b/src/routes/console/(migration-wizard)/index.ts @@ -0,0 +1,23 @@ +import { createMigrationFormStore, createMigrationProviderStore } from '$lib/stores/migration'; +import { wizard } from '$lib/stores/wizard'; +import { requestedMigration } from '$routes/store'; +import { get, writable } from 'svelte/store'; +import Wizard from './wizard.svelte'; + +export const formData = createMigrationFormStore(); + +export function openMigrationWizard() { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + wizard.start(Wizard as any); + const migData = get(requestedMigration); + provider.set({ + provider: 'appwrite', + apiKey: migData?.apiKey, + endpoint: migData?.endpoint, + projectID: migData?.projectId + }); +} + +export const selectedProject = writable(null); + +export const provider = createMigrationProviderStore(); diff --git a/src/routes/console/(migration-wizard)/resource-form.svelte b/src/routes/console/(migration-wizard)/resource-form.svelte new file mode 100644 index 000000000..bab1a9a2e --- /dev/null +++ b/src/routes/console/(migration-wizard)/resource-form.svelte @@ -0,0 +1,338 @@ + + +
+
+ Good to know +
+
+ +
+
+

Project settings are not imported

+

You will need to set service and project settings manually

+
+
+
+
+ +
+
+

Keep your project plan limits in mind

+

Make sure to have enough storage in your project plan when importing files

+
+
+
+
+ +
+
+

Transfer is free of charge

+

You won't be charged for Appwrite bandwidth usage for importing data

+
+
+
+
+ +
    +
  • + +
  • + +
  • + +
  • +
+ +
    + {#if resources.includes('user')} +
  • + +
    + Users + + {report?.user ?? '...'} +
    +
    + Import all users + + {#if resources.includes('team')} +
      +
    • + +
      + Include teams + {report?.team ?? '...'} +
      +
      + Import all teams and the team memberships of your users +
    • +
    + {/if} +
  • + {/if} + + {#if resources.includes('database')} +
  • + +
    + Databases + {report?.database ?? '...'} +
    +
    + Import all databases, including collections, indexes and attributes + + {#if resources.includes('document')} +
      +
    • + +
      + Include documents + {report?.document ?? '...'} +
      +
      + Import all of your documents +
    • +
    + {/if} +
  • + {/if} + + {#if resources.includes('function')} +
  • + +
    + Functions + {report?.function ?? '...'} +
    +
    + Import all functions and their active deployment +
      + {#if resources.includes('envVar')} +
    • + +
      + Include environment variables +
      +
      + Import all environment variables +
    • + {/if} + {#if resources.includes('deployment')} +
    • + +
      + Include inactive deployments +
      +
      + Import all deployments that are not currently active +
    • + {/if} +
    +
  • + {/if} + {#if resources.includes('bucket') && resources.includes('file')} +
  • + +
    + Storage + + {report?.size ? `${report.size.toFixed(2)}MB` : '...'} + +
    +
    + + + Import all buckets {report?.bucket ?? '...'} and + files + {report?.file ?? '...'} + +
  • + {/if} +
+ + diff --git a/src/routes/console/organization-[organization]/(migration-wizard)/step1.svelte b/src/routes/console/(migration-wizard)/step1.svelte similarity index 100% rename from src/routes/console/organization-[organization]/(migration-wizard)/step1.svelte rename to src/routes/console/(migration-wizard)/step1.svelte diff --git a/src/routes/console/(migration-wizard)/step2.svelte b/src/routes/console/(migration-wizard)/step2.svelte new file mode 100644 index 000000000..75cb8ea8f --- /dev/null +++ b/src/routes/console/(migration-wizard)/step2.svelte @@ -0,0 +1,11 @@ + + + + Select data + + diff --git a/src/routes/console/organization-[organization]/(migration-wizard)/wizard.svelte b/src/routes/console/(migration-wizard)/wizard.svelte similarity index 64% rename from src/routes/console/organization-[organization]/(migration-wizard)/wizard.svelte rename to src/routes/console/(migration-wizard)/wizard.svelte index f563a0149..707816690 100644 --- a/src/routes/console/organization-[organization]/(migration-wizard)/wizard.svelte +++ b/src/routes/console/(migration-wizard)/wizard.svelte @@ -4,9 +4,12 @@ import Wizard from '$lib/layout/wizard.svelte'; import { migrationFormToResources } from '$lib/stores/migration'; import { onDestroy } from 'svelte'; - import { formData } from '.'; + import { formData, provider } from '.'; import Step1 from './step1.svelte'; import Step2 from './step2.svelte'; + import { sdk } from '$lib/stores/sdk'; + import { invalidate } from '$app/navigation'; + import { Dependencies } from '$lib/constants'; const onExit = () => { formData.reset(); @@ -14,8 +17,16 @@ const onFinish = async () => { const resources = migrationFormToResources($formData); - console.log('resources', resources); - // wizard.hide(); + if ($provider.provider !== 'appwrite') return; + + const res = await sdk.forProject.migrations.migrateAppwrite( + resources, + $provider.endpoint, + $provider.projectID, + $provider.apiKey + ); + console.log('appwrite', res); + invalidate(Dependencies.MIGRATIONS); }; onDestroy(onExit); diff --git a/src/routes/console/+layout.svelte b/src/routes/console/+layout.svelte index 5f7a97f43..1e75c9df7 100644 --- a/src/routes/console/+layout.svelte +++ b/src/routes/console/+layout.svelte @@ -21,6 +21,7 @@ import { CommandCenter, registerCommands } from '$lib/commandCenter'; import { AI, Organizations } from '$lib/commandCenter/panels'; import { addSubPanel } from '$lib/commandCenter/subPanels'; + import { openMigrationWizard } from './(migration-wizard)'; $: $registerCommands([ { @@ -108,6 +109,10 @@ $log.data = null; $log.func = null; } + + $: if ($requestedMigration) { + openMigrationWizard(); + } diff --git a/src/routes/console/organization-[organization]/(migration-wizard)/index.ts b/src/routes/console/organization-[organization]/(migration-wizard)/index.ts deleted file mode 100644 index c1e06f7c4..000000000 --- a/src/routes/console/organization-[organization]/(migration-wizard)/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { createMigrationFormStore } from '$lib/stores/migration'; -import { wizard } from '$lib/stores/wizard'; -import { writable } from 'svelte/store'; -import Wizard from './wizard.svelte'; - -export const formData = createMigrationFormStore(); - -export function openMigrationWizard() { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - wizard.start(Wizard as any); -} - -export const selectedProject = writable(null); diff --git a/src/routes/console/organization-[organization]/(migration-wizard)/step2.svelte b/src/routes/console/organization-[organization]/(migration-wizard)/step2.svelte deleted file mode 100644 index f240d1efc..000000000 --- a/src/routes/console/organization-[organization]/(migration-wizard)/step2.svelte +++ /dev/null @@ -1,296 +0,0 @@ - - - - Select data -
-
- Good to know -
-
- -
-
-

Project settings are not imported

-

You will need to set service and project settings manually

-
-
-
-
- -
-
-

Keep your project plan limits in mind

-

- Make sure to have enough storage in your project plan when importing files -

-
-
-
-
- -
-
-

Transfer is free of charge

-

You won’t be charged for Appwrite bandwidth usage for importing data

-
-
-
-
- -
    -
  • - -
  • - -
  • - -
  • -
- -
    -
  • - -
    - Users - {#if report} - {report.user} - {/if} -
    -
    - Import all users - -
      -
    • - -
      - Include teams - {#if report} - {report.team} - {/if} -
      -
      - Import all teams and the team memberships of your users -
    • -
    -
  • -
  • - -
    - Databases - {#if report} - {report.database} - {/if} -
    -
    - Import all databases, including collections, indexes and attributes - -
      -
    • - -
      - Include documents - {#if report} - {report.document} - {/if} -
      -
      - Import all of your documents -
    • -
    -
  • -
  • - -
    - Functions - {#if report} - {report.function} - {/if} -
    -
    - Import all functions and their active deployment -
      -
    • - -
      - Include environment variables -
      -
      - Import all environment variables -
    • -
    • - -
      - Include inactive deployments -
      -
      - Import all deployments that are not currently active -
    • -
    -
  • -
  • - -
    - Storage - {#if report} - {report.size.toFixed(2)}MB - {/if} -
    -
    - {#if report} - Import all buckets ({report.bucket}) and files ({report.file}) - {:else} - Import all buckets and files - {/if} -
  • -
-
- - diff --git a/src/routes/console/organization-[organization]/+layout.svelte b/src/routes/console/organization-[organization]/+layout.svelte index d43df7ebd..9e108e090 100644 --- a/src/routes/console/organization-[organization]/+layout.svelte +++ b/src/routes/console/organization-[organization]/+layout.svelte @@ -2,7 +2,7 @@ import { newOrgModal, newMemberModal } from '$lib/stores/organization'; import CreateMember from './createMember.svelte'; import Create from '../createOrganization.svelte'; - import { openMigrationWizard } from './(migration-wizard)'; + import { openMigrationWizard } from '../(migration-wizard)'; import { requestedMigration } from '$routes/store'; $: if ($requestedMigration) { diff --git a/src/routes/console/project-[project]/settings/migrations/(import)/index.ts b/src/routes/console/project-[project]/settings/migrations/(import)/index.ts index f13c20a7e..d4b7ccf70 100644 --- a/src/routes/console/project-[project]/settings/migrations/(import)/index.ts +++ b/src/routes/console/project-[project]/settings/migrations/(import)/index.ts @@ -1,91 +1,13 @@ -import { - PUBLIC_MOCK_APIKEY, - PUBLIC_MOCK_ENDPOINT, - PUBLIC_MOCK_PROJECTID, - PUBLIC_SUPABASE_TEST_ENDPOINT, - PUBLIC_SUPABASE_TEST_HOST, - PUBLIC_SUPABASE_TEST_KEY, - PUBLIC_SUPABASE_TEST_PASSWORD, - PUBLIC_SUPABASE_TEST_USERNAME, - PUBLIC_SUPABASE_TEST_PORT, - PUBLIC_NHOST_TEST_SUBDOMAIN, - PUBLIC_NHOST_TEST_REGION, - PUBLIC_NHOST_TEST_SECRET, - PUBLIC_NHOST_TEST_DATABASE, - PUBLIC_NHOST_TEST_USERNAME, - PUBLIC_NHOST_TEST_PASSWORD -} from '$env/static/public'; -import { createMigrationFormStore } from '$lib/stores/migration'; +import { createMigrationFormStore, createMigrationProviderStore } from '$lib/stores/migration'; import { wizard } from '$lib/stores/wizard'; -import { writable } from 'svelte/store'; import Wizard from './wizard.svelte'; -type AppwriteInput = { - provider: 'appwrite'; - endpoint?: string; - projectID?: string; - apiKey?: string; -}; - -type FirebaseInput = { - provider: 'firebase'; - serviceAccount?: string; -}; - -type SupabaseInput = { - provider: 'supabase'; - host?: string; - username?: string; - password?: string; - endpoint?: string; - apiKey?: string; - port?: number; -}; - -type NhostInput = { - provider: 'nhost'; - region?: string; - subdomain?: string; - database?: string; - username?: string; - password?: string; - adminSecret?: string; -}; - -type ProviderInput = AppwriteInput | NhostInput | SupabaseInput | FirebaseInput; - -const initialProvider: ProviderInput = { provider: 'appwrite' }; -// const mockProvider: ProviderInput = { -// provider: 'appwrite', -// endpoint: PUBLIC_MOCK_ENDPOINT, -// apiKey: PUBLIC_MOCK_APIKEY, -// projectID: PUBLIC_MOCK_PROJECTID -// }; -// const mockProvider: ProviderInput = { -// provider: 'supabase', -// endpoint: PUBLIC_SUPABASE_TEST_ENDPOINT, -// apiKey: PUBLIC_SUPABASE_TEST_KEY, -// host: PUBLIC_SUPABASE_TEST_HOST, -// port: Number(PUBLIC_SUPABASE_TEST_PORT), -// username: PUBLIC_SUPABASE_TEST_USERNAME, -// password: PUBLIC_SUPABASE_TEST_PASSWORD -// }; -const mockProvider: ProviderInput = { - provider: 'nhost', - subdomain: PUBLIC_NHOST_TEST_SUBDOMAIN, - region: PUBLIC_NHOST_TEST_REGION, - adminSecret: PUBLIC_NHOST_TEST_SECRET, - database: PUBLIC_NHOST_TEST_DATABASE, - username: PUBLIC_NHOST_TEST_USERNAME, - password: PUBLIC_NHOST_TEST_PASSWORD -}; - -export const provider = writable({ ...mockProvider }); +export const provider = createMigrationProviderStore(); export const formData = createMigrationFormStore(); export const resetImportStores = () => { - provider.set({ ...mockProvider }); + provider.changeProvider('appwrite'); formData.reset(); }; diff --git a/src/routes/console/project-[project]/settings/migrations/(import)/step2.svelte b/src/routes/console/project-[project]/settings/migrations/(import)/step2.svelte index 10313313b..6353b5968 100644 --- a/src/routes/console/project-[project]/settings/migrations/(import)/step2.svelte +++ b/src/routes/console/project-[project]/settings/migrations/(import)/step2.svelte @@ -1,333 +1,11 @@ - + Select data -
-
- Good to know -
-
- -
-
-

Project settings are not imported

-

You will need to set service and project settings manually

-
-
-
-
- -
-
-

Keep your project plan limits in mind

-

- Make sure to have enough storage in your project plan when importing files -

-
-
-
-
- -
-
-

Transfer is free of charge

-

You won't be charged for Appwrite bandwidth usage for importing data

-
-
-
-
- -
    -
  • - -
  • - -
  • - -
  • -
- -
    - {#if resources.includes('user')} -
  • - -
    - Users - - {report?.user ?? '...'} -
    -
    - Import all users - - {#if resources.includes('team')} -
      -
    • - -
      - Include teams - {report?.team ?? '...'} -
      -
      - Import all teams and the team memberships of your users -
    • -
    - {/if} -
  • - {/if} - - {#if resources.includes('database')} -
  • - -
    - Databases - {report?.database ?? '...'} -
    -
    - Import all databases, including collections, indexes and attributes - - {#if resources.includes('document')} -
      -
    • - -
      - Include documents - {report?.document ?? '...'} -
      -
      - Import all of your documents -
    • -
    - {/if} -
  • - {/if} - - {#if resources.includes('function')} -
  • - -
    - Functions - {report?.function ?? '...'} -
    -
    - Import all functions and their active deployment -
      - {#if resources.includes('envVar')} -
    • - -
      - Include environment variables -
      -
      - Import all environment variables -
    • - {/if} - {#if resources.includes('deployment')} -
    • - -
      - Include inactive deployments -
      -
      - Import all deployments that are not currently active -
    • - {/if} -
    -
  • - {/if} - {#if resources.includes('bucket') && resources.includes('file')} -
  • - -
    - Storage - - {report?.size ? `${report.size.toFixed(2)}MB` : '...'} - -
    -
    - - - Import all buckets {report?.bucket ?? '...'} and - files - {report?.file ?? '...'} - -
  • - {/if} -
+
- - diff --git a/src/routes/console/project-[project]/settings/migrations/+page.svelte b/src/routes/console/project-[project]/settings/migrations/+page.svelte index 4a5919e29..03ef5c8e3 100644 --- a/src/routes/console/project-[project]/settings/migrations/+page.svelte +++ b/src/routes/console/project-[project]/settings/migrations/+page.svelte @@ -21,7 +21,7 @@ import { openImportWizard } from './(import)'; import Details from './details.svelte'; import ExportModal from './exportModal.svelte'; - import { registerCommands } from '$lib/commandCenter'; + import { registerCommands, updateCommandGroupRanks } from '$lib/commandCenter'; export let data; let details: (typeof data.migrations)[number] | null = null; @@ -48,17 +48,24 @@ $: $registerCommands([ { label: 'Import data', - icon: 'upload', + icon: 'download', keys: ['i', 'd'], - callback: openImportWizard + callback: openImportWizard, + group: 'migrations' }, { label: 'Export data', - icon: 'download', + icon: 'upload', keys: ['e', 'd'], - callback: () => (showExport = true) + callback: () => (showExport = true), + group: 'migrations' } ]); + + $: $updateCommandGroupRanks((prev) => ({ + ...prev, + migrations: 100 + })); diff --git a/src/routes/console/project-[project]/settings/migrations/exportModal.svelte b/src/routes/console/project-[project]/settings/migrations/exportModal.svelte index 469a99ca0..e3781c9c7 100644 --- a/src/routes/console/project-[project]/settings/migrations/exportModal.svelte +++ b/src/routes/console/project-[project]/settings/migrations/exportModal.svelte @@ -2,6 +2,8 @@ import { Alert, Modal } from '$lib/components'; import { Button, InputText, InputTextarea } from '$lib/elements/forms'; import { getFormData } from '$lib/helpers/form'; + import { sdk } from '$lib/stores/sdk'; + import { project } from '../../store'; export let show = false; let submitted = false; @@ -39,7 +41,7 @@ return endpoint; }; - const onSubmit = (e: SubmitEvent) => { + const onSubmit = async (e: SubmitEvent) => { e.preventDefault(); submitted = true; @@ -56,10 +58,39 @@ } const currEndpoint = getCurrentEndpoint(); - // URI encode the current endpoint, so that it can be passed as a query string - const encodedCurrEndpoint = encodeURIComponent(currEndpoint); + // Create API key + const { secret } = await sdk.forConsole.projects.createKey( + $project.$id, + `[AUTO-GENERATED] Migration ${new Date().toISOString()}`, - const dest = `${removeTrailingSlash(endpoint)}/?migrate=${encodedCurrEndpoint}`; + [ + 'users.read', + 'teams.read', + 'databases.read', + 'collections.read', + 'attributes.read', + 'indexes.read', + 'documents.read', + 'files.read', + 'buckets.read', + 'functions.read', + 'execution.read', + 'locale.read', + 'avatars.read', + 'health.read' + ], + undefined + ); + + const migrationData = { + endpoint: currEndpoint, + projectId: $project.$id, + apiKey: secret + }; + + const dest = `${removeTrailingSlash(endpoint)}/?migrate=${encodeURIComponent( + JSON.stringify(migrationData) + )}`; window.location.href = dest; }; diff --git a/src/routes/store.ts b/src/routes/store.ts index 4f8096ae3..c2f973b21 100644 --- a/src/routes/store.ts +++ b/src/routes/store.ts @@ -7,4 +7,4 @@ export const loading = writable(true); export const organizations = derived(page, ($page) => { return $page.data.organizations as Models.TeamList; }); -export const requestedMigration = writable(null); +export const requestedMigration = writable | null>(null);