diff --git a/package-lock.json b/package-lock.json index c18802778..edf974b73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1", "dependencies": { "@analytics/google-analytics": "^1.0.5", - "@aw-labs/appwrite-console": "npm:matej-appwrite-console@7.1.8", + "@aw-labs/appwrite-console": "npm:matej-appwrite-console@7.1.9", "@aw-labs/icons": "0.0.0-77", "@aw-labs/ui": "0.0.0-77", "@popperjs/core": "^2.11.6", @@ -146,9 +146,9 @@ }, "node_modules/@aw-labs/appwrite-console": { "name": "matej-appwrite-console", - "version": "7.1.8", - "resolved": "https://registry.npmjs.org/matej-appwrite-console/-/matej-appwrite-console-7.1.8.tgz", - "integrity": "sha512-OhhxzcX0mZAjVSlS5A9U8AOw4LEQ8cPTFLsY86LQTqBqBTjEm+qT5MBTkeaeiEPXdL1+MzoqQgZOL+XXQ+RPJQ==", + "version": "7.1.9", + "resolved": "https://registry.npmjs.org/matej-appwrite-console/-/matej-appwrite-console-7.1.9.tgz", + "integrity": "sha512-3sYGFRfUZK0f6caBHCVTw4F6thKlq1/HgqLg5bOfB+gIz5u8ADRPhjPL5CukdN35vLyJkWvn92rOcCr65tY1tA==", "dependencies": { "cross-fetch": "3.1.5", "isomorphic-form-data": "2.0.0" @@ -7741,9 +7741,9 @@ "integrity": "sha512-1Yw7u/COtxx06BfwlI+kVhsa/upKYzmCNrT4c8QDeCY2KMYlnijkUjtHiPU08HxyTIVB5j6d75O0YWVIHwQS8g==" }, "@aw-labs/appwrite-console": { - "version": "npm:matej-appwrite-console@7.1.8", - "resolved": "https://registry.npmjs.org/matej-appwrite-console/-/matej-appwrite-console-7.1.8.tgz", - "integrity": "sha512-OhhxzcX0mZAjVSlS5A9U8AOw4LEQ8cPTFLsY86LQTqBqBTjEm+qT5MBTkeaeiEPXdL1+MzoqQgZOL+XXQ+RPJQ==", + "version": "npm:matej-appwrite-console@7.1.9", + "resolved": "https://registry.npmjs.org/matej-appwrite-console/-/matej-appwrite-console-7.1.9.tgz", + "integrity": "sha512-3sYGFRfUZK0f6caBHCVTw4F6thKlq1/HgqLg5bOfB+gIz5u8ADRPhjPL5CukdN35vLyJkWvn92rOcCr65tY1tA==", "requires": { "cross-fetch": "3.1.5", "isomorphic-form-data": "2.0.0" diff --git a/package.json b/package.json index 554f4753d..58cd3362b 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "dependencies": { "@analytics/google-analytics": "^1.0.5", "analytics": "^0.8.1", - "@aw-labs/appwrite-console": "npm:matej-appwrite-console@7.1.8", + "@aw-labs/appwrite-console": "npm:matej-appwrite-console@7.1.9", "@aw-labs/icons": "0.0.0-77", "@aw-labs/ui": "0.0.0-77", "@popperjs/core": "^2.11.6", diff --git a/src/routes/console/project-[project]/functions/createVariable.svelte b/src/lib/components/environmentVariables/create.svelte similarity index 96% rename from src/routes/console/project-[project]/functions/createVariable.svelte rename to src/lib/components/environmentVariables/create.svelte index 0fa4a6706..9fb90cc4c 100644 --- a/src/routes/console/project-[project]/functions/createVariable.svelte +++ b/src/lib/components/environmentVariables/create.svelte @@ -33,7 +33,7 @@ - {selectedVar ? 'Update' : 'Create'} Variable + {selectedVar ? 'Update' : 'Create'} Environment Variable + import { Modal } from '$lib/components'; + import Code from '$lib/components/code.svelte'; + import Tab from '$lib/components/tab.svelte'; + import Tabs from '$lib/components/tabs.svelte'; + import { Button } from '$lib/elements/forms'; + + export let showSnippet = false; + export let variableKey: string; + + // TODO: @Meldiron Finish or delete this component + + enum Language { + NodeJS, + Python, + Dart, + Ruby, + Java + } + let language: Language = Language.NodeJS; + + + + Code Snippet +

Snippet of a code showing how to read environment variables in Appwrite Functions.

+ + (language = Language.NodeJS)} selected={language === Language.NodeJS}> + Node.JS + + (language = Language.Python)} selected={language === Language.Python}> + Python + + (language = Language.Dart)} selected={language === Language.Dart}> + Dart + + (language = Language.Ruby)} selected={language === Language.Ruby}> + Ruby + + (language = Language.Java)} selected={language === Language.Java}> + Java + + + + {#if language === Language.NodeJS} + + {/if} + + + + +
diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/uploadVariables.svelte b/src/lib/components/environmentVariables/upload.svelte similarity index 86% rename from src/routes/console/project-[project]/functions/function-[function]/settings/uploadVariables.svelte rename to src/lib/components/environmentVariables/upload.svelte index 5c6122235..2081bb727 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/settings/uploadVariables.svelte +++ b/src/lib/components/environmentVariables/upload.svelte @@ -1,4 +1,6 @@ - Upload Variables + Upload Environment Variables

- Upload multiple variables via a .env file that will be passed to your function at runtime. + Upload multiple environment variables via a .env file that will be passed to your function + at runtime and during build.

diff --git a/src/lib/components/environmentVariables/variables.svelte b/src/lib/components/environmentVariables/variables.svelte new file mode 100644 index 000000000..bcc3ba9b1 --- /dev/null +++ b/src/lib/components/environmentVariables/variables.svelte @@ -0,0 +1,320 @@ + + +{#if variables.variables.length} + {#if !isWizard} +
+ + +
+ {/if} + + + + + + + + + {#if variables.total} + {#each variables.variables as variable, i} + + + + + + {/each} + {/if} + +
+ Key + + Value + +
+ {variable.key} + +
+ {#if showVariablesValue[i]} + {variable.value} + {:else} + •••••••• + {/if} +
+ + + + + + +
+
+
+ + + + { + selectedVar = variable; + showVariablesDropdown[i] = false; + showVariablesModal = true; + }}> + Edit + + { + handleVariableDeleted(variable); + showVariablesDropdown[i] = false; + }}> + Delete + + {#if !isShared && !isWizard} + { + showPromote = true; + promoteVariable = variable; + }}>Promote + {/if} + + +
+
+ +
+{:else} + (showVariablesModal = !showVariablesModal)} + >Create an environment variable to get started +{/if} + +{#if !isShared && !isWizard} + + Shared variables from project settings are also + available. When there is name conflict, function variable is used. + +{/if} + + +{#if showVariablesModal} + +{/if} + +{#if !isShared} + handlePromote(promoteVariable)} warning> + Promote To Shared Variable +

+ Are you sure you want to promote {promoteVariable.key}? This will move + variable into project settings and make it visible to all services. +

+ + + + +
+{/if} diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index 8c0cdc1e2..5ac9ac404 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -7,14 +7,13 @@ import { Health, Locale, Projects, + Project, Proxy, Storage, Teams, Users } from '@aw-labs/appwrite-console'; -import { Project } from './project'; - const endpoint = import.meta.env.VITE_APPWRITE_ENDPOINT?.toString() ?? `${window?.location?.origin}/v1`; const clientConsole = new Client(); diff --git a/src/routes/console/project-[project]/functions/createFunction.svelte b/src/routes/console/project-[project]/functions/createFunction.svelte index e7a33229e..6fc964238 100644 --- a/src/routes/console/project-[project]/functions/createFunction.svelte +++ b/src/routes/console/project-[project]/functions/createFunction.svelte @@ -87,7 +87,7 @@ optional: true }); stepsComponents.set(5, { - label: 'Variables', + label: 'Environment Variables', component: Step5, optional: true }); diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/+page.svelte b/src/routes/console/project-[project]/functions/function-[function]/settings/+page.svelte index 537d7645c..141d0c09e 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/settings/+page.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/settings/+page.svelte @@ -1,13 +1,5 @@ @@ -510,120 +427,19 @@ - Update Function Variables -

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

+ Update Function Environment Variables +

+ Set the environment variables (or secret keys) that will be passed to your function at + runtime and during build. +

+ -
- - -
- - - - - - - - - {#if data.variables.total} - {#each data.variables.variables as variable, i} - - - - - - {/each} - {/if} - -
- Key - - Value - -
- {variable.key} - -
- {#if showVariablesValue[i]} - {variable.value} - {:else} - •••••••• - {/if} -
- - - - -
-
-
- - - - { - selectedVar = variable; - showVariablesDropdown[i] = false; - showVariablesModal = true; - }}> - Edit - - { - handleVariableDeleted(variable); - showVariablesDropdown[i] = false; - }}> - Delete - - - -
-
- -
+
@@ -649,12 +465,6 @@
-{#if showVariablesModal} - -{/if} + diff --git a/src/routes/console/project-[project]/functions/wizard/step5.svelte b/src/routes/console/project-[project]/functions/wizard/step5.svelte index f3cf1c9ae..c2f709584 100644 --- a/src/routes/console/project-[project]/functions/wizard/step5.svelte +++ b/src/routes/console/project-[project]/functions/wizard/step5.svelte @@ -1,120 +1,46 @@ - Variables + Environment Variables - Create a variable (or secret key) that will be passed to your function at runtime. + Create an environment variable (or secret key) that will be passed to your function at + runtime and during build. - {#if $createFunction.vars.length} - - - Key - Value - - - - {#each $createFunction.vars as variable, i} - - - {variable.key} - - - - - - - - - { - selectedVar = $createFunction.vars[i]; - showDropdown[i] = false; - showCreate = true; - }}> - Edit - - { - $createFunction.vars.splice(i, 1); - $createFunction = $createFunction; - showDropdown[i] = false; - }}> - Delete - - - - - - {/each} - -
-
- -
- {:else} - (showCreate = !showCreate)}>Create a variable to get started - {/if} +
- -{#if showCreate} - -{/if} diff --git a/src/routes/console/project-[project]/settings/header.svelte b/src/routes/console/project-[project]/settings/header.svelte index 47bfca70d..0b494a3cd 100644 --- a/src/routes/console/project-[project]/settings/header.svelte +++ b/src/routes/console/project-[project]/settings/header.svelte @@ -21,6 +21,11 @@ href: `${path}/webhooks`, title: 'Webhooks', event: 'webhooks' + }, + { + href: `${path}/variables`, + title: 'Shared Variables', + event: 'sharedVariables' } ]; diff --git a/src/routes/console/project-[project]/settings/variables/+page.svelte b/src/routes/console/project-[project]/settings/variables/+page.svelte new file mode 100644 index 000000000..032cacb5c --- /dev/null +++ b/src/routes/console/project-[project]/settings/variables/+page.svelte @@ -0,0 +1,38 @@ + + + + + Update Shared Environment Variables +

Set the environment variables (or secret keys) that will be passed to all resources.

+ + + + +
+
diff --git a/src/routes/console/project-[project]/settings/variables/+page.ts b/src/routes/console/project-[project]/settings/variables/+page.ts new file mode 100644 index 000000000..db6b04dd5 --- /dev/null +++ b/src/routes/console/project-[project]/settings/variables/+page.ts @@ -0,0 +1,12 @@ +import { Dependencies } from '$lib/constants'; +import { sdkForProject } from '$lib/stores/sdk'; +import type { PageLoad } from './$types'; + +export const load: PageLoad = async ({ parent, depends }) => { + await parent(); + depends(Dependencies.VARIABLES); + + return { + variables: await sdkForProject.project.listVariables() + }; +};