From 49e9c824cd0a6b7e3020d272c30040075baa287c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 31 May 2023 16:36:02 +0200 Subject: [PATCH 001/198] Update dependencies --- package-lock.json | 9 +++++---- package.json | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 46a8434389..11b897e0aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,7 @@ "name": "@appwrite/console", "dependencies": { "@analytics/google-analytics": "^1.0.5", - "@appwrite.io/console": "0.1.0", + "@appwrite.io/console": "npm:matej-appwrite-console@7.1.63", "@appwrite.io/pink": "^0.0.6-rc.10", "@popperjs/core": "^2.11.6", "@sentry/svelte": "^7.44.2", @@ -147,9 +147,10 @@ "integrity": "sha512-1Yw7u/COtxx06BfwlI+kVhsa/upKYzmCNrT4c8QDeCY2KMYlnijkUjtHiPU08HxyTIVB5j6d75O0YWVIHwQS8g==" }, "node_modules/@appwrite.io/console": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@appwrite.io/console/-/console-0.1.0.tgz", - "integrity": "sha512-GzCRUmaXAVgpGwxBNI3PrtCLHz7CM+epBHDDTHw8B2u61KbijGBO3GrwreXy91fy00RJiEzGlMSRzDgwsF3Tsg==", + "name": "matej-appwrite-console", + "version": "7.1.63", + "resolved": "https://registry.npmjs.org/matej-appwrite-console/-/matej-appwrite-console-7.1.63.tgz", + "integrity": "sha512-qdQ+mYQzr2bqpIiUc70AG/BbC8YDmpxp/Bx+VuNsOE75/aSD2dRKfMbqcLtcNY9HtnMbX4x1Bo6jmTdE00MDxw==", "dependencies": { "cross-fetch": "3.1.5", "isomorphic-form-data": "2.0.0" diff --git a/package.json b/package.json index 0e7ec8d6e1..9296c6f855 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@analytics/google-analytics": "^1.0.5", - "@appwrite.io/console": "0.1.0", + "@appwrite.io/console": "npm:matej-appwrite-console@7.1.63", "@appwrite.io/pink": "^0.0.6-rc.10", "@popperjs/core": "^2.11.6", "@sentry/svelte": "^7.44.2", From 2866a84646c8c42b69b770e929916744c3766428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 2 Jun 2023 14:09:26 +0200 Subject: [PATCH 002/198] New iteration of env variables --- package-lock.json | 8 +- package.json | 2 +- src/lib/actions/analytics.ts | 1 + src/lib/constants.ts | 1 + src/lib/stores/sdk.ts | 4 +- .../{functions => }/createVariable.svelte | 29 +- .../function-[function]/settings/+page.svelte | 30 +- .../function-[function]/settings/+page.ts | 24 +- .../function-[function]/settings/store.ts | 8 - .../settings/updateSchedule.svelte | 3 +- .../settings/updateVariables.svelte | 233 ----------- .../functions/wizard/step5.svelte | 4 +- .../promoteVariableModal.svelte | 40 ++ .../rawVariableEditor.svelte | 196 ++++++++++ .../project-[project]/settings/+page.svelte | 27 ++ .../project-[project]/settings/+page.ts | 11 + .../project-[project]/updateVariables.svelte | 364 ++++++++++++++++++ .../settings => }/uploadVariablesModal.svelte | 33 +- 18 files changed, 743 insertions(+), 275 deletions(-) rename src/routes/console/project-[project]/{functions => }/createVariable.svelte (54%) delete mode 100644 src/routes/console/project-[project]/functions/function-[function]/settings/store.ts delete mode 100644 src/routes/console/project-[project]/functions/function-[function]/settings/updateVariables.svelte create mode 100644 src/routes/console/project-[project]/promoteVariableModal.svelte create mode 100644 src/routes/console/project-[project]/rawVariableEditor.svelte create mode 100644 src/routes/console/project-[project]/settings/+page.ts create mode 100644 src/routes/console/project-[project]/updateVariables.svelte rename src/routes/console/project-[project]/{functions/function-[function]/settings => }/uploadVariablesModal.svelte (62%) diff --git a/package-lock.json b/package-lock.json index 11b897e0aa..835beaecbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,7 @@ "name": "@appwrite/console", "dependencies": { "@analytics/google-analytics": "^1.0.5", - "@appwrite.io/console": "npm:matej-appwrite-console@7.1.63", + "@appwrite.io/console": "npm:matej-appwrite-console@7.1.65", "@appwrite.io/pink": "^0.0.6-rc.10", "@popperjs/core": "^2.11.6", "@sentry/svelte": "^7.44.2", @@ -148,9 +148,9 @@ }, "node_modules/@appwrite.io/console": { "name": "matej-appwrite-console", - "version": "7.1.63", - "resolved": "https://registry.npmjs.org/matej-appwrite-console/-/matej-appwrite-console-7.1.63.tgz", - "integrity": "sha512-qdQ+mYQzr2bqpIiUc70AG/BbC8YDmpxp/Bx+VuNsOE75/aSD2dRKfMbqcLtcNY9HtnMbX4x1Bo6jmTdE00MDxw==", + "version": "7.1.65", + "resolved": "https://registry.npmjs.org/matej-appwrite-console/-/matej-appwrite-console-7.1.65.tgz", + "integrity": "sha512-410zM0jX+ndZP/g6biKc7M96mV9Bir/86v9rlkrI+C4CaPzU1FPNOWNfmQNUgFvYriKaw9f2p79/3LlfCheIjg==", "dependencies": { "cross-fetch": "3.1.5", "isomorphic-form-data": "2.0.0" diff --git a/package.json b/package.json index 9296c6f855..abf2930dc2 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@analytics/google-analytics": "^1.0.5", - "@appwrite.io/console": "npm:matej-appwrite-console@7.1.63", + "@appwrite.io/console": "npm:matej-appwrite-console@7.1.65", "@appwrite.io/pink": "^0.0.6-rc.10", "@popperjs/core": "^2.11.6", "@sentry/svelte": "^7.44.2", diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts index 84c178cc46..8c84b714a4 100644 --- a/src/lib/actions/analytics.ts +++ b/src/lib/actions/analytics.ts @@ -180,6 +180,7 @@ export enum Submit { VariableCreate = 'submit_variable_create', VariableDelete = 'submit_variable_delete', VariableUpdate = 'submit_variable_update', + VariableEditor = 'submit_variable_editor', KeyCreate = 'submit_key_create', KeyDelete = 'submit_key_delete', KeyUpdateName = 'submit_key_update_name', diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 2b3b701257..d7e16823c9 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -5,6 +5,7 @@ export const INTERVAL = 5 * 60000; // default interval to check for feedback export enum Dependencies { ORGANIZATION = 'dependency:organization', PROJECT = 'dependency:project', + PROJECT_SETTINGS = 'dependency:project_settings', PROJECTS = 'dependency:projects', ACCOUNT = 'dependency:account', ACCOUNT_SESSIONS = 'dependency:account_sessions', diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index 481b930ead..f0ae42a37f 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -12,7 +12,8 @@ import { Projects, Storage, Teams, - Users + Users, + Project as ProjectApi } from '@appwrite.io/console'; const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`; @@ -31,6 +32,7 @@ const sdkForProject = { health: new Health(clientProject), locale: new Locale(clientProject), project: new Project(clientProject), + projectApi: new ProjectApi(clientProject), storage: new Storage(clientProject), teams: new Teams(clientProject), users: new Users(clientProject) diff --git a/src/routes/console/project-[project]/functions/createVariable.svelte b/src/routes/console/project-[project]/createVariable.svelte similarity index 54% rename from src/routes/console/project-[project]/functions/createVariable.svelte rename to src/routes/console/project-[project]/createVariable.svelte index dd1252a36d..6e65f5bbe9 100644 --- a/src/routes/console/project-[project]/functions/createVariable.svelte +++ b/src/routes/console/project-[project]/createVariable.svelte @@ -4,7 +4,10 @@ import { InputText, FormList } from '$lib/elements/forms'; import { createEventDispatcher } from 'svelte'; import type { Models } from '@appwrite.io/console'; + import Alert from '$lib/components/alert.svelte'; + import { project } from './store'; + export let isGlobal: boolean; export let showCreate = false; export let selectedVar: Partial = null; @@ -31,15 +34,35 @@ } - + - {selectedVar ? 'Update' : 'Create'} Variable + {selectedVar ? 'Update' : 'Create'} + {isGlobal ? 'global' : 'environment'} variable +
+

+ Set the environment variables or secret keys that will be passed to {isGlobal + ? 'all functions within your project' + : 'your function'}. +

+ {#if !isGlobal} + +

+ When there is a naming conflict with a global variable in your + project settings and a function environment variable, the global variable + will be ignored. +

+
+ {/if} +
{ + await sdk.forProject.functions.createVariable($func.$id, key, value); + await invalidate(Dependencies.VARIABLES); + }; + + const sdkUpdateVariable = async (variableId: string, key: string, value: string) => { + await sdk.forProject.functions.updateVariable($func.$id, variableId, key, value); + await invalidate(Dependencies.VARIABLES); + }; + + const sdkDeleteVariable = async (variableId: string) => { + await sdk.forProject.functions.deleteVariable($func.$id, variableId); + await invalidate(Dependencies.VARIABLES); + }; @@ -19,7 +38,14 @@ - + diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/+page.ts b/src/routes/console/project-[project]/functions/function-[function]/settings/+page.ts index 803c98e163..d09a56b134 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/settings/+page.ts +++ b/src/routes/console/project-[project]/functions/function-[function]/settings/+page.ts @@ -5,7 +5,29 @@ import type { PageLoad } from './$types'; export const load: PageLoad = async ({ params, depends }) => { depends(Dependencies.VARIABLES); + const globalVariables = await sdk.forProject.projectApi.listVariables(); + const variables = await sdk.forProject.functions.listVariables(params.function); + + // Conflicting variables first + variables.variables = variables.variables.sort((var1, var2) => { + const isVar1Global = + globalVariables.variables.find((variable) => variable.key === var1.key) !== undefined; + const isVar2Global = + globalVariables.variables.find((variable) => variable.key === var2.key) !== undefined; + + if (isVar1Global && isVar2Global) { + return -var1.$createdAt.localeCompare(var2.$createdAt); + } else if (isVar1Global) { + return -1; + } else if (isVar2Global) { + return 1; + } else { + return -var1.$createdAt.localeCompare(var2.$createdAt); + } + }); + return { - variables: await sdk.forProject.functions.listVariables(params.function) + variables, + globalVariables }; }; diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/store.ts b/src/routes/console/project-[project]/functions/function-[function]/settings/store.ts deleted file mode 100644 index 1307021c34..0000000000 --- a/src/routes/console/project-[project]/functions/function-[function]/settings/store.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { page } from '$app/stores'; -import { derived } from 'svelte/store'; -import type { Models } from '@appwrite.io/console'; - -export const variables = derived( - page, - ($page) => $page.data.variables.variables as Models.Variable[] -); diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/updateSchedule.svelte b/src/routes/console/project-[project]/functions/function-[function]/settings/updateSchedule.svelte index e60ba6e99b..212f343f0f 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/settings/updateSchedule.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/settings/updateSchedule.svelte @@ -53,7 +53,8 @@ target="_blank" rel="noopener noreferrer" class="link"> - More details on Cron syntax here. + More details on Cron syntax here.

diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/updateVariables.svelte b/src/routes/console/project-[project]/functions/function-[function]/settings/updateVariables.svelte deleted file mode 100644 index c3915babc4..0000000000 --- a/src/routes/console/project-[project]/functions/function-[function]/settings/updateVariables.svelte +++ /dev/null @@ -1,233 +0,0 @@ - - - - Variables -

Set the variables (or secret keys) that will be passed to your function at runtime.

- -
- - -
- {@const limit = 10} - {@const sum = variableList.total} - {#if sum} -
- - - Key - Value - - - - {#each variableList.variables.slice(offset, offset + limit) as variable, i} - - - - {variable.key} - - - - - - - - - - - { - selectedVar = variable; - showVariablesDropdown[i] = false; - showVariablesModal = true; - }}> - Edit - - { - handleVariableDeleted(variable); - showVariablesDropdown[i] = false; - }}> - Delete - - - - - - {/each} - -
- -
-

Total variables: {sum}

- -
-
- {:else} - (showVariablesModal = !showVariablesModal)}> - Create a variable to get started - - {/if} -
-
- -{#if showVariablesModal} - -{/if} -{#if showVariablesUpload} - -{/if} diff --git a/src/routes/console/project-[project]/functions/wizard/step5.svelte b/src/routes/console/project-[project]/functions/wizard/step5.svelte index 33b1050074..aa3a257091 100644 --- a/src/routes/console/project-[project]/functions/wizard/step5.svelte +++ b/src/routes/console/project-[project]/functions/wizard/step5.svelte @@ -1,7 +1,7 @@ + + { + dispatch('promoted'); + }} + icon="exclamation" + state="warning" + headerDivider={false}> + {isConflicting ? 'Overwrite global variable' : 'Promote variable'} + {#if isConflicting} +

+ Promoting this variable will overwrite your global variable with the same name. Are you + sure you want to promote {selectedVar.key}? +

+ {:else} +

+ Are you sure you want to promote {selectedVar.key}? + This will convert it to a global variable that can be accessed by other functions in + your project. +

+ {/if} + + + + +
diff --git a/src/routes/console/project-[project]/rawVariableEditor.svelte b/src/routes/console/project-[project]/rawVariableEditor.svelte new file mode 100644 index 0000000000..de5634feaa --- /dev/null +++ b/src/routes/console/project-[project]/rawVariableEditor.svelte @@ -0,0 +1,196 @@ + + + + Raw editor +

+ Edit environment variables below or download as a .{tab} file. +

+ +
+
    +
  • + +
  • +
  • + +
  • +
+ + {#if tab === 'env'} +