diff --git a/web/backoffice/package-lock.json b/web/backoffice/package-lock.json index 1a517aac..2573fa7a 100644 --- a/web/backoffice/package-lock.json +++ b/web/backoffice/package-lock.json @@ -17,14 +17,14 @@ "@sveltejs/vite-plugin-svelte": "^3.0.2", "autoprefixer": "^10.4.17", "btc2fiat": "*", - "daisyui": "^4.6.1", + "daisyui": "^4.7.2", "eslint": "^8.56.0", "eslint-plugin-svelte": "^2.35.1", "nostr-tools": "^1.13.1", "npm-run-all": "4.x", - "postcss": "^8.4.33", - "svelte": "^4.2.9", - "svelte-check": "^3.6.3", + "postcss": "^8.4.35", + "svelte": "^4.2.11", + "svelte-check": "^3.6.4", "svelte-toasts": "1.x", "tailwindcss": "^3.4.1", "typescript": "^5.0.0", @@ -2010,9 +2010,9 @@ } }, "node_modules/daisyui": { - "version": "4.6.1", - "resolved": "https://registry.npmjs.org/daisyui/-/daisyui-4.6.1.tgz", - "integrity": "sha512-IXI8ypN/hkl1AKsag1XPlWt0wfvL4NedTUtUkv/VFP5q/xDbBZrZthq3/9M2yU1egcbbLhp01rluIz0GICUc+g==", + "version": "4.7.2", + "resolved": "https://registry.npmjs.org/daisyui/-/daisyui-4.7.2.tgz", + "integrity": "sha512-9UCss12Zmyk/22u+JbkVrHHxOzFOyY17HuqP5LeswI4hclbj6qbjJTovdj2zRy8cCH6/n6Wh0lTLjriGnyGh0g==", "dev": true, "dependencies": { "css-selector-tokenizer": "^0.8", @@ -4072,9 +4072,9 @@ } }, "node_modules/postcss": { - "version": "8.4.33", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.33.tgz", - "integrity": "sha512-Kkpbhhdjw2qQs2O2DGX+8m5OVqEcbB9HRBvuYM9pgrjEFUg30A9LmXNlTAUj4S9kgtGyrMbTzVjH7E+s5Re2yg==", + "version": "8.4.35", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.35.tgz", + "integrity": "sha512-u5U8qYpBCpN13BsiEB0CbR1Hhh4Gc0zLFuedrHJKMctHCHAGrMdG0PRM/KErzAL3CU6/eckEtmHNB3x6e3c0vA==", "dev": true, "funding": [ { @@ -4834,9 +4834,9 @@ } }, "node_modules/svelte": { - "version": "4.2.9", - "resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.9.tgz", - "integrity": "sha512-hsoB/WZGEPFXeRRLPhPrbRz67PhP6sqYgvwcAs+gWdSQSvNDw+/lTeUJSWe5h2xC97Fz/8QxAOqItwBzNJPU8w==", + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.11.tgz", + "integrity": "sha512-YIQk3J4X89wOLhjsqIW8tqY3JHPuBdtdOIkASP2PZeAMcSW9RsIjQzMesCrxOF3gdWYC0mKknlKF7OqmLM+Zqg==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.1", @@ -4859,9 +4859,9 @@ } }, "node_modules/svelte-check": { - "version": "3.6.3", - "resolved": "https://registry.npmjs.org/svelte-check/-/svelte-check-3.6.3.tgz", - "integrity": "sha512-Q2nGnoysxUnB9KjnjpQLZwdjK62DHyW6nuH/gm2qteFnDk0lCehe/6z8TsIvYeKjC6luKaWxiNGyOcWiLLPSwA==", + "version": "3.6.4", + "resolved": "https://registry.npmjs.org/svelte-check/-/svelte-check-3.6.4.tgz", + "integrity": "sha512-mY/dqucqm46p72M8yZmn81WPZx9mN6uuw8UVfR3ZKQeLxQg5HDGO3HHm5AZuWZPYNMLJ+TRMn+TeN53HfQ/vsw==", "dev": true, "dependencies": { "@jridgewell/trace-mapping": "^0.3.17", diff --git a/web/backoffice/package.json b/web/backoffice/package.json index cb623577..fe19b0b7 100644 --- a/web/backoffice/package.json +++ b/web/backoffice/package.json @@ -7,14 +7,14 @@ "@sveltejs/vite-plugin-svelte": "^3.0.2", "autoprefixer": "^10.4.17", "btc2fiat": "*", - "daisyui": "^4.6.1", + "daisyui": "^4.7.2", "eslint": "^8.56.0", "eslint-plugin-svelte": "^2.35.1", "nostr-tools": "^1.13.1", "npm-run-all": "4.x", - "postcss": "^8.4.33", - "svelte": "^4.2.9", - "svelte-check": "^3.6.3", + "postcss": "^8.4.35", + "svelte": "^4.2.11", + "svelte-check": "^3.6.4", "svelte-toasts": "1.x", "tailwindcss": "^3.4.1", "typescript": "^5.0.0", diff --git a/web/backoffice/src/routes/+layout.js b/web/backoffice/src/routes/+layout.js new file mode 100644 index 00000000..94926662 --- /dev/null +++ b/web/backoffice/src/routes/+layout.js @@ -0,0 +1,16 @@ +import {getConfigurationFromFile} from "$sharedLib/utils"; +import {fileConfiguration} from "$sharedLib/stores"; +import { browser } from "$app/environment"; + +// Load configuration from file before +// any other component code runs +async function loadConfig() { + let config = await getConfigurationFromFile() ?? {}; + config.backend_present = true; + fileConfiguration.set(config); +} + +if (browser) { + loadConfig() + .catch(error => console.log('Error while trying to load config from file:', error)); +} diff --git a/web/backoffice/src/routes/+layout.svelte b/web/backoffice/src/routes/+layout.svelte index 72c42c7d..63516743 100644 --- a/web/backoffice/src/routes/+layout.svelte +++ b/web/backoffice/src/routes/+layout.svelte @@ -5,13 +5,51 @@ import { browser } from '$app/environment'; import { page } from '$app/stores'; import { user } from "$lib/stores"; - import { Info, Error, token, NostrPublicKey } from "$sharedLib/stores"; + import { + Info, + Error, + token, + NostrPublicKey, + fileConfiguration, + isSuperAdmin, + NostrGlobalConfig + } from "$sharedLib/stores"; import type { Placement } from "$sharedLib/stores"; import { getProfile } from "$lib/services/api"; import Navbar from "$sharedLib/components/Navbar.svelte"; import Footer from "$sharedLib/components/Footer.svelte"; import LoginModalLightning from "$lib/components/auth/Modal.svelte"; import LoginModal from "$sharedLib/components/login/Modal.svelte"; + import {getConfigurationKey, subscribeConfiguration} from "$sharedLib/services/nostr"; + + function subscribeGlobalConf() { + let receivedAt = 0; + + const serializedGlobalConfig = localStorage.getItem("NostrGlobalConfig"); + if (serializedGlobalConfig) { + $NostrGlobalConfig = JSON.parse(serializedGlobalConfig); + receivedAt = parseInt(localStorage.getItem("NostrGlobalConfigReceivedAt") ?? '0'); + } + + subscribeConfiguration($fileConfiguration.admin_pubkeys, [getConfigurationKey('site_specific_config')], + (setup, rcAt) => { + if (rcAt > receivedAt) { + receivedAt = rcAt; + + $NostrGlobalConfig = setup; + localStorage.setItem('NostrGlobalConfig', JSON.stringify(setup)); + localStorage.setItem('NostrGlobalConfigReceivedAt', receivedAt.toString()); + } + }); + } + + $: if ($fileConfiguration?.admin_pubkeys?.length > 0) { + subscribeGlobalConf(); + } + + $: if ($NostrPublicKey && $fileConfiguration?.admin_pubkeys?.includes($NostrPublicKey)) { + $isSuperAdmin = true; + } const infoUnsubscribe = Info.subscribe(value => { if (value) { diff --git a/web/frontoffice/package-lock.json b/web/frontoffice/package-lock.json index 87eb8842..9538b7cd 100644 --- a/web/frontoffice/package-lock.json +++ b/web/frontoffice/package-lock.json @@ -31,7 +31,7 @@ "eslint-plugin-svelte": "^2.35.1", "npm-run-all": "4.x", "postcss": "^8.4.35", - "svelte": "^4.2.10", + "svelte": "^4.2.11", "svelte-check": "^3.6.4", "svelte-dnd-action": "^0.9.38", "svelte-meta-tags": "^3.1.0", @@ -5361,9 +5361,9 @@ } }, "node_modules/svelte": { - "version": "4.2.10", - "resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.10.tgz", - "integrity": "sha512-Ep06yCaCdgG1Mafb/Rx8sJ1QS3RW2I2BxGp2Ui9LBHSZ2/tO/aGLc5WqPjgiAP6KAnLJGaIr/zzwQlOo1b8MxA==", + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.11.tgz", + "integrity": "sha512-YIQk3J4X89wOLhjsqIW8tqY3JHPuBdtdOIkASP2PZeAMcSW9RsIjQzMesCrxOF3gdWYC0mKknlKF7OqmLM+Zqg==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.1", @@ -9641,9 +9641,9 @@ "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==" }, "svelte": { - "version": "4.2.10", - "resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.10.tgz", - "integrity": "sha512-Ep06yCaCdgG1Mafb/Rx8sJ1QS3RW2I2BxGp2Ui9LBHSZ2/tO/aGLc5WqPjgiAP6KAnLJGaIr/zzwQlOo1b8MxA==", + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.11.tgz", + "integrity": "sha512-YIQk3J4X89wOLhjsqIW8tqY3JHPuBdtdOIkASP2PZeAMcSW9RsIjQzMesCrxOF3gdWYC0mKknlKF7OqmLM+Zqg==", "dev": true, "requires": { "@ampproject/remapping": "^2.2.1", diff --git a/web/frontoffice/package.json b/web/frontoffice/package.json index e8d66303..deb1f5b3 100644 --- a/web/frontoffice/package.json +++ b/web/frontoffice/package.json @@ -15,7 +15,7 @@ "eslint-plugin-svelte": "^2.35.1", "npm-run-all": "4.x", "postcss": "^8.4.35", - "svelte": "^4.2.10", + "svelte": "^4.2.11", "svelte-check": "^3.6.4", "svelte-dnd-action": "^0.9.38", "svelte-meta-tags": "^3.1.0", diff --git a/web/shared/package-lock.json b/web/shared/package-lock.json index 061eb772..ef91d849 100644 --- a/web/shared/package-lock.json +++ b/web/shared/package-lock.json @@ -27,8 +27,8 @@ "eslint": "^8.56.0", "eslint-plugin-svelte": "^2.35.1", "publint": "^0.2.7", - "svelte": "^4.2.10", - "svelte-check": "^3.6.3", + "svelte": "^4.2.11", + "svelte-check": "^3.6.4", "tslib": "^2.6.2", "typescript": "^5.0.0", "vite": "^5.0.12" @@ -3941,9 +3941,9 @@ } }, "node_modules/svelte": { - "version": "4.2.10", - "resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.10.tgz", - "integrity": "sha512-Ep06yCaCdgG1Mafb/Rx8sJ1QS3RW2I2BxGp2Ui9LBHSZ2/tO/aGLc5WqPjgiAP6KAnLJGaIr/zzwQlOo1b8MxA==", + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.11.tgz", + "integrity": "sha512-YIQk3J4X89wOLhjsqIW8tqY3JHPuBdtdOIkASP2PZeAMcSW9RsIjQzMesCrxOF3gdWYC0mKknlKF7OqmLM+Zqg==", "dependencies": { "@ampproject/remapping": "^2.2.1", "@jridgewell/sourcemap-codec": "^1.4.15", @@ -3965,9 +3965,9 @@ } }, "node_modules/svelte-check": { - "version": "3.6.3", - "resolved": "https://registry.npmjs.org/svelte-check/-/svelte-check-3.6.3.tgz", - "integrity": "sha512-Q2nGnoysxUnB9KjnjpQLZwdjK62DHyW6nuH/gm2qteFnDk0lCehe/6z8TsIvYeKjC6luKaWxiNGyOcWiLLPSwA==", + "version": "3.6.4", + "resolved": "https://registry.npmjs.org/svelte-check/-/svelte-check-3.6.4.tgz", + "integrity": "sha512-mY/dqucqm46p72M8yZmn81WPZx9mN6uuw8UVfR3ZKQeLxQg5HDGO3HHm5AZuWZPYNMLJ+TRMn+TeN53HfQ/vsw==", "dev": true, "dependencies": { "@jridgewell/trace-mapping": "^0.3.17", diff --git a/web/shared/package.json b/web/shared/package.json index d910a4dd..377ac850 100644 --- a/web/shared/package.json +++ b/web/shared/package.json @@ -35,8 +35,8 @@ "eslint": "^8.56.0", "eslint-plugin-svelte": "^2.35.1", "publint": "^0.2.7", - "svelte": "^4.2.10", - "svelte-check": "^3.6.3", + "svelte": "^4.2.11", + "svelte-check": "^3.6.4", "tslib": "^2.6.2", "typescript": "^5.0.0", "vite": "^5.0.12" diff --git a/web/shared/src/lib/components/Navbar.svelte b/web/shared/src/lib/components/Navbar.svelte index 999d182b..1221ce49 100644 --- a/web/shared/src/lib/components/Navbar.svelte +++ b/web/shared/src/lib/components/Navbar.svelte @@ -99,6 +99,11 @@ virtualPages = getPages(); + let retries = 5; + while ((!$fileConfiguration || Object.keys($fileConfiguration).length === 0) && retries-- > 0) { + await new Promise(resolve => setTimeout(resolve, 30)); + } + if ($fileConfiguration?.admin_pubkeys?.length > 0) { let allPagesListReceivedAt = 0;