@veroxm/react-sdk 1.4.0 → 1.6.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.
@@ -34,8 +34,59 @@ export type SlotFieldDef = (BaseField & {
34
34
  max?: number;
35
35
  }) | (BaseField & {
36
36
  type: 'chart';
37
+ }) | (BaseField & {
38
+ type: 'component';
39
+ components: Record<string, ComponentSchema>;
37
40
  });
38
41
  export type SlotFieldDefs = Record<string, SlotFieldDef>;
42
+ /** What VeroXM is told about a registered component: its fields, and the version of that field list. */
43
+ export interface ComponentSchema<F extends SlotFieldDefs = SlotFieldDefs> {
44
+ label?: string;
45
+ /** Raise it when the fields change in a way values saved for the old fields don't fit. */
46
+ version: number;
47
+ fields: F;
48
+ }
49
+ /**
50
+ * A component registered with defineComponent: its schema, plus the React component that renders it. The render
51
+ * component gets the values a marketer entered, typed from `fields`.
52
+ */
53
+ export interface RegisteredComponent<N extends string = string, F extends SlotFieldDefs = SlotFieldDefs> extends ComponentSchema<F> {
54
+ name: N;
55
+ render(props: {
56
+ values: SlotValues<F>;
57
+ }): ReactNode;
58
+ }
59
+ /** A component field's value: the registered component chosen, the version its values were saved for, and its values. */
60
+ export interface SlotComponentValue<N extends string = string, F extends SlotFieldDefs = SlotFieldDefs> {
61
+ component: N;
62
+ /** The component's version when the values were saved; null for a fallback from code. */
63
+ version: number | null;
64
+ values: SlotValues<F>;
65
+ }
66
+ type ComponentsOf<L extends readonly RegisteredComponent[]> = {
67
+ [C in L[number] as C['name']]: ComponentSchema<C['fields']>;
68
+ };
69
+ /**
70
+ * Registers a component marketers can choose for a place on the page (a component field, or <VeroxmRegion>). Only
71
+ * `fields` are ever editable: VeroXM stores values for them, checked like any slot field's, and never code.
72
+ *
73
+ * ```tsx
74
+ * export const Hero = defineComponent('hero', {
75
+ * label: 'Hero',
76
+ * version: 1,
77
+ * fields: { title: field.text({ max: 80, required: true }), image: field.media() },
78
+ * render: ({ values }) => <section><h1>{values.title}</h1></section>,
79
+ * });
80
+ * ```
81
+ */
82
+ export declare function defineComponent<const N extends string, F extends SlotFieldDefs>(name: N, def: {
83
+ label?: string;
84
+ version?: number;
85
+ fields: F;
86
+ render: (props: {
87
+ values: SlotValues<F>;
88
+ }) => ReactNode;
89
+ }): RegisteredComponent<N, F>;
39
90
  /** Field builders for a slot's `fields` prop. */
40
91
  export declare const field: {
41
92
  text: (o?: BaseField & {
@@ -119,7 +170,19 @@ export declare const field: {
119
170
  required?: boolean;
120
171
  type: "chart";
121
172
  };
173
+ /**
174
+ * One of the components you registered (defineComponent), chosen by a marketer, with that component's own fields.
175
+ * A component's fields can't be components or charts. Render the value with renderComponent.
176
+ */
177
+ component: <const L extends readonly RegisteredComponent[]>(components: L, o?: BaseField) => {
178
+ label?: string;
179
+ required?: boolean;
180
+ type: "component";
181
+ components: ComponentsOf<L>;
182
+ };
122
183
  };
184
+ /** The schemas of registered components, by name (what is reported to VeroXM; the render functions stay in code). */
185
+ export declare function componentSchemas(components: readonly RegisteredComponent[]): Record<string, ComponentSchema>;
123
186
  /** A media field's value: the image as stored in the VeroXM media library. */
124
187
  export interface SlotMedia {
125
188
  id: number;
@@ -202,7 +265,12 @@ type SlotValue<F> = F extends {
202
265
  type: 'map';
203
266
  } ? SlotMap | null : F extends {
204
267
  type: 'chart';
205
- } ? SlotChart | null : never;
268
+ } ? SlotChart | null : F extends {
269
+ type: 'component';
270
+ components: infer C extends Record<string, ComponentSchema>;
271
+ } ? {
272
+ [K in keyof C & string]: SlotComponentValue<K, C[K]['fields']>;
273
+ }[keyof C & string] | null : never;
206
274
  /** The values a slot renders with, typed from its field definitions. */
207
275
  export type SlotValues<F extends SlotFieldDefs> = {
208
276
  [K in keyof F]: SlotValue<F[K]>;
@@ -251,6 +319,11 @@ export interface SlotsConfig {
251
319
  * page reaches the browser. Default: VEROXM_EDGE=1.
252
320
  */
253
321
  edge?: boolean;
322
+ /**
323
+ * The secret of a project webhook (Settings > Webhooks) sent to your /api/veroxm/revalidate route: content changes
324
+ * then refresh cached content reads at once. Default: VEROXM_WEBHOOK_SECRET. Server only.
325
+ */
326
+ webhookSecret?: string;
254
327
  }
255
328
  /** Overrides the environment-variable defaults for every slot in this process. */
256
329
  export declare function configureSlots(next: SlotsConfig): void;
@@ -263,6 +336,7 @@ export declare function resolveSlotsConfig(): {
263
336
  report: boolean;
264
337
  revalidate: number;
265
338
  edge: boolean;
339
+ webhookSecret: string;
266
340
  fetch: typeof fetch | undefined;
267
341
  ready: boolean;
268
342
  };
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Registers a component marketers can choose for a place on the page (a component field, or <VeroxmRegion>). Only
3
+ * `fields` are ever editable: VeroXM stores values for them, checked like any slot field's, and never code.
4
+ *
5
+ * ```tsx
6
+ * export const Hero = defineComponent('hero', {
7
+ * label: 'Hero',
8
+ * version: 1,
9
+ * fields: { title: field.text({ max: 80, required: true }), image: field.media() },
10
+ * render: ({ values }) => <section><h1>{values.title}</h1></section>,
11
+ * });
12
+ * ```
13
+ */
14
+ export function defineComponent(name, def) {
15
+ return { name, label: def.label, version: def.version ?? 1, fields: def.fields, render: def.render };
16
+ }
1
17
  /** Field builders for a slot's `fields` prop. */
2
18
  export const field = {
3
19
  text: (o = {}) => ({ type: 'text', ...o }),
@@ -17,7 +33,23 @@ export const field = {
17
33
  map: (o = {}) => ({ type: 'map', ...o }),
18
34
  /** A chart: numbers typed in, read from your own systems (Connected APIs), or from VeroXM's analytics. */
19
35
  chart: (o = {}) => ({ type: 'chart', ...o }),
36
+ /**
37
+ * One of the components you registered (defineComponent), chosen by a marketer, with that component's own fields.
38
+ * A component's fields can't be components or charts. Render the value with renderComponent.
39
+ */
40
+ component: (components, o = {}) => ({
41
+ type: 'component',
42
+ components: componentSchemas(components),
43
+ ...o,
44
+ }),
20
45
  };
46
+ /** The schemas of registered components, by name (what is reported to VeroXM; the render functions stay in code). */
47
+ export function componentSchemas(components) {
48
+ const out = {};
49
+ for (const c of components)
50
+ out[c.name] = { ...(c.label ? { label: c.label } : {}), version: c.version, fields: c.fields };
51
+ return out;
52
+ }
21
53
  let config = {};
22
54
  let warned = false;
23
55
  /** Overrides the environment-variable defaults for every slot in this process. */
@@ -41,6 +73,7 @@ export function resolveSlotsConfig() {
41
73
  report: config.report ?? isServer,
42
74
  revalidate: config.revalidate ?? 30,
43
75
  edge: config.edge ?? ['1', 'true'].includes((env('VEROXM_EDGE') ?? '').toLowerCase()),
76
+ webhookSecret: config.webhookSecret ?? env('VEROXM_WEBHOOK_SECRET') ?? '',
44
77
  fetch: config.fetch ?? (typeof fetch === 'function' ? fetch.bind(globalThis) : undefined),
45
78
  ready: Boolean(baseUrl && projectId && apiKey),
46
79
  };
@@ -242,13 +275,38 @@ function emptyValue(def) {
242
275
  export function mergeSlotValues(fields, fallback, published) {
243
276
  const out = {};
244
277
  for (const [name, def] of Object.entries(fields)) {
278
+ const fb = fallback?.[name];
279
+ if (def.type === 'component') {
280
+ out[name] = mergeComponentValue(def.components, published?.[name], fb);
281
+ continue;
282
+ }
245
283
  const live = published?.[name];
246
284
  const hasLive = live !== undefined && live !== null && live !== '';
247
- const fb = fallback?.[name];
248
285
  out[name] = hasLive ? live : fb !== undefined && fb !== null ? fb : emptyValue(def);
249
286
  }
250
287
  return out;
251
288
  }
289
+ function asComponentValue(v) {
290
+ return v && typeof v === 'object' && !Array.isArray(v) && typeof v.component === 'string'
291
+ ? v
292
+ : null;
293
+ }
294
+ /**
295
+ * A component field's value: the published choice when it names a component the code still registers, else the
296
+ * fallback's; its values merged field by field like a slot's (the fallback's values only when it chose the same
297
+ * component). Null when there is neither.
298
+ */
299
+ function mergeComponentValue(components, published, fallback) {
300
+ const live = asComponentValue(published);
301
+ const fb = asComponentValue(fallback);
302
+ const chosen = live && components[live.component] ? live : fb && components[fb.component] ? fb : null;
303
+ if (!chosen)
304
+ return null;
305
+ const schema = components[chosen.component];
306
+ const sameAsFallback = fb && fb.component === chosen.component ? fb.values : undefined;
307
+ const values = mergeSlotValues(schema.fields, sameAsFallback, chosen === live ? (live.values ?? {}) : null);
308
+ return { component: chosen.component, version: chosen === live ? (live.version ?? null) : null, values };
309
+ }
252
310
  /** SlotInfo for published content (or the fallback when null). */
253
311
  export function slotInfo(name, published) {
254
312
  return {
@@ -33,6 +33,20 @@ export interface VeroxmTrackerLike {
33
33
  subscribe?(listener: () => void): () => void;
34
34
  /** Recommendations (Phase 3). Optional like getExperience. */
35
35
  viewContent?(contentId: number, properties?: Record<string, unknown>): void;
36
+ /**
37
+ * Standard events (@veroxm/sdk 1.10): `$slot_impression` and `$form_submitted`. Optional so older trackers still
38
+ * type-check; without them nothing is recorded.
39
+ * @since 1.5.0
40
+ */
41
+ slotImpression?(slot: string, test?: {
42
+ experienceId: number;
43
+ variantId: number;
44
+ } | null): void;
45
+ /** @since 1.5.0 */
46
+ formSubmitted?(form: string, submission?: {
47
+ responseId?: string;
48
+ endingId?: string | null;
49
+ }): void;
36
50
  getRecommendations?<TEntry = Record<string, unknown>>(collection: string, options?: {
37
51
  limit?: number;
38
52
  exclude?: number[];
@@ -125,6 +139,34 @@ export interface ExperienceProps<TContent, TConfig> {
125
139
  * the fallback, so "control = the current site" needs no extra code.
126
140
  */
127
141
  export declare function Experience<TContent = Record<string, unknown>, TConfig = Record<string, unknown>>({ placement, fallback, loading, timeoutMs, children, }: ExperienceProps<TContent, TConfig>): ReactElement;
142
+ /**
143
+ * Records that a slot was shown (`$slot_impression`), with the visitor's variant when it is under test. Pass null
144
+ * while there is nothing to count yet (still loading, or in the on-page editor). The tracker counts each slot and
145
+ * variant once per page view. `<VeroxmSlot>` from '@veroxm/react-sdk/client' does this for you.
146
+ * @since 1.5.0
147
+ */
148
+ export declare function useSlotImpression(slot: string | null | undefined, test?: {
149
+ experienceId: number;
150
+ variantId: number;
151
+ } | null): void;
152
+ export interface VeroxmSlotImpressionProps {
153
+ /** The slot's name (`slot.name`). */
154
+ name: string;
155
+ /** The visitor's variant (`slot.test`), when the slot is under test. */
156
+ test?: {
157
+ experienceId: number;
158
+ variantId: number;
159
+ } | null;
160
+ /** True in VeroXM's on-page editor (`slot.editing`): nothing is recorded. */
161
+ editing?: boolean;
162
+ }
163
+ /**
164
+ * Records a `$slot_impression` for a slot rendered by a Server Component, which can't use the tracker itself:
165
+ * `{(values, slot) => <><Hero {...values} /><VeroxmSlotImpression name={slot.name} test={slot.test} editing={slot.editing} /></>}`.
166
+ * Renders nothing. Needs a `<VeroxmTrackerProvider>` above it.
167
+ * @since 1.5.0
168
+ */
169
+ export declare function VeroxmSlotImpression({ name, test, editing }: VeroxmSlotImpressionProps): null;
128
170
  /** Records one view of a CMS entry when it is shown (the signal behind recommendations). */
129
171
  export declare function useContentView(contentId: number | null | undefined, properties?: Record<string, unknown>): void;
130
172
  export interface RecommendationsState<TEntry> {
package/dist/tracking.js CHANGED
@@ -104,6 +104,32 @@ export function Experience({ placement, fallback, loading, timeoutMs, children,
104
104
  return _jsx(_Fragment, { children: fallback });
105
105
  return _jsx(_Fragment, { children: children(d) });
106
106
  }
107
+ /**
108
+ * Records that a slot was shown (`$slot_impression`), with the visitor's variant when it is under test. Pass null
109
+ * while there is nothing to count yet (still loading, or in the on-page editor). The tracker counts each slot and
110
+ * variant once per page view. `<VeroxmSlot>` from '@veroxm/react-sdk/client' does this for you.
111
+ * @since 1.5.0
112
+ */
113
+ export function useSlotImpression(slot, test) {
114
+ const tracker = useTracker();
115
+ const experienceId = test?.experienceId;
116
+ const variantId = test?.variantId;
117
+ useEffect(() => {
118
+ if (!slot)
119
+ return;
120
+ tracker.slotImpression?.(slot, experienceId && variantId ? { experienceId, variantId } : null);
121
+ }, [slot, experienceId, variantId, tracker]);
122
+ }
123
+ /**
124
+ * Records a `$slot_impression` for a slot rendered by a Server Component, which can't use the tracker itself:
125
+ * `{(values, slot) => <><Hero {...values} /><VeroxmSlotImpression name={slot.name} test={slot.test} editing={slot.editing} /></>}`.
126
+ * Renders nothing. Needs a `<VeroxmTrackerProvider>` above it.
127
+ * @since 1.5.0
128
+ */
129
+ export function VeroxmSlotImpression({ name, test, editing }) {
130
+ useSlotImpression(editing ? null : name, test);
131
+ return null;
132
+ }
107
133
  /** Records one view of a CMS entry when it is shown (the signal behind recommendations). */
108
134
  export function useContentView(contentId, properties) {
109
135
  const tracker = useTracker();
package/dist/types.d.ts CHANGED
@@ -57,6 +57,11 @@ export interface EntriesQueryOptions {
57
57
  where?: WhereClause[];
58
58
  /** e.g. "created_at:desc" or "title:asc,created_at:desc". */
59
59
  sort?: string;
60
+ /**
61
+ * Query text instead of `where` and `sort` (not both): `city = "Riyadh" AND area >= 500 ORDER BY area DESC`. Needs a
62
+ * VeroXM server with query text (October 2026 or later); without `q`, requests are exactly what they were.
63
+ */
64
+ q?: string;
60
65
  /** Omitted matches the project's default locale, same fallback semantics as the REST API -- see packages/sdk-js/src/content.ts's ListOptions.locale for the full explanation. */
61
66
  locale?: string;
62
67
  /** Pass "only_draft" to include unpublished entries; anything else (including omitted) returns published-only. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veroxm/react-sdk",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
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.",
5
5
  "keywords": [
6
6
  "veroxm",
@@ -71,7 +71,7 @@
71
71
  "api:report": "node ../../scripts/api-report.mjs . --write"
72
72
  },
73
73
  "dependencies": {
74
- "graphql-request": "^7.0.0"
74
+ "@veroxm/sdk": "^1.10.0"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "react": "^18.0.0 || ^19.0.0",