diff --git a/src/routes/(console)/project-[project]/overview/+layout.svelte b/src/routes/(console)/project-[project]/overview/+layout.svelte index d0f59d1fc0..e1a191776b 100644 --- a/src/routes/(console)/project-[project]/overview/+layout.svelte +++ b/src/routes/(console)/project-[project]/overview/+layout.svelte @@ -21,7 +21,7 @@ import Onboard from './onboard.svelte'; import Realtime from './realtime.svelte'; import Requests from './requests.svelte'; - import { usage } from './store'; + import { isStandardApiKey, usage } from './store'; import { formatNum } from '$lib/helpers/string'; import { total } from '$lib/helpers/array'; import type { Metric } from '$lib/sdk/usage'; @@ -32,6 +32,14 @@ $: path = `${base}/project-${projectId}/overview`; let period: UsagePeriods = '30d'; + $: currentKeyType = $page.url.searchParams.get('mode') || 'standard'; + + $: isSelected = (mode: string): boolean => { + return $page.url.pathname === `${path}/keys` && currentKeyType === mode; + }; + + $: isStandardApiKey.set(isSelected('standard')); + onMount(handle); afterNavigate(handle); @@ -69,6 +77,16 @@ keys: ['c', 'k'], group: 'integrations', disabled: !$canWriteProjects + }, + { + label: 'Create Dev Key', + icon: 'plus', + callback() { + createApiKey(); + }, + keys: ['c', 'd'], + group: 'integrations', + disabled: !$canWriteProjects } ]); @@ -222,11 +240,21 @@ Platforms + event="platforms" + >Platforms + + API keys + API keys + href={`${path}/keys?mode=dev`} + selected={isSelected('dev')} + event="dev-keys" + >Dev keys + diff --git a/src/routes/(console)/project-[project]/overview/keys/+page.svelte b/src/routes/(console)/project-[project]/overview/keys/+page.svelte index 7a54cf0186..fefc9bb678 100644 --- a/src/routes/(console)/project-[project]/overview/keys/+page.svelte +++ b/src/routes/(console)/project-[project]/overview/keys/+page.svelte @@ -24,6 +24,7 @@ import { get } from 'svelte/store'; import type { PageData } from './$types'; import Wizard from './wizard.svelte'; + import { isStandardApiKey } from '../store'; export let data: PageData; @@ -34,7 +35,9 @@ {/if} @@ -68,10 +71,11 @@ {:else} + {/if} diff --git a/src/routes/(console)/project-[project]/overview/keys/+page.ts b/src/routes/(console)/project-[project]/overview/keys/+page.ts index 160a525606..c51d5b35e5 100644 --- a/src/routes/(console)/project-[project]/overview/keys/+page.ts +++ b/src/routes/(console)/project-[project]/overview/keys/+page.ts @@ -2,12 +2,24 @@ import { Dependencies } from '$lib/constants'; import { sdk } from '$lib/stores/sdk'; import { selectedTab } from '../store'; import type { PageLoad } from './$types'; +import { sleep } from '$lib/helpers/promises'; selectedTab.set('keys'); -export const load: PageLoad = async ({ params, depends }) => { +export const load: PageLoad = async ({ params, depends, url }) => { depends(Dependencies.KEYS); + + const currentKeyType = url.searchParams.get('mode') || 'standard'; + + const isStandardApiKey = currentKeyType === 'standard'; + + // TODO: (@itznotabug) Replace this delay with a proper API call + // for development keys once the backend is implemented. + if (!isStandardApiKey) await sleep(1250); + return { + // TODO: (@itznotabug) Update this logic to fetch actual development keys from the backend + // when the console SDK supports it. keys: await sdk.forConsole.projects.listKeys(params.project) }; }; diff --git a/src/routes/(console)/project-[project]/overview/keys/expirationInput.svelte b/src/routes/(console)/project-[project]/overview/keys/expirationInput.svelte index 843cc9f3d4..1f0fe1930a 100644 --- a/src/routes/(console)/project-[project]/overview/keys/expirationInput.svelte +++ b/src/routes/(console)/project-[project]/overview/keys/expirationInput.svelte @@ -19,7 +19,7 @@ return date.toISOString(); } - const options = [ + const defaultOptions = [ { label: 'Never', value: null @@ -46,10 +46,31 @@ } ]; + const limitedOptions = [ + { + label: '1 Day', + value: incrementToday(1, 'day') + }, + { + label: '7 Days', + value: incrementToday(7, 'day') + }, + { + label: '30 days', + value: incrementToday(30, 'day') + } + ]; + export let value: string | null = null; + export let isStandardApiKey: boolean = false; + + const options = isStandardApiKey ? defaultOptions : limitedOptions; + function initExpirationSelect() { - if (value === null || !isValidDate(value)) return null; + if (value === null || !isValidDate(value)) { + return options[0]?.value ?? null; + } let result = 'custom'; for (const option of options) { diff --git a/src/routes/(console)/project-[project]/overview/keys/wizard.svelte b/src/routes/(console)/project-[project]/overview/keys/wizard.svelte index e6c6701fae..da34315877 100644 --- a/src/routes/(console)/project-[project]/overview/keys/wizard.svelte +++ b/src/routes/(console)/project-[project]/overview/keys/wizard.svelte @@ -11,9 +11,14 @@ import { onDestroy } from 'svelte'; import { onboarding } from '../../store'; import { Dependencies } from '$lib/constants'; - import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; + import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; import { base } from '$app/paths'; + import { isStandardApiKey } from '../store'; + // TODO: check onFinish as to which key type was generated, standard or development. + // Based on that, call appropriate creator method and update notification. + + // TODO: also check if we should add different keys for events based on standard/dev keys. async function onFinish() { try { const { $id } = await sdk.forConsole.projects.createKey( @@ -53,4 +58,7 @@ }); - + diff --git a/src/routes/(console)/project-[project]/overview/keys/wizard/step1.svelte b/src/routes/(console)/project-[project]/overview/keys/wizard/step1.svelte index cb53ed0346..78a0df02db 100644 --- a/src/routes/(console)/project-[project]/overview/keys/wizard/step1.svelte +++ b/src/routes/(console)/project-[project]/overview/keys/wizard/step1.svelte @@ -3,18 +3,28 @@ import { WizardStep } from '$lib/layout'; import ExpirationInput from '../expirationInput.svelte'; import { key } from './store'; + import { isStandardApiKey } from '../../store'; + + const keyTypeName = $isStandardApiKey ? 'API' : 'Dev'; - API key - Let's create an API key. + {keyTypeName} key + + {#if $isStandardApiKey} + Generate API keys to authenticate your application. While still in development, use Dev + keys instead, as they're better suited for debugging. + {:else} + Test your app without rate limits and more detailed error messages. + {/if} + - + diff --git a/src/routes/(console)/project-[project]/overview/onboard.svelte b/src/routes/(console)/project-[project]/overview/onboard.svelte index 677258ccc6..61142c29d3 100644 --- a/src/routes/(console)/project-[project]/overview/onboard.svelte +++ b/src/routes/(console)/project-[project]/overview/onboard.svelte @@ -13,6 +13,7 @@ import Wizard from './keys/wizard.svelte'; import { canWriteKeys, canWritePlatforms } from '$lib/stores/roles'; import { base } from '$app/paths'; + import { isStandardApiKey } from './store'; export let projectId: string; @@ -44,8 +45,9 @@ } ]; - function createKey() { + function createKey(isDevKey: boolean = false) { wizard.start(Wizard); + isStandardApiKey.set(!isDevKey); } $: onBoardImage1Mobile = $app.themeInUse === 'dark' ? OnboardDark1Mobile : OnboardLight1Mobile; @@ -121,7 +123,7 @@ +
  • + +
  • = writable('platforms'); + +export const isStandardApiKey = writable(true);