@hexclave/shared 1.0.13 → 1.0.15

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 (108) hide show
  1. package/dist/ai/unified-prompts/reminders.js +1 -1
  2. package/dist/apps/apps-config.d.ts +6 -0
  3. package/dist/apps/apps-config.js +6 -0
  4. package/dist/apps/apps-config.js.map +1 -1
  5. package/dist/config/schema.d.ts +170 -170
  6. package/dist/config-authoring.d.ts.map +1 -1
  7. package/dist/config-authoring.js.map +1 -1
  8. package/dist/config-authoring.test.js +1 -1
  9. package/dist/config-authoring.test.js.map +1 -1
  10. package/dist/config-rendering.d.ts +2 -2
  11. package/dist/config-rendering.js +16 -0
  12. package/dist/config-rendering.js.map +1 -1
  13. package/dist/esm/ai/unified-prompts/reminders.js +1 -1
  14. package/dist/esm/apps/apps-config.d.ts +6 -0
  15. package/dist/esm/apps/apps-config.js +6 -0
  16. package/dist/esm/apps/apps-config.js.map +1 -1
  17. package/dist/esm/config/schema.d.ts +170 -170
  18. package/dist/esm/config-authoring.d.ts.map +1 -1
  19. package/dist/esm/config-authoring.js.map +1 -1
  20. package/dist/esm/config-authoring.test.js +1 -1
  21. package/dist/esm/config-authoring.test.js.map +1 -1
  22. package/dist/esm/config-rendering.d.ts +2 -2
  23. package/dist/esm/config-rendering.js +16 -2
  24. package/dist/esm/config-rendering.js.map +1 -1
  25. package/dist/esm/hexclave-config-file.d.ts +24 -1
  26. package/dist/esm/hexclave-config-file.d.ts.map +1 -1
  27. package/dist/esm/hexclave-config-file.js +69 -2
  28. package/dist/esm/hexclave-config-file.js.map +1 -1
  29. package/dist/esm/interface/admin-interface.d.ts +19 -1
  30. package/dist/esm/interface/admin-interface.d.ts.map +1 -1
  31. package/dist/esm/interface/admin-interface.js +14 -0
  32. package/dist/esm/interface/admin-interface.js.map +1 -1
  33. package/dist/esm/interface/admin-metrics.d.ts +99 -5
  34. package/dist/esm/interface/admin-metrics.d.ts.map +1 -1
  35. package/dist/esm/interface/admin-metrics.js +61 -1
  36. package/dist/esm/interface/admin-metrics.js.map +1 -1
  37. package/dist/esm/interface/conversations.d.ts +35 -35
  38. package/dist/esm/interface/crud/current-user.d.ts +2 -2
  39. package/dist/esm/interface/crud/email-outbox.d.ts +66 -66
  40. package/dist/esm/interface/crud/invoices.d.ts +2 -2
  41. package/dist/esm/interface/crud/projects.d.ts +35 -35
  42. package/dist/esm/interface/crud/team-member-profiles.d.ts +10 -10
  43. package/dist/esm/interface/crud/users.d.ts +10 -10
  44. package/dist/esm/interface/webhooks.d.ts +2 -2
  45. package/dist/esm/utils/analytics-clickmap-overlay.d.ts +18 -0
  46. package/dist/esm/utils/analytics-clickmap-overlay.d.ts.map +1 -0
  47. package/dist/esm/utils/analytics-clickmap-overlay.js +19 -0
  48. package/dist/esm/utils/analytics-clickmap-overlay.js.map +1 -0
  49. package/dist/esm/utils/dev-tool.d.ts +31 -0
  50. package/dist/esm/utils/dev-tool.d.ts.map +1 -0
  51. package/dist/esm/utils/dev-tool.js +32 -0
  52. package/dist/esm/utils/dev-tool.js.map +1 -0
  53. package/dist/esm/utils/dom.d.ts +7 -1
  54. package/dist/esm/utils/dom.d.ts.map +1 -1
  55. package/dist/esm/utils/dom.js +20 -1
  56. package/dist/esm/utils/dom.js.map +1 -1
  57. package/dist/esm/utils/elements-chain.d.ts +38 -0
  58. package/dist/esm/utils/elements-chain.d.ts.map +1 -0
  59. package/dist/esm/utils/elements-chain.js +297 -0
  60. package/dist/esm/utils/elements-chain.js.map +1 -0
  61. package/dist/hexclave-config-file.d.ts +24 -1
  62. package/dist/hexclave-config-file.d.ts.map +1 -1
  63. package/dist/hexclave-config-file.js +71 -1
  64. package/dist/hexclave-config-file.js.map +1 -1
  65. package/dist/interface/admin-interface.d.ts +19 -1
  66. package/dist/interface/admin-interface.d.ts.map +1 -1
  67. package/dist/interface/admin-interface.js +14 -0
  68. package/dist/interface/admin-interface.js.map +1 -1
  69. package/dist/interface/admin-metrics.d.ts +99 -5
  70. package/dist/interface/admin-metrics.d.ts.map +1 -1
  71. package/dist/interface/admin-metrics.js +65 -0
  72. package/dist/interface/admin-metrics.js.map +1 -1
  73. package/dist/interface/conversations.d.ts +35 -35
  74. package/dist/interface/crud/current-user.d.ts +2 -2
  75. package/dist/interface/crud/email-outbox.d.ts +66 -66
  76. package/dist/interface/crud/invoices.d.ts +2 -2
  77. package/dist/interface/crud/projects.d.ts +35 -35
  78. package/dist/interface/crud/team-member-profiles.d.ts +10 -10
  79. package/dist/interface/crud/users.d.ts +10 -10
  80. package/dist/interface/webhooks.d.ts +2 -2
  81. package/dist/utils/analytics-clickmap-overlay.d.ts +18 -0
  82. package/dist/utils/analytics-clickmap-overlay.d.ts.map +1 -0
  83. package/dist/utils/analytics-clickmap-overlay.js +23 -0
  84. package/dist/utils/analytics-clickmap-overlay.js.map +1 -0
  85. package/dist/utils/dev-tool.d.ts +31 -0
  86. package/dist/utils/dev-tool.d.ts.map +1 -0
  87. package/dist/utils/dev-tool.js +37 -0
  88. package/dist/utils/dev-tool.js.map +1 -0
  89. package/dist/utils/dom.d.ts +7 -1
  90. package/dist/utils/dom.d.ts.map +1 -1
  91. package/dist/utils/dom.js +20 -0
  92. package/dist/utils/dom.js.map +1 -1
  93. package/dist/utils/elements-chain.d.ts +38 -0
  94. package/dist/utils/elements-chain.d.ts.map +1 -0
  95. package/dist/utils/elements-chain.js +304 -0
  96. package/dist/utils/elements-chain.js.map +1 -0
  97. package/package.json +1 -1
  98. package/src/apps/apps-config.ts +6 -0
  99. package/src/config-authoring.test.ts +1 -1
  100. package/src/config-authoring.ts +6 -6
  101. package/src/config-rendering.ts +24 -2
  102. package/src/hexclave-config-file.ts +90 -1
  103. package/src/interface/admin-interface.ts +43 -1
  104. package/src/interface/admin-metrics.ts +92 -4
  105. package/src/utils/analytics-clickmap-overlay.tsx +15 -0
  106. package/src/utils/dev-tool.tsx +30 -0
  107. package/src/utils/dom.tsx +42 -0
  108. package/src/utils/elements-chain.tsx +349 -0
@@ -0,0 +1,304 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/utils/elements-chain.tsx
4
+ const ELEMENTS_CHAIN_MAX_DEPTH = 8;
5
+ const ELEMENTS_CHAIN_TEXT_MAX = 80;
6
+ const ELEMENTS_CHAIN_ATTR_MAX = 200;
7
+ const ELEMENTS_CHAIN_ATTRS = [
8
+ "id",
9
+ "data-testid",
10
+ "data-test-id",
11
+ "data-hexclave-id",
12
+ "name",
13
+ "type",
14
+ "role",
15
+ "aria-label",
16
+ "placeholder",
17
+ "title"
18
+ ];
19
+ function escapeElementsChainValue(value) {
20
+ return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
21
+ }
22
+ function escapeElementsChainClass(value) {
23
+ return value.replace(/\\/g, "\\\\").replace(/\./g, "\\.").replace(/:/g, "\\:");
24
+ }
25
+ function getElementClasses(element) {
26
+ const className = element.className;
27
+ if (typeof className !== "string" || className.trim() === "") return [];
28
+ return className.trim().split(/\s+/).filter(Boolean).slice(0, 4);
29
+ }
30
+ function getNthChildIndex(element) {
31
+ const parent = element.parentElement;
32
+ if (parent == null) return null;
33
+ const index = Array.prototype.indexOf.call(parent.children, element);
34
+ return index >= 0 ? index + 1 : null;
35
+ }
36
+ function getNthOfTypeIndex(element) {
37
+ const parent = element.parentElement;
38
+ if (parent == null) return null;
39
+ const tagName = element.tagName;
40
+ const siblings = Array.from(parent.children).filter((child) => child.tagName === tagName);
41
+ if (siblings.length <= 1) return null;
42
+ const index = siblings.indexOf(element);
43
+ return index >= 0 ? index + 1 : null;
44
+ }
45
+ function serializeElementsChainSegment(element) {
46
+ const parts = [];
47
+ parts.push(element.tagName.toLowerCase());
48
+ const classes = getElementClasses(element);
49
+ if (classes.length > 0) parts.push(`.${classes.map(escapeElementsChainClass).join(".")}`);
50
+ const text = element.textContent.trim().replace(/\s+/g, " ").slice(0, ELEMENTS_CHAIN_TEXT_MAX);
51
+ const nthChild = getNthChildIndex(element);
52
+ const nthOfType = getNthOfTypeIndex(element);
53
+ const attrPairs = [];
54
+ if (nthChild != null) attrPairs.push(`nth-child="${nthChild}"`);
55
+ if (nthOfType != null) attrPairs.push(`nth-of-type="${nthOfType}"`);
56
+ if (text !== "") attrPairs.push(`text="${escapeElementsChainValue(text)}"`);
57
+ for (const attrName of ELEMENTS_CHAIN_ATTRS) {
58
+ const value = element.getAttribute(attrName);
59
+ if (value == null || value === "") continue;
60
+ attrPairs.push(`attr__${attrName}="${escapeElementsChainValue(value.slice(0, ELEMENTS_CHAIN_ATTR_MAX))}"`);
61
+ }
62
+ if (element.tagName === "A") {
63
+ const href = element.getAttribute("href");
64
+ if (href != null && href !== "") attrPairs.push(`href="${escapeElementsChainValue(href.slice(0, ELEMENTS_CHAIN_ATTR_MAX))}"`);
65
+ }
66
+ if (attrPairs.length > 0) parts.push(`:${attrPairs.join(":")}`);
67
+ return parts.join("");
68
+ }
69
+ /**
70
+ * Serialise a clicked element and up to {@link ELEMENTS_CHAIN_MAX_DEPTH}
71
+ * ancestors (leaf-first) into an `elements_chain` string.
72
+ */
73
+ function buildElementsChain(element) {
74
+ const segments = [];
75
+ let current = element;
76
+ let depth = 0;
77
+ while (current != null && depth < ELEMENTS_CHAIN_MAX_DEPTH && current !== document.documentElement) {
78
+ segments.push(serializeElementsChainSegment(current));
79
+ current = current.parentElement;
80
+ depth += 1;
81
+ }
82
+ return segments.join(";");
83
+ }
84
+ function splitEscapedDots(input) {
85
+ const out = [];
86
+ let cur = "";
87
+ for (let i = 0; i < input.length; i++) {
88
+ const ch = input[i];
89
+ if (ch === "\\" && i + 1 < input.length) {
90
+ cur += input[i + 1];
91
+ i += 1;
92
+ continue;
93
+ }
94
+ if (ch === ".") {
95
+ out.push(cur);
96
+ cur = "";
97
+ continue;
98
+ }
99
+ cur += ch;
100
+ }
101
+ out.push(cur);
102
+ return out;
103
+ }
104
+ function applyElementsChainAttr(key, value) {
105
+ if (key === "nth-child") {
106
+ const n = Number.parseInt(value, 10);
107
+ return Number.isFinite(n) ? { nthChild: n } : {};
108
+ }
109
+ if (key === "nth-of-type") {
110
+ const n = Number.parseInt(value, 10);
111
+ return Number.isFinite(n) ? { nthOfType: n } : {};
112
+ }
113
+ if (key === "text") return { text: value };
114
+ if (key === "href") return {
115
+ href: value,
116
+ attrKey: key,
117
+ attrValue: value
118
+ };
119
+ if (key.startsWith("attr__")) return {
120
+ attrKey: key.slice(6),
121
+ attrValue: value
122
+ };
123
+ return {
124
+ attrKey: key,
125
+ attrValue: value
126
+ };
127
+ }
128
+ function parseElementsChainSegment(segment) {
129
+ const trimmed = segment.trim();
130
+ if (trimmed === "") return null;
131
+ let prefixEnd = trimmed.length;
132
+ let inQuotes = false;
133
+ for (let i = 0; i < trimmed.length; i++) {
134
+ const ch = trimmed[i];
135
+ if (ch === "\\" && i + 1 < trimmed.length) {
136
+ i += 1;
137
+ continue;
138
+ }
139
+ if (ch === "\"") {
140
+ inQuotes = !inQuotes;
141
+ continue;
142
+ }
143
+ if (ch === ":" && !inQuotes) {
144
+ prefixEnd = i;
145
+ break;
146
+ }
147
+ }
148
+ const prefix = trimmed.slice(0, prefixEnd);
149
+ const rest = trimmed.slice(prefixEnd);
150
+ const prefixParts = splitEscapedDots(prefix);
151
+ const tag = prefixParts[0].trim().toLowerCase();
152
+ if (tag === "") return null;
153
+ const classes = prefixParts.slice(1).map((c) => c.trim()).filter((c) => c !== "");
154
+ const attrs = {};
155
+ let nthChild = null;
156
+ let nthOfType = null;
157
+ let text = null;
158
+ let href = null;
159
+ let i = 0;
160
+ while (i < rest.length) {
161
+ if (rest[i] !== ":") {
162
+ i += 1;
163
+ continue;
164
+ }
165
+ i += 1;
166
+ let keyEnd = i;
167
+ while (keyEnd < rest.length && rest[keyEnd] !== "=" && rest[keyEnd] !== ":") keyEnd += 1;
168
+ const key = rest.slice(i, keyEnd).trim();
169
+ if (keyEnd >= rest.length || rest[keyEnd] !== "=") {
170
+ i = keyEnd;
171
+ continue;
172
+ }
173
+ let valStart = keyEnd + 1;
174
+ if (rest[valStart] !== "\"") {
175
+ let end = valStart;
176
+ while (end < rest.length && rest[end] !== ":") end += 1;
177
+ const result = applyElementsChainAttr(key, rest.slice(valStart, end));
178
+ if (result.nthChild != null) nthChild = result.nthChild;
179
+ if (result.nthOfType != null) nthOfType = result.nthOfType;
180
+ if (result.text != null) text = result.text;
181
+ if (result.href != null) href = result.href;
182
+ if (result.attrKey != null) attrs[result.attrKey] = result.attrValue ?? "";
183
+ i = end;
184
+ continue;
185
+ }
186
+ valStart += 1;
187
+ let end = valStart;
188
+ let value = "";
189
+ while (end < rest.length) {
190
+ const ch = rest[end];
191
+ if (ch === "\\" && end + 1 < rest.length) {
192
+ const next = rest[end + 1];
193
+ if (next === "\"" || next === "\\") {
194
+ value += next;
195
+ end += 2;
196
+ continue;
197
+ }
198
+ value += ch;
199
+ end += 1;
200
+ continue;
201
+ }
202
+ if (ch === "\"") break;
203
+ value += ch;
204
+ end += 1;
205
+ }
206
+ const result = applyElementsChainAttr(key, value);
207
+ if (result.nthChild != null) nthChild = result.nthChild;
208
+ if (result.nthOfType != null) nthOfType = result.nthOfType;
209
+ if (result.text != null) text = result.text;
210
+ if (result.href != null) href = result.href;
211
+ if (result.attrKey != null) attrs[result.attrKey] = result.attrValue ?? "";
212
+ i = end + 1;
213
+ }
214
+ return {
215
+ tag,
216
+ classes,
217
+ attrs,
218
+ text,
219
+ nthChild,
220
+ nthOfType,
221
+ href
222
+ };
223
+ }
224
+ /** Parse an `elements_chain` string into structured, leaf-first segments. */
225
+ function parseElementsChain(chain) {
226
+ const segments = [];
227
+ let current = "";
228
+ let inQuotes = false;
229
+ for (let i = 0; i < chain.length; i++) {
230
+ const ch = chain[i];
231
+ if (ch === "\\" && i + 1 < chain.length) {
232
+ current += ch + chain[i + 1];
233
+ i += 1;
234
+ continue;
235
+ }
236
+ if (ch === "\"") {
237
+ inQuotes = !inQuotes;
238
+ current += ch;
239
+ continue;
240
+ }
241
+ if (ch === ";" && !inQuotes) {
242
+ segments.push(current);
243
+ current = "";
244
+ continue;
245
+ }
246
+ current += ch;
247
+ }
248
+ if (current.length > 0) segments.push(current);
249
+ return segments.map(parseElementsChainSegment).filter((segment) => segment != null);
250
+ }
251
+ (void 0)?.test("parseElementsChain parses a simple leaf+ancestor chain", ({ expect }) => {
252
+ expect(parseElementsChain("button.btn.btn-primary:nth-of-type=\"1\":text=\"Save\":attr__id=\"save-btn\";div.container")).toEqual([{
253
+ tag: "button",
254
+ classes: ["btn", "btn-primary"],
255
+ attrs: { id: "save-btn" },
256
+ text: "Save",
257
+ nthChild: null,
258
+ nthOfType: 1,
259
+ href: null
260
+ }, {
261
+ tag: "div",
262
+ classes: ["container"],
263
+ attrs: {},
264
+ text: null,
265
+ nthChild: null,
266
+ nthOfType: null,
267
+ href: null
268
+ }]);
269
+ });
270
+ (void 0)?.test("parseElementsChain reverses class escaping for Tailwind-style tokens", ({ expect }) => {
271
+ expect(parseElementsChain("a.md\\:hover\\:bg-blue-500.w-\\[1\\.5rem\\]:href=\"/p?a=1\"")).toEqual([{
272
+ tag: "a",
273
+ classes: ["md:hover:bg-blue-500", "w-[1.5rem]"],
274
+ attrs: { href: "/p?a=1" },
275
+ text: null,
276
+ nthChild: null,
277
+ nthOfType: null,
278
+ href: "/p?a=1"
279
+ }]);
280
+ });
281
+ (void 0)?.test("parseElementsChain unescapes quotes/backslashes and ignores ';' inside quoted values", ({ expect }) => {
282
+ expect(parseElementsChain("span:text=\"a \\\"b\\\"; c \\\\ d\"")).toEqual([{
283
+ tag: "span",
284
+ classes: [],
285
+ attrs: {},
286
+ text: "a \"b\"; c \\ d",
287
+ nthChild: null,
288
+ nthOfType: null,
289
+ href: null
290
+ }]);
291
+ });
292
+ (void 0)?.test("parseElementsChain drops empty/tagless segments", ({ expect }) => {
293
+ expect(parseElementsChain("")).toEqual([]);
294
+ expect(parseElementsChain(";;")).toEqual([]);
295
+ });
296
+
297
+ //#endregion
298
+ exports.ELEMENTS_CHAIN_ATTRS = ELEMENTS_CHAIN_ATTRS;
299
+ exports.ELEMENTS_CHAIN_ATTR_MAX = ELEMENTS_CHAIN_ATTR_MAX;
300
+ exports.ELEMENTS_CHAIN_MAX_DEPTH = ELEMENTS_CHAIN_MAX_DEPTH;
301
+ exports.ELEMENTS_CHAIN_TEXT_MAX = ELEMENTS_CHAIN_TEXT_MAX;
302
+ exports.buildElementsChain = buildElementsChain;
303
+ exports.parseElementsChain = parseElementsChain;
304
+ //# sourceMappingURL=elements-chain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elements-chain.js","names":[],"sources":["../../src/utils/elements-chain.tsx"],"sourcesContent":["/**\n * PostHog-style `elements_chain` format — the single owner of both halves of the\n * contract. The event tracker {@link buildElementsChain serializes} a clicked\n * element (and its ancestors) into a string; the clickmap overlay\n * {@link parseElementsChain parses} that string back into structured segments so\n * it can re-locate the element in a live DOM.\n *\n * Encode and decode MUST round-trip exactly, which is why they live together:\n * the escaping applied here on the write side is reversed by the parser below,\n * and a single round-trip test in `elements-chain.test.tsx` guards the pair.\n *\n * Segment shape (leaf-first, joined by `;`):\n * tag.class1.class2:nth-child=\"2\":nth-of-type=\"1\":text=\"Save\":attr__id=\"x\":href=\"...\"\n */\n\nexport type ElementsChainSegment = {\n tag: string,\n classes: string[],\n attrs: Record<string, string>,\n text: string | null,\n nthChild: number | null,\n nthOfType: number | null,\n href: string | null,\n};\n\nexport const ELEMENTS_CHAIN_MAX_DEPTH = 8;\nexport const ELEMENTS_CHAIN_TEXT_MAX = 80;\nexport const ELEMENTS_CHAIN_ATTR_MAX = 200;\n\n// Attributes we serialise into elements_chain. Mirrors the set PostHog persists:\n// stable identifiers (id, data-testid), semantics (role, type, name, aria-label),\n// and a few we expect downstream tooling to want to match against.\nexport const ELEMENTS_CHAIN_ATTRS = [\n \"id\",\n \"data-testid\",\n \"data-test-id\",\n \"data-hexclave-id\",\n \"name\",\n \"type\",\n \"role\",\n \"aria-label\",\n \"placeholder\",\n \"title\",\n] as const;\n\n// ---------------------------------------------------------------------------\n// Serialization (DOM element -> elements_chain string)\n// ---------------------------------------------------------------------------\n\nfunction escapeElementsChainValue(value: string): string {\n return value.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n}\n\n// Class tokens are written into the unquoted, dot-joined prefix of a segment, so\n// any \".\" or \":\" inside a class (e.g. Tailwind variants like `md:hover:bg-blue-500`\n// or arbitrary values like `w-[1.5rem]`) must be escaped to round-trip through the\n// parser, which splits the prefix on unescaped \".\" and the segment on unescaped \":\".\nfunction escapeElementsChainClass(value: string): string {\n return value.replace(/\\\\/g, \"\\\\\\\\\").replace(/\\./g, \"\\\\.\").replace(/:/g, \"\\\\:\");\n}\n\nfunction getElementClasses(element: Element): string[] {\n const className = (element as HTMLElement).className;\n if (typeof className !== \"string\" || className.trim() === \"\") {\n return [];\n }\n return className.trim().split(/\\s+/).filter(Boolean).slice(0, 4);\n}\n\nfunction getNthChildIndex(element: Element): number | null {\n const parent = element.parentElement;\n if (parent == null) return null;\n const index = Array.prototype.indexOf.call(parent.children, element);\n return index >= 0 ? index + 1 : null;\n}\n\nfunction getNthOfTypeIndex(element: Element): number | null {\n const parent = element.parentElement;\n if (parent == null) return null;\n const tagName = element.tagName;\n const siblings = Array.from(parent.children).filter((child) => child.tagName === tagName);\n if (siblings.length <= 1) return null;\n const index = siblings.indexOf(element);\n return index >= 0 ? index + 1 : null;\n}\n\nfunction serializeElementsChainSegment(element: Element): string {\n const parts: string[] = [];\n parts.push(element.tagName.toLowerCase());\n const classes = getElementClasses(element);\n if (classes.length > 0) {\n parts.push(`.${classes.map(escapeElementsChainClass).join(\".\")}`);\n }\n const text = element.textContent.trim().replace(/\\s+/g, \" \").slice(0, ELEMENTS_CHAIN_TEXT_MAX);\n const nthChild = getNthChildIndex(element);\n const nthOfType = getNthOfTypeIndex(element);\n const attrPairs: string[] = [];\n if (nthChild != null) attrPairs.push(`nth-child=\"${nthChild}\"`);\n if (nthOfType != null) attrPairs.push(`nth-of-type=\"${nthOfType}\"`);\n if (text !== \"\") attrPairs.push(`text=\"${escapeElementsChainValue(text)}\"`);\n for (const attrName of ELEMENTS_CHAIN_ATTRS) {\n const value = element.getAttribute(attrName);\n if (value == null || value === \"\") continue;\n attrPairs.push(`attr__${attrName}=\"${escapeElementsChainValue(value.slice(0, ELEMENTS_CHAIN_ATTR_MAX))}\"`);\n }\n if (element.tagName === \"A\") {\n const href = element.getAttribute(\"href\");\n if (href != null && href !== \"\") {\n attrPairs.push(`href=\"${escapeElementsChainValue(href.slice(0, ELEMENTS_CHAIN_ATTR_MAX))}\"`);\n }\n }\n if (attrPairs.length > 0) {\n parts.push(`:${attrPairs.join(\":\")}`);\n }\n return parts.join(\"\");\n}\n\n/**\n * Serialise a clicked element and up to {@link ELEMENTS_CHAIN_MAX_DEPTH}\n * ancestors (leaf-first) into an `elements_chain` string.\n */\nexport function buildElementsChain(element: Element): string {\n const segments: string[] = [];\n let current: Element | null = element;\n let depth = 0;\n while (current != null && depth < ELEMENTS_CHAIN_MAX_DEPTH && current !== document.documentElement) {\n segments.push(serializeElementsChainSegment(current));\n current = current.parentElement;\n depth += 1;\n }\n return segments.join(\";\");\n}\n\n// ---------------------------------------------------------------------------\n// Parsing (elements_chain string -> structured segments)\n// ---------------------------------------------------------------------------\n\n// Split a string on unescaped occurrences of `.`, unescaping `\\.`, `\\:` and `\\\\`\n// back to their literal characters. Reverses `escapeElementsChainClass`.\nfunction splitEscapedDots(input: string): string[] {\n const out: string[] = [];\n let cur = '';\n for (let i = 0; i < input.length; i++) {\n const ch = input[i];\n if (ch === '\\\\' && i + 1 < input.length) {\n cur += input[i + 1];\n i += 1;\n continue;\n }\n if (ch === '.') {\n out.push(cur);\n cur = '';\n continue;\n }\n cur += ch;\n }\n out.push(cur);\n return out;\n}\n\ntype ElementsChainAttrResult = {\n nthChild?: number,\n nthOfType?: number,\n text?: string,\n href?: string,\n attrKey?: string,\n attrValue?: string,\n};\n\nfunction applyElementsChainAttr(key: string, value: string): ElementsChainAttrResult {\n if (key === 'nth-child') {\n const n = Number.parseInt(value, 10);\n return Number.isFinite(n) ? { nthChild: n } : {};\n }\n if (key === 'nth-of-type') {\n const n = Number.parseInt(value, 10);\n return Number.isFinite(n) ? { nthOfType: n } : {};\n }\n if (key === 'text') {\n return { text: value };\n }\n if (key === 'href') {\n return { href: value, attrKey: key, attrValue: value };\n }\n if (key.startsWith('attr__')) {\n return { attrKey: key.slice('attr__'.length), attrValue: value };\n }\n return { attrKey: key, attrValue: value };\n}\n\nfunction parseElementsChainSegment(segment: string): ElementsChainSegment | null {\n const trimmed = segment.trim();\n if (trimmed === '') return null;\n\n // Find first ':' at top level — separates tag/classes prefix from attribute pairs.\n let prefixEnd = trimmed.length;\n let inQuotes = false;\n for (let i = 0; i < trimmed.length; i++) {\n const ch = trimmed[i];\n if (ch === '\\\\' && i + 1 < trimmed.length) {\n i += 1;\n continue;\n }\n if (ch === '\"') {\n inQuotes = !inQuotes;\n continue;\n }\n if (ch === ':' && !inQuotes) {\n prefixEnd = i;\n break;\n }\n }\n\n const prefix = trimmed.slice(0, prefixEnd);\n const rest = trimmed.slice(prefixEnd);\n const prefixParts = splitEscapedDots(prefix);\n const tag = prefixParts[0].trim().toLowerCase();\n if (tag === '') return null;\n const classes = prefixParts.slice(1).map((c) => c.trim()).filter((c) => c !== '');\n\n const attrs: Record<string, string> = {};\n let nthChild: number | null = null;\n let nthOfType: number | null = null;\n let text: string | null = null;\n let href: string | null = null;\n\n // Parse :key=\"value\" pairs from rest.\n let i = 0;\n while (i < rest.length) {\n if (rest[i] !== ':') {\n i += 1;\n continue;\n }\n i += 1; // skip ':'\n // read key up to '='\n let keyEnd = i;\n while (keyEnd < rest.length && rest[keyEnd] !== '=' && rest[keyEnd] !== ':') keyEnd += 1;\n const key = rest.slice(i, keyEnd).trim();\n if (keyEnd >= rest.length || rest[keyEnd] !== '=') {\n i = keyEnd;\n continue;\n }\n let valStart = keyEnd + 1;\n if (rest[valStart] !== '\"') {\n // unquoted — read until next ':' at top level\n let end = valStart;\n while (end < rest.length && rest[end] !== ':') end += 1;\n const value = rest.slice(valStart, end);\n const result = applyElementsChainAttr(key, value);\n if (result.nthChild != null) nthChild = result.nthChild;\n if (result.nthOfType != null) nthOfType = result.nthOfType;\n if (result.text != null) text = result.text;\n if (result.href != null) href = result.href;\n if (result.attrKey != null) attrs[result.attrKey] = result.attrValue ?? '';\n i = end;\n continue;\n }\n // quoted value — find unescaped closing quote\n valStart += 1;\n let end = valStart;\n let value = '';\n while (end < rest.length) {\n const ch = rest[end];\n if (ch === '\\\\' && end + 1 < rest.length) {\n const next = rest[end + 1];\n if (next === '\"' || next === '\\\\') {\n value += next;\n end += 2;\n continue;\n }\n value += ch;\n end += 1;\n continue;\n }\n if (ch === '\"') break;\n value += ch;\n end += 1;\n }\n const result = applyElementsChainAttr(key, value);\n if (result.nthChild != null) nthChild = result.nthChild;\n if (result.nthOfType != null) nthOfType = result.nthOfType;\n if (result.text != null) text = result.text;\n if (result.href != null) href = result.href;\n if (result.attrKey != null) attrs[result.attrKey] = result.attrValue ?? '';\n i = end + 1; // skip closing quote\n }\n\n return { tag, classes, attrs, text, nthChild, nthOfType, href };\n}\n\n/** Parse an `elements_chain` string into structured, leaf-first segments. */\nexport function parseElementsChain(chain: string): ElementsChainSegment[] {\n // Split top-level by ';' respecting quoted strings.\n const segments: string[] = [];\n let current = '';\n let inQuotes = false;\n for (let i = 0; i < chain.length; i++) {\n const ch = chain[i];\n if (ch === '\\\\' && i + 1 < chain.length) {\n current += ch + chain[i + 1];\n i += 1;\n continue;\n }\n if (ch === '\"') {\n inQuotes = !inQuotes;\n current += ch;\n continue;\n }\n if (ch === ';' && !inQuotes) {\n segments.push(current);\n current = '';\n continue;\n }\n current += ch;\n }\n if (current.length > 0) {\n segments.push(current);\n }\n return segments.map(parseElementsChainSegment).filter((segment): segment is ElementsChainSegment => segment != null);\n}\n\nimport.meta.vitest?.test(\"parseElementsChain parses a simple leaf+ancestor chain\", ({ expect }) => {\n const parsed = parseElementsChain('button.btn.btn-primary:nth-of-type=\"1\":text=\"Save\":attr__id=\"save-btn\";div.container');\n expect(parsed).toEqual([\n { tag: \"button\", classes: [\"btn\", \"btn-primary\"], attrs: { id: \"save-btn\" }, text: \"Save\", nthChild: null, nthOfType: 1, href: null },\n { tag: \"div\", classes: [\"container\"], attrs: {}, text: null, nthChild: null, nthOfType: null, href: null },\n ]);\n});\n\nimport.meta.vitest?.test(\"parseElementsChain reverses class escaping for Tailwind-style tokens\", ({ expect }) => {\n // `md:hover:bg-blue-500` and `w-[1.5rem]` contain the prefix delimiters `:`/`.`,\n // so the serializer escapes them; the parser must recover the literal classes.\n const parsed = parseElementsChain('a.md\\\\:hover\\\\:bg-blue-500.w-\\\\[1\\\\.5rem\\\\]:href=\"/p?a=1\"');\n expect(parsed).toEqual([\n { tag: \"a\", classes: [\"md:hover:bg-blue-500\", \"w-[1.5rem]\"], attrs: { href: \"/p?a=1\" }, text: null, nthChild: null, nthOfType: null, href: \"/p?a=1\" },\n ]);\n});\n\nimport.meta.vitest?.test(\"parseElementsChain unescapes quotes/backslashes and ignores ';' inside quoted values\", ({ expect }) => {\n const parsed = parseElementsChain('span:text=\"a \\\\\"b\\\\\"; c \\\\\\\\ d\"');\n expect(parsed).toEqual([\n { tag: \"span\", classes: [], attrs: {}, text: 'a \"b\"; c \\\\ d', nthChild: null, nthOfType: null, href: null },\n ]);\n});\n\nimport.meta.vitest?.test(\"parseElementsChain drops empty/tagless segments\", ({ expect }) => {\n expect(parseElementsChain(\"\")).toEqual([]);\n expect(parseElementsChain(\";;\")).toEqual([]);\n});\n"],"mappings":";;;AAyBA,MAAa,2BAA2B;AACxC,MAAa,0BAA0B;AACvC,MAAa,0BAA0B;AAKvC,MAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAMD,SAAS,yBAAyB,OAAuB;AACvD,QAAO,MAAM,QAAQ,OAAO,OAAO,CAAC,QAAQ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AAO,EAAE;EAAE,MAAM;EAAM,UAAU;EAAM,WAAW;EAAM,MAAM;EAAM,CAC3G,CAAC;EACF;CAEF,SAAW,KAAC,yEAA4E,EAAA,aAAY;AAIlG,QADe,mBAAmB,8DAA4D,CAChF,CAAC,QAAQ,CACrB;EAAE,KAAK;EAAK,SAAS,CAAC,wBAAwB,aAAa;EAAE,OAAO,EAAE,MAAM,UAAU;EAAE,MAAM;EAAM,UAAU;EAAM,WAAW;EAAM,MAAM;EAAU,CACtJ,CAAC;EACF;CAEF,SAAW,KAAC,yFAA4F,EAAA,aAAY;AAElH,QADe,mBAAmB,sCAAkC,CACtD,CAAC,QAAQ,CACrB;EAAE,KAAK;EAAQ,SAAS,EAAE;EAAE,OAAO,EAAE;EAAE,MAAM;EAAiB,UAAU;EAAM,WAAW;EAAM,MAAM;EAAM,CAC5G,CAAC;EACF;CAEF,SAAW,KAAC,oDAAqD,EAAA,aAAc;AAC7E,QAAO,mBAAmB,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC1C,QAAO,mBAAmB,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;EAC5C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexclave/shared",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "repository": "https://github.com/hexclave/hexclave",
5
5
  "files": [
6
6
  "README.md",
@@ -168,6 +168,12 @@ export const ALL_APPS = {
168
168
  tags: ["developers", "operations"],
169
169
  stage: "stable",
170
170
  },
171
+ "clickmaps": {
172
+ displayName: "Clickmaps",
173
+ subtitle: "Visualize where users click across your app",
174
+ tags: ["developers", "operations"],
175
+ stage: "alpha",
176
+ },
171
177
  "session-replays": {
172
178
  displayName: "Session Replays",
173
179
  subtitle: "Watch real user sessions to understand how people use your app",
@@ -1,6 +1,6 @@
1
1
  import { expect, it } from "vitest";
2
- import { typeAssertExtends } from "./utils/types";
3
2
  import { defineStackConfig, type StackConfig } from "./config-authoring";
3
+ import { typeAssertExtends } from "./utils/types";
4
4
 
5
5
  const validConfig = defineStackConfig({
6
6
  payments: {
@@ -10,16 +10,16 @@ export type HexclaveConfig = StackConfigObject | typeof showOnboardingHexclaveCo
10
10
 
11
11
  type StrictConfigShape<Actual, Expected> =
12
12
  Expected extends readonly unknown[]
13
- ? Actual extends readonly unknown[]
13
+ ? Actual extends readonly unknown[]
14
14
  ? { [K in keyof Actual]: K extends keyof Expected ? StrictConfigShape<Actual[K], Expected[K]> : never }
15
- : Actual
15
+ : Actual
16
16
  : Expected extends object
17
- ? Actual extends object
17
+ ? Actual extends object
18
18
  ? Exclude<keyof Actual, keyof Expected> extends never
19
19
  ? { [K in keyof Actual]: K extends keyof Expected ? StrictConfigShape<Actual[K], Expected[K]> : never }
20
- : never
21
- : Actual
22
- : Actual;
20
+ : never
21
+ : Actual
22
+ : Actual;
23
23
 
24
24
  type StrictStackConfig<T extends StackConfig> =
25
25
  T extends StackConfigObject
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync } from "fs";
2
2
  import path from "path";
3
- import { parseHexclaveConfigFileContent, renderConfigFileContent } from "./hexclave-config-file";
4
- export { parseHexclaveConfigFileContent, renderConfigFileContent };
3
+ import { hexclaveConfigFileExportsConfig, parseHexclaveConfigFileContent, renderConfigFileContent, tryParseHexclaveConfigFileContent } from "./hexclave-config-file";
4
+ export { hexclaveConfigFileExportsConfig, parseHexclaveConfigFileContent, renderConfigFileContent, tryParseHexclaveConfigFileContent };
5
5
 
6
6
  /**
7
7
  * Packages that export the `HexclaveConfig` type, in priority order.
@@ -106,6 +106,28 @@ import.meta.vitest?.test("parseHexclaveConfigFileContent rejects dynamic config
106
106
  expect(() => parseHexclaveConfigFileContent("export const config = makeConfig();", "stack.config.ts")).toThrow(/Unsupported config expression/);
107
107
  });
108
108
 
109
+ import.meta.vitest?.test("tryParseHexclaveConfigFileContent returns the config for static exports", ({ expect }) => {
110
+ expect(tryParseHexclaveConfigFileContent("export const config = { auth: { allowSignUp: true } };", "stack.config.ts")).toEqual({
111
+ auth: { allowSignUp: true },
112
+ });
113
+ });
114
+
115
+ import.meta.vitest?.test("tryParseHexclaveConfigFileContent returns null for non-static exports", ({ expect }) => {
116
+ // Wrapped in a helper call (e.g. defineStackConfig) -> not a plain literal.
117
+ expect(tryParseHexclaveConfigFileContent("export const config = makeConfig();", "stack.config.ts")).toBeNull();
118
+ // References an imported value -> has structure to preserve.
119
+ expect(tryParseHexclaveConfigFileContent('import x from "./x.txt" with { type: "text" };\nexport const config = { a: x };', "stack.config.ts")).toBeNull();
120
+ // Syntax error.
121
+ expect(tryParseHexclaveConfigFileContent("export const config = {", "stack.config.ts")).toBeNull();
122
+ });
123
+
124
+ import.meta.vitest?.test("hexclaveConfigFileExportsConfig detects a config export", ({ expect }) => {
125
+ expect(hexclaveConfigFileExportsConfig("export const config = { a: 1 };", "stack.config.ts")).toBe(true);
126
+ expect(hexclaveConfigFileExportsConfig('import x from "./x.txt" with { type: "text" };\nexport const config = { a: x };', "stack.config.ts")).toBe(true);
127
+ expect(hexclaveConfigFileExportsConfig("export const notConfig = { a: 1 };", "stack.config.ts")).toBe(false);
128
+ expect(hexclaveConfigFileExportsConfig("export const config = {", "stack.config.ts")).toBe(false);
129
+ });
130
+
109
131
  import.meta.vitest?.test("renderConfigFileContent rejects conflicting dotted keys", ({ expect }) => {
110
132
  expect(() => renderConfigFileContent({
111
133
  "a.b": 1,
@@ -100,11 +100,100 @@ function evaluateStaticConfigExpression(expression: t.Expression): unknown {
100
100
  throw new Error(`Unsupported config expression: ${unwrapped.type}`);
101
101
  }
102
102
 
103
+ /**
104
+ * Like {@link parseHexclaveConfigFileContent}, but returns `null` instead of
105
+ * throwing when the file is not a plain static config (e.g. it wraps the config
106
+ * in a helper call, references imported values, or has a syntax error). Useful
107
+ * for deciding whether a config file can be safely regenerated deterministically
108
+ * or whether it has custom structure that must be preserved.
109
+ */
110
+ export function tryParseHexclaveConfigFileContent(content: string, filePath: string): ParsedStackConfig | null {
111
+ try {
112
+ return parseHexclaveConfigFileContent(content, filePath);
113
+ } catch {
114
+ return null;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Returns whether `content` parses as a module that exports a `config` binding.
120
+ * Used as a lightweight structural sanity check after editing config files whose
121
+ * values can't be evaluated by our loader (e.g. they import external text
122
+ * files), where a full semantic comparison isn't possible.
123
+ */
124
+ export function hexclaveConfigFileExportsConfig(content: string, filePath: string): boolean {
125
+ let ast: parser.ParseResult<t.File>;
126
+ try {
127
+ ast = parser.parse(content, {
128
+ sourceType: "module",
129
+ sourceFilename: filePath,
130
+ plugins: ["typescript", "importAttributes"],
131
+ });
132
+ } catch {
133
+ return false;
134
+ }
135
+ for (const statement of ast.program.body) {
136
+ if (!t.isExportNamedDeclaration(statement)) {
137
+ continue;
138
+ }
139
+ // Ignore type-only exports (`export type { config }`): they don't produce a
140
+ // runtime `config` value, so they must not satisfy the structural check.
141
+ if (statement.exportKind === "type") {
142
+ continue;
143
+ }
144
+ if (t.isVariableDeclaration(statement.declaration)) {
145
+ for (const declaration of statement.declaration.declarations) {
146
+ if (t.isIdentifier(declaration.id) && declaration.id.name === "config" && declaration.init != null) {
147
+ return true;
148
+ }
149
+ }
150
+ }
151
+ for (const specifier of statement.specifiers) {
152
+ if (t.isExportSpecifier(specifier) && specifier.exportKind !== "type") {
153
+ const exportedName = t.isIdentifier(specifier.exported) ? specifier.exported.name : specifier.exported.value;
154
+ if (exportedName === "config") {
155
+ return true;
156
+ }
157
+ }
158
+ }
159
+ }
160
+ return false;
161
+ }
162
+
163
+ /**
164
+ * Returns the relative import sources (those starting with `./` or `../`)
165
+ * declared in `content`. Used to discover the external files a config update may
166
+ * touch — e.g. `import x from "./welcome-email.tsx" with { type: "text" }` — so
167
+ * they can be snapshotted and rolled back if an in-place update fails. Returns
168
+ * an empty array if the file can't be parsed.
169
+ */
170
+ export function getRelativeImportSpecifiers(content: string): string[] {
171
+ let ast: parser.ParseResult<t.File>;
172
+ try {
173
+ ast = parser.parse(content, {
174
+ sourceType: "module",
175
+ plugins: ["typescript", "importAttributes"],
176
+ });
177
+ } catch {
178
+ return [];
179
+ }
180
+ const sources: string[] = [];
181
+ for (const statement of ast.program.body) {
182
+ if (t.isImportDeclaration(statement)) {
183
+ const source = statement.source.value;
184
+ if (source.startsWith("./") || source.startsWith("../")) {
185
+ sources.push(source);
186
+ }
187
+ }
188
+ }
189
+ return sources;
190
+ }
191
+
103
192
  export function parseHexclaveConfigFileContent(content: string, filePath: string): ParsedStackConfig {
104
193
  if (content.trim() === "") return {};
105
194
  const ast = parser.parse(content, {
106
195
  sourceType: "module",
107
- plugins: ["typescript"],
196
+ plugins: ["typescript", "importAttributes"],
108
197
  });
109
198
 
110
199
  for (const statement of ast.program.body) {
@@ -6,7 +6,7 @@ import type { MoneyAmount } from "../utils/currency-constants";
6
6
  import type { Json } from "../utils/json";
7
7
  import { Result } from "../utils/results";
8
8
  import { urlString } from "../utils/urls";
9
- import type { MetricsResponse, MetricsUserCounts, UserActivityResponse } from "./admin-metrics";
9
+ import type { AnalyticsClickmapDevice, AnalyticsClickmapKind, AnalyticsClickmapResponse, AnalyticsClickmapTokenResponse, MetricsResponse, MetricsUserCounts, UserActivityResponse } from "./admin-metrics";
10
10
  import type { AnalyticsQueryOptions, AnalyticsQueryResponse } from "./crud/analytics";
11
11
  import { EmailOutboxCrud } from "./crud/email-outbox";
12
12
  import { InternalEmailsCrud } from "./crud/emails";
@@ -435,6 +435,48 @@ export class HexclaveAdminInterface extends HexclaveServerInterface {
435
435
  return (await response.json()) as UserActivityResponse;
436
436
  }
437
437
 
438
+ async getAnalyticsClickmap(options: {
439
+ kind: AnalyticsClickmapKind,
440
+ member_user_ids?: string[],
441
+ route_path?: string,
442
+ route_regex?: string,
443
+ url_pattern?: string,
444
+ user_id?: string,
445
+ replay_id?: string,
446
+ device?: AnalyticsClickmapDevice,
447
+ viewport_width_min?: number,
448
+ viewport_width_max?: number,
449
+ sampling?: number,
450
+ since: string,
451
+ until: string,
452
+ }): Promise<AnalyticsClickmapResponse> {
453
+ const response = await this.sendAdminRequest(
454
+ "/internal/analytics/clickmap",
455
+ {
456
+ method: "POST",
457
+ headers: { "content-type": "application/json" },
458
+ body: JSON.stringify(options),
459
+ },
460
+ null,
461
+ );
462
+ return (await response.json()) as AnalyticsClickmapResponse;
463
+ }
464
+
465
+ async createAnalyticsClickmapToken(options: {
466
+ origin: string,
467
+ }): Promise<AnalyticsClickmapTokenResponse> {
468
+ const response = await this.sendAdminRequest(
469
+ "/internal/analytics/clickmap-token",
470
+ {
471
+ method: "POST",
472
+ headers: { "content-type": "application/json" },
473
+ body: JSON.stringify(options),
474
+ },
475
+ null,
476
+ );
477
+ return (await response.json()) as AnalyticsClickmapTokenResponse;
478
+ }
479
+
438
480
  async getMetricsUserCounts(): Promise<MetricsUserCounts> {
439
481
  const response = await this.sendAdminRequest(
440
482
  "/internal/metrics/user-counts",