@dargmuesli/nuxt-vio 23.1.10 → 24.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,6 +45,8 @@
45
45
  <script setup lang="ts">
46
46
  import type { BaseValidation } from '@vuelidate/core'
47
47
 
48
+ import type { BackendError } from '../../../../shared/types/api'
49
+
48
50
  const {
49
51
  errors = undefined,
50
52
  errorsPgIds = undefined,
@@ -16,6 +16,8 @@
16
16
  <script setup lang="ts">
17
17
  import type { UnwrapRef } from 'vue'
18
18
 
19
+ import type { ApiData } from '../../../../shared/types/api'
20
+
19
21
  const {
20
22
  api,
21
23
  errorPgIds = undefined,
@@ -61,7 +61,7 @@ export const useAppLayout = () => {
61
61
  useSeoMeta({
62
62
  titleTemplate: (title) =>
63
63
  TITLE_TEMPLATE({
64
- siteName: siteConfig.name,
64
+ siteName: siteConfig.name || '',
65
65
  title,
66
66
  }),
67
67
  })
@@ -78,7 +78,7 @@ export const useHeadDefault = (
78
78
  const description =
79
79
  toValue(input.description) || (siteConfig.description as string)
80
80
  const title = TITLE_TEMPLATE({
81
- siteName: siteConfig.name,
81
+ siteName: siteConfig.name || '',
82
82
  title: toValue(input.title)?.toString() || undefined,
83
83
  })
84
84
 
@@ -25,8 +25,7 @@ export const useGetServiceHref = () => {
25
25
  }
26
26
 
27
27
  export const useHost = () => {
28
- const { ssrContext } = useNuxtApp()
29
- const host = ssrContext ? getHost(ssrContext.event) : location.host
28
+ const host = useRequestURL().host
30
29
 
31
30
  if (!host) throw new Error('Host is not given!')
32
31
 
@@ -1,14 +1,6 @@
1
- import { SERVICES } from './services'
2
- import type { Service, ServiceName } from './services'
3
- import { SITE_URL_TYPED } from './static'
4
-
5
- export const getHost = (event: { headers: Headers }) => {
6
- const host = event.headers.get('host')
7
-
8
- if (!host) throw new Error('Host header is not given!')
9
-
10
- return host
11
- }
1
+ import { SERVICES } from './services.ts'
2
+ import type { Service, ServiceName } from './services.ts'
3
+ import { SITE_URL_TYPED } from './static/index.ts'
12
4
 
13
5
  // derives the origins this project itself talks to, so Sentry's trace context is only propagated
14
6
  // to its own services and never to third parties
@@ -1,3 +1,3 @@
1
- export * from './environment'
2
- export * from './nuxt'
3
- export * from './sentry'
1
+ export * from './environment.ts'
2
+ export * from './nuxt.ts'
3
+ export * from './sentry.ts'
@@ -1,8 +1,8 @@
1
1
  import type { defineNuxtConfig } from 'nuxt/config'
2
2
 
3
- import type { Service } from '../services'
4
- import { SERVICES } from '../services'
5
- import { IS_IN_FRONTEND_DEVELOPMENT } from './'
3
+ import type { Service } from '../services.ts'
4
+ import { SERVICES } from '../services.ts'
5
+ import { IS_IN_FRONTEND_DEVELOPMENT } from './environment.ts'
6
6
 
7
7
  export const VIO_NUXT_BASE_CONFIG = ({
8
8
  services,
package/nuxt.config.ts CHANGED
@@ -12,13 +12,13 @@ import {
12
12
  NUXT_PUBLIC_SENTRY_RELEASE,
13
13
  SITE_URL,
14
14
  VIO_NUXT_BASE_CONFIG,
15
- } from './node/static'
15
+ } from './node/static/index.ts'
16
16
  import {
17
17
  GTAG_COOKIE_ID,
18
18
  TIMEZONE_COOKIE_NAME,
19
19
  VIO_GET_CSP,
20
20
  VIO_SITE_NAME,
21
- } from './shared/utils/constants'
21
+ } from './shared/utils/constants.ts'
22
22
 
23
23
  const { resolve } = createResolver(import.meta.url)
24
24
  // mirrors the suffix `mkcert.sh` and the node and static test servers use for the local certificates
@@ -67,13 +67,12 @@ export default defineNuxtConfig(
67
67
  },
68
68
  experimental: {
69
69
  early404: true,
70
- inlineErrorRendering: true,
71
70
  prefetchPreloadTags: true,
72
71
  prerenderErrorPages: true,
73
- routeTypedFetch: true,
74
72
  strictRouteTypes: true,
75
- typedPages: true,
76
- watcher: 'builder',
73
+ },
74
+ future: {
75
+ compatibilityVersion: 5,
77
76
  },
78
77
  hooks: {
79
78
  // consumers' generated tsconfigs exclude `node_modules`, so this layer's type augmentations need explicit references
@@ -150,9 +149,6 @@ export default defineNuxtConfig(
150
149
  ],
151
150
  nitro: {
152
151
  compressPublicAssets: true,
153
- experimental: {
154
- asyncContext: true,
155
- },
156
152
  },
157
153
  routeRules: {
158
154
  '/**': {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "@nuxt/image": "2.2.1",
12
12
  "@nuxtjs/color-mode": "4.1.0",
13
13
  "@nuxtjs/html-validator": "2.1.0",
14
- "@nuxtjs/i18n": "10.6.0",
14
+ "@nuxtjs/i18n": "10.7.0",
15
15
  "@nuxtjs/seo": "6.0.1",
16
16
  "@nuxtjs/turnstile": "1.1.3",
17
17
  "@pinia/nuxt": "1.0.3",
@@ -105,7 +105,7 @@
105
105
  "url": "git+https://github.com/dargmuesli/vio.git"
106
106
  },
107
107
  "type": "module",
108
- "version": "23.1.10",
108
+ "version": "24.0.0-beta.1",
109
109
  "scripts": {
110
110
  "build": "pnpm run build:node",
111
111
  "build:node": "NUXT_PUBLIC_I18N_BASE_URL=https://app.localhost:3001 nuxt build playground",
@@ -1,13 +1,9 @@
1
1
  import { defineEventHandler } from 'nuxt/server'
2
2
 
3
+ import { getTimeZone } from '../utils/dateTime'
4
+ import { useIsTesting } from '../utils/testing'
5
+
3
6
  export default defineEventHandler(async (event) => {
4
- const isTesting = useIsTesting()
7
+ const isTesting = useIsTesting({ event })
5
8
  event.context.$timeZone = await getTimeZone({ event, isTesting })
6
9
  })
7
-
8
- // h3 handlers, `useEvent()` and the app's `ssrContext.event` still see h3's context
9
- declare module 'h3' {
10
- interface H3EventContext {
11
- $timeZone?: string
12
- }
13
- }
@@ -1,5 +1,7 @@
1
+ import { defineEventHandler, useRuntimeConfig } from 'nuxt/server'
2
+
1
3
  export default defineEventHandler((event) => {
2
- const runtimeConfig = useRuntimeConfig(event)
4
+ const runtimeConfig = useRuntimeConfig()
3
5
  const sentryConfig = runtimeConfig.public.sentry
4
6
 
5
7
  if (
@@ -20,13 +22,11 @@ export default defineEventHandler((event) => {
20
22
  .filter(Boolean)
21
23
  .join('&')
22
24
 
23
- appendHeader(
24
- event,
25
+ event.res.headers.append(
25
26
  'NEL',
26
27
  '\'{"report_to":"sentry","max_age":31536000,"include_subdomains":true}\'',
27
28
  )
28
- appendHeader(
29
- event,
29
+ event.res.headers.append(
30
30
  'Report-To',
31
31
  `'{"group":"sentry","max_age":31536000,"endpoints":[{"url":"https://${sentryConfig.host}/api/${sentryConfig.project.id}/security/?${securityEndpointParams}"}],"include_subdomains":true}'`,
32
32
  )
@@ -1,4 +1,6 @@
1
- import { createTransport, type Transporter } from 'nodemailer'
1
+ import { defineNitroPlugin } from 'nitropack/runtime'
2
+ import { createTransport } from 'nodemailer'
3
+ import { useRuntimeConfig } from 'nuxt/server'
2
4
 
3
5
  export default defineNitroPlugin((nitroApp) => {
4
6
  const runtimeConfig = useRuntimeConfig()
@@ -26,14 +28,3 @@ export default defineNitroPlugin((nitroApp) => {
26
28
  transporter.close()
27
29
  })
28
30
  })
29
-
30
- // h3 handlers and `useEvent()` still see h3's context
31
- declare module 'h3' {
32
- interface H3EventContext {
33
- $email?: {
34
- nodemailer: {
35
- transporter: Transporter
36
- }
37
- }
38
- }
39
- }
@@ -1,6 +1,10 @@
1
1
  import { defu } from 'defu'
2
+ import { defineNitroPlugin } from 'nitropack/runtime'
2
3
  import type { ModuleOptions } from 'nuxt-security'
3
4
 
5
+ import { VIO_GET_CSP } from '../../shared/utils/constants'
6
+ import { useSiteUrl } from '../utils/site'
7
+
4
8
  // remove invalid `'none'`s and duplicates
5
9
  export const cleanupCsp = (
6
10
  nuxtSecurityConfiguration: Partial<ModuleOptions>,
@@ -1,5 +1,7 @@
1
1
  import { getCookie, getRequestIP, type RequestEvent } from 'nuxt/server'
2
2
 
3
+ import { TIMEZONE_COOKIE_NAME } from '../../shared/utils/constants'
4
+
3
5
  export const getTimeZone = async ({
4
6
  event,
5
7
  isTesting,
@@ -26,15 +28,13 @@ export const getTimeZone = async ({
26
28
  }
27
29
  }
28
30
 
29
- // the `dateTime` middleware has already resolved the time zone for every request
30
- export const useTimeZone = async () => useEvent().context.$timeZone
31
-
32
31
  export const getTimeZoneByIpApi = async ({ ip }: { ip: string }) => {
33
- const ipApiResult = await $fetch<{ timezone: string }>(
34
- `http://geoip:8080/${ip}`,
35
- ).catch(() => {})
32
+ const response = await fetch(`http://geoip:8080/${ip}`).catch(() => {})
36
33
 
37
- if (ipApiResult) {
38
- return ipApiResult.timezone
39
- }
34
+ if (!response?.ok) return
35
+
36
+ const ipApiResult = (await response.json().catch(() => {})) as
37
+ { timezone?: string } | undefined
38
+
39
+ return ipApiResult?.timezone
40
40
  }
@@ -1,9 +1,18 @@
1
- import type { H3Event } from 'h3'
1
+ import {
2
+ getRequestHost,
3
+ useRuntimeConfig,
4
+ type RequestEvent,
5
+ } from 'nuxt/server'
2
6
 
3
- export const useGetServiceHref = ({ event }: { event?: H3Event } = {}) => {
7
+ import { getServiceHref } from '../../node/networking'
8
+ import type { ServiceName } from '../../node/services'
9
+ import { useSiteUrl } from './site'
10
+ import { useIsTesting } from './testing'
11
+
12
+ export const useGetServiceHref = ({ event }: { event?: RequestEvent } = {}) => {
4
13
  const host = useHost({ event })
5
14
  const runtimeConfig = useRuntimeConfig()
6
- const isTesting = useIsTesting()
15
+ const isTesting = useIsTesting({ event })
7
16
 
8
17
  return ({
9
18
  allowInternal = true,
@@ -26,9 +35,9 @@ export const useGetServiceHref = ({ event }: { event?: H3Event } = {}) => {
26
35
  })
27
36
  }
28
37
 
29
- export const useHost = ({ event }: { event?: H3Event } = {}) => {
38
+ export const useHost = ({ event }: { event?: RequestEvent } = {}) => {
30
39
  const { siteUrlTyped: siteUrl } = useSiteUrl()
31
- const host = event ? getHost(event) : siteUrl.host
40
+ const host = event ? getRequestHost(event) : siteUrl.host
32
41
 
33
42
  if (!host) throw new Error('Host is not given!')
34
43
 
@@ -1,3 +1,5 @@
1
+ import { useRuntimeConfig } from 'nuxt/server'
2
+
1
3
  export const useSiteUrl = () => {
2
4
  const runtimeConfig = useRuntimeConfig()
3
5
  const siteUrl = runtimeConfig.public.i18n.baseUrl
@@ -1,23 +1,14 @@
1
- import type { H3Event } from 'h3'
1
+ import { getCookie, useRuntimeConfig, type RequestEvent } from 'nuxt/server'
2
2
 
3
- // `useEvent()` throws whenever there is no Nitro request context, which is the case for everything that runs at startup, such as a Nitro plugin's hooks.
4
- // Testing detection still works there through the runtime config, so fall back to no event rather than letting that error escape.
5
- const tryUseEvent = () => {
6
- try {
7
- return useEvent()
8
- } catch {
9
- return undefined
10
- }
11
- }
3
+ import { TESTING_COOKIE_NAME } from '../../shared/utils/constants'
12
4
 
13
5
  export const useIsTesting = ({
6
+ event,
14
7
  isCookieEnabled = true,
15
- }:
16
- | {
17
- isCookieEnabled?: boolean
18
- }
19
- | undefined = {}) => {
20
- const event = tryUseEvent()
8
+ }: {
9
+ event?: RequestEvent
10
+ isCookieEnabled?: boolean
11
+ } = {}) => {
21
12
  const runtimeConfig = useRuntimeConfig()
22
13
 
23
14
  return getIsTesting({ event, isCookieEnabled, runtimeConfig })
@@ -28,7 +19,7 @@ export const getIsTesting = ({
28
19
  isCookieEnabled,
29
20
  runtimeConfig,
30
21
  }: {
31
- event?: H3Event
22
+ event?: RequestEvent
32
23
  isCookieEnabled?: boolean
33
24
  runtimeConfig: ReturnType<typeof useRuntimeConfig>
34
25
  }) => {
@@ -2,7 +2,7 @@ import { DEFAULTS } from '@dargmuesli/nuxt-cookie-control/runtime/types.js'
2
2
  import { helpers } from '@vuelidate/validators'
3
3
  import { defu } from 'defu'
4
4
 
5
- export { IS_IN_FRONTEND_DEVELOPMENT } from '../../node/static'
5
+ export { IS_IN_FRONTEND_DEVELOPMENT } from '../../node/static/index.ts'
6
6
 
7
7
  export const VIO_SITE_NAME = 'Vio'
8
8
 
@@ -4,7 +4,7 @@ import type { Ref } from 'vue'
4
4
 
5
5
  import type { ApiData, BackendError } from '../types/api'
6
6
 
7
- export { getHost, getRootHost, getServiceHref } from '../../node/networking'
7
+ export { getRootHost, getServiceHref } from '../../node/networking'
8
8
 
9
9
  export const getApiDataDefault = (): ApiData =>
10
10
  computed(() =>