@duffcloudservices/cms 0.13.4 → 0.13.6
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/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.d.ts +10 -4
- package/dist/plugins/index.js +37 -30
- package/dist/plugins/index.js.map +1 -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/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duffcloudservices/cms",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.6",
|
|
4
4
|
"description": "Vue 3 composables and Vite plugins for DCS CMS integration",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"config": {
|
|
7
|
+
"agentApiBaseUrl": "https://portal.duffcloudservices.com",
|
|
8
|
+
"agentWidgetScriptUrl": "https://files.duffcloudservices.com/agent-widget/v1/dcs-agent-widget.js"
|
|
9
|
+
},
|
|
6
10
|
"exports": {
|
|
7
11
|
".": {
|
|
8
12
|
"types": "./dist/index.d.ts",
|
|
@@ -58,7 +62,7 @@
|
|
|
58
62
|
},
|
|
59
63
|
"dependencies": {
|
|
60
64
|
"js-yaml": "^4.1.0",
|
|
61
|
-
"@duffcloudservices/cms-core": "0.8.
|
|
65
|
+
"@duffcloudservices/cms-core": "0.8.6"
|
|
62
66
|
},
|
|
63
67
|
"devDependencies": {
|
|
64
68
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -79,7 +83,9 @@
|
|
|
79
83
|
"vite": "^6.3.5",
|
|
80
84
|
"vitest": "^3.2.3",
|
|
81
85
|
"vue": "^3.5.16",
|
|
82
|
-
"vue-router": "^4.5.1"
|
|
86
|
+
"vue-router": "^4.5.1",
|
|
87
|
+
"@dcs/test-utils": "0.1.0",
|
|
88
|
+
"@dcs/eslint-rules": "0.1.0"
|
|
83
89
|
},
|
|
84
90
|
"keywords": [
|
|
85
91
|
"vue",
|
|
@@ -1,11 +1,84 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
2
2
|
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { pinEventClock, unpinEventClock } from '@dcs/test-utils/pinEventClock'
|
|
3
4
|
import LiteMediaEmbed from './LiteMediaEmbed.vue'
|
|
4
5
|
|
|
6
|
+
// W283 (2026-09-17) — THE CLOCK PIN BELOW IS LOAD-BEARING. Do not remove it
|
|
7
|
+
// because "this spec has no timers"; it is not here for timers.
|
|
8
|
+
//
|
|
9
|
+
// CI run 35265225886 (Test Gate, commit 2fe5e0590) failed exactly two tests in
|
|
10
|
+
// this file — ":41 expected true, received false" on the YouTube facade's
|
|
11
|
+
// on-click iframe — while the same suite ran 817/817 green on a dev box minutes
|
|
12
|
+
// later. Nothing in the component or the spec had been touched in that push.
|
|
13
|
+
//
|
|
14
|
+
// The cause is the self-hosted runner's wall clock, which takes real BACKWARD
|
|
15
|
+
// steps (39 backward jumps in one run, worst -1903ms, measured by
|
|
16
|
+
// cli/check-run-log-monotonicity.mjs), and mechanism M2:
|
|
17
|
+
//
|
|
18
|
+
// invoker.attached = getNow() // = Date.now() at MOUNT
|
|
19
|
+
// const getNow = () => cachedNow || (…, cachedNow = Date.now())
|
|
20
|
+
// if (!e._vts) { e._vts = Date.now() }
|
|
21
|
+
// else if (e._vts <= invoker.attached) { return } // handler SKIPPED
|
|
22
|
+
// @vue/runtime-dom@3.5.25, runtime-dom.cjs.js:657, 660-664
|
|
23
|
+
//
|
|
24
|
+
// and vue-test-utils buys exactly ONE millisecond of headroom:
|
|
25
|
+
// event._vts = Date.now() + 1 // @vue/test-utils@2.4.6, :7322 (test-utils#1854)
|
|
26
|
+
//
|
|
27
|
+
// Both readings are plain `Date.now()` — this Vue version has no
|
|
28
|
+
// `performance.now()` fallback — so if the host clock moves back by 1ms or more
|
|
29
|
+
// between the mount and the click, `_vts <= attached` holds, Vue returns, and
|
|
30
|
+
// `await trigger('click')` RESOLVES HAVING DISPATCHED NOTHING. No error, no
|
|
31
|
+
// warning. The spec then fails on the un-mutated DOM, and the report points at
|
|
32
|
+
// the component instead of at the host.
|
|
33
|
+
//
|
|
34
|
+
// Verified locally on 2026-09-17 by stepping Date.now() back 1903ms between the
|
|
35
|
+
// mount and the click: the click is swallowed and `iframe.exists()` is false —
|
|
36
|
+
// the CI red, reproduced on a box with a healthy clock.
|
|
37
|
+
//
|
|
38
|
+
// Pinning the clock in `beforeEach` makes `Date.now()` the FAKE timer's reading,
|
|
39
|
+
// which the host cannot move. `attached` and `_vts` are then both taken from the
|
|
40
|
+
// frozen instant, `_vts` is `attached + 1`, and the handler always runs. The pin
|
|
41
|
+
// sits in `beforeEach` (never in a test body) so it runs before any mount and
|
|
42
|
+
// can never itself be the backward step — which is what
|
|
43
|
+
// `dcs-test/no-backward-clock-with-trigger` now enforces for this package.
|
|
44
|
+
//
|
|
45
|
+
// This removes ONE exposure. It does not fix the runner: every other click spec
|
|
46
|
+
// in the fleet on a real clock is still exposed, and the host clock itself is
|
|
47
|
+
// owner action C-1749 / Q-862.
|
|
48
|
+
// `toFake: ['Date']` is LOAD-BEARING and must not be dropped to a bare
|
|
49
|
+
// `useFakeTimers({ now })`. Only `Date` is the clock Vue's invoker reads, so
|
|
50
|
+
// only `Date` needs freezing; faking the timer functions as well would change
|
|
51
|
+
// `setTimeout`/`setInterval` behaviour for every other test in this file, none
|
|
52
|
+
// of which asked for it (W283 shipped that mistake and corrected it in
|
|
53
|
+
// cd48579df). W286 replaced the hand-rolled pin with the canonical helper, which
|
|
54
|
+
// C-1752 lifted out of portal into `@dcs/test-utils` precisely so a second copy
|
|
55
|
+
// of the idiom could not drift here. `pinEventClock.spec.ts` (portal) proves the
|
|
56
|
+
// Date-only guarantee on every portal run.
|
|
57
|
+
const FIXED_CLOCK = new Date('2026-01-01T00:00:00.000Z')
|
|
58
|
+
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
pinEventClock(FIXED_CLOCK)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
unpinEventClock()
|
|
65
|
+
})
|
|
66
|
+
|
|
5
67
|
const YT_URL = 'https://www.youtube.com/watch?v=vz7F8bc1QQ0'
|
|
6
68
|
const YT_ID = 'vz7F8bc1QQ0'
|
|
7
69
|
const IG_URL = 'https://www.instagram.com/p/AbCdEfGhIjK/'
|
|
8
70
|
|
|
71
|
+
describe('LiteMediaEmbed — the clock this file dispatches under', () => {
|
|
72
|
+
// W283 — the guard on the pin above. Deleting the `beforeEach` (or letting a
|
|
73
|
+
// later edit drop `now`) turns this red immediately and names the reason,
|
|
74
|
+
// rather than leaving the file to fail intermittently on a runner months
|
|
75
|
+
// later with ":41 expected true, received false".
|
|
76
|
+
it('runs under a PINNED Date.now, so a backward host clock step cannot reach Vue (M2)', () => {
|
|
77
|
+
expect(Date.now()).toBe(FIXED_CLOCK.getTime())
|
|
78
|
+
expect(new Date().getTime()).toBe(FIXED_CLOCK.getTime())
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
9
82
|
describe('LiteMediaEmbed — YouTube facade', () => {
|
|
10
83
|
it('renders the poster (thumbnail + play button) and NO iframe initially', () => {
|
|
11
84
|
const wrapper = mount(LiteMediaEmbed, {
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
2
2
|
import { mount } from '@vue/test-utils'
|
|
3
3
|
import ManagedImage from './ManagedImage.vue'
|
|
4
|
+
import { pinEventClock, unpinEventClock } from '@dcs/test-utils/pinEventClock'
|
|
5
|
+
|
|
6
|
+
// C-1752 (the Q-862 / C-1415 event-clock class): this spec MOUNTS and DISPATCHES,
|
|
7
|
+
// so Vue's `_vts <= invoker.attached` check can swallow a dispatch outright when
|
|
8
|
+
// the host clock steps BACKWARD between the mount and the event - the shape that
|
|
9
|
+
// redded CI run 35265225886 on a healthy component. Date-only pin; timers stay
|
|
10
|
+
// real, so flushPromises/nextTick/setTimeout behave exactly as before.
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
pinEventClock()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
unpinEventClock()
|
|
17
|
+
})
|
|
18
|
+
|
|
4
19
|
|
|
5
20
|
/**
|
|
6
21
|
* A CDN URL whose UUID/extension triggers responsive variant resolution
|
|
@@ -86,6 +86,8 @@
|
|
|
86
86
|
<script setup lang="ts">
|
|
87
87
|
import { ref, computed, onMounted, onBeforeUnmount, watch } from 'vue'
|
|
88
88
|
|
|
89
|
+
import { resolveApiBaseUrl } from '../composables/resolveApiBaseUrl'
|
|
90
|
+
|
|
89
91
|
/*
|
|
90
92
|
* NO cms-core VALUE imports in this file. The `./components` export ships RAW SFC
|
|
91
93
|
* source (tsup builds no .vue), so consumer sites type-check this file directly —
|
|
@@ -241,9 +243,15 @@ onMounted(async () => {
|
|
|
241
243
|
// The site is resolved server-side (request Host / DCS_SITE_SLUG); the slug
|
|
242
244
|
// is no longer encoded in the path. VITE_SITE_SLUG is retained for source
|
|
243
245
|
// compatibility but is not required here.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
246
|
+
// C-1062: the env or nothing - never a silent production default.
|
|
247
|
+
const base = resolveApiBaseUrl(
|
|
248
|
+
(import.meta.env as Record<string, string | undefined>).VITE_API_BASE_URL,
|
|
249
|
+
'PreviewRibbon',
|
|
250
|
+
)
|
|
251
|
+
// No configured base: the warning above already said why; do not read
|
|
252
|
+
// relative, where an SWA's 200 HTML shell would trip the C-298 misroute
|
|
253
|
+
// check below and blame the platform for an unset env.
|
|
254
|
+
if (base === '') return
|
|
247
255
|
// C-298 layer 2, INLINED (see the no-cms-core-value-imports note at the top of
|
|
248
256
|
// this <script>): the `catch { /* non-critical */ }` below is a swallow site, so
|
|
249
257
|
// a non-JSON (HTML-shell) body must go LOUD here before it can be swallowed.
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
2
2
|
import { mount } from '@vue/test-utils'
|
|
3
3
|
import ResponsiveImage from './ResponsiveImage.vue'
|
|
4
|
+
import { pinEventClock, unpinEventClock } from '@dcs/test-utils/pinEventClock'
|
|
5
|
+
|
|
6
|
+
// C-1752 (the Q-862 / C-1415 event-clock class): this spec MOUNTS and DISPATCHES,
|
|
7
|
+
// so Vue's `_vts <= invoker.attached` check can swallow a dispatch outright when
|
|
8
|
+
// the host clock steps BACKWARD between the mount and the event - the shape that
|
|
9
|
+
// redded CI run 35265225886 on a healthy component. Date-only pin; timers stay
|
|
10
|
+
// real, so flushPromises/nextTick/setTimeout behave exactly as before.
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
pinEventClock()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
unpinEventClock()
|
|
17
|
+
})
|
|
18
|
+
|
|
4
19
|
|
|
5
20
|
const ORIGINAL = 'https://files.duffcloudservices.com/kept/assets/hero/abc-123.jpg'
|
|
6
21
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { readFileSync, readdirSync } from 'node:fs'
|
|
3
|
-
import { join } from 'node:path'
|
|
2
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs'
|
|
3
|
+
import { dirname, join, relative, resolve } from 'node:path'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The `./components` export ships RAW SFC source (tsup builds no .vue), so every
|
|
@@ -13,9 +13,89 @@ import { join } from 'node:path'
|
|
|
13
13
|
* Measured on the 0.13.0 canary (2026-08-10): one value import in PreviewRibbon.vue
|
|
14
14
|
* would have redded CI on kept (the payer), boogie-babies, bryans and mi-handyman.
|
|
15
15
|
* `import type` is erased at compile time and stays allowed.
|
|
16
|
+
*
|
|
17
|
+
* C-1564 companion (from the C-1062 judge's F5): the guard now follows RELATIVE
|
|
18
|
+
* imports transitively from each shipped .vue, so a .vue reached through another
|
|
19
|
+
* .vue is held to the same rule. A value import of cms-core in a shipped .ts hop
|
|
20
|
+
* (src/composables, also shipped raw) is REPORTED, not failed: it is measured
|
|
21
|
+
* harmless in the fleet - handyman-bryan's own ResponsiveImage.vue wraps
|
|
22
|
+
* `@duffcloudservices/cms/responsive-image`, whose ResponsiveImage.vue imports
|
|
23
|
+
* `../composables/useResponsiveImage.ts`, which value-imports cms-core, and that
|
|
24
|
+
* site's CI type-check gate (C-303) is green on cms ^0.13.2. TS resolves a .ts
|
|
25
|
+
* module's bare imports from the module's own location inside the installed
|
|
26
|
+
* package, where cms-core is a declared dependency; the .vue case differs because
|
|
27
|
+
* vue-tsc compiles the SFC as part of the consumer's program. The known .ts hops
|
|
28
|
+
* are listed below so a NEW one is still visible in the failure text.
|
|
16
29
|
*/
|
|
17
|
-
|
|
30
|
+
|
|
31
|
+
const VALUE_IMPORT = /^\s*import\s+(?!type\b)[^;'"]*['"]@duffcloudservices\/cms-core['"]/gm
|
|
32
|
+
const RELATIVE_IMPORT = /^\s*import\s+(?:type\s+)?[^;'"]*['"](\.{1,2}\/[^'"]+)['"]/gm
|
|
33
|
+
|
|
34
|
+
export interface Hop {
|
|
35
|
+
/** Path relative to src/, forward slashes. */
|
|
36
|
+
file: string
|
|
37
|
+
/** The import chain that reached it, starting at the shipped .vue. */
|
|
38
|
+
via: string[]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface WalkResult {
|
|
42
|
+
/** Value imports of cms-core in a .vue anywhere on the chain: the broken class. */
|
|
43
|
+
vueValueImports: Hop[]
|
|
44
|
+
/** Value imports of cms-core in a .ts hop: reported, measured harmless. */
|
|
45
|
+
tsValueImports: Hop[]
|
|
46
|
+
/** Every file visited. */
|
|
47
|
+
visited: string[]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Resolve a relative specifier the way the consumer's bundler / tsc would. */
|
|
51
|
+
function resolveSpecifier(fromFile: string, spec: string, exists: (p: string) => boolean): string | null {
|
|
52
|
+
const base = resolve(dirname(fromFile), spec)
|
|
53
|
+
const candidates = [base, `${base}.ts`, `${base}.vue`, join(base, 'index.ts')]
|
|
54
|
+
for (const c of candidates) if (exists(c)) return c
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Pure walker: `read` and `exists` are injected so the polarity can be proven on
|
|
60
|
+
* an in-memory file map without touching the tree.
|
|
61
|
+
*/
|
|
62
|
+
export function walkShippedVue(
|
|
63
|
+
srcDir: string,
|
|
64
|
+
entries: string[],
|
|
65
|
+
read: (p: string) => string,
|
|
66
|
+
exists: (p: string) => boolean,
|
|
67
|
+
): WalkResult {
|
|
68
|
+
const out: WalkResult = { vueValueImports: [], tsValueImports: [], visited: [] }
|
|
69
|
+
const seen = new Set<string>()
|
|
70
|
+
const rel = (p: string) => relative(srcDir, p).replace(/\\/g, '/')
|
|
71
|
+
const visit = (file: string, via: string[]) => {
|
|
72
|
+
if (seen.has(file)) return
|
|
73
|
+
seen.add(file)
|
|
74
|
+
out.visited.push(rel(file))
|
|
75
|
+
const source = read(file)
|
|
76
|
+
const chain = [...via, rel(file)]
|
|
77
|
+
if (Array.from(source.matchAll(VALUE_IMPORT)).length > 0) {
|
|
78
|
+
;(file.endsWith('.vue') ? out.vueValueImports : out.tsValueImports).push({ file: rel(file), via: chain })
|
|
79
|
+
}
|
|
80
|
+
for (const m of source.matchAll(RELATIVE_IMPORT)) {
|
|
81
|
+
const target = resolveSpecifier(file, m[1], exists)
|
|
82
|
+
if (target) visit(target, chain)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
for (const entry of entries) visit(entry, [])
|
|
86
|
+
return out
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The .ts hops known and measured at the C-1564 landing (see the header). */
|
|
90
|
+
const KNOWN_TS_HOPS = [
|
|
91
|
+
'composables/useResponsiveImage.ts',
|
|
92
|
+
'composables/useTextContent.ts',
|
|
93
|
+
'composables/resolveApiBaseUrl.ts', // imports nothing; listed so a future cms-core import there is a deliberate change
|
|
94
|
+
].filter((f) => f !== 'composables/resolveApiBaseUrl.ts')
|
|
95
|
+
|
|
96
|
+
describe('raw-source-imports: shipped .vue exports must not value-import cms-core', () => {
|
|
18
97
|
const dir = __dirname
|
|
98
|
+
const srcDir = resolve(dir, '..')
|
|
19
99
|
const vueFiles = readdirSync(dir).filter((f) => f.endsWith('.vue'))
|
|
20
100
|
|
|
21
101
|
it('finds the raw-shipped component set (non-vacuity)', () => {
|
|
@@ -26,7 +106,7 @@ describe('raw-source .vue exports must not value-import cms-core', () => {
|
|
|
26
106
|
for (const file of vueFiles) {
|
|
27
107
|
it(`${file} has no cms-core value import`, () => {
|
|
28
108
|
const src = readFileSync(join(dir, file), 'utf8')
|
|
29
|
-
const valueImports = Array.from(src.matchAll(
|
|
109
|
+
const valueImports = Array.from(src.matchAll(VALUE_IMPORT))
|
|
30
110
|
expect(
|
|
31
111
|
valueImports.map((m) => m[0].trim()),
|
|
32
112
|
`${file} value-imports cms-core — this ships as raw source and breaks every consumer site's type-check (see header comment)`,
|
|
@@ -34,6 +114,29 @@ describe('raw-source .vue exports must not value-import cms-core', () => {
|
|
|
34
114
|
})
|
|
35
115
|
}
|
|
36
116
|
|
|
117
|
+
const walk = walkShippedVue(
|
|
118
|
+
srcDir,
|
|
119
|
+
vueFiles.map((f) => join(dir, f)),
|
|
120
|
+
(p) => readFileSync(p, 'utf8'),
|
|
121
|
+
existsSync,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
it('follows relative imports transitively: no .vue reached from a shipped .vue value-imports cms-core', () => {
|
|
125
|
+
expect(walk.visited.length).toBeGreaterThan(vueFiles.length)
|
|
126
|
+
expect(
|
|
127
|
+
walk.vueValueImports.map((h) => `${h.file} via ${h.via.join(' -> ')}`),
|
|
128
|
+
'a .vue reached through a shipped .vue value-imports cms-core (see header comment)',
|
|
129
|
+
).toEqual([])
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('every .ts hop that value-imports cms-core is a known, measured one', () => {
|
|
133
|
+
const found = walk.tsValueImports.map((h) => h.file).sort()
|
|
134
|
+
expect(
|
|
135
|
+
found,
|
|
136
|
+
'a NEW shipped .ts hop value-imports cms-core: measure it against a fleet site type-check before adding it to KNOWN_TS_HOPS',
|
|
137
|
+
).toEqual([...KNOWN_TS_HOPS].sort())
|
|
138
|
+
})
|
|
139
|
+
|
|
37
140
|
it('kill-test: the guard regex catches the 0.13.0 defect shape', () => {
|
|
38
141
|
const bad = "import { platformFetch } from '@duffcloudservices/cms-core'"
|
|
39
142
|
const good = "import type { PlatformFetchOptions } from '@duffcloudservices/cms-core'"
|
|
@@ -41,4 +144,25 @@ describe('raw-source .vue exports must not value-import cms-core', () => {
|
|
|
41
144
|
expect(Array.from(bad.matchAll(re)).length).toBe(1)
|
|
42
145
|
expect(Array.from(good.matchAll(re)).length).toBe(0)
|
|
43
146
|
})
|
|
147
|
+
|
|
148
|
+
it('polarity: a two-hop chain (.vue -> .vue -> cms-core value import) is caught; a .ts hop is reported', () => {
|
|
149
|
+
const files: Record<string, string> = {
|
|
150
|
+
'/m/src/components/A.vue': "import B from './B.vue'\nimport { x } from '../composables/useX'\n",
|
|
151
|
+
'/m/src/components/B.vue': "import { platformFetch } from '@duffcloudservices/cms-core'\n",
|
|
152
|
+
'/m/src/composables/useX.ts': "import { platformFetch } from '@duffcloudservices/cms-core'\nimport type { T } from '@duffcloudservices/cms-core'\n",
|
|
153
|
+
'/m/src/components/C.vue': "import type { T } from '@duffcloudservices/cms-core'\nimport { y } from '../composables/useY'\n",
|
|
154
|
+
'/m/src/composables/useY.ts': "import { ref } from 'vue'\n",
|
|
155
|
+
}
|
|
156
|
+
// path.resolve on Windows prefixes the drive letter; the in-memory map has none.
|
|
157
|
+
const norm = (p: string) => p.replace(/\\/g, '/').replace(/^[A-Za-z]:/, '')
|
|
158
|
+
const r = walkShippedVue(
|
|
159
|
+
'/m/src',
|
|
160
|
+
['/m/src/components/A.vue', '/m/src/components/C.vue'],
|
|
161
|
+
(p) => files[norm(p)] ?? '',
|
|
162
|
+
(p) => norm(p) in files,
|
|
163
|
+
)
|
|
164
|
+
expect(r.vueValueImports.map((h) => h.via.join(' -> '))).toEqual(['components/A.vue -> components/B.vue'])
|
|
165
|
+
expect(r.tsValueImports.map((h) => h.file)).toEqual(['composables/useX.ts'])
|
|
166
|
+
expect(r.visited).toContain('composables/useY.ts')
|
|
167
|
+
})
|
|
44
168
|
})
|
|
@@ -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.
|