@duffcloudservices/cms 0.13.3 → 0.13.5
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/README.md +6 -2
- package/dist/{chunk-OGAJX4KM.js → chunk-GBHJVHXR.js} +116 -3
- package/dist/chunk-GBHJVHXR.js.map +1 -0
- package/dist/{chunk-64BUBTW7.js → chunk-W5Q6SOAP.js} +35 -3
- package/dist/chunk-W5Q6SOAP.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +22 -5
- package/dist/index.js.map +1 -1
- package/dist/{installSeoHead-EE0Z7UmK.d.ts → installSeoHead-CuVdVCis.d.ts} +1 -1
- package/dist/plugins/index.d.ts +12 -6
- package/dist/plugins/index.js +49 -33
- package/dist/plugins/index.js.map +1 -1
- package/dist/seo/index.d.ts +132 -7
- package/dist/seo/index.js +2 -2
- package/dist/{vitepressTransform-Ds5Hff8t.d.ts → vitepressTransform-CZ_IB3dq.d.ts} +47 -1
- package/package.json +9 -3
- package/src/components/LiteMediaEmbed.test.ts +74 -1
- package/src/components/ManagedImage.test.ts +16 -1
- package/src/components/PreviewRibbon.vue +11 -3
- package/src/components/ResponsiveImage.test.ts +16 -1
- package/src/components/raw-source-imports.test.ts +128 -4
- package/src/composables/resolveApiBaseUrl.test.ts +71 -0
- package/src/composables/resolveApiBaseUrl.ts +49 -0
- package/src/composables/useReleaseNotes.ts +3 -1
- package/src/composables/useSiteVersion.ts +3 -1
- package/dist/chunk-64BUBTW7.js.map +0 -1
- package/dist/chunk-OGAJX4KM.js.map +0 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import { API_BASE_URL_ENV, resetApiBaseUrlWarning, resolveApiBaseUrl } from './resolveApiBaseUrl'
|
|
7
|
+
|
|
8
|
+
// C-1062: the runtime composables' API base comes from VITE_API_BASE_URL and
|
|
9
|
+
// from nowhere else. A missing env is LOUD (one warning) and yields '' so the
|
|
10
|
+
// read goes relative to the site's own origin - never to the production portal.
|
|
11
|
+
|
|
12
|
+
describe('resolveApiBaseUrl (C-1062)', () => {
|
|
13
|
+
let warn: ReturnType<typeof vi.spyOn>
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
resetApiBaseUrlWarning()
|
|
17
|
+
warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
18
|
+
})
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
warn.mockRestore()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('returns the configured base with trailing slashes stripped, silently', () => {
|
|
24
|
+
expect(resolveApiBaseUrl('https://api.example.test/', 'x')).toBe('https://api.example.test')
|
|
25
|
+
expect(resolveApiBaseUrl('https://api.example.test///', 'x')).toBe('https://api.example.test')
|
|
26
|
+
expect(resolveApiBaseUrl('http://localhost:8080', 'x')).toBe('http://localhost:8080')
|
|
27
|
+
expect(warn).not.toHaveBeenCalled()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('an unset env yields the empty string and exactly one warning naming the env', () => {
|
|
31
|
+
expect(resolveApiBaseUrl(undefined, 'useReleaseNotes')).toBe('')
|
|
32
|
+
expect(resolveApiBaseUrl(undefined, 'useSiteVersion')).toBe('')
|
|
33
|
+
expect(resolveApiBaseUrl('', 'PreviewRibbon')).toBe('')
|
|
34
|
+
expect(resolveApiBaseUrl(' ', 'PreviewRibbon')).toBe('')
|
|
35
|
+
expect(warn).toHaveBeenCalledTimes(1)
|
|
36
|
+
const text = String(warn.mock.calls[0]?.[0])
|
|
37
|
+
expect(text).toContain(API_BASE_URL_ENV)
|
|
38
|
+
expect(text).toContain('useReleaseNotes')
|
|
39
|
+
expect(text).not.toMatch(/duffcloudservices\.com/)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('never returns a production origin the caller did not configure', () => {
|
|
43
|
+
for (const raw of [undefined, '', ' ']) {
|
|
44
|
+
expect(resolveApiBaseUrl(raw, 'x')).not.toMatch(/duffcloudservices\.com/)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('the three call sites route through this helper and carry no production literal', () => {
|
|
49
|
+
const here = resolve(__dirname)
|
|
50
|
+
const sites = [
|
|
51
|
+
['useReleaseNotes.ts', "from './resolveApiBaseUrl'", "resolveApiBaseUrl(getEnvVar(API_BASE_URL_ENV), 'useReleaseNotes')"],
|
|
52
|
+
['useSiteVersion.ts', "from './resolveApiBaseUrl'", "resolveApiBaseUrl(getEnvVar(API_BASE_URL_ENV), 'useSiteVersion')"],
|
|
53
|
+
['../components/PreviewRibbon.vue', "from '../composables/resolveApiBaseUrl'", "'PreviewRibbon'"],
|
|
54
|
+
] as const
|
|
55
|
+
for (const [file, importLine, call] of sites) {
|
|
56
|
+
const src = readFileSync(resolve(here, file), 'utf8')
|
|
57
|
+
expect(src, file).toContain(importLine)
|
|
58
|
+
expect(src, file).toContain(call)
|
|
59
|
+
expect(src, file).not.toMatch(/https:\/\/(portal|api)\.duffcloudservices\.com/)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('the ribbon skips its read on an empty base instead of blaming a C-298 misroute', () => {
|
|
64
|
+
const src = readFileSync(resolve(__dirname, '../components/PreviewRibbon.vue'), 'utf8')
|
|
65
|
+
const from = src.indexOf("'PreviewRibbon',")
|
|
66
|
+
const fetchAt = src.indexOf('await fetch(', from)
|
|
67
|
+
const guardAt = src.indexOf("if (base === '') return", from)
|
|
68
|
+
expect(guardAt).toBeGreaterThan(from)
|
|
69
|
+
expect(fetchAt).toBeGreaterThan(guardAt)
|
|
70
|
+
})
|
|
71
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runtime composables' API base (C-1062): `VITE_API_BASE_URL`, or NOTHING.
|
|
3
|
+
*
|
|
4
|
+
* Until 0.13.4 three call sites (useReleaseNotes, useSiteVersion, PreviewRibbon)
|
|
5
|
+
* silently fell back to the production portal origin when the env was unset. In
|
|
6
|
+
* CI the canonical site-deploy workflow always sets the env, so the literal was
|
|
7
|
+
* reached only by local / preview builds on repos with no `.env` - and there a
|
|
8
|
+
* silent production default is the hazard C-1039 documented: a dev build that
|
|
9
|
+
* quietly talks to the live API. The fallback is now the empty string plus ONE
|
|
10
|
+
* console warning per module instance naming the env. What each caller does with
|
|
11
|
+
* '' is its own: useSiteVersion reads relative and treats a non-ok response as no
|
|
12
|
+
* version; useReleaseNotes reads relative and surfaces its normal not-found error;
|
|
13
|
+
* PreviewRibbon skips its read entirely (an SWA answers a relative miss with a
|
|
14
|
+
* 200 HTML shell, which its C-298 misroute check would otherwise blame on the
|
|
15
|
+
* platform).
|
|
16
|
+
*
|
|
17
|
+
* The composables ship both bundled (`dist/index.js`) and as raw source
|
|
18
|
+
* (`src/composables`, imported by the raw-shipped PreviewRibbon.vue), so a site
|
|
19
|
+
* that uses both can see the warning twice. That is accepted: the point is that
|
|
20
|
+
* it is not silent.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export const API_BASE_URL_ENV = 'VITE_API_BASE_URL'
|
|
24
|
+
|
|
25
|
+
let warned = false
|
|
26
|
+
|
|
27
|
+
/** Test seam: forget that the warning was issued. */
|
|
28
|
+
export function resetApiBaseUrlWarning(): void {
|
|
29
|
+
warned = false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param raw the env value as read by the caller (`import.meta.env.VITE_API_BASE_URL`)
|
|
34
|
+
* @param caller who is asking, for the warning text
|
|
35
|
+
* @returns the configured base with trailing slashes removed, or `''`
|
|
36
|
+
*/
|
|
37
|
+
export function resolveApiBaseUrl(raw: string | undefined, caller: string): string {
|
|
38
|
+
const value = (raw ?? '').trim()
|
|
39
|
+
if (value !== '') return value.replace(/\/+$/, '')
|
|
40
|
+
if (!warned) {
|
|
41
|
+
warned = true
|
|
42
|
+
console.warn(
|
|
43
|
+
`[dcs-cms] ${caller}: ${API_BASE_URL_ENV} is not set; API reads go relative to this ` +
|
|
44
|
+
'origin. The production origin is no longer assumed (C-1062) - set it in .env for ' +
|
|
45
|
+
'local and preview builds.',
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
return ''
|
|
49
|
+
}
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
import { platformFetch } from '@duffcloudservices/cms-core'
|
|
32
32
|
import { ref, onMounted } from 'vue'
|
|
33
33
|
import type { ReleaseNote, ReleaseNotesReturn } from '../types/release-notes'
|
|
34
|
+
import { API_BASE_URL_ENV, resolveApiBaseUrl } from './resolveApiBaseUrl'
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* Get environment variable value.
|
|
@@ -64,7 +65,8 @@ export function useReleaseNotes(
|
|
|
64
65
|
): ReleaseNotesReturn {
|
|
65
66
|
const { fetchOnMount = true } = options
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
// C-1062: the env or nothing - never a silent production default.
|
|
69
|
+
const apiBaseUrl = resolveApiBaseUrl(getEnvVar(API_BASE_URL_ENV), 'useReleaseNotes')
|
|
68
70
|
// @deprecated VITE_SITE_SLUG: the site is now resolved server-side from the
|
|
69
71
|
// request Host or the dedicated Container App's DCS_SITE_SLUG. It is retained
|
|
70
72
|
// only for cache-key continuity and source compatibility, not for routing.
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
import { platformFetch } from '@duffcloudservices/cms-core'
|
|
26
26
|
import { ref, computed, onMounted } from 'vue'
|
|
27
27
|
import type { SiteVersionReturn } from '../types/release-notes'
|
|
28
|
+
import { API_BASE_URL_ENV, resolveApiBaseUrl } from './resolveApiBaseUrl'
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Get environment variable value.
|
|
@@ -54,7 +55,8 @@ const CACHE_TTL = 10 * 60 * 1000 // 10 minutes
|
|
|
54
55
|
export function useSiteVersion(options: { fetchOnMount?: boolean } = {}): SiteVersionReturn {
|
|
55
56
|
const { fetchOnMount = true } = options
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
// C-1062: the env or nothing - never a silent production default.
|
|
59
|
+
const apiBaseUrl = resolveApiBaseUrl(getEnvVar(API_BASE_URL_ENV), 'useSiteVersion')
|
|
58
60
|
// @deprecated VITE_SITE_SLUG: the site is now resolved server-side from the
|
|
59
61
|
// request Host or the dedicated Container App's DCS_SITE_SLUG. It is no longer
|
|
60
62
|
// used for routing; retained only for source compatibility.
|