@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,152 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useRef, useState } from 'react';
3
+ const TrackerContext = createContext(null);
4
+ /**
5
+ * Makes a visitor tracker available to useTracker()/usePageViews()
6
+ * (Experience OS Phase 1). `tracker` may be null during server rendering --
7
+ * the hooks then do nothing -- so create it only in the browser:
8
+ *
9
+ * ```tsx
10
+ * const tracker = typeof window === 'undefined' ? null
11
+ * : createTracker({ baseUrl, projectId, eventsKey });
12
+ * <VeroxmTrackerProvider tracker={tracker}>...</VeroxmTrackerProvider>
13
+ * ```
14
+ */
15
+ export function VeroxmTrackerProvider({ tracker, children }) {
16
+ return _jsx(TrackerContext.Provider, { value: tracker, children: children });
17
+ }
18
+ const noop = {
19
+ track() { },
20
+ page() { },
21
+ identify: async () => { },
22
+ consent: async () => { },
23
+ getConsent: () => ({ analytics: 'unknown', personalization: 'unknown', marketing: 'unknown' }),
24
+ getVisitorId: () => '',
25
+ reset() { },
26
+ };
27
+ /** The current tracker, or a no-op one outside a provider / during server rendering -- tracking never breaks rendering. */
28
+ export function useTracker() {
29
+ return useContext(TrackerContext) ?? noop;
30
+ }
31
+ /**
32
+ * Records a page view whenever `path` changes. Pass your router's current
33
+ * path, e.g. Next.js App Router: `usePageViews(usePathname())`.
34
+ */
35
+ export function usePageViews(path, properties) {
36
+ const tracker = useTracker();
37
+ const last = useRef(null);
38
+ const props = useRef(properties);
39
+ props.current = properties;
40
+ useEffect(() => {
41
+ if (!path || last.current === path)
42
+ return;
43
+ last.current = path;
44
+ tracker.page(props.current);
45
+ }, [path, tracker]);
46
+ }
47
+ /**
48
+ * This visitor's variant of a placement (Experience OS Phase 2):
49
+ *
50
+ * ```tsx
51
+ * const { decision, loading } = useExperience<HeroEntry>('home.hero');
52
+ * if (loading) return <HeroSkeleton />;
53
+ * return decision?.content ? <Hero entry={decision.content} /> : <DefaultHero />;
54
+ * ```
55
+ *
56
+ * Asks again when consent, identity or the visitor changes. Never throws:
57
+ * errors, timeouts and missing consent come back as reason "none".
58
+ */
59
+ export function useExperience(placement, options = {}) {
60
+ const tracker = useTracker();
61
+ const [state, setState] = useState({ decision: null, loading: true });
62
+ const [version, setVersion] = useState(0);
63
+ const timeoutMs = options.timeoutMs;
64
+ useEffect(() => tracker.subscribe?.(() => setVersion((v) => v + 1)), [tracker]);
65
+ useEffect(() => {
66
+ if (!tracker.getExperience) {
67
+ setState({ decision: noDecision(placement), loading: false });
68
+ return;
69
+ }
70
+ let cancelled = false;
71
+ setState((s) => ({ decision: s.decision, loading: true }));
72
+ tracker.getExperience(placement, timeoutMs ? { timeoutMs } : undefined).then((decision) => {
73
+ if (!cancelled)
74
+ setState({ decision, loading: false });
75
+ });
76
+ return () => {
77
+ cancelled = true;
78
+ };
79
+ }, [tracker, placement, timeoutMs, version]);
80
+ return state;
81
+ }
82
+ function noDecision(placement) {
83
+ return { placement, experienceId: null, variantId: null, variant: null, reason: 'none', content: null, config: null };
84
+ }
85
+ /**
86
+ * Declarative form of useExperience:
87
+ *
88
+ * ```tsx
89
+ * <Experience<HeroEntry> placement="home.hero" fallback={<DefaultHero />}>
90
+ * {(d) => <Hero entry={d.content!} cta={d.config?.cta} />}
91
+ * </Experience>
92
+ * ```
93
+ *
94
+ * A variant with neither content nor config (usually the control) renders
95
+ * the fallback, so "control = the current site" needs no extra code.
96
+ */
97
+ export function Experience({ placement, fallback, loading, timeoutMs, children, }) {
98
+ const state = useExperience(placement, { timeoutMs });
99
+ if (state.loading && !state.decision)
100
+ return _jsx(_Fragment, { children: loading !== undefined ? loading : fallback });
101
+ const d = state.decision;
102
+ if (!d || d.reason === 'none' || (d.content == null && d.config == null))
103
+ return _jsx(_Fragment, { children: fallback });
104
+ return _jsx(_Fragment, { children: children(d) });
105
+ }
106
+ /** Records one view of a CMS entry when it is shown (the signal behind recommendations). */
107
+ export function useContentView(contentId, properties) {
108
+ const tracker = useTracker();
109
+ const props = useRef(properties);
110
+ props.current = properties;
111
+ useEffect(() => {
112
+ if (contentId)
113
+ tracker.viewContent?.(contentId, props.current);
114
+ }, [contentId, tracker]);
115
+ }
116
+ /**
117
+ * Entries of a collection ranked for this visitor (Experience OS Phase 3):
118
+ *
119
+ * ```tsx
120
+ * const { items } = useRecommendations<Article>('articles', { limit: 3, exclude: [article.id] });
121
+ * ```
122
+ *
123
+ * Personal when the visitor allowed personalisation and has read a few
124
+ * entries, otherwise the most read. Asks again when consent or identity
125
+ * changes. Never throws (an error gives an empty list).
126
+ */
127
+ export function useRecommendations(collection, options = {}) {
128
+ const tracker = useTracker();
129
+ const [state, setState] = useState({ items: [], strategy: null, loading: true });
130
+ const [version, setVersion] = useState(0);
131
+ const limit = options.limit;
132
+ const exclude = (options.exclude ?? []).join(',');
133
+ useEffect(() => tracker.subscribe?.(() => setVersion((v) => v + 1)), [tracker]);
134
+ useEffect(() => {
135
+ if (!tracker.getRecommendations) {
136
+ setState({ items: [], strategy: null, loading: false });
137
+ return;
138
+ }
139
+ let cancelled = false;
140
+ setState((s) => ({ ...s, loading: true }));
141
+ tracker
142
+ .getRecommendations(collection, { limit, exclude: exclude ? exclude.split(',').map(Number) : undefined })
143
+ .then((r) => {
144
+ if (!cancelled)
145
+ setState({ items: r.items, strategy: r.strategy, loading: false });
146
+ });
147
+ return () => {
148
+ cancelled = true;
149
+ };
150
+ }, [tracker, collection, limit, exclude, version]);
151
+ return state;
152
+ }
@@ -0,0 +1,106 @@
1
+ export interface CollectionFieldMeta {
2
+ name: string;
3
+ label: string;
4
+ type: string;
5
+ }
6
+ /** A collection's field list -- see apps/api's CollectionMetaModel, which this mirrors exactly. */
7
+ export interface CollectionMeta {
8
+ slug: string;
9
+ name: string;
10
+ description?: string | null;
11
+ fields: CollectionFieldMeta[];
12
+ }
13
+ /**
14
+ * `T` is whatever shape you expect `data` to be -- the API's actual
15
+ * response is a plain object per the collection's own fields, so this is
16
+ * a cast you opt into, same convention as @veroxm/sdk's ContentResource.
17
+ * `createdAt`/`updatedAt`/`publishedAt` come back as ISO date STRINGS
18
+ * (GraphQL's `Date` scalar serializes to ISO-8601 over the wire), not
19
+ * `Date` instances -- parse them yourself if you need `Date` objects.
20
+ */
21
+ export interface Entry<T = Record<string, unknown>> {
22
+ id: number;
23
+ locale: string | null;
24
+ createdAt?: string | null;
25
+ updatedAt?: string | null;
26
+ publishedAt?: string | null;
27
+ data: T;
28
+ }
29
+ export interface EntryConnection<T = Record<string, unknown>> {
30
+ items: Entry<T>[];
31
+ /** Only present when `withTotalCount: true` was passed to useEntries()/listEntries() -- see EntriesQueryOptions. */
32
+ totalCount?: number;
33
+ }
34
+ /**
35
+ * One AND'ed filter clause. Matches the GraphQL schema's WhereClauseInput
36
+ * exactly (apps/api/src/public-api/graphql/models/entry.model.ts) -- the
37
+ * REST v2 operator vocabulary (like/not/in/not_in/lt/lte/gt/gte/between/
38
+ * not_between/null/not_null); omit `op` entirely for a plain equality
39
+ * match.
40
+ */
41
+ export interface WhereClause {
42
+ field: string;
43
+ op?: string;
44
+ value?: unknown;
45
+ }
46
+ /**
47
+ * Mirrors ListOptions from @veroxm/sdk/the REST v2 API (see
48
+ * packages/sdk-js/src/content.ts) -- porting REST-based fetching code to
49
+ * useEntries()/listEntries() is mostly a hook-name-and-shape swap, not a
50
+ * rewrite. The one real difference is `where`, which is a typed array of
51
+ * WhereClause here instead of REST's untyped where/whereRelation JSON DSL
52
+ * (see docs/REACT-SDK-GRAPHQL-IMPLEMENTATION-PLAN.md §4.2) -- OR
53
+ * semantics (REST's `{or: {...}}` form) has no typed GraphQL equivalent
54
+ * yet, same documented follow-up as the server side.
55
+ */
56
+ export interface EntriesQueryOptions {
57
+ where?: WhereClause[];
58
+ /** e.g. "created_at:desc" or "title:asc,created_at:desc". */
59
+ sort?: string;
60
+ /** 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
+ locale?: string;
62
+ /** Pass "only_draft" to include unpublished entries; anything else (including omitted) returns published-only. */
63
+ state?: 'only_draft' | string;
64
+ offset?: number;
65
+ limit?: number;
66
+ /** Include created_at/updated_at/published_at in each returned entry. */
67
+ timestamps?: boolean;
68
+ /**
69
+ * Ask for `totalCount` alongside `items`. Costs one extra count query
70
+ * server-side (apps/api/src/public-api/graphql/content.resolver.ts's
71
+ * lazy @ResolveField) -- only set this when you actually need it (e.g.
72
+ * pagination UI), the same "ask for only what you need" GraphQL win
73
+ * the plan doc calls out. Defaults to false, so a plain useEntries()
74
+ * call never pays for it.
75
+ */
76
+ withTotalCount?: boolean;
77
+ }
78
+ /** Mirrors MediaViewModel exactly (apps/api/src/public-api/graphql/models/media-view.model.ts) -- see that file's own comment: thumbUrl/width/height stay null for a non-image file. */
79
+ export interface MediaView {
80
+ id: number;
81
+ fileName: string;
82
+ fullUrl: string;
83
+ thumbUrl?: string | null;
84
+ thumbWebpUrl?: string | null;
85
+ fullWebpUrl?: string | null;
86
+ caption?: string | null;
87
+ tags: string[];
88
+ size?: number | null;
89
+ width?: number | null;
90
+ height?: number | null;
91
+ /** What crops keep in view: fractions (0 to 1) of the width and height from the top left. Null = the centre. */
92
+ focalPoint?: {
93
+ x: number;
94
+ y: number;
95
+ } | null;
96
+ /** Labelled points on the image (same fractions), e.g. products in a photo. */
97
+ hotspots?: MediaHotspot[];
98
+ }
99
+ /** A labelled point on an image; `url` is an http(s) address or a path on your site. */
100
+ export interface MediaHotspot {
101
+ id: string;
102
+ x: number;
103
+ y: number;
104
+ label: string;
105
+ url?: string | null;
106
+ }
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ // Client-side counterparts to the GraphQL schema's own types
2
+ // (apps/api/src/public-api/graphql/models/*.ts) -- kept as plain,
3
+ // JSON-serializable interfaces (not classes) since every hook in
4
+ // ./hooks needs to compare an options object by VALUE across renders
5
+ // (see hooks/use-entries.ts), which a class instance would complicate.
6
+ export {};
package/package.json CHANGED
@@ -1,6 +1,97 @@
1
1
  {
2
2
  "name": "@veroxm/react-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
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
+ "keywords": [
6
+ "veroxm",
7
+ "react",
8
+ "nextjs",
9
+ "cms",
10
+ "headless-cms",
11
+ "a-b-testing",
12
+ "personalization",
13
+ "graphql"
14
+ ],
15
+ "homepage": "https://docs.veroxm.com/platform-tools/react-sdk",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/codewithsyedz/VeroXM.git",
19
+ "directory": "packages/sdk-react"
20
+ },
21
+ "license": "MIT",
22
+ "author": "VeroXM",
23
+ "type": "module",
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ },
31
+ "./next": {
32
+ "types": "./dist/next/index.d.ts",
33
+ "import": "./dist/next/index.js"
34
+ },
35
+ "./next/route": {
36
+ "types": "./dist/next/route.d.ts",
37
+ "import": "./dist/next/route.js"
38
+ },
39
+ "./next/llms": {
40
+ "types": "./dist/next/llms.d.ts",
41
+ "import": "./dist/next/llms.js"
42
+ },
43
+ "./client": {
44
+ "types": "./dist/client-slots.d.ts",
45
+ "import": "./dist/client-slots.js"
46
+ },
47
+ "./node": {
48
+ "types": "./dist/node.d.ts",
49
+ "import": "./dist/node.js"
50
+ },
51
+ "./next/cache-components": {
52
+ "types": "./dist/next/cache-components.d.ts",
53
+ "import": "./dist/next/cache-components.js"
54
+ }
55
+ },
56
+ "files": [
57
+ "dist",
58
+ "README.md",
59
+ "CHANGELOG.md",
60
+ "LICENSE"
61
+ ],
62
+ "engines": {
63
+ "node": ">=18.18"
64
+ },
65
+ "publishConfig": {
66
+ "access": "public"
67
+ },
68
+ "scripts": {
69
+ "build": "rm -rf dist && tsc -p tsconfig.json",
70
+ "test": "vitest run"
71
+ },
72
+ "dependencies": {
73
+ "graphql-request": "^7.0.0"
74
+ },
75
+ "peerDependencies": {
76
+ "react": "^18.0.0 || ^19.0.0",
77
+ "react-dom": "^18.0.0 || ^19.0.0",
78
+ "next": ">=15.0.0"
79
+ },
80
+ "peerDependenciesMeta": {
81
+ "react-dom": {
82
+ "optional": true
83
+ },
84
+ "next": {
85
+ "optional": true
86
+ }
87
+ },
88
+ "devDependencies": {
89
+ "vitest": "^4.1.2",
90
+ "jsdom": "^30.0.0",
91
+ "react": "19.2.8",
92
+ "react-dom": "19.2.8",
93
+ "@testing-library/react": "^16.3.0",
94
+ "@testing-library/dom": "^10.0.0",
95
+ "@types/react-dom": "^19.0.0"
96
+ }
97
+ }