@dargmuesli/nuxt-vio 21.0.10 → 22.0.0-beta.2
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.
- package/.config/lint.js +1 -1
- package/app/composables/networking.ts +16 -1
- package/app/composables/strapi.ts +7 -6
- package/app/composables/testing.ts +10 -3
- package/app/utils/dateTime.ts +2 -2
- package/node/static/environment.ts +1 -0
- package/package.json +1 -1
- package/server/middleware/dateTime.ts +3 -2
- package/server/utils/dateTime.ts +25 -12
- package/server/utils/dependencies/dargstack.ts +1 -0
- package/server/utils/dependencies/index.ts +1 -0
- package/server/utils/networking.ts +14 -7
- package/server/utils/testing.ts +23 -4
- package/shared/utils/networking.ts +25 -8
package/.config/lint.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
export const useGetServiceHref = () => {
|
|
2
2
|
const host = useHost()
|
|
3
3
|
const runtimeConfig = useRuntimeConfig()
|
|
4
|
+
const isTesting = useIsTesting()
|
|
4
5
|
|
|
5
6
|
return ({
|
|
6
7
|
isSsr = true,
|
|
7
8
|
name,
|
|
9
|
+
path,
|
|
8
10
|
port,
|
|
9
11
|
}: {
|
|
10
12
|
isSsr?: boolean
|
|
11
|
-
name
|
|
13
|
+
name: string
|
|
14
|
+
path?: string
|
|
12
15
|
port?: number
|
|
13
16
|
}) =>
|
|
14
17
|
getServiceHref({
|
|
15
18
|
host,
|
|
16
19
|
isSsr,
|
|
20
|
+
isTesting,
|
|
17
21
|
name,
|
|
22
|
+
path,
|
|
18
23
|
port,
|
|
19
24
|
stagingHost: runtimeConfig.public.vio.stagingHost,
|
|
20
25
|
})
|
|
@@ -28,3 +33,13 @@ export const useHost = () => {
|
|
|
28
33
|
|
|
29
34
|
return host
|
|
30
35
|
}
|
|
36
|
+
|
|
37
|
+
export const useServiceFetch = (
|
|
38
|
+
options: Parameters<ReturnType<typeof useGetServiceHref>>[0],
|
|
39
|
+
) => {
|
|
40
|
+
const getServiceHref = useGetServiceHref()
|
|
41
|
+
|
|
42
|
+
return $fetch.create({
|
|
43
|
+
baseURL: getServiceHref(options),
|
|
44
|
+
})
|
|
45
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export const useStrapiFetch = (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export const useStrapiFetch = (
|
|
2
|
+
options?: Parameters<ReturnType<typeof useGetServiceHref>>[0],
|
|
3
|
+
) =>
|
|
4
|
+
useServiceFetch({
|
|
5
|
+
...(options ? options : {}),
|
|
6
|
+
name: options?.name || 'strapi',
|
|
7
|
+
path: options?.path || '/api',
|
|
6
8
|
})
|
|
7
|
-
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
export const useIsTesting = (
|
|
2
|
-
|
|
1
|
+
export const useIsTesting = ({
|
|
2
|
+
isCookieEnabled = true,
|
|
3
|
+
}: { isCookieEnabled?: boolean } | undefined = {}) => {
|
|
3
4
|
const runtimeConfig = useRuntimeConfig()
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
const isTestingByRuntimeConfig = runtimeConfig.public.vio.isTesting
|
|
7
|
+
if (isTestingByRuntimeConfig) return true
|
|
8
|
+
|
|
9
|
+
if (isCookieEnabled) {
|
|
10
|
+
const isTestingByCookie = !!useCookie(TESTING_COOKIE_NAME).value
|
|
11
|
+
if (isTestingByCookie) return true
|
|
12
|
+
}
|
|
6
13
|
}
|
package/app/utils/dateTime.ts
CHANGED
package/package.json
CHANGED
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"url": "git+https://github.com/dargmuesli/vio.git"
|
|
98
98
|
},
|
|
99
99
|
"type": "module",
|
|
100
|
-
"version": "
|
|
100
|
+
"version": "22.0.0-beta.2",
|
|
101
101
|
"scripts": {
|
|
102
102
|
"build": "pnpm run build:node",
|
|
103
103
|
"build:node": "NUXT_PUBLIC_I18N_BASE_URL=https://app.localhost:3001 nuxt build playground",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export default defineEventHandler(async (event) => {
|
|
2
|
-
|
|
2
|
+
const isTesting = useIsTesting()
|
|
3
|
+
event.context.$timeZone = await getTimeZone({ event, isTesting })
|
|
3
4
|
})
|
|
4
5
|
|
|
5
6
|
declare module 'h3' {
|
|
6
7
|
interface H3EventContext {
|
|
7
|
-
$
|
|
8
|
+
$timeZone?: string
|
|
8
9
|
}
|
|
9
10
|
}
|
package/server/utils/dateTime.ts
CHANGED
|
@@ -1,28 +1,41 @@
|
|
|
1
1
|
import type { H3Event } from 'h3'
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
3
|
+
export const getTimeZone = async ({
|
|
4
|
+
event,
|
|
5
|
+
isTesting,
|
|
6
|
+
}: {
|
|
7
|
+
event: H3Event
|
|
8
|
+
isTesting?: boolean
|
|
9
|
+
}) => {
|
|
10
|
+
const timeZoneBySsr = event.context.$timeZone
|
|
5
11
|
|
|
6
|
-
if (
|
|
12
|
+
if (timeZoneBySsr) return timeZoneBySsr
|
|
7
13
|
|
|
8
|
-
const
|
|
14
|
+
const timeZoneByCookie = getCookie(event, TIMEZONE_COOKIE_NAME)
|
|
9
15
|
|
|
10
|
-
if (
|
|
16
|
+
if (timeZoneByCookie) return timeZoneByCookie
|
|
11
17
|
|
|
12
|
-
|
|
18
|
+
if (!isTesting) {
|
|
19
|
+
const ip = getRequestIP(event, { xForwardedFor: true })
|
|
13
20
|
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
if (ip) {
|
|
22
|
+
const timeZoneByIpApi = await getTimeZoneByIpApi({ ip })
|
|
16
23
|
|
|
17
|
-
|
|
24
|
+
if (timeZoneByIpApi) return timeZoneByIpApi
|
|
25
|
+
}
|
|
18
26
|
}
|
|
19
27
|
}
|
|
20
28
|
|
|
21
|
-
export const
|
|
22
|
-
|
|
29
|
+
export const useTimeZone = async () => {
|
|
30
|
+
const event = useEvent()
|
|
31
|
+
const isTesting = useIsTesting()
|
|
23
32
|
|
|
33
|
+
return await getTimeZone({ event, isTesting })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const getTimeZoneByIpApi = async ({ ip }: { ip: string }) => {
|
|
24
37
|
const ipApiResult = await $fetch<{ timezone: string }>(
|
|
25
|
-
`http://
|
|
38
|
+
`http://geoip:8080/${ip}`,
|
|
26
39
|
).catch(() => {})
|
|
27
40
|
|
|
28
41
|
if (ipApiResult) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DARGSTACK_SECRET_UNUSED_THIRD_PARTY = 'UNSET THIRD PARTY SECRET'
|
|
@@ -1,28 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { H3Event } from 'h3'
|
|
2
|
+
|
|
3
|
+
export const useGetServiceHref = ({ event }: { event?: H3Event } = {}) => {
|
|
4
|
+
const host = useHost({ event })
|
|
3
5
|
const runtimeConfig = useRuntimeConfig()
|
|
6
|
+
const isTesting = useIsTesting()
|
|
4
7
|
|
|
5
8
|
return ({
|
|
6
9
|
isSsr = true,
|
|
7
10
|
name,
|
|
11
|
+
path,
|
|
8
12
|
port,
|
|
9
13
|
}: {
|
|
10
14
|
isSsr?: boolean
|
|
11
|
-
name
|
|
15
|
+
name: string
|
|
16
|
+
path?: string
|
|
12
17
|
port?: number
|
|
13
18
|
}) =>
|
|
14
19
|
getServiceHref({
|
|
15
20
|
host,
|
|
16
21
|
isSsr,
|
|
22
|
+
isTesting,
|
|
17
23
|
name,
|
|
24
|
+
path,
|
|
18
25
|
port,
|
|
19
26
|
stagingHost: runtimeConfig.public.vio.stagingHost,
|
|
20
|
-
})
|
|
27
|
+
})
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
export const useHost = () => {
|
|
24
|
-
const
|
|
25
|
-
const host = getHost(event)
|
|
30
|
+
export const useHost = ({ event }: { event?: H3Event } = {}) => {
|
|
31
|
+
const { siteUrlTyped: siteUrl } = useSiteUrl()
|
|
32
|
+
const host = event ? getHost(event) : siteUrl.host
|
|
26
33
|
|
|
27
34
|
if (!host) throw new Error('Host is not given!')
|
|
28
35
|
|
package/server/utils/testing.ts
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
import type { H3Event } from 'h3'
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
3
|
+
export const useIsTesting = ({
|
|
4
|
+
isCookieEnabled = true,
|
|
5
|
+
}:
|
|
6
|
+
| {
|
|
7
|
+
isCookieEnabled?: boolean
|
|
8
|
+
}
|
|
9
|
+
| undefined = {}) => {
|
|
10
|
+
const event = useEvent()
|
|
11
|
+
const runtimeConfig = useRuntimeConfig()
|
|
5
12
|
|
|
13
|
+
return getIsTesting({ event, isCookieEnabled, runtimeConfig })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const getIsTesting = ({
|
|
17
|
+
event,
|
|
18
|
+
isCookieEnabled,
|
|
19
|
+
runtimeConfig,
|
|
20
|
+
}: {
|
|
21
|
+
event?: H3Event
|
|
22
|
+
isCookieEnabled?: boolean
|
|
23
|
+
runtimeConfig: ReturnType<typeof useRuntimeConfig>
|
|
24
|
+
}) => {
|
|
25
|
+
const isTestingByRuntimeConfig = runtimeConfig.public.vio.isTesting
|
|
6
26
|
if (isTestingByRuntimeConfig) return true
|
|
7
27
|
|
|
8
|
-
if (event) {
|
|
28
|
+
if (isCookieEnabled && event) {
|
|
9
29
|
const isTestingByCookie = !!getCookie(event, TESTING_COOKIE_NAME)
|
|
10
|
-
|
|
11
30
|
if (isTestingByCookie) return true
|
|
12
31
|
}
|
|
13
32
|
}
|
|
@@ -3,6 +3,7 @@ import type { H3Event } from 'h3'
|
|
|
3
3
|
import { computed, reactive } from 'vue'
|
|
4
4
|
import type { Ref } from 'vue'
|
|
5
5
|
|
|
6
|
+
import { SITE_URL_TYPED } from '../../node/static'
|
|
6
7
|
import type { ApiData, BackendError } from '../types/api'
|
|
7
8
|
|
|
8
9
|
export const getApiDataDefault = (): ApiData =>
|
|
@@ -87,25 +88,41 @@ export const getHost = (event: H3Event) => {
|
|
|
87
88
|
export const getServiceHref = ({
|
|
88
89
|
host,
|
|
89
90
|
isSsr = true,
|
|
91
|
+
isTesting,
|
|
90
92
|
name,
|
|
93
|
+
path,
|
|
91
94
|
port,
|
|
92
95
|
stagingHost,
|
|
93
96
|
}: {
|
|
94
|
-
host
|
|
97
|
+
host?: string
|
|
95
98
|
isSsr?: boolean
|
|
96
|
-
|
|
99
|
+
isTesting?: boolean
|
|
100
|
+
name: string
|
|
101
|
+
path?: string
|
|
97
102
|
port?: number
|
|
98
103
|
stagingHost?: string
|
|
99
104
|
}) => {
|
|
100
|
-
const nameSubdomain =
|
|
105
|
+
const nameSubdomain =
|
|
106
|
+
name !== VIO_SITE_NAME ? name?.replaceAll('_', '-') : undefined
|
|
101
107
|
const nameSubdomainString = nameSubdomain ? `${nameSubdomain}.` : ''
|
|
102
108
|
const portString = port ? `:${port}` : ''
|
|
109
|
+
const pathString = path ? `/${path.replace(/^\/+/, '')}` : ''
|
|
110
|
+
|
|
111
|
+
if (isTesting) {
|
|
112
|
+
return `${SITE_URL_TYPED.protocol}//${nameSubdomainString}${SITE_URL_TYPED.host}${pathString}`
|
|
113
|
+
}
|
|
103
114
|
|
|
104
115
|
if (stagingHost) {
|
|
105
|
-
return `https://${nameSubdomainString}${stagingHost}`
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return `
|
|
116
|
+
return `https://${nameSubdomainString}${stagingHost}${pathString}`
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (import.meta.server && isSsr) {
|
|
120
|
+
return `http://${name}${portString}${pathString}`
|
|
110
121
|
}
|
|
122
|
+
|
|
123
|
+
if (host) {
|
|
124
|
+
return `https://${nameSubdomainString}${host}${pathString}`
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
throw new Error('Could not get service href!')
|
|
111
128
|
}
|