@devalon.dev/credits 1.0.0 → 1.0.2

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 (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -2
  3. package/dist/chunk-IJASKDEW.mjs +1 -0
  4. package/dist/chunk-PYZQVHOF.mjs +16 -0
  5. package/dist/chunk-RZ4S6JFB.mjs +11 -0
  6. package/dist/core/backlink.d.ts +21 -2
  7. package/dist/core/index.d.ts +2 -2
  8. package/dist/next/index.d.ts +4 -0
  9. package/dist/next/index.js +9 -9
  10. package/dist/next/index.mjs +1 -1
  11. package/dist/next/source.d.ts +12 -0
  12. package/dist/react/index.d.ts +2 -1
  13. package/dist/react/index.js +19 -19
  14. package/dist/react/index.mjs +1 -1
  15. package/dist/signals/component.d.ts +16 -0
  16. package/dist/signals/config.d.ts +9 -0
  17. package/dist/signals/detect.d.ts +24 -0
  18. package/dist/signals/event.d.ts +13 -0
  19. package/dist/signals/index.d.ts +7 -0
  20. package/dist/signals/index.js +17 -0
  21. package/dist/signals/index.mjs +17 -0
  22. package/dist/signals/meta/index.d.ts +3 -0
  23. package/dist/signals/meta/pixel.d.ts +18 -0
  24. package/dist/signals/meta/types.d.ts +21 -0
  25. package/dist/signals/signal.d.ts +9 -0
  26. package/dist/signals/types.d.ts +26 -0
  27. package/dist/vite/index.js +23 -23
  28. package/dist/vite/index.mjs +4 -4
  29. package/dist/vite/plugin.d.ts +1 -1
  30. package/docs/nextjs/05-performance-checklist.md +1 -1
  31. package/docs/nextjs/06-backlink-component.md +50 -27
  32. package/docs/react/02-csr-vite.md +6 -0
  33. package/docs/react/03-i18n.md +8 -8
  34. package/docs/react/05-backlink-component.md +15 -10
  35. package/docs/react/08-validator.md +1 -1
  36. package/docs/signals/01-meta-pixel.md +203 -0
  37. package/package.json +11 -4
  38. package/scripts/backlink.test.mjs +178 -0
  39. package/scripts/signals.test.mjs +459 -0
  40. package/dist/chunk-QU6SEFG7.mjs +0 -16
  41. package/dist/chunk-YF7SVQTC.mjs +0 -11
@@ -0,0 +1,178 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+
4
+ import {
5
+ devalonBacklinkHtml,
6
+ devalonInjectHtml,
7
+ detect_site_url,
8
+ resolve_backlink,
9
+ } from "../dist/react/index.mjs";
10
+ import { devalonBacklinkSiteUrlFromHeaders } from "../dist/next/index.mjs";
11
+ import { devalonVite } from "../dist/vite/index.mjs";
12
+
13
+ const CLEAN = "https://devalon.dev";
14
+ const UTM =
15
+ "https://devalon.dev/?utm_source=example.com&utm_medium=credit&utm_campaign=devalon-credits";
16
+
17
+ describe("backlink defaults", () => {
18
+ it("uses the short localized sentences", () => {
19
+ assert.equal(resolve_backlink({ locale: "en" }).text, "Designed and built by");
20
+ assert.equal(resolve_backlink({ locale: "ro" }).text, "Proiectat și realizat de");
21
+ assert.equal(resolve_backlink({ locale: "de" }).text, "Entworfen und entwickelt von");
22
+ });
23
+
24
+ it("emits a clean link when no source is available", () => {
25
+ assert.equal(resolve_backlink({}).href, CLEAN);
26
+ assert.equal(resolve_backlink({ locale: "ro" }).href, CLEAN);
27
+ });
28
+
29
+ it("appends hostname-only UTM by default", () => {
30
+ const result = resolve_backlink({
31
+ site_url: "https://www.Example.com/ro/about?x=1",
32
+ locale: "ro",
33
+ });
34
+ assert.equal(result.href, UTM);
35
+ assert.equal(result.link_text, "Devalon");
36
+ });
37
+
38
+ it("honours utm: false and an explicit sentence/anchor", () => {
39
+ assert.equal(
40
+ resolve_backlink({ site_url: "https://example.com", utm: false }).href,
41
+ CLEAN,
42
+ );
43
+ const result = resolve_backlink({ sentence: "Custom text", anchor: "Studio" });
44
+ assert.equal(result.text, "Custom text");
45
+ assert.equal(result.link_text, "Studio");
46
+ });
47
+
48
+ it("still rejects invalid explicit site_url values", () => {
49
+ assert.throws(() => resolve_backlink({ site_url: "/despre" }), TypeError);
50
+ });
51
+ });
52
+
53
+ describe("source detection", () => {
54
+ it("normalizes bare hosts and strips paths", () => {
55
+ assert.equal(detect_site_url({ SITE_URL: "Example.com/ro" }), "https://example.com");
56
+ assert.equal(
57
+ detect_site_url({ SITE_URL: "http://example.com:8080/x" }),
58
+ "http://example.com",
59
+ );
60
+ });
61
+
62
+ it("respects priority and skips unusable values", () => {
63
+ assert.equal(
64
+ detect_site_url({
65
+ NEXT_PUBLIC_SITE_URL: "ok.com",
66
+ SITE_URL: "ftp://bad.example",
67
+ }),
68
+ "https://ok.com",
69
+ );
70
+ assert.equal(
71
+ detect_site_url({ SITE_URL: "not a url", VERCEL_URL: "app.vercel.app" }),
72
+ "https://app.vercel.app",
73
+ );
74
+ assert.equal(detect_site_url({}), undefined);
75
+ });
76
+
77
+ it("derives an absolute URL from request headers", () => {
78
+ assert.equal(
79
+ devalonBacklinkSiteUrlFromHeaders(
80
+ new Headers({ host: "example.com", "x-forwarded-proto": "http" }),
81
+ ),
82
+ "http://example.com",
83
+ );
84
+ assert.equal(
85
+ devalonBacklinkSiteUrlFromHeaders(
86
+ new Headers({
87
+ "x-forwarded-host": "www.Example.com, proxy",
88
+ host: "internal.local",
89
+ }),
90
+ ),
91
+ "https://example.com",
92
+ );
93
+ assert.equal(devalonBacklinkSiteUrlFromHeaders(undefined), undefined);
94
+ });
95
+
96
+ it("auto-detects from process.env in the HTML helper", () => {
97
+ const original = process.env.SITE_URL;
98
+ process.env.SITE_URL = "env-site.com";
99
+ try {
100
+ const html = devalonBacklinkHtml({ locale: "ro" });
101
+ assert.match(html, /Proiectat și realizat de/);
102
+ assert.match(html, /utm_source=env-site\.com/);
103
+ } finally {
104
+ if (original === undefined) delete process.env.SITE_URL;
105
+ else process.env.SITE_URL = original;
106
+ }
107
+ });
108
+
109
+ it("injects a UTM link into HTML from build-time env", () => {
110
+ const original = process.env.SITE_URL;
111
+ process.env.SITE_URL = "vite-site.com";
112
+ try {
113
+ const plugin = devalonVite({
114
+ site_url: "https://vite-site.com",
115
+ site_name: "Vite Site",
116
+ backlink: { locale: "ro" },
117
+ });
118
+ const html = plugin.transformIndexHtml.handler(
119
+ "<html><head></head><body></body></html>",
120
+ );
121
+ assert.match(html, /utm_source=vite-site\.com/);
122
+ assert.match(html, /Proiectat și realizat de/);
123
+ } finally {
124
+ if (original === undefined) delete process.env.SITE_URL;
125
+ else process.env.SITE_URL = original;
126
+ }
127
+ });
128
+
129
+ it("prefers explicit site_url over detection and still honours utm: false", () => {
130
+ const original = process.env.SITE_URL;
131
+ process.env.SITE_URL = "vite-site.com";
132
+ try {
133
+ const explicit = devalonVite({
134
+ site_url: "https://vite-site.com",
135
+ site_name: "Vite Site",
136
+ backlink: { locale: "ro", site_url: "https://explicit.com/ro" },
137
+ });
138
+ const explicit_html = explicit.transformIndexHtml.handler(
139
+ "<html><head></head><body></body></html>",
140
+ );
141
+ assert.match(explicit_html, /utm_source=explicit\.com/);
142
+ assert.doesNotMatch(explicit_html, /utm_source=vite-site\.com/);
143
+
144
+ const disabled = devalonVite({
145
+ site_url: "https://vite-site.com",
146
+ site_name: "Vite Site",
147
+ backlink: { locale: "ro", utm: false },
148
+ });
149
+ const disabled_html = disabled.transformIndexHtml.handler(
150
+ "<html><head></head><body></body></html>",
151
+ );
152
+ assert.match(disabled_html, /href="https:\/\/devalon\.dev"/);
153
+ assert.doesNotMatch(disabled_html, /utm_source=/);
154
+ } finally {
155
+ if (original === undefined) delete process.env.SITE_URL;
156
+ else process.env.SITE_URL = original;
157
+ }
158
+ });
159
+
160
+ it("keeps devalonInjectHtml clean with no detectable source", () => {
161
+ const original = process.env.SITE_URL;
162
+ delete process.env.SITE_URL;
163
+ try {
164
+ const html = devalonInjectHtml(
165
+ "<html><head></head><body></body></html>",
166
+ {
167
+ site_url: "https://example.com",
168
+ site_name: "Example",
169
+ backlink: { locale: "ro" },
170
+ },
171
+ );
172
+ assert.match(html, /href="https:\/\/devalon\.dev"/);
173
+ assert.doesNotMatch(html, /utm_source=/);
174
+ } finally {
175
+ if (original !== undefined) process.env.SITE_URL = original;
176
+ }
177
+ });
178
+ });
@@ -0,0 +1,459 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+
4
+ import {
5
+ DEVALON_CUSTOM_EVENT_NAMES,
6
+ META_REQUIRED_EVENT_PARAMS,
7
+ DevalonSignal,
8
+ PIXEL_READY_CHECK_DELAY_MS,
9
+ create_signal_event,
10
+ create_signal_event_id,
11
+ devalon_meta_pixel_html,
12
+ devalon_meta_pixel_noscript,
13
+ devalon_meta_pixel_script,
14
+ loadMetaPixel,
15
+ pixel_sdk_ready,
16
+ reset_signal_pixel_id,
17
+ set_signal_pixel_id,
18
+ signal as sendSignal,
19
+ } from "../dist/signals/index.mjs";
20
+
21
+ const PIXEL_ID = "1683475309995701";
22
+ const OTHER_PIXEL_ID = "999999999999999";
23
+
24
+ const CANONICAL_SCRIPT = `!function(f,b,e,v,n,t,s)
25
+ {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
26
+ n.callMethod.apply(n,arguments):n.queue.push(arguments)};
27
+ if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
28
+ n.queue=[];t=b.createElement(e);t.async=!0;
29
+ t.src=v;s=b.getElementsByTagName(e)[0];
30
+ s.parentNode.insertBefore(t,s)}(window, document,'script',
31
+ 'https://connect.facebook.net/en_US/fbevents.js');
32
+ fbq('init', '${PIXEL_ID}');
33
+ fbq('track', 'PageView');`;
34
+
35
+ function stub_fbq({ ready = true } = {}) {
36
+ const calls = [];
37
+ const fbq = (...args) => calls.push(args);
38
+ if (ready) fbq.callMethod = () => {};
39
+ globalThis.fbq = fbq;
40
+ return calls;
41
+ }
42
+
43
+ function capture_logs() {
44
+ const info = [];
45
+ const warn = [];
46
+ const original_info = console.info;
47
+ const original_warn = console.warn;
48
+
49
+ console.info = (...args) => info.push(args.join(" "));
50
+ console.warn = (...args) => warn.push(args.join(" "));
51
+
52
+ return {
53
+ info,
54
+ warn,
55
+ restore() {
56
+ console.info = original_info;
57
+ console.warn = original_warn;
58
+ },
59
+ };
60
+ }
61
+
62
+ function clear_pixel_config() {
63
+ reset_signal_pixel_id();
64
+ delete globalThis.__DEVALON_SIGNAL_PIXEL_ID;
65
+ }
66
+
67
+ describe("meta pixel snippet", () => {
68
+ it("reproduces the Events Manager script byte-for-byte", () => {
69
+ assert.equal(devalon_meta_pixel_script(PIXEL_ID), CANONICAL_SCRIPT);
70
+ });
71
+
72
+ it("changes only the pixel id between two IDs", () => {
73
+ assert.equal(
74
+ devalon_meta_pixel_script("123456789"),
75
+ CANONICAL_SCRIPT.replaceAll(PIXEL_ID, "123456789"),
76
+ );
77
+ });
78
+
79
+ it("interpolates the id into the noscript fallback URL", () => {
80
+ assert.equal(
81
+ devalon_meta_pixel_noscript(PIXEL_ID),
82
+ `<img height="1" width="1" style="display:none"\n` +
83
+ `src="https://www.facebook.com/tr?id=${PIXEL_ID}&ev=PageView&noscript=1"\n` +
84
+ `/>`,
85
+ );
86
+ });
87
+
88
+ it("assembles the full snippet with markers and the pixel id twice", () => {
89
+ const { script, noscript, html } = devalon_meta_pixel_html(PIXEL_ID);
90
+
91
+ assert.equal(script, CANONICAL_SCRIPT);
92
+ assert.match(html, /^<!-- Meta Pixel Code -->\n<script>\n/);
93
+ assert.match(html, /\n<\/script>\n<noscript>/);
94
+ assert.match(html, /<!-- End Meta Pixel Code -->$/);
95
+ assert.equal(html.match(new RegExp(PIXEL_ID, "g"))?.length, 2);
96
+ assert.equal(html.includes(noscript), true);
97
+ });
98
+
99
+ it("puts a nonce on the script tag only", () => {
100
+ const { html } = devalon_meta_pixel_html(PIXEL_ID, "abc123");
101
+ assert.match(html, /<script nonce="abc123">/);
102
+ assert.doesNotMatch(html, /<img[^>]*nonce/);
103
+ });
104
+
105
+ it("rejects invalid pixel IDs and nonces", () => {
106
+ assert.throws(() => devalon_meta_pixel_script("not-a-number"), TypeError);
107
+ assert.throws(() => devalon_meta_pixel_noscript(""), TypeError);
108
+ assert.throws(() => devalon_meta_pixel_html(PIXEL_ID, 'x" onload="'), TypeError);
109
+ });
110
+ });
111
+
112
+ describe("signals component", () => {
113
+ it("renders the bridge, the canonical snippet and the noscript", () => {
114
+ const [bridge, script, noscript] = DevalonSignal({
115
+ pixelId: PIXEL_ID,
116
+ }).props.children;
117
+
118
+ assert.equal(bridge.type, "script");
119
+ assert.equal(
120
+ bridge.props.dangerouslySetInnerHTML.__html,
121
+ `window.__DEVALON_SIGNAL_PIXEL_ID="${PIXEL_ID}";`,
122
+ );
123
+ assert.equal(script.type, "script");
124
+ assert.equal(script.props.dangerouslySetInnerHTML.__html, CANONICAL_SCRIPT);
125
+ assert.equal(noscript.type, "noscript");
126
+ assert.equal(
127
+ noscript.props.dangerouslySetInnerHTML.__html,
128
+ devalon_meta_pixel_noscript(PIXEL_ID),
129
+ );
130
+ });
131
+
132
+ it("forwards the CSP nonce to both script tags", () => {
133
+ const [bridge, script, noscript] = DevalonSignal({
134
+ pixelId: PIXEL_ID,
135
+ nonce: "abc123",
136
+ }).props.children;
137
+
138
+ assert.equal(bridge.props.nonce, "abc123");
139
+ assert.equal(script.props.nonce, "abc123");
140
+ assert.equal(noscript.props.nonce, undefined);
141
+ });
142
+ });
143
+
144
+ describe("client-side loader", () => {
145
+ function stub_document() {
146
+ const appended = [];
147
+ const by_id = new Map();
148
+
149
+ globalThis.document = {
150
+ createElement(tag) {
151
+ return { tag, id: "", textContent: "" };
152
+ },
153
+ getElementById(id) {
154
+ return by_id.get(id) ?? null;
155
+ },
156
+ head: {
157
+ appendChild(node) {
158
+ appended.push(node);
159
+ by_id.set(node.id, node);
160
+ },
161
+ },
162
+ };
163
+
164
+ return appended;
165
+ }
166
+
167
+ it("injects the canonical script once per pixel id", () => {
168
+ const appended = stub_document();
169
+ const id = "111111111111111";
170
+
171
+ try {
172
+ loadMetaPixel(id);
173
+ loadMetaPixel(id);
174
+
175
+ assert.equal(appended.length, 1);
176
+ assert.equal(appended[0].tag, "script");
177
+ assert.equal(
178
+ appended[0].textContent,
179
+ CANONICAL_SCRIPT.replaceAll(PIXEL_ID, id),
180
+ );
181
+ } finally {
182
+ delete globalThis.document;
183
+ clear_pixel_config();
184
+ }
185
+ });
186
+
187
+ it("registers our id on an fbq installed by another pixel", () => {
188
+ const calls = stub_fbq();
189
+ const appended = stub_document();
190
+
191
+ try {
192
+ loadMetaPixel("333333333333333");
193
+
194
+ assert.deepEqual(calls, [["init", "333333333333333"]]);
195
+ assert.equal(appended.length, 0);
196
+ } finally {
197
+ delete globalThis.fbq;
198
+ delete globalThis.document;
199
+ clear_pixel_config();
200
+ }
201
+ });
202
+
203
+ it("does nothing without a DOM", () => {
204
+ try {
205
+ assert.doesNotThrow(() => loadMetaPixel("222222222222222"));
206
+ } finally {
207
+ delete globalThis.fbq;
208
+ clear_pixel_config();
209
+ }
210
+ });
211
+ });
212
+
213
+ describe("signal() with multiple Meta Pixels", () => {
214
+ it("sends standard events only to Devalon's pixel with a dedup id", () => {
215
+ const calls = stub_fbq();
216
+ const logs = capture_logs();
217
+ set_signal_pixel_id(PIXEL_ID);
218
+
219
+ try {
220
+ // Simulate two other pixels initialized in the same shared queue.
221
+ globalThis.fbq("init", OTHER_PIXEL_ID);
222
+
223
+ const event = sendSignal(
224
+ "Purchase",
225
+ { value: 10, currency: "USD" },
226
+ { debug: true },
227
+ );
228
+
229
+ assert.deepEqual(calls.at(-1), [
230
+ "trackSingle",
231
+ PIXEL_ID,
232
+ "Purchase",
233
+ { value: 10, currency: "USD" },
234
+ { eventID: event.event_id },
235
+ ]);
236
+ assert.equal(
237
+ calls.some((call) => call[0] === "track" || call[0] === "trackCustom"),
238
+ false,
239
+ );
240
+ assert.match(logs.info[0], new RegExp(`Pixel ${PIXEL_ID} ✓`));
241
+ } finally {
242
+ logs.restore();
243
+ delete globalThis.fbq;
244
+ clear_pixel_config();
245
+ }
246
+ });
247
+
248
+ it("uses trackSingleCustom for names outside the standard catalog", () => {
249
+ const calls = stub_fbq();
250
+ set_signal_pixel_id(PIXEL_ID);
251
+
252
+ try {
253
+ const event = sendSignal("DevalonCredit", { form: "footer" });
254
+ assert.deepEqual(calls, [
255
+ [
256
+ "trackSingleCustom",
257
+ PIXEL_ID,
258
+ "DevalonCredit",
259
+ { form: "footer" },
260
+ { eventID: event.event_id },
261
+ ],
262
+ ]);
263
+ } finally {
264
+ delete globalThis.fbq;
265
+ clear_pixel_config();
266
+ }
267
+ });
268
+
269
+ it("reads the pixel id from the server-rendered bridge", () => {
270
+ const calls = stub_fbq();
271
+ globalThis.__DEVALON_SIGNAL_PIXEL_ID = PIXEL_ID;
272
+
273
+ try {
274
+ const event = sendSignal("Lead", {}, { eventId: "shared-id" });
275
+ assert.equal(calls[0][1], PIXEL_ID);
276
+ assert.equal(event.event_id, "shared-id");
277
+ } finally {
278
+ delete globalThis.fbq;
279
+ clear_pixel_config();
280
+ }
281
+ });
282
+
283
+ it("reports when no Devalon pixel id is known and sends nothing", () => {
284
+ const calls = stub_fbq();
285
+ const logs = capture_logs();
286
+ clear_pixel_config();
287
+
288
+ try {
289
+ const event = sendSignal("Purchase", {}, { debug: true });
290
+ assert.equal(calls.length, 0);
291
+ assert.match(logs.warn[0], /no Devalon pixel id configured/);
292
+ assert.match(logs.warn[0], new RegExp(event.event_id));
293
+ } finally {
294
+ logs.restore();
295
+ delete globalThis.fbq;
296
+ }
297
+ });
298
+
299
+ it("stays silent without the debug flag", () => {
300
+ stub_fbq();
301
+ set_signal_pixel_id(PIXEL_ID);
302
+ const logs = capture_logs();
303
+
304
+ try {
305
+ sendSignal("Purchase", { value: 1 });
306
+ assert.equal(logs.info.length, 0);
307
+ assert.equal(logs.warn.length, 0);
308
+ } finally {
309
+ logs.restore();
310
+ delete globalThis.fbq;
311
+ clear_pixel_config();
312
+ }
313
+ });
314
+
315
+ it("reports a missing fbq and tells the caller to use CAPI", () => {
316
+ set_signal_pixel_id(PIXEL_ID);
317
+ const logs = capture_logs();
318
+
319
+ try {
320
+ const event = sendSignal("Lead", {}, { debug: true });
321
+ assert.equal(logs.warn.length, 1);
322
+ assert.match(logs.warn[0], /MISSING/);
323
+ assert.match(logs.warn[0], /send via CAPI/);
324
+ assert.match(logs.warn[0], new RegExp(PIXEL_ID));
325
+ assert.match(logs.warn[0], new RegExp(event.event_id));
326
+ } finally {
327
+ logs.restore();
328
+ delete globalThis.fbq;
329
+ clear_pixel_config();
330
+ }
331
+ });
332
+
333
+ it("reports a blocked Pixel when only the stub is present", async () => {
334
+ const calls = stub_fbq({ ready: false });
335
+ const logs = capture_logs();
336
+ set_signal_pixel_id(PIXEL_ID);
337
+
338
+ try {
339
+ const event = sendSignal(
340
+ "Purchase",
341
+ { value: 5, currency: "USD" },
342
+ { debug: true },
343
+ );
344
+
345
+ assert.equal(calls.length, 1);
346
+ assert.equal(pixel_sdk_ready(), false);
347
+ await new Promise((resolve) =>
348
+ setTimeout(resolve, PIXEL_READY_CHECK_DELAY_MS + 50),
349
+ );
350
+
351
+ assert.match(logs.warn[0], /BLOCKED/);
352
+ assert.match(logs.warn[0], /fbevents_not_loaded/);
353
+ assert.match(logs.warn[0], /send via CAPI/);
354
+ assert.match(logs.warn[0], new RegExp(PIXEL_ID));
355
+ assert.match(logs.warn[0], new RegExp(event.event_id));
356
+ } finally {
357
+ logs.restore();
358
+ delete globalThis.fbq;
359
+ clear_pixel_config();
360
+ }
361
+ });
362
+ });
363
+
364
+ describe("event catalog", () => {
365
+ it("exposes a broad, duplicate-free custom catalog", () => {
366
+ assert.ok(DEVALON_CUSTOM_EVENT_NAMES.length > 100);
367
+ assert.equal(
368
+ new Set(DEVALON_CUSTOM_EVENT_NAMES).size,
369
+ DEVALON_CUSTOM_EVENT_NAMES.length,
370
+ );
371
+ for (const name of ["HeroCtaClick", "NewsletterSignup", "PaymentError"]) {
372
+ assert.ok(DEVALON_CUSTOM_EVENT_NAMES.includes(name));
373
+ }
374
+ });
375
+
376
+ it("maps the expected params for standard events", () => {
377
+ assert.deepEqual(META_REQUIRED_EVENT_PARAMS.Purchase, [
378
+ "value",
379
+ "currency",
380
+ ]);
381
+ assert.deepEqual(META_REQUIRED_EVENT_PARAMS.Search, ["search_string"]);
382
+ });
383
+
384
+ it("warns about missing standard params in debug but still sends", () => {
385
+ const calls = stub_fbq();
386
+ const logs = capture_logs();
387
+ set_signal_pixel_id(PIXEL_ID);
388
+
389
+ try {
390
+ const event = sendSignal("Purchase", {}, { debug: true });
391
+
392
+ assert.equal(calls.length, 1);
393
+ assert.match(logs.warn[0], /missing recommended params: value, currency/);
394
+ assert.equal(logs.info.length, 1);
395
+ assert.ok(event.event_id);
396
+ } finally {
397
+ logs.restore();
398
+ delete globalThis.fbq;
399
+ clear_pixel_config();
400
+ }
401
+ });
402
+
403
+ it("stays silent when all required params are present", () => {
404
+ stub_fbq();
405
+ set_signal_pixel_id(PIXEL_ID);
406
+ const logs = capture_logs();
407
+
408
+ try {
409
+ sendSignal(
410
+ "Purchase",
411
+ { value: 10, currency: "USD" },
412
+ { debug: true },
413
+ );
414
+ assert.equal(logs.warn.length, 0);
415
+ } finally {
416
+ logs.restore();
417
+ delete globalThis.fbq;
418
+ clear_pixel_config();
419
+ }
420
+ });
421
+
422
+ it("does not validate custom events or reject unknown names", () => {
423
+ const calls = stub_fbq();
424
+ set_signal_pixel_id(PIXEL_ID);
425
+ const logs = capture_logs();
426
+
427
+ try {
428
+ sendSignal("HeroCtaClick", {}, { debug: true });
429
+ sendSignal("BrandNewEvent123", {}, { debug: true });
430
+
431
+ assert.deepEqual(
432
+ calls.map((call) => call[0]),
433
+ ["trackSingleCustom", "trackSingleCustom"],
434
+ );
435
+ assert.equal(logs.warn.length, 0);
436
+ } finally {
437
+ logs.restore();
438
+ delete globalThis.fbq;
439
+ clear_pixel_config();
440
+ }
441
+ });
442
+ });
443
+
444
+ describe("event envelope", () => {
445
+ it("generates unique event ids", () => {
446
+ assert.notEqual(create_signal_event_id(), create_signal_event_id());
447
+ });
448
+
449
+ it("builds a vendor-neutral envelope", () => {
450
+ const event = create_signal_event("Purchase", { value: 10 }, "fixed-id");
451
+ assert.deepEqual(event, {
452
+ event_name: "Purchase",
453
+ event_id: "fixed-id",
454
+ params: { value: 10 },
455
+ emitted_at: event.emitted_at,
456
+ });
457
+ assert.equal(Number.isNaN(Date.parse(event.emitted_at)), false);
458
+ });
459
+ });
@@ -1,16 +0,0 @@
1
- import{a as d,b as g,e as h,i as v,j as f,m as y,r as w}from"./chunk-SHIXBOQB.mjs";function u(e){let n;try{n=new URL(e)}catch{throw new TypeError("site_url must be an absolute HTTP(S) URL.")}if(n.protocol!=="https:"&&n.protocol!=="http:")throw new TypeError("site_url must be an absolute HTTP(S) URL.");return n.hash="",n.search="",n.pathname=n.pathname.replace(/\/+$/,"")||"/",n.toString().replace(/\/$/,"")}var x="<!-- devalon:start -->",k="<!-- devalon:end -->",E="/* devalon:start */",m="/* devalon:end */";function L(e){return new Response(e,{headers:{"Content-Type":"text/plain; charset=utf-8"}})}function N(e){let n=f,t=new Set;for(let r of e){let o=n[r]??r,s=v[o];if(!s)throw new TypeError(`Unknown Devalon service: ${String(r)}`);t.add(s.name)}return[...t]}function T(e){let n=N(e.services??[]),t=[x,"## Credits","",`Built and maintained by [Devalon](${d}), an AI & software development studio.`];return n.length>0&&t.push(`Services: ${n.join(", ")}.`),t.push(k),t.join(`
2
- `)}function b(e){let n=e.site_name.trim();if(!n)throw new TypeError("site_name must not be empty.");let t=e.description?.trim()??`Official website of ${n}.`;return[`# ${n}`,"",`> ${t}`,"",`- Canonical: ${u(e.site_url)}`,"",T(e),""].join(`
3
- `)}function H(e,n,t,r){let o=e.indexOf(n),s=e.indexOf(t);if(o!==-1&&s!==-1&&s>o)return e.slice(0,o)+r+e.slice(s+t.length);let i=e.trimEnd();return i?`${i}
4
-
5
- ${r}
6
- `:`${r}
7
- `}function A(e,n){return H(e,x,k,T(n))}function G(e){return L(e.source?.trim()?A(e.source,e):b(e))}function D(e){return[E,"Developer: Devalon",`URL: ${d}`,m].join(`
8
- `)}function $(e){let n=e.site_name.trim();if(!n)throw new TypeError("site_name must not be empty.");return["/* TEAM */",D(e),"","/* SITE */",`Name: ${n}`,`URL: ${u(e.site_url)}`,""].join(`
9
- `)}function U(e,n){let t=D(n),r=e.indexOf(E),o=e.indexOf(m);if(r!==-1&&o!==-1&&o>r)return e.slice(0,r)+t+e.slice(o+m.length);let s="/* TEAM */",i=e.indexOf(s);if(i!==-1){let l=i+s.length,a=e.indexOf("/*",l),_=a===-1?e.length:a,p=e.slice(0,_).trimEnd(),C=e.slice(_);return`${p}
10
- ${t}
11
-
12
- ${C.trimStart()}`}let c=e.trimEnd();return c?`${c}
13
-
14
- ${t}
15
- `:`${t}
16
- `}function F(e){return L(e.source?.trim()?U(e.source,e):$(e))}function J(e){return{"llms.txt":e.source?.trim()?A(e.source,e):b(e),"humans.txt":$(e)}}function I(e){let t=f[e]??e;if(!(t in v))throw new TypeError(`Unknown Devalon service: ${String(e)}`);return t}function j(e){let n=new Set;for(let t of e){let r=y[t];if(!r)throw new TypeError(`Unknown Devalon contribution: ${String(t)}`);n.add(r.relationship)}return[...n]}function S(e){let{site_url:n,services:t=[],contributions:r=["development","engineering"],locale:o}=e,s=u(n),i=[...new Set(t.map(I))],c=j(r);if(o!==void 0&&!h.includes(o))throw new TypeError(`Unsupported Devalon locale: ${String(o)}`);let l=[{key:"X-Devalon-Creator",value:"Devalon"},{key:"X-Devalon-Creator-Url",value:d},{key:"X-Devalon-Creator-Id",value:g},{key:"X-Devalon-Project",value:s},{key:"X-Built-By",value:`Devalon (${d})`},{key:"Link",value:`<${d}>; rel="author"`}];i.length>0&&l.push({key:"X-Devalon-Services",value:i.join(", ")});let a=[...new Set(r)];return a.length>0&&l.push({key:"X-Devalon-Contributions",value:a.join(", ")}),c.length>0&&l.push({key:"X-Devalon-Relationships",value:c.join(", ")}),o&&l.push({key:"X-Devalon-Locale",value:o}),l}function Y(e){return(n,t,r)=>{let{localeFromPath:o,...s}=e,i=s.locale;if(!i&&o?.length){let a=(n.url?.split("?")[0]??"").split("/")[1];a&&o.includes(a)&&(i=a)}let c=S(i?{...s,locale:i}:s);for(let{key:l,value:a}of c){if(l.toLowerCase()==="link"){let _=t.getHeader("Link")??t.getHeader("link"),p=Array.isArray(_)?_.join(", "):typeof _=="string"?_:"";t.setHeader("Link",p?`${p.replace(/,\s*$/,"")}, ${a}`:a);continue}t.setHeader(l,a)}r()}}function Z(e,n){for(let{key:t,value:r}of S(n)){if(t.toLowerCase()==="link"){let o=e.headers.get("link");e.headers.set("link",o?`${o.replace(/,\s*$/,"")}, ${r}`:r);continue}e.headers.set(t,r)}return e}var R={en:"This site was designed and built by",ro:"Acest site a fost proiectat \u0219i construit de",ru:"\u042D\u0442\u043E\u0442 \u0441\u0430\u0439\u0442 \u0441\u043F\u0440\u043E\u0435\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u043D \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043E\u0442\u0430\u043D",de:"Diese Website wurde entworfen und entwickelt von",da:"Denne hjemmeside er designet og udviklet af",fr:"Ce site a \xE9t\xE9 con\xE7u et d\xE9velopp\xE9 par",es:"Este sitio fue dise\xF1ado y desarrollado por"},V="Devalon";function X(e){let n;try{n=new URL(e)}catch{throw new TypeError("site_url must be an absolute HTTP(S) URL.")}if(n.protocol!=="https:"&&n.protocol!=="http:")throw new TypeError("site_url must be an absolute HTTP(S) URL.");return n.hostname.replace(/^www\./,"")}function te(e){let{site_url:n,locale:t="en",sentence:r,anchor:o=V,utm:s=!1}=e;if(!(t in R))throw new TypeError(`Unsupported Devalon backlink locale: ${String(t)}`);let i=(r??R[t]).trim(),c=o.trim();if(!i)throw new TypeError("sentence must not be empty.");if(!c)throw new TypeError("anchor must not be empty.");let l=d;if(s){if(!n)throw new TypeError("site_url is required when utm is enabled.");let a=X(n);l=`${d}/?utm_source=${encodeURIComponent(a)}&utm_medium=credit&utm_campaign=devalon-credits`}return{text:i,link_text:c,href:l}}function O(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function B(e){let n=JSON.stringify(e);if(n===void 0)throw new TypeError("Devalon JSON-LD could not be serialized.");return n.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function M(e){return B(w(e))}function ae(e){let{nonce:n,...t}=e;return`<script type="application/ld+json"${n?` nonce="${O(n)}"`:""}>${M(t)}</script>`}export{T as a,b,A as c,G as d,D as e,$ as f,U as g,F as h,J as i,te as j,S as k,Y as l,Z as m,O as n,M as o,ae as p};
@@ -1,11 +0,0 @@
1
- import{j as f,n as l,p as k}from"./chunk-QU6SEFG7.mjs";import{q as d}from"./chunk-SHIXBOQB.mjs";var i="<!-- devalon:head:start -->",s="<!-- devalon:head:end -->",c="<!-- devalon:backlink:start -->",_="<!-- devalon:backlink:end -->";function v(e){let{canonical:o,languages:a}=d(e),n=[`<link rel="canonical" href="${l(o)}" />`];for(let[t,r]of Object.entries(a))r&&n.push(`<link rel="alternate" hreflang="${l(t)}" href="${l(r)}" />`);return n.join(`
2
- `)}function $(e){let{alternates:o,...a}=e,n=[k(a)];return o&&n.push(v(o)),n.join(`
3
- `)}function b(e){let{text:o,link_text:a,href:n}=f(e),t=e.className?.trim();return`<span${t?` class="${l(t)}"`:""}>${l(o)} <a href="${l(n)}" target="_blank" rel="noopener" referrerpolicy="origin">${l(a)}</a></span>`}function p(e,o,a){let n=e.indexOf(o),t=e.indexOf(a);return n!==-1&&t!==-1&&t>n}function g(e,o,a,n){let t=e.indexOf(o),r=e.indexOf(a);return e.slice(0,t)+n+e.slice(r+a.length)}function A(e,o){let a=`${i}
4
- ${$(o)}
5
- ${s}`,n;if(p(e,i,s))n=g(e,i,s,a);else{let t=/<head\b[^>]*>/i.exec(e);if(t){let r=t.index+t[0].length;n=`${e.slice(0,r)}
6
- ${a}${e.slice(r)}`}else n=`${a}
7
- ${e}`}if(o.backlink){let t=`${c}
8
- ${b(o.backlink)}
9
- ${_}`;if(p(n,c,_))n=g(n,c,_,t);else{let r=/<\/body\s*>/i.exec(n);r?n=`${n.slice(0,r.index)}${t}
10
- ${n.slice(r.index)}`:n=`${n}
11
- ${t}`}}return n}export{i as a,s as b,c,_ as d,v as e,$ as f,b as g,A as h};