@duffcloudservices/cms 0.13.15 → 0.15.0

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.
@@ -0,0 +1,10 @@
1
+ // package.json
2
+ var config = {
3
+ agentApiBaseUrl: "https://portal.duffcloudservices.com",
4
+ previewPortalOrigin: "https://portal.duffcloudservices.com",
5
+ agentWidgetScriptUrl: "https://files.duffcloudservices.com/agent-widget/v1/dcs-agent-widget.js"
6
+ };
7
+
8
+ export { config };
9
+ //# sourceMappingURL=chunk-ZGVP7AKD.js.map
10
+ //# sourceMappingURL=chunk-ZGVP7AKD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../package.json"],"names":[],"mappings":";AAKE,IAAA,MAAA,GAAU;AAAA,EACR,eAAA,EAAmB,sCAAA;AAAA,EACnB,mBAAA,EAAuB,sCAAA;AAAA,EACvB,oBAAA,EAAwB;AAC1B","file":"chunk-ZGVP7AKD.js","sourcesContent":["{\n \"name\": \"@duffcloudservices/cms\",\n \"version\": \"0.15.0\",\n \"description\": \"Vue 3 composables and Vite plugins for DCS CMS integration\",\n \"type\": \"module\",\n \"config\": {\n \"agentApiBaseUrl\": \"https://portal.duffcloudservices.com\",\n \"previewPortalOrigin\": \"https://portal.duffcloudservices.com\",\n \"agentWidgetScriptUrl\": \"https://files.duffcloudservices.com/agent-widget/v1/dcs-agent-widget.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\"\n },\n \"./plugins\": {\n \"types\": \"./dist/plugins/index.d.ts\",\n \"import\": \"./dist/plugins/index.js\"\n },\n \"./editor\": {\n \"types\": \"./dist/editor/editorBridge.d.ts\",\n \"import\": \"./dist/editor/editorBridge.js\"\n },\n \"./seo\": {\n \"types\": \"./dist/seo/index.d.ts\",\n \"import\": \"./dist/seo/index.js\"\n },\n \"./components\": {\n \"import\": \"./src/components/PreviewRibbon.vue\"\n },\n \"./responsive-image\": {\n \"import\": \"./src/components/ResponsiveImage.vue\"\n },\n \"./managed-image\": {\n \"import\": \"./src/components/ManagedImage.vue\"\n },\n \"./review-showcase\": {\n \"import\": \"./src/components/DcsReviewShowcase.vue\"\n },\n \"./call-button\": {\n \"import\": \"./src/components/DcsCallButton.vue\"\n },\n \"./lite-media-embed\": {\n \"import\": \"./src/components/LiteMediaEmbed.vue\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"files\": [\n \"dist\",\n \"src/components\",\n \"src/composables\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"verify:honesty-rails\": \"node scripts/verify-honesty-rails.mjs\",\n \"probe:live-urls\": \"node scripts/probe-live-emitted-urls.mjs\",\n \"verify:served-honesty\": \"node scripts/probe-live-emitted-urls.mjs\",\n \"type-check\": \"tsc --noEmit\",\n \"lint\": \"eslint .\",\n \"lint:fix\": \"eslint . --fix\",\n \"prepublishOnly\": \"pnpm run build\"\n },\n \"peerDependencies\": {\n \"@unhead/vue\": \"^1.9.0\",\n \"playwright\": \"^1.40.0\",\n \"vue\": \"^3.4.0\"\n },\n \"peerDependenciesMeta\": {\n \"playwright\": {\n \"optional\": true\n }\n },\n \"dependencies\": {\n \"@duffcloudservices/cms-core\": \"workspace:*\",\n \"js-yaml\": \"^4.1.0\"\n },\n \"devDependencies\": {\n \"@dcs/eslint-rules\": \"workspace:*\",\n \"@dcs/test-utils\": \"workspace:*\",\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/markdown-it\": \"^14.1.0\",\n \"@types/node\": \"^20.11.0\",\n \"@unhead/vue\": \"^2.0.5\",\n \"@unhead/vue-v1\": \"npm:@unhead/vue@1.11.20\",\n \"@vitejs/plugin-vue\": \"^6.0.1\",\n \"@vitest/eslint-plugin\": \"^1.3.4\",\n \"@vue/eslint-config-typescript\": \"^14.6.0\",\n \"@vue/test-utils\": \"^2.4.0\",\n \"eslint\": \"^9.31.0\",\n \"eslint-plugin-vue\": \"~10.3.0\",\n \"jiti\": \"^2.4.2\",\n \"markdown-it\": \"^14.3.3\",\n \"tsup\": \"^8.0.0\",\n \"typescript\": \"~5.6.3\",\n \"vite\": \"^6.3.5\",\n \"vitepress\": \"1.6.4\",\n \"vitest\": \"^3.2.3\",\n \"vue\": \"^3.5.44\",\n \"vue-router\": \"^4.5.1\"\n },\n \"keywords\": [\n \"vue\",\n \"vitepress\",\n \"cms\",\n \"dcs\",\n \"composables\",\n \"duff-cloud-services\"\n ],\n \"author\": \"Duff Cloud Services\",\n \"license\": \"MIT\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/NateDuff/dcs\"\n },\n \"homepage\": \"https://portal.duffcloudservices.com\",\n \"bugs\": {\n \"url\": \"https://github.com/NateDuff/dcs/issues\"\n },\n \"engines\": {\n \"node\": \">=18.0.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n"]}
@@ -108,6 +108,15 @@ declare function revertImageOverrideIfImageKey(key: string, value: string): bool
108
108
  declare function revertImageAltOverrideIfAltKey(key: string, value: string): boolean;
109
109
  /** Clear all pending image overrides (test isolation). */
110
110
  declare function clearPendingImageOverrides(): void;
111
- declare function initEditorBridge(): void;
111
+ interface EditorBridgeOptions {
112
+ /**
113
+ * The site build's `VITE_DCS_PORTAL_ORIGIN`, passed through as it is (the
114
+ * editor plugin does this). `undefined` means the variable is not set. Any
115
+ * other value makes that origin the only one the bridge talks to; an empty
116
+ * or malformed value makes the bridge refuse every message.
117
+ */
118
+ portalOrigin?: unknown;
119
+ }
120
+ declare function initEditorBridge(options?: EditorBridgeOptions): void;
112
121
 
113
- export { type EditorReadyPayload, type SectionInfo, applyImageOverride, applyPendingImageOverrides, clearPendingImageOverrides, initEditorBridge, recordPendingImageOverride, revertImageAltOverrideIfAltKey, revertImageOverrideIfImageKey };
122
+ export { type EditorBridgeOptions, type EditorReadyPayload, type SectionInfo, applyImageOverride, applyPendingImageOverrides, clearPendingImageOverrides, initEditorBridge, recordPendingImageOverride, revertImageAltOverrideIfAltKey, revertImageOverrideIfImageKey };
@@ -1,10 +1,74 @@
1
+ import { config } from '../chunk-ZGVP7AKD.js';
2
+
1
3
  // src/editor/bridgeTrust.ts
4
+ var PREVIEW_SANDBOX_DOMAIN = "dcs-preview.dev";
5
+ var BUILT_IN_PORTAL_ORIGIN = config.previewPortalOrigin;
6
+ var LOOPBACK_HOSTS = ["localhost", "127.0.0.1", "[::1]"];
7
+ var DNS_HOST = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/;
8
+ function parseConfiguredPortalOrigin(value) {
9
+ if (typeof value !== "string" || value.length === 0 || value.length > 2048) return null;
10
+ let url;
11
+ try {
12
+ url = new URL(value);
13
+ } catch {
14
+ return null;
15
+ }
16
+ if (url.origin !== value) return null;
17
+ if (url.protocol === "https:" && DNS_HOST.test(url.hostname)) return value;
18
+ if (url.protocol === "http:" && LOOPBACK_HOSTS.includes(url.hostname)) return value;
19
+ return null;
20
+ }
21
+ function isPreviewSandboxHost(hostname) {
22
+ if (typeof hostname !== "string") return false;
23
+ let host = hostname.toLowerCase();
24
+ if (host.endsWith(".")) host = host.slice(0, -1);
25
+ return host === PREVIEW_SANDBOX_DOMAIN || host.endsWith("." + PREVIEW_SANDBOX_DOMAIN);
26
+ }
27
+ var configuredPortalOrigin = { set: false };
28
+ var sessionNonce = null;
29
+ function configurePortalOrigin(value) {
30
+ configuredPortalOrigin = value === void 0 ? { set: false } : { set: true, origin: parseConfiguredPortalOrigin(value) };
31
+ sessionNonce = null;
32
+ }
33
+ function portalTrustMode(win = globalThis.window) {
34
+ if (configuredPortalOrigin.set) return configuredPortalOrigin.origin ? "configured" : "refused";
35
+ return isPreviewSandboxHost(win.location.hostname) ? "sandbox" : "legacy";
36
+ }
37
+ var NONCE = /^[A-Za-z0-9-]{16,128}$/;
38
+ function speaksProtocol2(win = globalThis.window) {
39
+ const mode = portalTrustMode(win);
40
+ return mode === "configured" || mode === "sandbox";
41
+ }
42
+ function resetProtocolSession() {
43
+ sessionNonce = null;
44
+ }
45
+ function acceptProtocolInit(raw, win = globalThis.window) {
46
+ if (!speaksProtocol2(win)) return false;
47
+ if (!isRecord(raw) || raw.type !== "dcs:init" || !isRecord(raw.data)) return false;
48
+ const { protocol, nonce } = raw.data;
49
+ if (protocol !== 2 || typeof nonce !== "string" || !NONCE.test(nonce)) return false;
50
+ sessionNonce = nonce;
51
+ return true;
52
+ }
53
+ function withSessionNonce(data) {
54
+ if (sessionNonce === null) return data;
55
+ return isRecord(data) ? { ...data, nonce: sessionNonce } : { nonce: sessionNonce };
56
+ }
57
+ function carriesSessionNonce(raw) {
58
+ if (sessionNonce === null) return true;
59
+ return isRecord(raw) && isRecord(raw.data) && raw.data.nonce === sessionNonce;
60
+ }
2
61
  var trustedPortalOrigins = [];
3
62
  function isTrustedParentOrigin(origin, selfOrigin) {
4
63
  if (!origin || origin === "null") return false;
5
64
  return origin === selfOrigin || trustedPortalOrigins.includes(origin);
6
65
  }
7
66
  function resolveParentOrigin(win = globalThis.window) {
67
+ if (configuredPortalOrigin.set) return configuredPortalOrigin.origin;
68
+ if (isPreviewSandboxHost(win.location.hostname)) return BUILT_IN_PORTAL_ORIGIN;
69
+ return inferParentOrigin(win);
70
+ }
71
+ function inferParentOrigin(win) {
8
72
  const selfOrigin = win.location.origin;
9
73
  let candidate = null;
10
74
  try {
@@ -109,7 +173,7 @@ function postToParent(type, data) {
109
173
  if (!isInIframe()) return;
110
174
  const targetOrigin = resolveParentOrigin();
111
175
  if (!targetOrigin) return;
112
- globalThis.self.parent.postMessage({ type, data }, targetOrigin);
176
+ globalThis.self.parent.postMessage({ type, data: withSessionNonce(data) }, targetOrigin);
113
177
  }
114
178
  var TEXT_KEY_SELECTOR = "[data-text-key], [data-dcs-text]";
115
179
  var REVIEW_SELECTOR = "[data-dcs-reviews]";
@@ -1232,6 +1296,11 @@ function handleMessage(event) {
1232
1296
  if (event.source !== globalThis.self.parent) return;
1233
1297
  const parentOrigin = resolveParentOrigin();
1234
1298
  if (!parentOrigin || event.origin !== parentOrigin) return;
1299
+ if (acceptProtocolInit(event.data)) {
1300
+ rediscoverAndNotify();
1301
+ return;
1302
+ }
1303
+ if (!carriesSessionNonce(event.data)) return;
1235
1304
  const cmd = parseInboundCommand(event.data);
1236
1305
  if (!cmd) return;
1237
1306
  switch (cmd.type) {
@@ -1316,7 +1385,8 @@ function measureContentHeight(sections) {
1316
1385
  const bodyHeight = document.body.scrollHeight;
1317
1386
  return Math.max(sectionHeight, bodyHeight);
1318
1387
  }
1319
- function initEditorBridge() {
1388
+ function initEditorBridge(options) {
1389
+ if (options) configurePortalOrigin(options.portalOrigin);
1320
1390
  if (!isInIframe()) return;
1321
1391
  injectEditorHeightFix();
1322
1392
  if (!bridgeInitialized) {
@@ -1379,6 +1449,10 @@ function initEditorBridge() {
1379
1449
  const eventEl = document.querySelector(EVENT_CONTENT_SELECTOR);
1380
1450
  const blogTitleEl = document.querySelector("[data-blog-title]");
1381
1451
  const blogSummaryEl = document.querySelector("[data-blog-summary]");
1452
+ if (speaksProtocol2()) {
1453
+ resetProtocolSession();
1454
+ postToParent("dcs:hello", { protocol: 2 });
1455
+ }
1382
1456
  postToParent("dcs:ready", {
1383
1457
  sections,
1384
1458
  textKeys,