@veroxm/react-sdk 0.0.0-stage → 0.1.1

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.
Files changed (98) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +21 -0
  3. package/README.md +295 -2
  4. package/dist/cache.d.ts +69 -0
  5. package/dist/cache.js +89 -0
  6. package/dist/client-slots.d.ts +35 -0
  7. package/dist/client-slots.js +169 -0
  8. package/dist/client.d.ts +65 -0
  9. package/dist/client.js +87 -0
  10. package/dist/editor/constants.d.ts +12 -0
  11. package/dist/editor/constants.js +12 -0
  12. package/dist/editor/handler.d.ts +16 -0
  13. package/dist/editor/handler.js +175 -0
  14. package/dist/editor/inline.d.ts +25 -0
  15. package/dist/editor/inline.js +149 -0
  16. package/dist/editor/menu-input.d.ts +26 -0
  17. package/dist/editor/menu-input.js +110 -0
  18. package/dist/editor/overlay.d.ts +31 -0
  19. package/dist/editor/overlay.js +856 -0
  20. package/dist/editor/rich-text.d.ts +21 -0
  21. package/dist/editor/rich-text.js +232 -0
  22. package/dist/editor/server.d.ts +9 -0
  23. package/dist/editor/server.js +43 -0
  24. package/dist/errors.d.ts +20 -0
  25. package/dist/errors.js +26 -0
  26. package/dist/hooks/use-cached-query.d.ts +21 -0
  27. package/dist/hooks/use-cached-query.js +59 -0
  28. package/dist/hooks/use-collection.d.ts +10 -0
  29. package/dist/hooks/use-collection.js +14 -0
  30. package/dist/hooks/use-entries.d.ts +18 -0
  31. package/dist/hooks/use-entries.js +25 -0
  32. package/dist/hooks/use-entry.d.ts +21 -0
  33. package/dist/hooks/use-entry.js +22 -0
  34. package/dist/hooks/use-media.d.ts +9 -0
  35. package/dist/hooks/use-media.js +13 -0
  36. package/dist/hydration-boundary.d.ts +35 -0
  37. package/dist/hydration-boundary.js +38 -0
  38. package/dist/image.d.ts +34 -0
  39. package/dist/image.js +39 -0
  40. package/dist/index.d.ts +46 -0
  41. package/dist/index.js +32 -0
  42. package/dist/next/cache-components.d.ts +15 -0
  43. package/dist/next/cache-components.js +25 -0
  44. package/dist/next/cached.d.ts +9 -0
  45. package/dist/next/cached.js +20 -0
  46. package/dist/next/edge-slot.d.ts +21 -0
  47. package/dist/next/edge-slot.js +29 -0
  48. package/dist/next/editor.d.ts +7 -0
  49. package/dist/next/editor.js +13 -0
  50. package/dist/next/index.d.ts +17 -0
  51. package/dist/next/index.js +21 -0
  52. package/dist/next/llms.d.ts +2 -0
  53. package/dist/next/llms.js +44 -0
  54. package/dist/next/route.d.ts +12 -0
  55. package/dist/next/route.js +16 -0
  56. package/dist/next/slot.d.ts +21 -0
  57. package/dist/next/slot.js +160 -0
  58. package/dist/node.d.ts +43 -0
  59. package/dist/node.js +67 -0
  60. package/dist/preview.d.ts +35 -0
  61. package/dist/preview.js +46 -0
  62. package/dist/provider.d.ts +29 -0
  63. package/dist/provider.js +37 -0
  64. package/dist/query-keys.d.ts +19 -0
  65. package/dist/query-keys.js +49 -0
  66. package/dist/site/chart-view.d.ts +14 -0
  67. package/dist/site/chart-view.js +44 -0
  68. package/dist/site/chart.d.ts +127 -0
  69. package/dist/site/chart.js +639 -0
  70. package/dist/site/map-embed.d.ts +32 -0
  71. package/dist/site/map-embed.js +139 -0
  72. package/dist/site/map-math.d.ts +27 -0
  73. package/dist/site/map-math.js +89 -0
  74. package/dist/site/nav-menu.d.ts +19 -0
  75. package/dist/site/nav-menu.js +76 -0
  76. package/dist/site/site-parts.d.ts +87 -0
  77. package/dist/site/site-parts.js +46 -0
  78. package/dist/site/slider.d.ts +17 -0
  79. package/dist/site/slider.js +78 -0
  80. package/dist/site/styles.d.ts +3 -0
  81. package/dist/site/styles.js +155 -0
  82. package/dist/site/video-embed.d.ts +15 -0
  83. package/dist/site/video-embed.js +27 -0
  84. package/dist/site/video.d.ts +18 -0
  85. package/dist/site/video.js +73 -0
  86. package/dist/slots-core.d.ts +397 -0
  87. package/dist/slots-core.js +367 -0
  88. package/dist/slots.d.ts +13 -0
  89. package/dist/slots.js +30 -0
  90. package/dist/ssr.d.ts +20 -0
  91. package/dist/ssr.js +35 -0
  92. package/dist/structured-data.d.ts +13 -0
  93. package/dist/structured-data.js +36 -0
  94. package/dist/tracking.d.ts +142 -0
  95. package/dist/tracking.js +152 -0
  96. package/dist/types.d.ts +106 -0
  97. package/dist/types.js +6 -0
  98. package/package.json +95 -4
@@ -0,0 +1,397 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ChartValue } from './site/chart.js';
3
+ interface BaseField {
4
+ label?: string;
5
+ required?: boolean;
6
+ }
7
+ export type SlotFieldDef = (BaseField & {
8
+ type: 'text';
9
+ max?: number;
10
+ }) | (BaseField & {
11
+ type: 'richText';
12
+ max?: number;
13
+ }) | (BaseField & {
14
+ type: 'media';
15
+ }) | (BaseField & {
16
+ type: 'link';
17
+ }) | (BaseField & {
18
+ type: 'number';
19
+ }) | (BaseField & {
20
+ type: 'boolean';
21
+ }) | (BaseField & {
22
+ type: 'select';
23
+ options: readonly string[];
24
+ }) | (BaseField & {
25
+ type: 'menu';
26
+ depth?: 1 | 2 | 3;
27
+ }) | (BaseField & {
28
+ type: 'video';
29
+ }) | (BaseField & {
30
+ type: 'slides';
31
+ max?: number;
32
+ }) | (BaseField & {
33
+ type: 'map';
34
+ max?: number;
35
+ }) | (BaseField & {
36
+ type: 'chart';
37
+ });
38
+ export type SlotFieldDefs = Record<string, SlotFieldDef>;
39
+ /** Field builders for a slot's `fields` prop. */
40
+ export declare const field: {
41
+ text: (o?: BaseField & {
42
+ max?: number;
43
+ }) => {
44
+ label?: string;
45
+ required?: boolean;
46
+ max?: number;
47
+ type: "text";
48
+ };
49
+ richText: (o?: BaseField & {
50
+ max?: number;
51
+ }) => {
52
+ label?: string;
53
+ required?: boolean;
54
+ max?: number;
55
+ type: "richText";
56
+ };
57
+ media: (o?: BaseField) => {
58
+ label?: string;
59
+ required?: boolean;
60
+ type: "media";
61
+ };
62
+ link: (o?: BaseField) => {
63
+ label?: string;
64
+ required?: boolean;
65
+ type: "link";
66
+ };
67
+ number: (o?: BaseField) => {
68
+ label?: string;
69
+ required?: boolean;
70
+ type: "number";
71
+ };
72
+ boolean: (o?: BaseField) => {
73
+ label?: string;
74
+ required?: boolean;
75
+ type: "boolean";
76
+ };
77
+ select: <const T extends readonly [string, ...string[]]>(options: T, o?: BaseField) => {
78
+ label?: string;
79
+ required?: boolean;
80
+ type: "select";
81
+ options: T;
82
+ };
83
+ /** A navigation menu marketers edit: links, with sub-menus up to `depth` levels (default 2, at most 3). */
84
+ menu: (o?: BaseField & {
85
+ depth?: 1 | 2 | 3;
86
+ }) => {
87
+ label?: string;
88
+ required?: boolean;
89
+ depth?: 1 | 2 | 3;
90
+ type: "menu";
91
+ };
92
+ /** A YouTube or Vimeo link, or a video file, that the site shows as a player. */
93
+ video: (o?: BaseField) => {
94
+ label?: string;
95
+ required?: boolean;
96
+ type: "video";
97
+ };
98
+ /** Slides for a slider: each an image with optional title, text and link. `max` 1 to 20 (default 10). */
99
+ slides: (o?: BaseField & {
100
+ max?: number;
101
+ }) => {
102
+ label?: string;
103
+ required?: boolean;
104
+ max?: number;
105
+ type: "slides";
106
+ };
107
+ /** Places on a map (OpenStreetMap): each with a name, an address and a position. `max` 1 to 50 places (default 20). */
108
+ map: (o?: BaseField & {
109
+ max?: number;
110
+ }) => {
111
+ label?: string;
112
+ required?: boolean;
113
+ max?: number;
114
+ type: "map";
115
+ };
116
+ /** A chart: numbers typed in, read from your own systems (Connected APIs), or from VeroXM's analytics. */
117
+ chart: (o?: BaseField) => {
118
+ label?: string;
119
+ required?: boolean;
120
+ type: "chart";
121
+ };
122
+ };
123
+ /** A media field's value: the image as stored in the VeroXM media library. */
124
+ export interface SlotMedia {
125
+ id: number;
126
+ url: string;
127
+ webpUrl: string | null;
128
+ width: number | null;
129
+ height: number | null;
130
+ alt: string;
131
+ /** The part of the image to keep in view when it's cropped (0 to 1 from the left and top). */
132
+ focalPoint?: {
133
+ x: number;
134
+ y: number;
135
+ } | null;
136
+ }
137
+ /** A video field's value: the link, and what VeroXM recognised in it. */
138
+ export interface SlotVideo {
139
+ url: string;
140
+ provider: 'youtube' | 'vimeo' | 'file';
141
+ /** YouTube's id, Vimeo's number, or the file's address. */
142
+ id: string;
143
+ start?: number;
144
+ hash?: string;
145
+ title?: string;
146
+ }
147
+ /** One place on a map field. */
148
+ export interface SlotPlace {
149
+ lat: number;
150
+ lng: number;
151
+ name: string;
152
+ address?: string;
153
+ /** A page about the place, e.g. the branch's own page. */
154
+ link?: string;
155
+ }
156
+ /** A map field's value. Without a zoom, the map fits all its places. */
157
+ export interface SlotMap {
158
+ places: SlotPlace[];
159
+ zoom?: number;
160
+ }
161
+ /** A chart field's value: always with its numbers, whatever their source (VeroXM fills them in when the slot is read). */
162
+ export type SlotChart = ChartValue;
163
+ /** One slide of a slides field. `image` is null only when the image was deleted from the library. */
164
+ export interface SlotSlide {
165
+ image: SlotMedia | null;
166
+ title?: string;
167
+ text?: string;
168
+ link?: SlotLink;
169
+ }
170
+ export interface SlotLink {
171
+ label: string;
172
+ href: string;
173
+ }
174
+ /** One item of a menu field: a link, a heading for sub-items, or both. */
175
+ export interface SlotMenuItem {
176
+ label: string;
177
+ /** Empty for an item that only opens its sub-items. */
178
+ href: string;
179
+ newTab?: boolean;
180
+ children?: SlotMenuItem[];
181
+ }
182
+ type SlotValue<F> = F extends {
183
+ type: 'text' | 'richText';
184
+ } ? string : F extends {
185
+ type: 'media';
186
+ } ? SlotMedia | null : F extends {
187
+ type: 'link';
188
+ } ? SlotLink | null : F extends {
189
+ type: 'number';
190
+ } ? number | null : F extends {
191
+ type: 'boolean';
192
+ } ? boolean : F extends {
193
+ type: 'select';
194
+ options: readonly (infer O)[];
195
+ } ? O : F extends {
196
+ type: 'menu';
197
+ } ? SlotMenuItem[] : F extends {
198
+ type: 'video';
199
+ } ? SlotVideo | null : F extends {
200
+ type: 'slides';
201
+ } ? SlotSlide[] : F extends {
202
+ type: 'map';
203
+ } ? SlotMap | null : F extends {
204
+ type: 'chart';
205
+ } ? SlotChart | null : never;
206
+ /** The values a slot renders with, typed from its field definitions. */
207
+ export type SlotValues<F extends SlotFieldDefs> = {
208
+ [K in keyof F]: SlotValue<F[K]>;
209
+ };
210
+ /** What the render function gets as its second argument. */
211
+ export interface SlotInfo {
212
+ name: string;
213
+ /** Version shown (the last published one while editing a draft), or null when showing the fallback. */
214
+ version: number | null;
215
+ /** 'draft' only inside VeroXM's on-page editor (Next.js draft mode). */
216
+ source: 'published' | 'fallback' | 'draft';
217
+ /** True inside VeroXM's on-page editor: render a placeholder for a slot that would otherwise show nothing, so it can be clicked. */
218
+ editing: boolean;
219
+ /** The A/B test variant this visitor sees, when the slot is under a live test. */
220
+ test?: SlotTest | null;
221
+ /**
222
+ * Marks an element as the place a field is edited on the page. Spread it
223
+ * on the element that shows the field: `<h1 {...slot.edit('title')}>`.
224
+ * Adds nothing outside VeroXM's on-page editor.
225
+ */
226
+ edit(fieldName: string): Record<string, string>;
227
+ }
228
+ export interface SlotsConfig {
229
+ /** VeroXM API origin, e.g. https://exp.example.com. Default: VEROXM_API_BASE. */
230
+ baseUrl?: string;
231
+ /** Project UUID. Default: VEROXM_PROJECT_ID. */
232
+ projectId?: string;
233
+ /**
234
+ * API key. Default: VEROXM_API_KEY. On the server use a key with "read"
235
+ * (needed to report slot definitions); in the browser a key with "Send
236
+ * events" is enough to read published slots.
237
+ */
238
+ apiKey?: string;
239
+ /** Default locale when a slot doesn't pass one. */
240
+ locale?: string;
241
+ /** Report slot definitions on first render. Default: true on the server, false in the browser. */
242
+ report?: boolean;
243
+ /** Seconds Next.js may cache slot reads (fetch `next.revalidate`). Default 30. */
244
+ revalidate?: number;
245
+ /** Custom fetch, for tests or special runtimes. */
246
+ fetch?: typeof fetch;
247
+ /**
248
+ * Edge delivery: the site is served through @veroxm/edge (Vercel,
249
+ * Netlify or Cloudflare). Slots under a live test then put every variant
250
+ * in the page, and the edge worker shows each visitor theirs before the
251
+ * page reaches the browser. Default: VEROXM_EDGE=1.
252
+ */
253
+ edge?: boolean;
254
+ }
255
+ /** Overrides the environment-variable defaults for every slot in this process. */
256
+ export declare function configureSlots(next: SlotsConfig): void;
257
+ /** The effective slots configuration (configureSlots over environment variables). */
258
+ export declare function resolveSlotsConfig(): {
259
+ baseUrl: string;
260
+ projectId: string;
261
+ apiKey: string;
262
+ locale: string | undefined;
263
+ report: boolean;
264
+ revalidate: number;
265
+ edge: boolean;
266
+ fetch: typeof fetch | undefined;
267
+ ready: boolean;
268
+ };
269
+ export interface PublishedSlot {
270
+ values: Record<string, unknown>;
271
+ version: number;
272
+ /** The slot has a live A/B test: ask again with the visitor's id for their variant. */
273
+ testing?: boolean;
274
+ /** Set when values are a visitor's A/B test variant. */
275
+ test?: SlotTest | null;
276
+ /** Edge delivery: every variant of the slot's live test, to prerender (only asked for in edge mode). */
277
+ variants?: SlotTestVariants | null;
278
+ /** The slot has personalised versions: ask again with who the person is (`person`) to get theirs. */
279
+ personalised?: boolean;
280
+ /** A personalised version hides the slot for this person: render nothing (not the fallback). */
281
+ hidden?: boolean;
282
+ }
283
+ /**
284
+ * Who the visitor is, for slots with personalised versions. Your server
285
+ * passes it; VeroXM reads the values the versions test from your systems
286
+ * (Connected APIs) for this one request and stores nothing. Server only:
287
+ * the key needs "read".
288
+ */
289
+ export interface SlotPerson {
290
+ /** The person's id in your systems ({userId} in Connected APIs). */
291
+ userId?: string | null;
292
+ /** Other context your Connected APIs values use ({ctx.<name>}), e.g. { sku: 'A1' }. */
293
+ ctx?: Record<string, string | number>;
294
+ /** The visitor's country (two letters), e.g. from your host's geo header. */
295
+ country?: string | null;
296
+ /** The person agreed to personalised content (values that declare that purpose are only read then). */
297
+ consent?: boolean;
298
+ }
299
+ /** Every variant of a slot's live A/B test (edge delivery). */
300
+ export interface SlotTestVariants {
301
+ experienceId: number;
302
+ variants: Array<{
303
+ variantId: number;
304
+ label: string;
305
+ values: Record<string, unknown>;
306
+ }>;
307
+ }
308
+ /** Which A/B test variant a visitor sees in a slot. */
309
+ export interface SlotTest {
310
+ experienceId: number;
311
+ variantId: number;
312
+ label: string;
313
+ isControl: boolean;
314
+ }
315
+ /** Published content of one slot; requests made in the same tick share one HTTP call. */
316
+ export declare function loadPublishedSlot(name: string, locale?: string): Promise<PublishedSlot | null>;
317
+ /** What the site shows for a slot before anything is published, sent with its definition. */
318
+ export interface ShownValues {
319
+ values: Record<string, unknown>;
320
+ locale?: string;
321
+ }
322
+ /** Queues a slot definition to be reported; each distinct definition is sent once per process. */
323
+ /**
324
+ * Runs the batched report. Defaults to a timer; Next.js passes `after()`,
325
+ * because work left on a timer may never run while a page is prerendered.
326
+ */
327
+ export type ReportScheduler = (send: () => Promise<void>) => void;
328
+ export declare function reportSlot(name: string, fields: SlotFieldDefs, label?: string, path?: string, schedule?: ReportScheduler, shown?: ShownValues): void;
329
+ /**
330
+ * Reports one slot right away and waits for the answer (once per process,
331
+ * like reportSlot). For code that must finish its requests inside the
332
+ * render, such as a Next.js 'use cache' function.
333
+ */
334
+ export declare function reportSlotNow(name: string, fields: SlotFieldDefs, label?: string, path?: string, shown?: ShownValues): Promise<void>;
335
+ /**
336
+ * The values a slot shows from its `fallback` alone (fields the fallback
337
+ * leaves empty are left out): what the site shows before anything is
338
+ * published, sent to VeroXM so its dashboard can show it in empty fields.
339
+ */
340
+ export declare function fallbackValues<F extends SlotFieldDefs>(fields: F, fallback: Partial<SlotValues<F>> | undefined): Record<string, unknown>;
341
+ /** Published value where there is one, else the fallback, else an empty value for the field type. */
342
+ export declare function mergeSlotValues<F extends SlotFieldDefs>(fields: F, fallback: Partial<SlotValues<F>> | undefined, published: Record<string, unknown> | null): SlotValues<F>;
343
+ /** SlotInfo for published content (or the fallback when null). */
344
+ export declare function slotInfo(name: string, published: PublishedSlot | null): SlotInfo;
345
+ export interface LoadSlotOptions<F extends SlotFieldDefs> {
346
+ fields: F;
347
+ fallback?: Partial<SlotValues<F>>;
348
+ label?: string;
349
+ locale?: string;
350
+ /** Page path, shown in the dashboard as where the slot was last seen. */
351
+ path?: string;
352
+ /** Who the visitor is, for slots with personalised versions (server only). */
353
+ person?: SlotPerson | null;
354
+ }
355
+ /**
356
+ * Published content of one slot, fetched on its own (no batching, no
357
+ * Next.js fetch cache) -- for callers that cache it themselves, such as
358
+ * the Cache Components path in '@veroxm/react-sdk/next'.
359
+ */
360
+ export declare function fetchPublishedSlot(name: string, locale?: string): Promise<PublishedSlot | null>;
361
+ /**
362
+ * One visitor's values for slots under a live A/B test (uncached): their
363
+ * variant over the published values. Null when it can't be loaded.
364
+ */
365
+ export declare function loadSlotForVisitor(name: string, visitorId: string, locale?: string): Promise<PublishedSlot | null>;
366
+ /** The query a person's read adds: userId, consent, country and ctx.<name>. */
367
+ export declare function personQuery(person: SlotPerson | null | undefined, qs: URLSearchParams): URLSearchParams;
368
+ /**
369
+ * One person's values for a slot (uncached): their A/B variant when given
370
+ * the visitor's id, and their personalised version when given `person`.
371
+ * Null when it can't be loaded.
372
+ */
373
+ export declare function loadSlotFor(name: string, who: {
374
+ visitorId?: string | null;
375
+ person?: SlotPerson | null;
376
+ }, locale?: string): Promise<PublishedSlot | null>;
377
+ /** Loads one slot (batched), reports its definition, and merges in the fallback. `hidden`: render nothing. */
378
+ export declare function loadSlot<F extends SlotFieldDefs>(name: string, options: LoadSlotOptions<F> & {
379
+ visitorId?: string | null;
380
+ }): Promise<{
381
+ values: SlotValues<F>;
382
+ slot: SlotInfo;
383
+ hidden: boolean;
384
+ }>;
385
+ export interface VeroxmSlotProps<F extends SlotFieldDefs> extends LoadSlotOptions<F> {
386
+ name: string;
387
+ children: (values: SlotValues<F>, slot: SlotInfo) => ReactNode;
388
+ }
389
+ /**
390
+ * Server component (Next.js App Router, React Server Components). Renders
391
+ * the slot's published content, or its fallback. For client-only React
392
+ * apps, use `useSlot` instead.
393
+ */
394
+ export declare function VeroxmSlot<F extends SlotFieldDefs>({ name, children, ...options }: VeroxmSlotProps<F>): Promise<ReactNode>;
395
+ /** Test helper: forgets configuration, queued requests and reported definitions. */
396
+ export declare function resetSlotsForTests(): void;
397
+ export {};