Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Remove the use of `import.meta.env` (#4705)
Olga Bulatde0079d70b77
diff --git a/frontend/.env.template b/frontend/.env.templatedeleted file mode 100644index 4c33a86dc..000000000--- a/frontend/.env.template+++ /dev/null@@ -1,58 +0,0 @@-PORT=8443--# ---------------------------- #-# REQUIRED LOCAL ENV VARIABLES #-# ---------------------------- #-# DEPLOYMENT_ENV=local-# SITE_DOMAIN=localhost-# SITE_URL=http://localhost:8443-#/**-#* We rely on the Nginx container running as `frontend_nginx`-#* in the local compose stack to proxy requests. Therefore, the-#* URL here is not for the Plausible container in the local stack,-#* but the Nginx service, which then itself forwards the requests-#* to the local Plausible instance.-#*-#* In production, the Nginx container is handling all requests-#* made to the root URL (openverse.org), and is configured to-#* forward Plausible requests to upstream Plausible.-#*/-# PLAUSIBLE_SITE_URL = http://localhost:50290--# ---------------------------- #-# OPTIONAL LOCAL ENV VARIABLES-# ---------------------------- #-### API settings--# NUXT_PUBLIC_API_URL=http://127.17.0.1:8000/ # local dev API-# NUXT_PUBLIC_API_URL=http://localhost:49153/ # talkback proxy-# NUXT_PUBLIC_API_URL=https://api.openverse.org/# prod API--# NUXT_API_CLIENT_ID=""-# NUXT_API_CLIENT_SECRET=""--# -------------------- #-# PRODUCTION VARIABLES #-# -------------------- #-# DEPLOYMENT_ENV=production-# NUXT_API_CLIENT_ID=""-# NUXT_API_CLIENT_SECRET=""-# NUXT_PUBLIC_API_URL=https://api.openverse.org/-# NUXT_PUBLIC_SENTRY_DSN=""-# NUXT_PUBLIC_SENTRY_RELEASE=""-# SITE_URL=https://openverse.org-# SITE_DOMAIN=openverse.org-# PLAUSIBLE_SITE_URL=https://openverse.org--# ----------------- #-# STAGING VARIABLES #-# ----------------- #-# DEPLOYMENT_ENV=staging-# NUXT_API_CLIENT_ID=""-# NUXT_API_CLIENT_SECRET=""-# NUXT_PUBLIC_API_URL=https://api-staging.openverse.org/-# NUXT_PUBLIC_SENTRY_DSN=""-# NUXT_PUBLIC_SENTRY_RELEASE=""-# SITE_URL=https://staging.openverse.org-# SITE_DOMAIN=staging.openverse.org-# PLAUSIBLE_SITE_URL=https://staging.openverse.orgdiff --git a/frontend/Dockerfile b/frontend/Dockerfileindex 19baf6a29..20b857aad 100644--- a/frontend/Dockerfile+++ b/frontend/Dockerfile@@ -39,10 +39,7 @@ RUN pnpm install && pnpm i18n# disable telemetry when building the appENV NUXT_TELEMETRY_DISABLED=1ENV NODE_ENV=production-ENV NUXT_PUBLIC_SENTRY_DSN=https://[email protected]/5799642-ARG API_URL=https://api.openverse.org/-ENV NUXT_PUBLIC_API_URL=$API_URL# Increase memory limit for the build process (necessary for i18n routes)ENV NODE_OPTIONS="--max_old_space_size=4096"@@ -69,12 +66,6 @@ COPY --from=builder --chown=node:node /home/node/frontend ./frontend/WORKDIR /home/node/frontend/ARG SEMANTIC_VERSION-ARG DEPLOYMENT_ENV=production-ARG API_URL=https://api.openverse.org/--ENV NUXT_PUBLIC_API_URL=$API_URL-ENV NUXT_PUBLIC_SENTRY_RELEASE=$SEMANTIC_VERSION-ENV NUXT_PUBLIC_SENTRY_ENVIRONMENT=$DEPLOYMENT_ENV# set app serving to permissive / assignedENV NUXT_HOST=0.0.0.0diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.tsindex 50fa9d59e..a02f64227 100644--- a/frontend/nuxt.config.ts+++ b/frontend/nuxt.config.ts@@ -1,116 +1,11 @@import { defineNuxtConfig } from "nuxt/config"-import { LOCAL, PRODUCTION } from "./src/constants/deploy-env"-+import { disallowedBots } from "./src/constants/disallowed-bots"import locales from "./src/locales/scripts/valid-locales.json"-import { meta as commonMeta } from "./src/constants/meta"import type { LocaleObject } from "@nuxtjs/i18n"-const favicons = [- // SVG favicon- {- rel: "icon",- href: "/favicon.ico",- },- {- rel: "icon",- href: "/openverse-logo.svg",- },- // SVG favicon for Safari- {- rel: "mask-icon",- href: "/opvenverse-logo.svg",- color: "#30272E",- },- // Fallback iPhone Icon- {- rel: "apple-touch-icon",- href: "/openverse-logo-180.png",- },-]--const disallowedBots = [- "GPTBot",- "CCBot",- "ChatGPT-User",- "Google-Extended",- "anthropic-ai",- "Omgilibot",- "Omgili",- "FacebookBot",- "Diffbot",- "Bytespider",- "ImagesiftBot",- "cohere-ai",-]--/**- * Robots.txt rules are configured here via the \@nuxtjs/robots package.- * @see {@link https://nuxtseo.com/robots/guides/nuxt-config|Robots Config Rules}- */-const robots = {- userAgent: "*",- disallow: ["/search", "/search/audio", "/search/image"],- groups: [- ...disallowedBots.map((bot) => ({- userAgent: [bot],- disallow: ["/"], // block bots from all routes- })),- ],-}--const isProductionBuild = import.meta.env.NODE_ENV === "production"-const isPlaywright = import.meta.env.PW === "true"-const isProdNotPlaywright = isProductionBuild && !isPlaywright-const isTest = import.meta.env.TEST === "true"-const deploymentEnv = import.meta.env.DEPLOYMENT_ENV || LOCAL--const apiUrl =- import.meta.env.NUXT_PUBLIC_API_URL || "https://api.openverse.org/"--const openverseLocales = [- {- /* Nuxt i18n fields */-- code: "en", // unique identifier for the locale in Vue i18n- dir: "ltr",- file: "en.json",- iso: "en", // used for SEO purposes (html lang attribute)-- /* Custom fields */-- name: "English",- nativeName: "English",- },- ...locales,-].filter((l) => Boolean(l.iso)) as LocaleObject[]-export default defineNuxtConfig({- app: {- head: {- title: "Openly Licensed Images, Audio and More | Openverse",- meta: commonMeta,- link: [- ...favicons,- {- rel: "search",- type: "application/opensearchdescription+xml",- title: "Openverse",- href: "/opensearch.xml",- },- {- rel: "dns-prefetch",- href: apiUrl,- },- {- rel: "preconnect",- href: apiUrl,- crossorigin: "",- },- ],- },- },srcDir: "src/",serverDir: "server/",devServer: {@@ -122,25 +17,29 @@ export default defineNuxtConfig({},compatibilityDate: "2024-07-23",css: ["~/assets/fonts.css", "~/styles/accent.css"],+ /**+ * Define available runtime configuration values and their defaults.+ *+ * See linked documentation for details, including how to override defaults+ * with runtime values using environment variables.+ *+ * @see {@link https://nuxt.com/docs/api/nuxt-config#runtimeconfig-1}+ */runtimeConfig: {apiClientId: "",apiClientSecret: "",public: {- // These values can be overridden by the NUXT_PUBLIC_* env variables- deploymentEnv,- apiUrl,- providerUpdateFrequency: 3600000,+ deploymentEnv: "local",+ apiUrl: "https://api.openverse.org/",savedSearchCount: 4,sentry: {dsn: "",- environment: deploymentEnv,- release: import.meta.env.SEMANTIC_VERSION,+ environment: "local",+ // Release is a build time variable, and as such, is defined in app.config.ts},- isPlaywright,},},site: {- indexable: deploymentEnv === PRODUCTION,trailingSlash: false,},/**@@ -167,13 +66,39 @@ export default defineNuxtConfig({"/meta-search": { redirect: { to: "/about", statusCode: 301 } },"/external-sources": { redirect: { to: "/about", statusCode: 301 } },},- robots,+ /**+ * Robots.txt rules are configured here via the \@nuxtjs/robots package.+ * @see {@link https://nuxtseo.com/robots/guides/nuxt-config|Robots Config Rules}+ */+ robots: {+ disallow: ["/search", "/search/audio", "/search/image"],+ groups: [+ ...disallowedBots.map((bot) => ({+ userAgent: [bot],+ disallow: ["/"], // block bots from all routes+ })),+ ],+ },tailwindcss: {cssPath: "~/styles/tailwind.css",},i18n: {- baseUrl: import.meta.env.SITE_URL,- locales: openverseLocales,+ locales: [+ {+ /* Nuxt i18n fields */++ code: "en", // unique identifier for the locale in Vue i18n+ dir: "ltr",+ file: "en.json",+ iso: "en", // used for SEO purposes (html lang attribute)++ /* Custom fields */++ name: "English",+ nativeName: "English",+ },+ ...locales,+ ].filter((l) => Boolean(l.iso)) as LocaleObject[],lazy: true,langDir: "locales",defaultLocale: "en",@@ -190,11 +115,8 @@ export default defineNuxtConfig({vueI18n: "./src/vue-i18n",},plausible: {- enabled: !isTest,- logIgnoredEvents: !isProductionBuild,- trackLocalhost: !isProdNotPlaywright,- autoPageviews: isProdNotPlaywright,- domain: import.meta.env.SITE_DOMAIN,- apiHost: import.meta.env.PLAUSIBLE_SITE_URL,+ // `trackLocalhost` is deprecated, but the replacement `ignoredHostnames: []`+ // has a bug, @see https://github.com/nuxt-modules/plausible/issues/30+ trackLocalhost: true,},})diff --git a/frontend/server/plugins/indexable.ts b/frontend/server/plugins/indexable.tsdeleted file mode 100644index 88056472e..000000000--- a/frontend/server/plugins/indexable.ts+++ /dev/null@@ -1,11 +0,0 @@-import { defineNitroPlugin } from "nitropack/runtime"--import { PRODUCTION } from "~/constants/deploy-env"--export default defineNitroPlugin(async (nitroApp) => {- nitroApp.hooks.hook("site-config:init", ({ siteConfig }) => {- siteConfig.push({- indexable: import.meta.env.DEPLOYMENT_ENV === PRODUCTION,- })- })-})diff --git a/frontend/server/plugins/sentry.ts b/frontend/server/plugins/sentry.tsindex dc467a10b..ae4f3cfb5 100644--- a/frontend/server/plugins/sentry.ts+++ b/frontend/server/plugins/sentry.ts@@ -1,4 +1,4 @@-import { useRuntimeConfig } from "#imports"+import { useRuntimeConfig, useAppConfig } from "#imports"import { defineNitroPlugin } from "nitropack/runtime"import * as Sentry from "@sentry/node"@@ -10,13 +10,18 @@ export default defineNitroPlugin((nitroApp) => {public: { sentry },} = useRuntimeConfig()- Sentry.init({+ const appConfig = useAppConfig()++ const sentryConfig = {dsn: sentry.dsn,environment: sentry.environment,- release: sentry.release,- })+ release: appConfig.semanticVersion,+ }++ Sentry.init(sentryConfig)+Sentry.setContext("render context", { platform: "server" })- logger.success("Initialized sentry on the server with config\n", sentry)+ logger.success("Initialized sentry on the server with config\n", sentryConfig)nitroApp.hooks.hook("request", (event) => {event.context.$sentry = Sentrydiff --git a/frontend/src/app.config.ts b/frontend/src/app.config.tsnew file mode 100644index 000000000..35052894b--- /dev/null+++ b/frontend/src/app.config.ts@@ -0,0 +1,5 @@+import { defineAppConfig } from "#imports"++export default defineAppConfig({+ semanticVersion: import.meta.env.SEMANTIC_VERSION as string,+})diff --git a/frontend/src/app.vue b/frontend/src/app.vueindex 0fa68b17a..453f83e0b 100644--- a/frontend/src/app.vue+++ b/frontend/src/app.vue@@ -1,5 +1,11 @@<script setup lang="ts">-import { computed, onMounted, useLocaleHead, useHead } from "#imports"+import {+ computed,+ onMounted,+ useLocaleHead,+ useHead,+ useRuntimeConfig,+} from "#imports"import { useUiStore } from "~/stores/ui"import { useFeatureFlagStore } from "~/stores/feature-flag"@@ -7,10 +13,14 @@ import { useFeatureFlagStore } from "~/stores/feature-flag"import { useLayout } from "~/composables/use-layout"import { useDarkMode } from "~/composables/use-dark-mode"+import { meta as commonMeta } from "~/constants/meta"+import VSkipToContentButton from "~/components/VSkipToContentButton.vue"const { updateBreakpoint } = useLayout()+const config = useRuntimeConfig()+const featureFlagStore = useFeatureFlagStore()const uiStore = useUiStore()@@ -26,8 +36,51 @@ const head = useLocaleHead({addSeoAttributes: true,})+const favicons = [+ // SVG favicon+ {+ rel: "icon",+ href: "/favicon.ico",+ },+ {+ rel: "icon",+ href: "/openverse-logo.svg",+ },+ // SVG favicon for Safari+ {+ rel: "mask-icon",+ href: "/opvenverse-logo.svg",+ color: "#30272E",+ },+ // Fallback iPhone Icon+ {+ rel: "apple-touch-icon",+ href: "/openverse-logo-180.png",+ },+]+useHead({bodyAttrs: { class: darkMode.cssClass },+ title: "Openly Licensed Images, Audio and More | Openverse",+ meta: commonMeta,+ link: [+ ...favicons,+ {+ rel: "search",+ type: "application/opensearchdescription+xml",+ title: "Openverse",+ href: "/opensearch.xml",+ },+ {+ rel: "dns-prefetch",+ href: config.public.apiUrl,+ },+ {+ rel: "preconnect",+ href: config.public.apiUrl,+ crossorigin: "",+ },+ ],})/**diff --git a/frontend/src/constants/disallowed-bots.ts b/frontend/src/constants/disallowed-bots.tsnew file mode 100644index 000000000..9e4ab9925--- /dev/null+++ b/frontend/src/constants/disallowed-bots.ts@@ -0,0 +1,17 @@+/**+ * Bot user agents blocked in our robots.txt file.+ */+export const disallowedBots = [+ "GPTBot",+ "CCBot",+ "ChatGPT-User",+ "Google-Extended",+ "anthropic-ai",+ "Omgilibot",+ "Omgili",+ "FacebookBot",+ "Diffbot",+ "Bytespider",+ "ImagesiftBot",+ "cohere-ai",+]diff --git a/frontend/src/plugins/01.sentry.client.ts b/frontend/src/plugins/01.sentry.client.tsindex f42e3b483..d5208c78b 100644--- a/frontend/src/plugins/01.sentry.client.ts+++ b/frontend/src/plugins/01.sentry.client.ts@@ -1,4 +1,4 @@-import { defineNuxtPlugin, useRuntimeConfig } from "#imports"+import { defineNuxtPlugin, useRuntimeConfig, useAppConfig } from "#imports"import * as Sentry from "@sentry/vue"@@ -7,6 +7,8 @@ export default defineNuxtPlugin((nuxtApp) => {public: { sentry },} = useRuntimeConfig()+ const { semanticVersion } = useAppConfig()+if (!sentry.dsn) {console.warn("Sentry DSN wasn't provided")}@@ -14,6 +16,7 @@ export default defineNuxtPlugin((nuxtApp) => {Sentry.init({dsn: sentry.dsn,environment: sentry.environment,+ release: semanticVersion,app: nuxtApp.vueApp,})Sentry.setContext("render context", { platform: "client" })diff --git a/frontend/src/stores/feature-flag.ts b/frontend/src/stores/feature-flag.tsindex 42b070b04..657f417e9 100644--- a/frontend/src/stores/feature-flag.ts+++ b/frontend/src/stores/feature-flag.ts@@ -1,4 +1,4 @@-import { useCookie } from "#imports"+import { useCookie, useRuntimeConfig } from "#imports"import { defineStore } from "pinia"import { useStorage } from "@vueuse/core"@@ -24,7 +24,7 @@ import {SESSION,SWITCHABLE,} from "~/constants/feature-flag"-import { DEPLOY_ENVS, DeployEnv, LOCAL } from "~/constants/deploy-env"+import { DEPLOY_ENVS, DeployEnv } from "~/constants/deploy-env"import {OpenverseCookieState,@@ -49,12 +49,15 @@ interface FeatureGroup {/*** Get the status of the flag. If the flag status is environment dependent, this* function will use the flag status for the current environment based on the- * `DEPLOYMENT_ENV` environment variable.+ * value from the runtime config.** @param flag - the flag for which to get the status+ * @param deploymentEnv - the current deployment environment*/-export const getFlagStatus = (flag: FeatureFlagRecord): FlagStatus => {- const deployEnv = (import.meta.env.DEPLOYMENT_ENV ?? LOCAL) as DeployEnv+export const getFlagStatus = (+ flag: FeatureFlagRecord,+ deploymentEnv: DeployEnv+): FlagStatus => {if (typeof flag.status === "string") {if (!FLAG_STATUSES.includes(flag.status as FlagStatus)) {warn(`Invalid ${flag.description} flag status: ${flag.status}`)@@ -62,7 +65,7 @@ export const getFlagStatus = (flag: FeatureFlagRecord): FlagStatus => {}return flag.status as FlagStatus} else {- const envIndex = DEPLOY_ENVS.indexOf(deployEnv)+ const envIndex = DEPLOY_ENVS.indexOf(deploymentEnv)for (let i = envIndex; i < DEPLOY_ENVS.length; i += 1) {if (DEPLOY_ENVS[i] in flag.status) {if (@@ -85,11 +88,13 @@ export const getFlagStatus = (flag: FeatureFlagRecord): FlagStatus => {* preferences of the user.** @param flag - the flag for which to get the state+ * @param deploymentEnv - the current deployment environment*/const getFeatureState = (- flag: FeatureFlag | FeatureFlagRecord+ flag: FeatureFlag | FeatureFlagRecord,+ deploymentEnv: DeployEnv): FeatureState => {- const status = getFlagStatus(flag)+ const status = getFlagStatus(flag, deploymentEnv)if (status === SWITCHABLE) {if ("preferredState" in flag) {return (flag.preferredState as FeatureState) ?? flag.defaultState ?? OFF@@ -102,7 +107,7 @@ const getFeatureState = (return OFF}-const initializeFlagState = () => {+export const initializeFlagState = (deploymentEnv: DeployEnv) => {// Resolve the status of the feature flags based on the current environmentconst features: Record<FlagName, FeatureFlag> = Object.entries(featureData.features as Record<FlagName, FeatureFlagRecord>@@ -111,8 +116,8 @@ const initializeFlagState = () => {acc[name as FlagName] = {...flag,name: name as FlagName,- state: getFeatureState(flag),- status: getFlagStatus(flag),+ state: getFeatureState(flag, deploymentEnv),+ status: getFlagStatus(flag, deploymentEnv),preferredState: undefined,}return acc@@ -126,7 +131,8 @@ const FEATURE_FLAG = "feature_flag"export const useFeatureFlagStore = defineStore(FEATURE_FLAG, {state: () => {- return initializeFlagState()+ const deploymentEnv = useRuntimeConfig().public.deploymentEnv as DeployEnv+ return initializeFlagState(deploymentEnv)},getters: {/**diff --git a/frontend/src/stores/search.ts b/frontend/src/stores/search.tsindex add16bf8d..a4ae3dc72 100644--- a/frontend/src/stores/search.ts+++ b/frontend/src/stores/search.ts@@ -1,4 +1,4 @@-import { useNuxtApp } from "#imports"+import { useNuxtApp, useRuntimeConfig } from "#imports"import { defineStore } from "pinia"@@ -57,8 +57,6 @@ export const isSearchTypeSupported = (return supportedSearchTypes.includes(st as SupportedSearchType)}-const SAVED_SEARCH_COUNT = 4-export interface SearchState {searchType: SearchTypestrategy: SearchStrategy@@ -68,6 +66,7 @@ export interface SearchState {searchTerm: stringlocalSearchTerm: stringfilters: Filters+ savedSearchCount: number}export function getSensitiveQuery(@@ -145,6 +144,7 @@ export const useSearchStore = defineStore("search", {localSearchTerm: "",recentSearches: useStorage<string[]>("recent-searches", []),filters: deepClone(filterData as DeepWriteable<typeof filterData>),+ savedSearchCount: useRuntimeConfig().public.savedSearchCount,}),/*** If the server set the search term, add it to the top of the recent searches stack saved in the local storage.@@ -155,7 +155,7 @@ export const useSearchStore = defineStore("search", {entriesStored.value = [state.searchTerm,...entriesStored.value.filter((i) => i !== state.searchTerm),- ].slice(0, SAVED_SEARCH_COUNT)+ ].slice(0, state.savedSearchCount)}state.recentSearches = entriesStored.value},@@ -410,7 +410,7 @@ export const useSearchStore = defineStore("search", {const entries = [search,...this.recentSearches.filter((i) => i !== search),- ].slice(0, SAVED_SEARCH_COUNT)+ ].slice(0, this.savedSearchCount)// directly setting value to this.recentSearches does not update the storage and watchersthis.updateRecentSearches(entries)},diff --git a/frontend/src/types/cookies.ts b/frontend/src/types/cookies.tsindex 8e846202f..4d011389e 100644--- a/frontend/src/types/cookies.ts+++ b/frontend/src/types/cookies.ts@@ -1,14 +1,13 @@import type { FeatureState } from "~/constants/feature-flag"import type { RealBreakpoint } from "~/constants/screens"import type { BannerId } from "~/types/banners"-import { PRODUCTION } from "~/constants/deploy-env"export type SnackbarState = "not_shown" | "visible" | "dismissed"const baseCookieOptions = {path: "/",sameSite: "strict",- secure: import.meta.env.DEPLOYMENT_ENV === PRODUCTION,+ secure: true,} as constexport const persistentCookieOptions = {diff --git a/frontend/src/utils/console.ts b/frontend/src/utils/console.tsindex e8d4cbcc4..d13a879c0 100644--- a/frontend/src/utils/console.ts+++ b/frontend/src/utils/console.ts@@ -1,18 +1,22 @@-import { PRODUCTION, STAGING } from "~/constants/deploy-env"+import { tryUseNuxtApp } from "#app"-const isProductionOrStaging = [PRODUCTION, STAGING].includes(- import.meta.env.DEPLOYMENT_ENV-)+import { LOCAL } from "~/constants/deploy-env"/**- * Silence logging on the client when deployed+ * Silence logging on the client in production and on staging.*/-export const getLogger = (level: "log" | "warn" | "error") =>- isProductionOrStaging && import.meta.client- ? () => {- // do nothing- }- : console[level]+export const getLogger = (level: "log" | "warn" | "error") => {+ if (+ import.meta.server ||+ (import.meta.client &&+ tryUseNuxtApp()?.$config?.public.deploymentEnv === LOCAL)+ ) {+ return console[level]+ }+ return () => {+ // do nothing+ }+}export const warn = getLogger("warn")export const log = getLogger("log")diff --git a/frontend/src/utils/focus-management.ts b/frontend/src/utils/focus-management.tsindex 58af6809c..d6c382ee6 100644--- a/frontend/src/utils/focus-management.ts+++ b/frontend/src/utils/focus-management.ts@@ -36,7 +36,7 @@ const focusableSelector = ["textarea:not([disabled])",].map(- import.meta.env.NODE_ENV === "test"+ import.meta.test? // TODO: Remove this once JSDOM fixes the issue where an element that is// "hidden" can be the document.activeElement, because this is not possible// in real browsers.diff --git a/frontend/test/playwright/e2e/preferences.spec.ts b/frontend/test/playwright/e2e/preferences.spec.tsindex 5773ac323..711e0c064 100644--- a/frontend/test/playwright/e2e/preferences.spec.ts+++ b/frontend/test/playwright/e2e/preferences.spec.ts@@ -10,7 +10,7 @@ import type {FlagName,} from "~/types/feature-flag"import { DISABLED, FLAG_STATUSES, FlagStatus } from "~/constants/feature-flag"-import { DEPLOY_ENVS, DeployEnv, LOCAL } from "~/constants/deploy-env"+import { DEPLOY_ENVS, DeployEnv } from "~/constants/deploy-env"const getFeatureCookies = async (page: Page, cookieName: string) => {const cookies = await page.context().cookies()@@ -23,8 +23,10 @@ const getFeatureCookies = async (page: Page, cookieName: string) => {return JSON.parse(decodeURIComponent(cookieValue))}-const getFlagStatus = (flag: FeatureFlagRecord): FlagStatus => {- const deployEnv = (process.env.DEPLOYMENT_ENV ?? LOCAL) as DeployEnv+const getFlagStatus = (+ flag: FeatureFlagRecord,+ deployEnv: DeployEnv+): FlagStatus => {if (typeof flag.status === "string") {if (!FLAG_STATUSES.includes(flag.status as FlagStatus)) {console.warn(`Invalid ${flag.description} flag status: ${flag.status}`)@@ -57,7 +59,7 @@ const getFeaturesToTest = () => {} as constfor (const [name, state] of Object.entries(testableFeatures)) {const flag = featureData.features[name as FlagName] as FeatureFlag- if (getFlagStatus(flag) !== "switchable") {+ if (getFlagStatus(flag, "staging") !== "switchable") {throw new Error(`Feature ${name} is not switchable`)}if (flag.defaultState !== state) {diff --git a/frontend/test/playwright/playwright.config.ts b/frontend/test/playwright/playwright.config.tsindex 634be2cdb..aca6a39f5 100644--- a/frontend/test/playwright/playwright.config.ts+++ b/frontend/test/playwright/playwright.config.ts@@ -1,4 +1,4 @@-import { PRODUCTION } from "~/constants/deploy-env"+import { STAGING } from "~/constants/deploy-env"import type { PlaywrightTestConfig } from "@playwright/test"@@ -30,8 +30,10 @@ const config: PlaywrightTestConfig = {API_URL,NUXT_PUBLIC_API_URL: API_URL,UPDATE_TAPES: UPDATE_TAPES,- DEPLOYMENT_ENV: PRODUCTION,- PW: "true",+ NUXT_PUBLIC_DEPLOYMENT_ENV: STAGING,+ NUXT_PUBLIC_PLAUSIBLE_ENABLED: "true",+ NUXT_PUBLIC_PLAUSIBLE_DOMAIN: "localhost",+ NUXT_PUBLIC_PLAUSIBLE_API_HOST: "http://localhost:50290",},},use: {diff --git a/frontend/test/unit/specs/stores/feature-flag-store.spec.js b/frontend/test/unit/specs/stores/feature-flag-store.spec.jsindex 1a7fa2f6b..223a4ca45 100644--- a/frontend/test/unit/specs/stores/feature-flag-store.spec.js+++ b/frontend/test/unit/specs/stores/feature-flag-store.spec.js@@ -2,10 +2,9 @@ import { beforeEach, describe, expect, vi } from "vitest"import { setActivePinia, createPinia } from "~~/test/unit/test-utils/pinia"-import { getFlagStatus, useFeatureFlagStore } from "~/stores/feature-flag"+import { initializeFlagState, useFeatureFlagStore } from "~/stores/feature-flag"import { OFF, COOKIE, SESSION } from "~/constants/feature-flag"-vi.resetModules()vi.mock("~~/feat/feature-flags.json", () => ({default: {features: {@@ -47,24 +46,27 @@ vi.mock("~~/feat/feature-flags.json", () => ({defaultState: "off",storage: "cookie",},+ feat_env_specific_no_local: {+ status: {+ staging: "switchable",+ production: "disabled",+ },+ description: "Depends on the environment",+ defaultState: "off",+ storage: "cookie",+ },},},}))describe("Feature flag store", () => {- let initialEnvbeforeEach(() => {setActivePinia(createPinia())- initialEnv = process.env.DEPLOYMENT_ENV- })-- afterEach(() => {- process.env.DEPLOYMENT_ENV = initialEnv})it("initialises state from JSON", () => {const featureFlagStore = useFeatureFlagStore()- expect(Object.keys(featureFlagStore.flags).length).toBe(6)+ expect(Object.keys(featureFlagStore.flags).length).toBe(7)})it.each`@@ -152,35 +154,23 @@ describe("Feature flag store", () => {`("returns $featureState for $environment",({ environment, featureState }) => {- // The value is cleaned up in afterEach- process.env.DEPLOYMENT_ENV = environment- const featureFlagStore = useFeatureFlagStore()-- expect(featureFlagStore.featureState("feat_env_specific")).toEqual(+ const featureFlagState = initializeFlagState(environment)+ expect(featureFlagState.flags.feat_env_specific.state).toEqual(featureState)- expect(featureFlagStore.isOn("feat_env_specific")).toEqual(- featureState === "on"- )})- it.each`- environment | flagStatus- ${"local"} | ${"switchable"}- ${"staging"} | ${"switchable"}- ${"production"} | ${"disabled"}- `(- "handles fallback for missing $environment",- ({ environment, flagStatus }) => {- // The value is cleaned up in afterEach- process.env.DEPLOYMENT_ENV = environment- const actualStatus = getFlagStatus({- status: { staging: "switchable" },- })- expect(actualStatus).toEqual(flagStatus)- }- )+ it("handles fallback for missing local environment", () => {+ const featureFlagState = initializeFlagState("local")++ expect(featureFlagState.flags["feat_env_specific_no_local"].status).toEqual(+ "switchable"+ )+ expect(featureFlagState.flags["feat_env_specific_no_local"].state).toEqual(+ "off"+ )+ })it.each`storage | flagNamediff --git a/frontend/test/unit/specs/stores/provider.spec.js b/frontend/test/unit/specs/stores/provider.spec.jsindex ef64d4c00..2196c4960 100644--- a/frontend/test/unit/specs/stores/provider.spec.js+++ b/frontend/test/unit/specs/stores/provider.spec.js@@ -5,8 +5,6 @@ import { setActivePinia, createPinia } from "~~/test/unit/test-utils/pinia"import { AUDIO, IMAGE } from "~/constants/media"import { useProviderStore } from "~/stores/provider"-process.env.providerUpdateFrequency = "0"-const testProviders = [{source_name: "test_source",diff --git a/frontend/test/unit/specs/stores/ui-store.spec.js b/frontend/test/unit/specs/stores/ui-store.spec.jsindex 7c57533da..750c46379 100644--- a/frontend/test/unit/specs/stores/ui-store.spec.js+++ b/frontend/test/unit/specs/stores/ui-store.spec.js@@ -4,6 +4,17 @@ import { setActivePinia, createPinia } from "~~/test/unit/test-utils/pinia"import { useUiStore } from "~/stores/ui"+vi.mock("~/types/cookies", async () => {+ const actual = await vi.importActual("~/types/cookies")+ return {+ ...actual,+ persistentCookieOptions: {+ ...actual.persistentCookieOptions,+ secure: false,+ },+ }+})+const initialState = {instructionsSnackbarState: "not_shown",innerFilterVisible: false,diff --git a/frontend/test/unit/specs/utils/api-token/api-token-missing-credentials.spec.js b/frontend/test/unit/specs/utils/api-token/api-token-missing-credentials.spec.jsindex f58348bb7..4486eb422 100644--- a/frontend/test/unit/specs/utils/api-token/api-token-missing-credentials.spec.js+++ b/frontend/test/unit/specs/utils/api-token/api-token-missing-credentials.spec.js@@ -1,4 +1,3 @@-// @vitest-environment nodeimport { describe, expect, it } from "vitest"import { getApiAccessToken } from "~/plugins/api-token.server"diff --git a/frontend/test/unit/specs/utils/api-token/api-token-parallel.spec.js b/frontend/test/unit/specs/utils/api-token/api-token-parallel.spec.jsindex b31e67ca9..c338eb9cf 100644--- a/frontend/test/unit/specs/utils/api-token/api-token-parallel.spec.js+++ b/frontend/test/unit/specs/utils/api-token/api-token-parallel.spec.js@@ -1,4 +1,3 @@-// @vitest-environment nodeimport { expect, it, vi } from "vitest"import axios from "axios"diff --git a/frontend/test/unit/specs/utils/api-token/api-token-successful.spec.js b/frontend/test/unit/specs/utils/api-token/api-token-successful.spec.jsindex 0388c8ff0..506ca0a92 100644--- a/frontend/test/unit/specs/utils/api-token/api-token-successful.spec.js+++ b/frontend/test/unit/specs/utils/api-token/api-token-successful.spec.js@@ -1,4 +1,3 @@-// @vitest-environment nodeimport axios from "axios"import { describe, expect, it, vi } from "vitest"diff --git a/frontend/typings/nuxt__types/index.d.ts b/frontend/typings/nuxt__types/index.d.tsindex c446f88c4..1fcd6f746 100644--- a/frontend/typings/nuxt__types/index.d.ts+++ b/frontend/typings/nuxt__types/index.d.ts@@ -1,34 +1,12 @@-import type { Plausible } from "plausible-tracker"--declare module "#app" {- interface NuxtApp {- $plausible: ReturnType<typeof Plausible>- $sentry: {- captureException: (error: Error | unknown, options?: unknown) => void- captureMessage: (message: string) => void- }- }-}-declare module "@nuxtjs/i18n" {/*** We put a little extra information in the Vue-i18n `locales` field such as the* locale's name and native name, which comes in use here.*/export interface LocaleObject {- name: stringnativeName: stringtranslated: number}}-declare module "nuxt/schema" {- interface RuntimeConfig {- apiSecret: string- }- interface PublicRuntimeConfig {- apiUrl: string- providerUpdateFrequency: number- savedSearchCount: number- }-}+export {}