@veroxm/react-sdk 1.6.0 → 1.7.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.7.0
4
+
5
+ - Product journeys: `<VeroxmJourney src="https://buy.example.com/ar/sports-insurance" />` (or `baseUrl` + `journey`)
6
+ shows a VeroXM quote-and-buy journey in your page, as published: its screens, shared blocks, brand and colours. It
7
+ runs in a frame of the hosted page, so prices, eligibility and payment links stay with VeroXM. `lang`, `chrome={false}`
8
+ (only the journey, for a page with its own header), `height`, and `onReady`, `onScreen`, `onLocaleChange`,
9
+ `onComplete`, `onEvent` (screen ids and steps, never what the person typed). The finish is recorded as
10
+ `$journey_completed` with the `<VeroxmTrackerProvider>`'s tracker (`track={false}` to skip). The journey must list
11
+ your site under Embedding; needs the VeroXM version with embeddable journeys (2026-10-27).
12
+
3
13
  ## 1.6.0
4
14
 
5
15
  - Query text: `useEntries(collection, { q })`, `listEntries` and the server helpers take `q`, one readable line instead
package/README.md CHANGED
@@ -282,6 +282,25 @@ function Account() {
282
282
  </SignedIn>;
283
283
  ```
284
284
 
285
+ ## Product journeys
286
+
287
+ A VeroXM quote-and-buy journey in your page, as published (its screens, shared blocks, brand and colours):
288
+
289
+ ```tsx
290
+ import { VeroxmJourney } from '@veroxm/react-sdk';
291
+
292
+ <VeroxmJourney src="https://buy.example.com/ar/sports-insurance" />
293
+
294
+ // Or by its link, without the brand around it, for a page with its own header:
295
+ <VeroxmJourney baseUrl="https://cms.example.com" journey="j_Ab3dEf7hJk9mNpQr2sTu" lang="en" chrome={false}
296
+ height={720} onScreen={(e) => console.log(e.step)} onComplete={() => router.push('/thank-you')} />
297
+ ```
298
+
299
+ It runs in a frame of the hosted journey: prices, eligibility and payment links stay with VeroXM, and events carry
300
+ screen ids and steps only, never what the person typed. List your site's origin under **Embedding** in the journey's
301
+ Look and brand (or in its page layout), or the browser refuses to show it. Works the same in Next.js (a client
302
+ component). The finish is recorded as `$journey_completed` with the `<VeroxmTrackerProvider>`'s tracker.
303
+
285
304
  ## Visitor tracking
286
305
 
287
306
  Pair with `@veroxm/sdk`'s `createTracker()` (see that package's README for
@@ -46,7 +46,7 @@ let routeBase = ROUTE_BASE;
46
46
  /** Where the server mounted veroxmMiddleware. Default '/api/veroxm'. */
47
47
  export function configureClientSlots(options) {
48
48
  if (options.routeBase)
49
- routeBase = options.routeBase.replace(/\/+$/, '');
49
+ routeBase = withoutTrailingSlashes(options.routeBase);
50
50
  }
51
51
  const pending = new Map();
52
52
  let scheduled = false;
@@ -170,3 +170,10 @@ export function resetClientSlotsForTests() {
170
170
  routeBase = ROUTE_BASE;
171
171
  resetSentFallbacksForTests();
172
172
  }
173
+ /** `url` without trailing slashes (a loop: /\/+$/ goes over a long run of slashes again from each position). */
174
+ function withoutTrailingSlashes(url) {
175
+ let end = url.length;
176
+ while (end > 0 && url[end - 1] === '/')
177
+ end--;
178
+ return url.slice(0, end);
179
+ }
package/dist/index.d.ts CHANGED
@@ -42,6 +42,8 @@ export type { VideoRef, VideoProvider } from './site/video.js';
42
42
  export type { CollectionFieldMeta, CollectionMeta, Entry, EntryConnection, EntriesQueryOptions, MediaView, MediaHotspot, WhereClause, } from './types.js';
43
43
  export { VeroxmForm, useVeroxmForm } from './form.js';
44
44
  export type { VeroxmFormProps, VeroxmFormOptions, VeroxmFormMode, VeroxmFormHandle } from './form.js';
45
+ export { VeroxmJourney } from './journey.js';
46
+ export type { VeroxmJourneyProps, VeroxmJourneyEvent } from './journey.js';
45
47
  export { VeroxmTrackerProvider, useTracker, usePageViews, useExperience, Experience, useContentView, useRecommendations, useSlotImpression, VeroxmSlotImpression, } from './tracking.js';
46
48
  export type { VeroxmTrackerProviderProps, VeroxmTrackerLike, ExperienceDecision, ExperienceState, ExperienceProps, RecommendationsState, VeroxmSlotImpressionProps, } from './tracking.js';
47
49
  export { VeroxmSlot, useSlot, field, configureSlots, loadSlot, mergeSlotValues } from './slots.js';
package/dist/index.js CHANGED
@@ -28,6 +28,8 @@ export { chartSvg, chartSummary, formatChartNumber, chartFromRows, chartDataFrom
28
28
  export { parseVideoUrl, videoEmbedUrl, videoThumbnailUrl } from './site/video.js';
29
29
  // Forms: inline, popup, full page or toast, through the embed script of your VeroXM address.
30
30
  export { VeroxmForm, useVeroxmForm } from './form.js';
31
+ // Product journeys: a quote-and-buy journey in your page, in a frame of its hosted page.
32
+ export { VeroxmJourney } from './journey.js';
31
33
  // Experience OS visitor tracking -- pair with @veroxm/sdk's createTracker().
32
34
  export { VeroxmTrackerProvider, useTracker, usePageViews, useExperience, Experience, useContentView, useRecommendations, useSlotImpression, VeroxmSlotImpression, } from './tracking.js';
33
35
  // Visual slots (Experience Layer): named regions marketers edit from VeroXM.
@@ -0,0 +1,76 @@
1
+ import { type CSSProperties } from 'react';
2
+ /** What the journey tells your page (never what the person typed). */
3
+ export type VeroxmJourneyEvent = {
4
+ event: 'ready';
5
+ journey: string;
6
+ locale: string;
7
+ } | {
8
+ event: 'screen';
9
+ journey: string;
10
+ screen: string;
11
+ step: string | null;
12
+ dialog: string | null;
13
+ } | {
14
+ event: 'locale';
15
+ journey: string;
16
+ locale: string;
17
+ } | {
18
+ event: 'complete';
19
+ journey: string;
20
+ };
21
+ export interface VeroxmJourneyProps {
22
+ /**
23
+ * The journey's address: its readable one (`https://buy.example.com/en/sports-insurance`) or its link
24
+ * (`https://cms.example.com/j/j_Ab3dEf7hJk9mNpQr2sTu`).
25
+ */
26
+ src?: string;
27
+ /** Or your VeroXM address and the journey's public id (j_...). */
28
+ baseUrl?: string;
29
+ journey?: string;
30
+ /** The language to show ("ar"), when the journey has it; otherwise the address's, then the visitor's browser's. */
31
+ lang?: string;
32
+ /** false: only the journey -- no logo, side stepper, footer links or top icons -- for a page with its own header. */
33
+ chrome?: boolean;
34
+ /** The frame's height: pixels or any CSS length (default 760). `"100%"` fills a sized parent. */
35
+ height?: number | string;
36
+ /** The frame's name for screen readers (default "Insurance quote"). */
37
+ title?: string;
38
+ className?: string;
39
+ style?: CSSProperties;
40
+ onReady?: (e: Extract<VeroxmJourneyEvent, {
41
+ event: 'ready';
42
+ }>) => void;
43
+ onScreen?: (e: Extract<VeroxmJourneyEvent, {
44
+ event: 'screen';
45
+ }>) => void;
46
+ onLocaleChange?: (e: Extract<VeroxmJourneyEvent, {
47
+ event: 'locale';
48
+ }>) => void;
49
+ onComplete?: (e: Extract<VeroxmJourneyEvent, {
50
+ event: 'complete';
51
+ }>) => void;
52
+ /** Every event, as it comes. */
53
+ onEvent?: (e: VeroxmJourneyEvent) => void;
54
+ /**
55
+ * Record the finish as `$journey_completed` (usable as an experience's goal) with the `<VeroxmTrackerProvider>`'s
56
+ * tracker. Default true; false records nothing.
57
+ */
58
+ track?: boolean;
59
+ }
60
+ /**
61
+ * The frame's address: the journey's, with ?embed=1, the language, chrome=0 and the page's own origin (where the
62
+ * journey sends its events). Null when neither src nor baseUrl + journey make an http(s) address. @internal
63
+ */
64
+ export declare function journeyFrameUrl(p: Pick<VeroxmJourneyProps, 'src' | 'baseUrl' | 'journey' | 'lang' | 'chrome'>, parent: string | null): URL | null;
65
+ /** A message from the journey's frame, checked: from its origin and window, in the journey's own format. @internal */
66
+ export declare function journeyEventOf(data: unknown): VeroxmJourneyEvent | null;
67
+ /**
68
+ * A VeroXM product journey in your page.
69
+ *
70
+ * ```tsx
71
+ * <VeroxmJourney src="https://buy.example.com/ar/sports-insurance" />
72
+ * <VeroxmJourney baseUrl="https://cms.example.com" journey="j_Ab3dEf7hJk9mNpQr2sTu" lang="en" chrome={false}
73
+ * onComplete={() => router.push('/thank-you')} />
74
+ * ```
75
+ */
76
+ export declare function VeroxmJourney({ src, baseUrl, journey, lang, chrome, height, title, className, style, track, ...handlers }: VeroxmJourneyProps): import("react").JSX.Element;
@@ -0,0 +1,114 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect, useMemo, useRef, useState } from 'react';
4
+ import { useTracker } from './tracking.js';
5
+ const LANG_PATH = /^\/([a-z]{2,3}(?:-[A-Za-z]{2,4})?)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)\/?$/;
6
+ /**
7
+ * The frame's address: the journey's, with ?embed=1, the language, chrome=0 and the page's own origin (where the
8
+ * journey sends its events). Null when neither src nor baseUrl + journey make an http(s) address. @internal
9
+ */
10
+ export function journeyFrameUrl(p, parent) {
11
+ let url;
12
+ try {
13
+ if (p.src)
14
+ url = new URL(p.src);
15
+ else if (p.baseUrl && p.journey && /^j_[A-Za-z0-9]{20}$/.test(p.journey))
16
+ url = new URL(`/j/${p.journey}`, p.baseUrl);
17
+ else
18
+ return null;
19
+ }
20
+ catch {
21
+ return null;
22
+ }
23
+ if (url.protocol !== 'https:' && url.protocol !== 'http:')
24
+ return null;
25
+ if (p.lang) {
26
+ // A readable address carries the language in its path (/ar/sports-insurance); a link takes ?lang=.
27
+ const at = LANG_PATH.exec(url.pathname);
28
+ if (at)
29
+ url.pathname = `/${p.lang}/${at[2]}`;
30
+ else
31
+ url.searchParams.set('lang', p.lang);
32
+ }
33
+ url.searchParams.set('embed', '1');
34
+ if (p.chrome === false)
35
+ url.searchParams.set('chrome', '0');
36
+ if (parent)
37
+ url.searchParams.set('parent', parent);
38
+ return url;
39
+ }
40
+ /** A message from the journey's frame, checked: from its origin and window, in the journey's own format. @internal */
41
+ export function journeyEventOf(data) {
42
+ const d = data;
43
+ if (!d || typeof d !== 'object' || d.source !== 'veroxm-journey' || d.version !== 1 || typeof d.journey !== 'string')
44
+ return null;
45
+ const journey = d.journey;
46
+ const str = (v) => (typeof v === 'string' ? v : null);
47
+ switch (d.event) {
48
+ case 'ready':
49
+ return { event: 'ready', journey, locale: str(d.locale) ?? '' };
50
+ case 'screen':
51
+ return typeof d.screen === 'string' ? { event: 'screen', journey, screen: d.screen, step: str(d.step), dialog: str(d.dialog) } : null;
52
+ case 'locale':
53
+ return { event: 'locale', journey, locale: str(d.locale) ?? '' };
54
+ case 'complete':
55
+ return { event: 'complete', journey };
56
+ default:
57
+ return null;
58
+ }
59
+ }
60
+ /**
61
+ * A VeroXM product journey in your page.
62
+ *
63
+ * ```tsx
64
+ * <VeroxmJourney src="https://buy.example.com/ar/sports-insurance" />
65
+ * <VeroxmJourney baseUrl="https://cms.example.com" journey="j_Ab3dEf7hJk9mNpQr2sTu" lang="en" chrome={false}
66
+ * onComplete={() => router.push('/thank-you')} />
67
+ * ```
68
+ */
69
+ export function VeroxmJourney({ src, baseUrl, journey, lang, chrome, height = 760, title = 'Insurance quote', className, style, track = true, ...handlers }) {
70
+ const frame = useRef(null);
71
+ // The page's own origin is known only in the browser: the frame is made there.
72
+ const [parent, setParent] = useState(null);
73
+ useEffect(() => setParent(window.location.origin), []);
74
+ const url = useMemo(() => (parent ? journeyFrameUrl({ src, baseUrl, journey, lang, chrome }, parent) : null), [src, baseUrl, journey, lang, chrome, parent]);
75
+ // Handlers change on every render; the listener calls the latest ones.
76
+ const latest = useRef({ handlers, track });
77
+ latest.current = { handlers, track };
78
+ const tracker = useTracker();
79
+ const trackerRef = useRef(tracker);
80
+ trackerRef.current = tracker;
81
+ const origin = url?.origin;
82
+ useEffect(() => {
83
+ if (!origin)
84
+ return;
85
+ const onMessage = (m) => {
86
+ if (m.origin !== origin || m.source !== frame.current?.contentWindow)
87
+ return;
88
+ const e = journeyEventOf(m.data);
89
+ if (!e)
90
+ return;
91
+ const h = latest.current.handlers;
92
+ h.onEvent?.(e);
93
+ if (e.event === 'ready')
94
+ h.onReady?.(e);
95
+ else if (e.event === 'screen')
96
+ h.onScreen?.(e);
97
+ else if (e.event === 'locale')
98
+ h.onLocaleChange?.(e);
99
+ else if (e.event === 'complete') {
100
+ if (latest.current.track)
101
+ trackerRef.current.track('$journey_completed', { journey: e.journey });
102
+ h.onComplete?.(e);
103
+ }
104
+ };
105
+ window.addEventListener('message', onMessage);
106
+ return () => window.removeEventListener('message', onMessage);
107
+ }, [origin]);
108
+ const box = { display: 'block', width: '100%', height: typeof height === 'number' ? `${height}px` : height, border: 0, ...style };
109
+ if (!url)
110
+ return _jsx("div", { className: className, style: box, "data-veroxm-journey-box": "" });
111
+ return (_jsx("iframe", { ref: frame, src: url.toString(), title: title, className: className, style: box,
112
+ // Payment links open in a new tab; copy-link buttons use the clipboard.
113
+ allow: "clipboard-write", sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", referrerPolicy: "strict-origin-when-cross-origin", "data-veroxm-journey": "" }));
114
+ }
@@ -17,7 +17,8 @@ const round6 = (v) => Math.round(v * 1e6) / 1e6;
17
17
  */
18
18
  export function parseMapLink(input) {
19
19
  const text = input.trim();
20
- const pair = /^(-?\d{1,2}(?:\.\d+)?)\s*[,\s]\s*(-?\d{1,3}(?:\.\d+)?)$/.exec(text);
20
+ // "lat, lng" or "lat lng": a comma with any spaces, or spaces alone (one way to match each, so no slow backtracking).
21
+ const pair = /^(-?\d{1,2}(?:\.\d+)?)(?:\s*,\s*|\s+)(-?\d{1,3}(?:\.\d+)?)$/.exec(text);
21
22
  if (pair) {
22
23
  const lat = Number(pair[1]);
23
24
  const lng = Number(pair[2]);
@@ -12,7 +12,7 @@ export function isSafeMenuHref(href) {
12
12
  const samePage = (href, current) => {
13
13
  if (!current || !href.startsWith('/'))
14
14
  return false;
15
- const clean = (p) => p.split(/[?#]/)[0].replace(/\/+$/, '') || '/';
15
+ const clean = (p) => withoutTrailingSlashes(p.split(/[?#]/)[0]) || '/';
16
16
  return clean(href) === clean(current);
17
17
  };
18
18
  function MenuLink({ item, currentPath, Link, onNavigate }) {
@@ -79,3 +79,10 @@ export function NavMenu({ items, label = 'Main', currentPath, linkComponent = 'a
79
79
  return null;
80
80
  return (_jsxs("nav", { ref: navRef, "aria-label": label, className: `vxs-nav${className ? ` ${className}` : ''}`, ...editProps, children: [_jsxs("button", { type: "button", className: "vxs-nav-toggle", "aria-expanded": mobileOpen, "aria-controls": `${id}-list`, onClick: () => setMobileOpen((v) => !v), children: [_jsx("span", { className: "vxs-burger", "aria-hidden": "true" }), _jsx("span", { className: "vxs-nav-toggle-text", children: toggleLabel })] }), list(items, '', 1)] }));
81
81
  }
82
+ /** `url` without trailing slashes (a loop: /\/+$/ goes over a long run of slashes again from each position). */
83
+ function withoutTrailingSlashes(url) {
84
+ let end = url.length;
85
+ while (end > 0 && url[end - 1] === '/')
86
+ end--;
87
+ return url.slice(0, end);
88
+ }
@@ -62,7 +62,7 @@ function env(name) {
62
62
  }
63
63
  /** The effective slots configuration (configureSlots over environment variables). */
64
64
  export function resolveSlotsConfig() {
65
- const baseUrl = (config.baseUrl ?? env('VEROXM_API_BASE') ?? '').replace(/\/+$/, '');
65
+ const baseUrl = withoutTrailingSlashes(config.baseUrl ?? env('VEROXM_API_BASE') ?? '');
66
66
  const projectId = config.projectId ?? env('VEROXM_PROJECT_ID') ?? '';
67
67
  const apiKey = config.apiKey ?? env('VEROXM_API_KEY') ?? '';
68
68
  return {
@@ -423,3 +423,10 @@ export function resetSlotsForTests() {
423
423
  flushScheduled = false;
424
424
  reportScheduled = false;
425
425
  }
426
+ /** `url` without trailing slashes (a loop: /\/+$/ goes over a long run of slashes again from each position). */
427
+ function withoutTrailingSlashes(url) {
428
+ let end = url.length;
429
+ while (end > 0 && url[end - 1] === '/')
430
+ end--;
431
+ return url.slice(0, end);
432
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@veroxm/react-sdk",
3
- "version": "1.6.0",
4
- "description": "React and Next.js SDK for VeroXM: content hooks, visual slots with A/B tests, the on-page editor, llms.txt and structured data.",
3
+ "version": "1.7.0",
4
+ "description": "React and Next.js SDK for VeroXM: content hooks, visual slots with A/B tests, the on-page editor, forms and product journeys, llms.txt and structured data.",
5
5
  "keywords": [
6
6
  "veroxm",
7
7
  "react",