@buildinams/tracking 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +86 -208
  2. package/dist/{sources/cart → cart}/index.d.ts +4 -4
  3. package/dist/{sources/cart → cart}/index.js +13 -3
  4. package/dist/cart/index.js.map +1 -0
  5. package/dist/chunk-JZ6HFGVJ.js +163 -0
  6. package/dist/chunk-JZ6HFGVJ.js.map +1 -0
  7. package/dist/{compatibility-Dc1JmTeG.d.ts → compatibility-wHn2I_ws.d.ts} +2 -2
  8. package/dist/{consent/index.d.ts → consent-types-DgKtGapr.d.ts} +5 -1
  9. package/dist/{consent/cookiebot → cookiebot}/index.d.ts +1 -1
  10. package/dist/{consent/cookiebot → cookiebot}/index.js +1 -1
  11. package/dist/cookiebot/index.js.map +1 -0
  12. package/dist/destination-types-DNMBOW_e.d.ts +22 -0
  13. package/dist/devtools/index.d.ts +18 -0
  14. package/dist/devtools/index.js +299 -0
  15. package/dist/devtools/index.js.map +1 -0
  16. package/dist/{sources/dom → dom}/index.d.ts +34 -40
  17. package/dist/{sources/dom → dom}/index.js +149 -247
  18. package/dist/dom/index.js.map +1 -0
  19. package/dist/events/index.d.ts +3 -6
  20. package/dist/events/index.js +5 -4
  21. package/dist/events/index.js.map +1 -1
  22. package/dist/flow/index.d.ts +10 -8
  23. package/dist/flow/index.js +23 -9
  24. package/dist/flow/index.js.map +1 -1
  25. package/dist/google/index.d.ts +32 -0
  26. package/dist/google/index.js +66 -0
  27. package/dist/google/index.js.map +1 -0
  28. package/dist/{page → navigation}/index.d.ts +7 -12
  29. package/dist/{page → navigation}/index.js +4 -10
  30. package/dist/navigation/index.js.map +1 -0
  31. package/dist/{consent/onetrust → onetrust}/index.d.ts +1 -1
  32. package/dist/{consent/onetrust → onetrust}/index.js +1 -1
  33. package/dist/onetrust/index.js.map +1 -0
  34. package/dist/shopify/index.d.ts +45 -0
  35. package/dist/{consent/shopify → shopify}/index.js +48 -20
  36. package/dist/shopify/index.js.map +1 -0
  37. package/dist/{sources/index.d.ts → source-types-fJXZeF2Q.d.ts} +1 -1
  38. package/dist/{types-DfPz7mBl.d.ts → types-CZEg03xW.d.ts} +3 -7
  39. package/docs/annotations.md +104 -0
  40. package/docs/context.md +64 -0
  41. package/docs/decisions/001-vendor-neutral-event-pipeline.md +2 -2
  42. package/docs/decisions/002-data-per-annotation-word.md +34 -0
  43. package/docs/events.md +93 -84
  44. package/docs/setup.md +189 -0
  45. package/package.json +41 -69
  46. package/dist/consent/cookiebot/index.js.map +0 -1
  47. package/dist/consent/index.js +0 -3
  48. package/dist/consent/index.js.map +0 -1
  49. package/dist/consent/onetrust/index.js.map +0 -1
  50. package/dist/consent/shopify/index.d.ts +0 -13
  51. package/dist/consent/shopify/index.js.map +0 -1
  52. package/dist/destinations/ga4/index.d.ts +0 -16
  53. package/dist/destinations/ga4/index.js +0 -15
  54. package/dist/destinations/ga4/index.js.map +0 -1
  55. package/dist/destinations/index.d.ts +0 -9
  56. package/dist/destinations/index.js +0 -17
  57. package/dist/destinations/index.js.map +0 -1
  58. package/dist/destinations/shopify/index.d.ts +0 -12
  59. package/dist/destinations/shopify/index.js +0 -18
  60. package/dist/destinations/shopify/index.js.map +0 -1
  61. package/dist/page/index.js.map +0 -1
  62. package/dist/sources/cart/index.js.map +0 -1
  63. package/dist/sources/cart/shopify/index.d.ts +0 -28
  64. package/dist/sources/cart/shopify/index.js +0 -16
  65. package/dist/sources/cart/shopify/index.js.map +0 -1
  66. package/dist/sources/dom/index.js.map +0 -1
  67. package/dist/sources/index.js +0 -3
  68. package/dist/sources/index.js.map +0 -1
  69. package/dist/types-BfJsv8AV.d.ts +0 -30
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/dom/clicks.ts","../../src/dom/create-dom-source.ts","../../src/dom/detail-views.ts","../../src/dom/forms.ts","../../src/dom/impressions.ts","../../src/dom/page-views.ts","../../src/dom/scroll.ts","../../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,QAAA,OAAA,CAAQ,gBAAA,EAAkB,IAAA,CAAK,KAAA,EAAO,GAAG,CAAC,CAAA;AAE1C,QAAA,SAAA,CAAU,OAAO,KAAK,CAAA;AAAA,MACvB,CAAA;AAGA,MAAA,MAAM,OAAA,GAAU,EAAE,OAAA,EAAS,IAAA,EAAK;AAChC,MAAA,QAAA,CAAS,gBAAA,CAAiB,MAAA,EAAQ,MAAA,EAAQ,OAAO,CAAA;AACjD,MAAA,QAAA,CAAS,gBAAA,CAAiB,YAAA,EAAc,YAAA,EAAc,OAAO,CAAA;AAC7D,MAAA,QAAA,CAAS,gBAAA,CAAiB,OAAA,EAAS,OAAA,EAAS,OAAO,CAAA;AACnD,MAAA,OAAO,MAAM;AACZ,QAAA,QAAA,CAAS,mBAAA,CAAoB,MAAA,EAAQ,MAAA,EAAQ,OAAO,CAAA;AACpD,QAAA,QAAA,CAAS,mBAAA,CAAoB,YAAA,EAAc,YAAA,EAAc,OAAO,CAAA;AAChE,QAAA,QAAA,CAAS,mBAAA,CAAoB,OAAA,EAAS,OAAA,EAAS,OAAO,CAAA;AAAA,MACvD,CAAA;AAAA,IACD,CAAA;AAAA,IACA,KAAA,GAAQ;AACP,MAAA,SAAA,uBAAgB,OAAA,EAAQ;AAAA,IACzB;AAAA,GACD;AACD","file":"index.js","sourcesContent":["import { flagSelector, isIgnored, readAnnotated } from \"./annotations\";\nimport { INTERACTIVE, isOptedIn, readText } from \"./opt-in\";\nimport type { Detector } from \"./types\";\n\nconst CLICKABLE = `${INTERACTIVE}, ${flagSelector(\"click\")}`;\n\nexport type LinkClickData = {\n\turl: string;\n\ttext: string;\n\t[field: string]: unknown;\n};\n\nexport type ButtonClickData = {\n\ttext: string;\n\t[field: string]: unknown;\n};\n\nexport type ClicksOptions = {\n\t/** Whether links and buttons are tracked where no `data-e-auto` decides. */\n\tauto?: { links?: boolean; buttons?: boolean };\n};\n\n/** Publishes `link:click` and `button:click` for opted-in links and buttons. */\nexport const clicks = ({ auto = {} }: ClicksOptions = {}): Detector<{\n\t\"link:click\": LinkClickData;\n\t\"button:click\": ButtonClickData;\n}> => ({\n\tevents: [\"link:click\", \"button:click\"],\n\tstart({ publish }) {\n\t\tconst onClick = (event: MouseEvent) => {\n\t\t\tif (!(event.target instanceof Element)) return;\n\t\t\tconst element = event.target.closest(CLICKABLE);\n\t\t\tif (!element || isIgnored(element)) return;\n\n\t\t\tconst isLink = element instanceof HTMLAnchorElement && !!element.href;\n\t\t\tconst tracked = isOptedIn(element, {\n\t\t\t\tflag: \"click\",\n\t\t\t\tkind: isLink ? \"links\" : \"buttons\",\n\t\t\t\tfallback: (isLink ? auto.links : auto.buttons) ?? false,\n\t\t\t});\n\t\t\tif (!tracked) return;\n\n\t\t\tconst { data, composed } = readAnnotated(element, \"click\");\n\t\t\tif (isLink)\n\t\t\t\tpublish(\"link:click\", {\n\t\t\t\t\tdata: { url: element.href, text: readText(element), ...data },\n\t\t\t\t\tcomposed,\n\t\t\t\t});\n\t\t\telse\n\t\t\t\tpublish(\"button:click\", {\n\t\t\t\t\tdata: { text: readText(element), ...data },\n\t\t\t\t\tcomposed,\n\t\t\t\t});\n\t\t};\n\t\tdocument.addEventListener(\"click\", onClick, { capture: true });\n\t\treturn () =>\n\t\t\tdocument.removeEventListener(\"click\", onClick, { capture: true });\n\t},\n});\n","import type { Catalog, EventBroker } from \"../events\";\nimport type { CheckPublished } from \"../events/compatibility\";\nimport type { Source } from \"../flow/source-types\";\nimport type { ClientNavigation } from \"../navigation\";\nimport {\n\tANNOTATION_ATTRIBUTE,\n\tCLONE_ATTRIBUTE,\n\tDATA_ATTRIBUTES,\n\tIGNORE_ATTRIBUTE,\n} from \"./annotations\";\nimport type { Detector, DetectorContext } from \"./types\";\n\nexport type DomSourceOptions = {\n\t/** Leave out when every navigation is a full page load. */\n\tclientNavigation?: Pick<ClientNavigation, \"subscribe\">;\n};\n\nexport type DomSource = Source & {\n\tflush(): void;\n};\n\nexport const createDomSource = <\n\tC extends Catalog,\n\t// `any`: Detector is invariant in its Data map, so specific Detectors aren't assignable to the default.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tconst D extends readonly Detector<any>[],\n>(\n\tbroker: EventBroker<C>,\n\tdetectors: [...D] & {\n\t\t[I in keyof D]: D[I] extends Detector<infer P>\n\t\t\t? Detector<CheckPublished<C, P>>\n\t\t\t: never;\n\t},\n\t{ clientNavigation }: DomSourceOptions = {},\n): DomSource => {\n\tconst flush = () => {\n\t\tfor (const detector of detectors) detector.flush?.();\n\t};\n\n\tconst mutationListeners = new Set<(records: MutationRecord[]) => void>();\n\tlet mutations: MutationObserver | undefined;\n\n\tconst context: DetectorContext = {\n\t\tpublish: (name, { data, composed }) =>\n\t\t\t(\n\t\t\t\tbroker.publish as (\n\t\t\t\t\tname: string,\n\t\t\t\t\tdata: unknown,\n\t\t\t\t\tcomposed: unknown,\n\t\t\t\t) => void\n\t\t\t)(name, data, composed),\n\t\tonMutation(listener) {\n\t\t\tif (!mutations) {\n\t\t\t\tmutations = new MutationObserver((records) => {\n\t\t\t\t\tfor (const notify of [...mutationListeners]) notify(records);\n\t\t\t\t});\n\t\t\t\tmutations.observe(document.documentElement, {\n\t\t\t\t\tchildList: true,\n\t\t\t\t\tsubtree: true,\n\t\t\t\t\tcharacterData: true,\n\t\t\t\t\tattributes: true,\n\t\t\t\t\tattributeFilter: [\n\t\t\t\t\t\tANNOTATION_ATTRIBUTE,\n\t\t\t\t\t\t...DATA_ATTRIBUTES,\n\t\t\t\t\t\tCLONE_ATTRIBUTE,\n\t\t\t\t\t\tIGNORE_ATTRIBUTE,\n\t\t\t\t\t\t\"hidden\",\n\t\t\t\t\t\t\"open\",\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\t\t\tmutationListeners.add(listener);\n\t\t\treturn () => {\n\t\t\t\tmutationListeners.delete(listener);\n\t\t\t\tif (mutationListeners.size) return;\n\t\t\t\tmutations?.disconnect();\n\t\t\t\tmutations = undefined;\n\t\t\t};\n\t\t},\n\t};\n\n\treturn {\n\t\tstart() {\n\t\t\tconst onVisibilityChange = () => {\n\t\t\t\tif (document.visibilityState === \"hidden\") flush();\n\t\t\t};\n\t\t\t// Before the router changes the URL, so batches still get the Page they belong to.\n\t\t\tconst onLinkClick = (event: MouseEvent) => {\n\t\t\t\tif (event.target instanceof Element && event.target.closest(\"a[href]\"))\n\t\t\t\t\tflush();\n\t\t\t};\n\t\t\tdocument.addEventListener(\"visibilitychange\", onVisibilityChange);\n\t\t\t// Registered before the Detectors' listeners, so batches go out before what the click itself publishes.\n\t\t\tdocument.addEventListener(\"click\", onLinkClick, { capture: true });\n\t\t\tconst stops = detectors.map((detector) => detector.start(context));\n\t\t\tconst unsubscribe = clientNavigation?.subscribe({\n\t\t\t\tleave: flush,\n\t\t\t\tenter: () => {\n\t\t\t\t\tfor (const detector of detectors) detector.reset?.();\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn () => {\n\t\t\t\tunsubscribe?.();\n\t\t\t\tflush();\n\t\t\t\tdocument.removeEventListener(\"visibilitychange\", onVisibilityChange);\n\t\t\t\tdocument.removeEventListener(\"click\", onLinkClick, { capture: true });\n\t\t\t\tfor (const stop of stops) stop();\n\t\t\t};\n\t\t},\n\t\tflush,\n\t};\n};\n","import { IS_DEVELOPMENT } from \"../config\";\nimport type { AnnotationData } from \"./annotations\";\nimport {\n\tflagSelector,\n\tisIgnored,\n\treadAnnotated,\n\troleSelector,\n} from \"./annotations\";\nimport type { Detector } from \"./types\";\n\nconst SELECTOR = `${roleSelector(\"item\")}${flagSelector(\"detail\")}`;\n\n// The Annotation itself may be `hidden`; a hidden ancestor means its page isn't shown, e.g. a route a router keeps for back navigation.\nconst isShown = (element: Element) =>\n\telement.parentElement?.checkVisibility?.() ?? true;\n\nexport type DetailViewsOptions = {\n\t/** What makes two detail Items the same Item; by default all their Data. E.g. `(data) => data.handle` counts a variant switch as the same product. */\n\tkey?: (data: AnnotationData) => string;\n};\n\n/** Publishes `item:view` when an Item flagged `detail` (`data-e=\"item detail\"`), e.g. a product page's, starts being shown. */\nexport const detailViews = ({\n\tkey = (data) => JSON.stringify(data),\n}: DetailViewsOptions = {}): Detector<{ \"item:view\": AnnotationData }> => {\n\t// Not reset per Page: a URL change that keeps showing the same Item, like a variant switch, isn't a new view.\n\tlet shown = new Set<string>();\n\tlet rescan = () => {};\n\n\treturn {\n\t\tevents: [\"item:view\"],\n\t\tstart({ publish, onMutation }) {\n\t\t\tlet scheduled = false;\n\t\t\tconst scan = () => {\n\t\t\t\tscheduled = false;\n\t\t\t\tconst showing = new Set<string>();\n\t\t\t\tfor (const element of document.querySelectorAll(SELECTOR)) {\n\t\t\t\t\tif (!isShown(element) || isIgnored(element)) continue;\n\t\t\t\t\tconst annotated = readAnnotated(element, \"item\");\n\t\t\t\t\tlet itemKey: string;\n\t\t\t\t\ttry {\n\t\t\t\t\t\titemKey = key(annotated.data);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (IS_DEVELOPMENT) console.error(error);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (showing.has(itemKey)) continue;\n\t\t\t\t\tshowing.add(itemKey);\n\t\t\t\t\tif (!shown.has(itemKey)) publish(\"item:view\", annotated);\n\t\t\t\t}\n\t\t\t\tshown = showing;\n\t\t\t};\n\t\t\tconst schedule = () => {\n\t\t\t\tif (scheduled) return;\n\t\t\t\tscheduled = true;\n\t\t\t\tqueueMicrotask(scan);\n\t\t\t};\n\n\t\t\trescan = schedule;\n\t\t\tconst stopObserving = onMutation(schedule);\n\t\t\tscan();\n\t\t\treturn () => {\n\t\t\t\tstopObserving();\n\t\t\t\trescan = () => {};\n\t\t\t\tshown = new Set();\n\t\t\t};\n\t\t},\n\t\t// A router can show a kept page again by changing only its styles, which the observer doesn't watch.\n\t\treset: () => rescan(),\n\t};\n};\n","import { isIgnored, readAnnotated, roleSelector } from \"./annotations\";\nimport { compact, isOptedIn, readText } from \"./opt-in\";\nimport type { Detector } from \"./types\";\n\nexport type FormEventData = {\n\tid?: string;\n\tname?: string;\n\t/** The form's `action`, absolute. */\n\tdestination?: string;\n\t[field: string]: unknown;\n};\n\nexport type FormSubmitData = FormEventData & {\n\t/** The submitting button's text. */\n\tsubmitText?: string;\n};\n\nexport type FormsOptions = {\n\t/** Whether forms are tracked where neither a Form Annotation nor `data-e-auto` decides. */\n\tauto?: boolean;\n};\n\n/** Publishes `form:start` on the first interaction with a form per Page, and `form:submit`; field values are never read. */\nexport const forms = ({ auto = false }: FormsOptions = {}): Detector<{\n\t\"form:start\": FormEventData;\n\t\"form:submit\": FormSubmitData;\n}> => {\n\tlet started = new WeakSet<Element>();\n\n\tconst resolve = (target: EventTarget | null) => {\n\t\tif (!(target instanceof Element)) return undefined;\n\t\tconst annotated = target.closest(roleSelector(\"form\"));\n\t\tconst form = target.closest(\"form\");\n\t\tconst element = annotated ?? form;\n\t\tif (!element || isIgnored(element)) return undefined;\n\t\tif (!annotated && !isOptedIn(element, { kind: \"forms\", fallback: auto }))\n\t\t\treturn undefined;\n\n\t\tconst { data, composed } = readAnnotated(element, \"form\");\n\t\tconst base: FormEventData = compact({\n\t\t\tid: form?.id,\n\t\t\tname: form?.getAttribute(\"name\") ?? undefined,\n\t\t\tdestination: form?.action,\n\t\t});\n\t\treturn { element, data: { ...base, ...data }, composed };\n\t};\n\n\treturn {\n\t\tevents: [\"form:start\", \"form:submit\"],\n\t\tstart({ publish }) {\n\t\t\tconst onInteraction = (event: Event) => {\n\t\t\t\tconst form = resolve(event.target);\n\t\t\t\tif (!form || started.has(form.element)) return;\n\t\t\t\tstarted.add(form.element);\n\t\t\t\tpublish(\"form:start\", form);\n\t\t\t};\n\t\t\tconst onSubmit = (event: SubmitEvent) => {\n\t\t\t\tconst form = resolve(event.target);\n\t\t\t\tif (!form) return;\n\t\t\t\tconst submitText = event.submitter\n\t\t\t\t\t? readText(event.submitter)\n\t\t\t\t\t: undefined;\n\t\t\t\tpublish(\"form:submit\", {\n\t\t\t\t\tdata: { ...compact({ submitText }), ...form.data },\n\t\t\t\t\tcomposed: form.composed,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst options = { capture: true };\n\t\t\tdocument.addEventListener(\"input\", onInteraction, options);\n\t\t\tdocument.addEventListener(\"change\", onInteraction, options);\n\t\t\tdocument.addEventListener(\"submit\", onSubmit, options);\n\t\t\treturn () => {\n\t\t\t\tdocument.removeEventListener(\"input\", onInteraction, options);\n\t\t\t\tdocument.removeEventListener(\"change\", onInteraction, options);\n\t\t\t\tdocument.removeEventListener(\"submit\", onSubmit, options);\n\t\t\t};\n\t\t},\n\t\treset() {\n\t\t\tstarted = new WeakSet();\n\t\t},\n\t};\n};\n","import {\n\tentryOf,\n\thasWord,\n\tindexIn,\n\tisIgnored,\n\tpromotionItems,\n\treadAnnotated,\n\treadData,\n\troleSelector,\n\tsurrounding,\n} from \"./annotations\";\nimport type { Detector, DetectorContext } from \"./types\";\n\nexport type ListViewItem = {\n\tindex: number;\n\t[field: string]: unknown;\n};\n\nexport type ListViewData = {\n\t/** The List's Items seen since the last batch, in List order. */\n\titems: ListViewItem[];\n\t[field: string]: unknown;\n};\n\nexport type PromotionData = {\n\t/** Every Item in the Promotion, in order, seen or not. */\n\titems: ListViewItem[];\n\t[field: string]: unknown;\n};\n\nexport type ImpressionsOptions = {\n\t/** Share of an element that must be visible. */\n\tthreshold?: number;\n\t/** Milliseconds Items are batched per List before `list:view` is published. */\n\tdelay?: number;\n};\n\nconst OBSERVED = [roleSelector(\"promotion\"), roleSelector(\"item\")].join(\", \");\n\n/**\n * Publishes `promotion:view` the first time a Promotion is visible on a Page, and\n * `list:view` with the Items of a List first visible on a Page, batched per List.\n */\nexport const impressions = ({\n\tthreshold = 0.5,\n\tdelay = 1000,\n}: ImpressionsOptions = {}): Detector<{\n\t\"promotion:view\": PromotionData;\n\t\"list:view\": ListViewData;\n}> => {\n\tlet seen = new WeakSet<Element>();\n\tlet batches = new Map<Element, Map<Element, ListViewItem>>();\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tlet context: DetectorContext | undefined;\n\tlet observer: IntersectionObserver | undefined;\n\n\tconst flush = () => {\n\t\tclearTimeout(timer);\n\t\ttimer = undefined;\n\t\tconst pending = batches;\n\t\tbatches = new Map();\n\t\tfor (const [list, items] of pending) {\n\t\t\tconst { data, composed } = readAnnotated(list, \"list\");\n\t\t\tcontext?.publish(\"list:view\", {\n\t\t\t\tdata: {\n\t\t\t\t\t...data,\n\t\t\t\t\titems: [...items.values()].sort((a, b) => a.index - b.index),\n\t\t\t\t},\n\t\t\t\tcomposed,\n\t\t\t});\n\t\t}\n\t};\n\n\tconst onVisible = (element: Element) => {\n\t\t// Checked when seen, as an area can be ignored or flagged after the element was observed.\n\t\tif (isIgnored(element)) return;\n\t\tif (element.matches(roleSelector(\"promotion\"))) {\n\t\t\tconst { data, composed } = readAnnotated(element, \"promotion\");\n\t\t\tcontext?.publish(\"promotion:view\", {\n\t\t\t\tdata: { ...data, items: promotionItems(element) },\n\t\t\t\tcomposed,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tif (hasWord(element, \"detail\")) return;\n\t\tconst list = surrounding(element, \"list\");\n\t\tif (!list) return;\n\t\tconst entry = entryOf(element, list, \"list\");\n\t\tif (!entry) return;\n\t\tif (entry !== element) {\n\t\t\tif (seen.has(entry)) return;\n\t\t\tseen.add(entry);\n\t\t}\n\t\tlet items = batches.get(list);\n\t\tif (!items) batches.set(list, (items = new Map()));\n\t\t// Read now: the Item may be gone or moved by the time the batch is published.\n\t\titems.set(entry, {\n\t\t\t...readData(entry, \"item\"),\n\t\t\tindex: indexIn(entry, list, \"list\")!,\n\t\t});\n\t\ttimer ??= setTimeout(flush, delay);\n\t};\n\n\tconst observeAll = (root: ParentNode) => {\n\t\tif (root instanceof Element && root.matches(OBSERVED))\n\t\t\tobserver?.observe(root);\n\t\tfor (const element of root.querySelectorAll(OBSERVED))\n\t\t\tobserver?.observe(element);\n\t};\n\n\treturn {\n\t\tevents: [\"promotion:view\", \"list:view\"],\n\t\tstart(nextContext) {\n\t\t\tcontext = nextContext;\n\t\t\tobserver = new IntersectionObserver(\n\t\t\t\t(entries) => {\n\t\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\t\tif (!entry.isIntersecting) continue;\n\t\t\t\t\t\t// Counted once per Page: `reset()` observes it again for the next.\n\t\t\t\t\t\tobserver?.unobserve(entry.target);\n\t\t\t\t\t\tif (seen.has(entry.target)) continue;\n\t\t\t\t\t\tseen.add(entry.target);\n\t\t\t\t\t\tonVisible(entry.target);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{ threshold },\n\t\t\t);\n\t\t\tconst stopObserving = nextContext.onMutation((records) => {\n\t\t\t\tfor (const record of records)\n\t\t\t\t\tfor (const node of record.addedNodes)\n\t\t\t\t\t\tif (node instanceof Element) observeAll(node);\n\t\t\t});\n\t\t\tobserveAll(document);\n\n\t\t\treturn () => {\n\t\t\t\tflush();\n\t\t\t\tstopObserving();\n\t\t\t\tobserver?.disconnect();\n\t\t\t\tobserver = undefined;\n\t\t\t\tcontext = undefined;\n\t\t\t};\n\t\t},\n\t\tflush,\n\t\treset() {\n\t\t\tseen = new WeakSet();\n\t\t\t// Re-observing makes the observer report elements already in view again.\n\t\t\tobserver?.disconnect();\n\t\t\tobserveAll(document);\n\t\t},\n\t};\n};\n","import type { AnnotationData } from \"./annotations\";\nimport { flagSelector, isIgnored, readData } from \"./annotations\";\nimport type { Detector, DetectorContext } from \"./types\";\n\nconst view = ({ publish }: DetectorContext) => {\n\tconst data: AnnotationData = {};\n\tfor (const element of document.querySelectorAll(flagSelector(\"page\")))\n\t\tif (!isIgnored(element)) Object.assign(data, readData(element, \"page\"));\n\tpublish(\"page:view\", { data, composed: {} });\n};\n\n/** Publishes `page:view` once per Page, with the Data of every element flagged `page` (`data-e=\"page\"`), later ones winning on conflicts. */\nexport const pageViews = (): Detector<{ \"page:view\": AnnotationData }> => {\n\tlet started: DetectorContext | undefined;\n\n\treturn {\n\t\tevents: [\"page:view\"],\n\t\tstart(context) {\n\t\t\tstarted = context;\n\t\t\tview(context);\n\t\t\treturn () => {\n\t\t\t\tstarted = undefined;\n\t\t\t};\n\t\t},\n\t\treset() {\n\t\t\tif (started) view(started);\n\t\t},\n\t};\n};\n","import type { Detector } from \"./types\";\n\nexport type ScrollOptions = {\n\t/** Percentages of the page height. */\n\tthresholds?: number[];\n};\n\n/** Publishes `page:scroll` once per threshold per Page, with `{ depth }`. */\nexport const scroll = ({\n\tthresholds = [25, 50, 75, 100],\n}: ScrollOptions = {}): Detector<{ \"page:scroll\": { depth: string } }> => {\n\tlet reached = new Set<number>();\n\tlet listen = () => {};\n\n\treturn {\n\t\tevents: [\"page:scroll\"],\n\t\tstart({ publish }) {\n\t\t\tlet frame: number | undefined;\n\t\t\tlet listening = false;\n\n\t\t\tconst check = () => {\n\t\t\t\tframe = undefined;\n\t\t\t\tconst { scrollHeight } = document.documentElement;\n\t\t\t\tif (!scrollHeight) return;\n\t\t\t\tconst depth =\n\t\t\t\t\t((window.scrollY + window.innerHeight) / scrollHeight) * 100;\n\t\t\t\tfor (const threshold of thresholds) {\n\t\t\t\t\tif (depth < threshold || reached.has(threshold)) continue;\n\t\t\t\t\treached.add(threshold);\n\t\t\t\t\tpublish(\"page:scroll\", {\n\t\t\t\t\t\tdata: { depth: String(threshold) },\n\t\t\t\t\t\tcomposed: {},\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (thresholds.every((threshold) => reached.has(threshold))) unlisten();\n\t\t\t};\n\t\t\t// Read once per frame: reading `scrollHeight` per scroll event can force a layout.\n\t\t\tconst onScroll = () => {\n\t\t\t\tframe ??= requestAnimationFrame(check);\n\t\t\t};\n\t\t\tconst unlisten = () => {\n\t\t\t\tlistening = false;\n\t\t\t\twindow.removeEventListener(\"scroll\", onScroll);\n\t\t\t};\n\t\t\tlisten = () => {\n\t\t\t\tif (listening) return;\n\t\t\t\tlistening = true;\n\t\t\t\twindow.addEventListener(\"scroll\", onScroll, { passive: true });\n\t\t\t};\n\n\t\t\tlisten();\n\t\t\treturn () => {\n\t\t\t\tunlisten();\n\t\t\t\tif (frame !== undefined) cancelAnimationFrame(frame);\n\t\t\t\tframe = undefined;\n\t\t\t\tlisten = () => {};\n\t\t\t};\n\t\t},\n\t\treset() {\n\t\t\treached = new Set();\n\t\t\tlisten();\n\t\t},\n\t};\n};\n","import {\n\thasWord,\n\tindexIn,\n\tisIgnored,\n\tpromotionItems,\n\treadAnnotated,\n\troleSelector,\n\tsurrounding,\n} from \"./annotations\";\nimport type { PromotionData } from \"./impressions\";\nimport { INTERACTIVE } from \"./opt-in\";\nimport type { Detector } from \"./types\";\n\nexport type ItemSelectData = {\n\t/** Position in its List, when it's in one. */\n\tindex?: number;\n\t[field: string]: unknown;\n};\n\n/**\n * Publishes `item:select` for link and button clicks in an Item, its List and Promotion in its\n * Composition, and `promotion:select` for link and button clicks in a Promotion outside any Item.\n * Clicks in an Item flagged `detail` select nothing.\n */\nexport const selections = (): Detector<{\n\t\"item:select\": ItemSelectData;\n\t\"promotion:select\": PromotionData;\n}> => ({\n\tevents: [\"item:select\", \"promotion:select\"],\n\tstart({ publish }) {\n\t\tconst onClick = (event: MouseEvent) => {\n\t\t\tif (!(event.target instanceof Element)) return;\n\t\t\tconst target = event.target.closest(INTERACTIVE);\n\t\t\tif (!target || isIgnored(target)) return;\n\t\t\tconst item = target.closest(roleSelector(\"item\"));\n\t\t\t// On its own detail page, clicking an Item's actions (add to cart, variants) isn't selecting it.\n\t\t\tif (item && hasWord(item, \"detail\")) return;\n\t\t\tif (item) {\n\t\t\t\tconst { data, composed } = readAnnotated(item, \"item\");\n\t\t\t\tconst list = surrounding(item, \"list\");\n\t\t\t\tconst promotion = surrounding(item, \"promotion\");\n\t\t\t\tconst index = list\n\t\t\t\t\t? indexIn(item, list, \"list\")\n\t\t\t\t\t: promotion && indexIn(item, promotion, \"promotion\");\n\t\t\t\tpublish(\"item:select\", {\n\t\t\t\t\tdata: index === undefined ? data : { ...data, index },\n\t\t\t\t\tcomposed,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst promotion = target.closest(roleSelector(\"promotion\"));\n\t\t\tif (!promotion) return;\n\t\t\tconst { data, composed } = readAnnotated(promotion, \"promotion\");\n\t\t\tpublish(\"promotion:select\", {\n\t\t\t\tdata: { ...data, items: promotionItems(promotion) },\n\t\t\t\tcomposed,\n\t\t\t});\n\t\t};\n\t\tdocument.addEventListener(\"click\", onClick, { capture: true });\n\t\treturn () =>\n\t\t\tdocument.removeEventListener(\"click\", onClick, { capture: true });\n\t},\n});\n","import { isIgnored, readAnnotated } from \"./annotations\";\nimport { compact, isOptedIn } from \"./opt-in\";\nimport type { Detector } from \"./types\";\n\nexport type VideoEventData = {\n\turl: string;\n\ttitle?: string;\n\t/** Seconds, rounded. */\n\tduration: number;\n\t/** Seconds, rounded. */\n\tcurrentTime: number;\n\t/** For `video:progress`, the threshold reached; otherwise the share played. */\n\tpercent: number;\n\t[field: string]: unknown;\n};\n\nexport type VideosOptions = {\n\t/** Whether videos are tracked where neither a `video` Flag nor `data-e-auto` decides. */\n\tauto?: boolean;\n\t/** Percentages reported once per video per Page. */\n\tthresholds?: number[];\n};\n\ntype Playback = { started: boolean; reached: Set<number> };\n\n/** Publishes `video:start`, `video:progress` and `video:complete` for opted-in `<video>` elements. */\nexport const videos = ({\n\tauto = false,\n\tthresholds = [10, 25, 50, 75],\n}: VideosOptions = {}): Detector<{\n\t\"video:start\": VideoEventData;\n\t\"video:progress\": VideoEventData;\n\t\"video:complete\": VideoEventData;\n}> => {\n\tlet playbacks = new WeakMap<HTMLVideoElement, Playback>();\n\n\tconst read = (video: HTMLVideoElement, percent?: number) => {\n\t\tconst { data, composed } = readAnnotated(video, \"video\");\n\t\tconst duration = Number.isFinite(video.duration) ? video.duration : 0;\n\t\tconst base: VideoEventData = compact({\n\t\t\turl: video.currentSrc || video.src,\n\t\t\ttitle: video.title || video.getAttribute(\"aria-label\") || undefined,\n\t\t\tduration: Math.round(duration),\n\t\t\tcurrentTime: Math.round(video.currentTime),\n\t\t\tpercent:\n\t\t\t\tpercent ??\n\t\t\t\t(duration ? Math.round((video.currentTime / duration) * 100) : 0),\n\t\t});\n\t\treturn { data: { ...base, ...data }, composed };\n\t};\n\n\tconst tracked = (target: EventTarget | null) =>\n\t\ttarget instanceof HTMLVideoElement &&\n\t\t!isIgnored(target) &&\n\t\tisOptedIn(target, {\n\t\t\tflag: \"video\",\n\t\t\tkind: \"videos\",\n\t\t\tfallback: auto,\n\t\t})\n\t\t\t? target\n\t\t\t: undefined;\n\n\tconst playback = (video: HTMLVideoElement) => {\n\t\tlet state = playbacks.get(video);\n\t\tif (!state)\n\t\t\tplaybacks.set(video, (state = { started: false, reached: new Set() }));\n\t\treturn state;\n\t};\n\n\treturn {\n\t\tevents: [\"video:start\", \"video:progress\", \"video:complete\"],\n\t\tstart({ publish }) {\n\t\t\tconst onPlay = (event: Event) => {\n\t\t\t\tconst video = tracked(event.target);\n\t\t\t\tif (!video) return;\n\t\t\t\tconst state = playback(video);\n\t\t\t\tif (state.started) return;\n\t\t\t\tstate.started = true;\n\t\t\t\tpublish(\"video:start\", read(video));\n\t\t\t};\n\t\t\tconst onTimeUpdate = (event: Event) => {\n\t\t\t\tconst video = tracked(event.target);\n\t\t\t\tif (!video || !Number.isFinite(video.duration) || !video.duration)\n\t\t\t\t\treturn;\n\t\t\t\tconst state = playback(video);\n\t\t\t\tconst percent = (video.currentTime / video.duration) * 100;\n\t\t\t\tfor (const threshold of thresholds) {\n\t\t\t\t\tif (percent < threshold || state.reached.has(threshold)) continue;\n\t\t\t\t\tstate.reached.add(threshold);\n\t\t\t\t\tpublish(\"video:progress\", read(video, threshold));\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst onEnded = (event: Event) => {\n\t\t\t\tconst video = tracked(event.target);\n\t\t\t\tif (!video) return;\n\t\t\t\tpublish(\"video:complete\", read(video, 100));\n\t\t\t\t// Playing it again is a new start.\n\t\t\t\tplaybacks.delete(video);\n\t\t\t};\n\n\t\t\t// Media events don't bubble, but capturing listeners on the document still see them.\n\t\t\tconst options = { capture: true };\n\t\t\tdocument.addEventListener(\"play\", onPlay, options);\n\t\t\tdocument.addEventListener(\"timeupdate\", onTimeUpdate, options);\n\t\t\tdocument.addEventListener(\"ended\", onEnded, options);\n\t\t\treturn () => {\n\t\t\t\tdocument.removeEventListener(\"play\", onPlay, options);\n\t\t\t\tdocument.removeEventListener(\"timeupdate\", onTimeUpdate, options);\n\t\t\t\tdocument.removeEventListener(\"ended\", onEnded, options);\n\t\t\t};\n\t\t},\n\t\treset() {\n\t\t\tplaybacks = new WeakMap();\n\t\t},\n\t};\n};\n"]}
@@ -1,14 +1,11 @@
1
- export { C as CheckPublished, R as RequireCompatible } from '../compatibility-Dc1JmTeG.js';
2
- import { C as Catalog, E as EventBroker, S as Shape } from '../types-DfPz7mBl.js';
3
- export { B as BrokerEvents, c as CatalogEntry, d as Composition, b as EventData, e as EventMeta, a as EventName, f as SubscribeOptions, T as TrackingEvent } from '../types-DfPz7mBl.js';
1
+ import { C as Catalog, b as EventBroker, S as Shape } from '../types-CZEg03xW.js';
2
+ export { c as CatalogEntry, d as Composition, a as EventData, e as EventMeta, E as EventName, f as SubscribeOptions, T as TrackingEvent } from '../types-CZEg03xW.js';
4
3
 
5
4
  type EventBrokerOptions<Cx> = {
6
5
  /** Read on every publish; its return type is the Events' Context. */
7
6
  context?: () => Cx;
8
- /** Events held while nobody asked for replay; past it the oldest are dropped. */
9
- limit?: number;
10
7
  };
11
- declare const createEventBroker: <C extends Catalog, Cx = undefined>(events: C, { context, limit }?: EventBrokerOptions<Cx>) => EventBroker<C, Cx>;
8
+ declare const createEventBroker: <C extends Catalog, Cx = undefined>(events: C, { context }?: EventBrokerOptions<Cx>) => EventBroker<C, Cx>;
12
9
 
13
10
  /** Declares a type in the Event Catalog; holds nothing at runtime. */
14
11
  declare const shape: <T>() => Shape<T>;
@@ -1,8 +1,9 @@
1
1
  import { IS_DEVELOPMENT } from '../chunk-KLN5K6PR.js';
2
2
 
3
3
  // src/events/create-event-broker.ts
4
+ var LIMIT = 100;
4
5
  var createId = () => globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
5
- var createEventBroker = (events, { context, limit = 100 } = {}) => {
6
+ var createEventBroker = (events, { context } = {}) => {
6
7
  const listeners = /* @__PURE__ */ new Set();
7
8
  const held = [];
8
9
  const queue = [];
@@ -43,11 +44,11 @@ var createEventBroker = (events, { context, limit = 100 } = {}) => {
43
44
  });
44
45
  if (!replaying) {
45
46
  held.push(event);
46
- if (held.length > limit) {
47
- const [dropped] = held.splice(0, held.length - limit);
47
+ if (held.length > LIMIT) {
48
+ const [dropped] = held.splice(0, held.length - LIMIT);
48
49
  if (IS_DEVELOPMENT)
49
50
  console.warn(
50
- `[tracking] More than ${limit} Events held for replay; dropped "${dropped?.name}".`
51
+ `[tracking] More than ${LIMIT} Events held for replay; dropped "${dropped?.name}".`
51
52
  );
52
53
  }
53
54
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/events/create-event-broker.ts","../../src/events/shape.ts"],"names":[],"mappings":";;;AAgBA,IAAM,QAAA,GAAW,MAChB,UAAA,CAAW,MAAA,EAAQ,cAAa,IAChC,CAAA,EAAG,IAAA,CAAK,GAAA,EAAI,CAAE,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA,EAAI,KAAK,MAAA,EAAO,CAAE,SAAS,EAAE,CAAA,CAAE,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAE3D,IAAM,iBAAA,GAAoB,CAChC,MAAA,EACA,EAAE,SAAS,KAAA,GAAQ,GAAA,EAAI,GAA4B,EAAC,KAC5B;AAIxB,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAAc;AACpC,EAAA,MAAM,OAAsB,EAAC;AAC7B,EAAA,MAAM,QAA0D,EAAC;AACjE,EAAA,IAAI,SAAA,GAAY,CAAA;AAChB,EAAA,I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,SAAA,EAAW;AACf,QAAA,IAAA,CAAK,KAAK,KAAK,CAAA;AACf,QAAA,IAAI,IAAA,CAAK,SAAS,KAAA,EAAO;AACxB,UAAA,MAAM,CAAC,OAAO,CAAA,GAAI,IAAA,CAAK,OAAO,CAAA,EAAG,IAAA,CAAK,SAAS,KAAK,CAAA;AACpD,UAAA,IAAI,cAAA;AACH,YAAA,OAAA,CAAQ,IAAA;AAAA,cACP,CAAA,qBAAA,EAAwB,KAAK,CAAA,kCAAA,EAAqC,OAAA,EAAS,IAAI,CAAA,EAAA;AAAA,aAChF;AAAA,QACF;AAAA,MACD;AACA,MAAA,KAAA,CAAM,IAAA,CAAK,EAAE,KAAA,EAAO,EAAA,EAAI,CAAC,GAAG,SAAS,GAAG,CAAA;AACxC,MAAA,KAAA,EAAM;AAAA,IACP,CAAA;AAAA,IAEA,UAAU,QAAA,EAAU,EAAE,SAAS,KAAA,EAAM,GAAI,EAAC,EAAG;AAC5C,MAAA,IAAI,MAAA,EAAQ;AACX,QAAA,SAAA,EAAA;AACA,QAAA,KAAA,MAAW,KAAA,IAAS,IAAA,CAAK,MAAA,CAAO,CAAC,CAAA;AAChC,UAAA,KAAA,CAAM,KAAK,EAAE,KAAA,EAAO,IAAI,CAAC,QAAQ,GAAG,CAAA;AAAA,MACtC;AACA,MAAA,SAAA,CAAU,IAAI,QAAQ,CAAA;AACtB,MAAA,KAAA,EAAM;AACN,MAAA,OAAO,MAAM;AACZ,QAAA,IAAI,SAAA,CAAU,MAAA,CAAO,QAAQ,CAAA,IAAK,MAAA,EAAQ,SAAA,EAAA;AAAA,MAC3C,CAAA;AAAA,IACD;AAAA,GACD;AACD;;;AChGO,IAAM,KAAA,GAAQ,OAAoB,EAAC","file":"index.js","sourcesContent":["import { IS_DEVELOPMENT } from \"../config\";\nimport type {\n\tBrokerEvents,\n\tCatalog,\n\tEventBroker,\n\tEventName,\n\tTrackingEvent,\n} from \"./types\";\n\nexport type EventBrokerOptions<Cx> = {\n\t/** Read on every publish; its return type is the Events' Context. */\n\tcontext?: () => Cx;\n\t/** Events held while nobody asked for replay; past it the oldest are dropped. */\n\tlimit?: number;\n};\n\nconst createId = () =>\n\tglobalThis.crypto?.randomUUID?.() ??\n\t`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;\n\nexport const createEventBroker = <C extends Catalog, Cx = undefined>(\n\tevents: C,\n\t{ context, limit = 100 }: EventBrokerOptions<Cx> = {},\n): EventBroker<C, Cx> => {\n\ttype BrokerEvent = TrackingEvent<C, EventName<C>, Cx>;\n\ttype Listener = (event: BrokerEvent) => void;\n\n\tconst listeners = new Set<Listener>();\n\tconst held: BrokerEvent[] = [];\n\tconst queue: { event: BrokerEvent; to: Iterable<Listener> }[] = [];\n\tlet replaying = 0;\n\tlet seq = 0;\n\tlet delivering = false;\n\n\tconst call = (listener: Listener, event: BrokerEvent) => {\n\t\ttry {\n\t\t\tlistener(event);\n\t\t} catch (error) {\n\t\t\tif (IS_DEVELOPMENT) console.error(error);\n\t\t}\n\t};\n\n\t// Delivered from a loop rather than recursively, so an Event published by a listener still arrives after the one being delivered.\n\tconst drain = () => {\n\t\tif (delivering) return;\n\t\tdelivering = true;\n\t\ttry {\n\t\t\tfor (let next = queue.shift(); next; next = queue.shift())\n\t\t\t\tfor (const listener of next.to) call(listener, next.event);\n\t\t} finally {\n\t\t\tdelivering = false;\n\t\t}\n\t};\n\n\treturn {\n\t\tevents: events as BrokerEvents<C, Cx>,\n\n\t\tpublish(name, data, composed) {\n\t\t\tif (typeof window === \"undefined\") return;\n\n\t\t\tconst event = Object.freeze({\n\t\t\t\tname,\n\t\t\t\tdata,\n\t\t\t\tcomposed: Object.freeze({ ...composed }),\n\t\t\t\tcontext: context && Object.freeze(context()),\n\t\t\t\tmeta: Object.freeze({\n\t\t\t\t\tid: createId(),\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\tseq: ++seq,\n\t\t\t\t}),\n\t\t\t}) as unknown as BrokerEvent;\n\n\t\t\tif (!replaying) {\n\t\t\t\theld.push(event);\n\t\t\t\tif (held.length > limit) {\n\t\t\t\t\tconst [dropped] = held.splice(0, held.length - limit);\n\t\t\t\t\tif (IS_DEVELOPMENT)\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`[tracking] More than ${limit} Events held for replay; dropped \"${dropped?.name}\".`,\n\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tqueue.push({ event, to: [...listeners] });\n\t\t\tdrain();\n\t\t},\n\n\t\tsubscribe(listener, { replay = false } = {}) {\n\t\t\tif (replay) {\n\t\t\t\treplaying++;\n\t\t\t\tfor (const event of held.splice(0))\n\t\t\t\t\tqueue.push({ event, to: [listener] });\n\t\t\t}\n\t\t\tlisteners.add(listener);\n\t\t\tdrain();\n\t\t\treturn () => {\n\t\t\t\tif (listeners.delete(listener) && replay) replaying--;\n\t\t\t};\n\t\t},\n\t};\n};\n","import type { Shape } from \"./types\";\n\n/** Declares a type in the Event Catalog; holds nothing at runtime. */\nexport const shape = <T>(): Shape<T> => ({});\n"]}
1
+ {"version":3,"sources":["../../src/events/create-event-broker.ts","../../src/events/shape.ts"],"names":[],"mappings":";;;AASA,IAAM,KAAA,GAAQ,GAAA;AAEd,IAAM,QAAA,GAAW,MAChB,UAAA,CAAW,MAAA,EAAQ,cAAa,IAChC,CAAA,EAAG,IAAA,CAAK,GAAA,EAAI,CAAE,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA,EAAI,KAAK,MAAA,EAAO,CAAE,SAAS,EAAE,CAAA,CAAE,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAE3D,IAAM,oBAAoB,CAChC,MAAA,EACA,EAAE,OAAA,EAAQ,GAA4B,EAAC,KACf;AAIxB,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAAc;AACpC,EAAA,MAAM,OAAsB,EAAC;AAC7B,EAAA,MAAM,QAA0D,EAAC;AACjE,EAAA,IAAI,SAAA,GAAY,CAAA;AAChB,EAAA,IAAI,G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,EAAW;AACf,QAAA,IAAA,CAAK,KAAK,KAAK,CAAA;AACf,QAAA,IAAI,IAAA,CAAK,SAAS,KAAA,EAAO;AACxB,UAAA,MAAM,CAAC,OAAO,CAAA,GAAI,IAAA,CAAK,OAAO,CAAA,EAAG,IAAA,CAAK,SAAS,KAAK,CAAA;AACpD,UAAA,IAAI,cAAA;AACH,YAAA,OAAA,CAAQ,IAAA;AAAA,cACP,CAAA,qBAAA,EAAwB,KAAK,CAAA,kCAAA,EAAqC,OAAA,EAAS,IAAI,CAAA,EAAA;AAAA,aAChF;AAAA,QACF;AAAA,MACD;AACA,MAAA,KAAA,CAAM,IAAA,CAAK,EAAE,KAAA,EAAO,EAAA,EAAI,CAAC,GAAG,SAAS,GAAG,CAAA;AACxC,MAAA,KAAA,EAAM;AAAA,IACP,CAAA;AAAA,IAEA,UAAU,QAAA,EAAU,EAAE,SAAS,KAAA,EAAM,GAAI,EAAC,EAAG;AAC5C,MAAA,IAAI,MAAA,EAAQ;AACX,QAAA,SAAA,EAAA;AACA,QAAA,KAAA,MAAW,KAAA,IAAS,IAAA,CAAK,MAAA,CAAO,CAAC,CAAA;AAChC,UAAA,KAAA,CAAM,KAAK,EAAE,KAAA,EAAO,IAAI,CAAC,QAAQ,GAAG,CAAA;AAAA,MACtC;AACA,MAAA,SAAA,CAAU,IAAI,QAAQ,CAAA;AACtB,MAAA,KAAA,EAAM;AACN,MAAA,OAAO,MAAM;AACZ,QAAA,IAAI,SAAA,CAAU,MAAA,CAAO,QAAQ,CAAA,IAAK,MAAA,EAAQ,SAAA,EAAA;AAAA,MAC3C,CAAA;AAAA,IACD;AAAA,GACD;AACD;;;AC3FO,IAAM,KAAA,GAAQ,OAAoB,EAAC","file":"index.js","sourcesContent":["import { IS_DEVELOPMENT } from \"../config\";\nimport type { Catalog, EventBroker, EventName, TrackingEvent } from \"./types\";\n\nexport type EventBrokerOptions<Cx> = {\n\t/** Read on every publish; its return type is the Events' Context. */\n\tcontext?: () => Cx;\n};\n\n/** Events held while nobody asked for replay; past it the oldest are dropped. */\nconst LIMIT = 100;\n\nconst createId = () =>\n\tglobalThis.crypto?.randomUUID?.() ??\n\t`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;\n\nexport const createEventBroker = <C extends Catalog, Cx = undefined>(\n\tevents: C,\n\t{ context }: EventBrokerOptions<Cx> = {},\n): EventBroker<C, Cx> => {\n\ttype BrokerEvent = TrackingEvent<C, EventName<C>, Cx>;\n\ttype Listener = (event: BrokerEvent) => void;\n\n\tconst listeners = new Set<Listener>();\n\tconst held: BrokerEvent[] = [];\n\tconst queue: { event: BrokerEvent; to: Iterable<Listener> }[] = [];\n\tlet replaying = 0;\n\tlet seq = 0;\n\tlet delivering = false;\n\n\tconst call = (listener: Listener, event: BrokerEvent) => {\n\t\ttry {\n\t\t\tlistener(event);\n\t\t} catch (error) {\n\t\t\tif (IS_DEVELOPMENT) console.error(error);\n\t\t}\n\t};\n\n\t// Delivered from a loop rather than recursively, so an Event published by a listener still arrives after the one being delivered.\n\tconst drain = () => {\n\t\tif (delivering) return;\n\t\tdelivering = true;\n\t\ttry {\n\t\t\tfor (let next = queue.shift(); next; next = queue.shift())\n\t\t\t\tfor (const listener of next.to) call(listener, next.event);\n\t\t} finally {\n\t\t\tdelivering = false;\n\t\t}\n\t};\n\n\treturn {\n\t\tevents,\n\n\t\tpublish(name, data, composed) {\n\t\t\tif (typeof window === \"undefined\") return;\n\n\t\t\tconst event = Object.freeze({\n\t\t\t\tname,\n\t\t\t\tdata,\n\t\t\t\tcomposed: Object.freeze({ ...composed }),\n\t\t\t\tcontext: context && Object.freeze(context()),\n\t\t\t\tmeta: Object.freeze({\n\t\t\t\t\tid: createId(),\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\tseq: ++seq,\n\t\t\t\t}),\n\t\t\t}) as unknown as BrokerEvent;\n\n\t\t\tif (!replaying) {\n\t\t\t\theld.push(event);\n\t\t\t\tif (held.length > LIMIT) {\n\t\t\t\t\tconst [dropped] = held.splice(0, held.length - LIMIT);\n\t\t\t\t\tif (IS_DEVELOPMENT)\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`[tracking] More than ${LIMIT} Events held for replay; dropped \"${dropped?.name}\".`,\n\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tqueue.push({ event, to: [...listeners] });\n\t\t\tdrain();\n\t\t},\n\n\t\tsubscribe(listener, { replay = false } = {}) {\n\t\t\tif (replay) {\n\t\t\t\treplaying++;\n\t\t\t\tfor (const event of held.splice(0))\n\t\t\t\t\tqueue.push({ event, to: [listener] });\n\t\t\t}\n\t\t\tlisteners.add(listener);\n\t\t\tdrain();\n\t\t\treturn () => {\n\t\t\t\tif (listeners.delete(listener) && replay) replaying--;\n\t\t\t};\n\t\t},\n\t};\n};\n","import type { Shape } from \"./types\";\n\n/** Declares a type in the Event Catalog; holds nothing at runtime. */\nexport const shape = <T>(): Shape<T> => ({});\n"]}
@@ -1,16 +1,18 @@
1
- import { ConsentSink, ConsentProvider } from '../consent/index.js';
2
- import { C as Catalog, E as EventBroker } from '../types-DfPz7mBl.js';
3
- import { D as Destinations } from '../types-BfJsv8AV.js';
4
- import { Source } from '../sources/index.js';
1
+ import { a as ConsentRequirement, c as ConsentSink, C as ConsentProvider } from '../consent-types-DgKtGapr.js';
2
+ export { d as Consent, b as ConsentCategory, e as ConsentMapping } from '../consent-types-DgKtGapr.js';
3
+ import { D as DestinationEvent, a as Destination, M as Mapping, b as MappedDestination } from '../destination-types-DNMBOW_e.js';
4
+ import { C as Catalog, b as EventBroker } from '../types-CZEg03xW.js';
5
+ import { S as Source } from '../source-types-fJXZeF2Q.js';
6
+
7
+ /** A Destination for `startTracking()`: receives what `mapping` makes of the broker's Events, once `requires` is consented to. */
8
+ declare const map: <C extends Catalog, Cx, E extends DestinationEvent>(_broker: EventBroker<C, Cx>, destination: Destination<E>, requires: ConsentRequirement, mapping: NoInfer<Mapping<C, E, Cx>>) => MappedDestination<C, Cx>;
5
9
 
6
10
  type TrackingOptions = {
7
11
  /** Started with the Flow and stopped with it. */
8
12
  sources?: Source[];
9
13
  /** Told every consent answer before Destinations receive Events under it. */
10
14
  consentSinks?: ConsentSink[];
11
- /** Events held per Destination while consent is unanswered. */
12
- limit?: number;
13
15
  };
14
- declare const startTracking: <C extends Catalog, Cx>(broker: EventBroker<C, Cx>, consentProvider: ConsentProvider, destinations: Destinations<C, Cx>, { sources, consentSinks, limit }?: TrackingOptions) => (() => void);
16
+ declare const startTracking: <C extends Catalog, Cx>(broker: EventBroker<C, Cx>, consentProvider: ConsentProvider, destinations: readonly MappedDestination<C, Cx>[], { sources, consentSinks }?: TrackingOptions) => (() => void);
15
17
 
16
- export { type TrackingOptions, startTracking };
18
+ export { ConsentProvider, ConsentRequirement, ConsentSink, Destination, DestinationEvent, MappedDestination, Mapping, Source, type TrackingOptions, map, startTracking };
@@ -1,6 +1,18 @@
1
1
  import { IS_DEVELOPMENT } from '../chunk-KLN5K6PR.js';
2
2
 
3
+ // src/flow/map.ts
4
+ var map = (_broker, destination, requires, mapping) => ({
5
+ name: destination.name,
6
+ requires,
7
+ deliver(event) {
8
+ const toEvent = mapping[event.name];
9
+ const mapped = toEvent?.(event);
10
+ if (mapped) return destination.send(mapped);
11
+ }
12
+ });
13
+
3
14
  // src/flow/start-tracking.ts
15
+ var LIMIT = 100;
4
16
  var CURRENT_FLOW = Symbol.for("@buildinams/tracking/flow");
5
17
  var isAllowed = (destination, consent) => {
6
18
  if (destination.requires === "none") return true;
@@ -22,30 +34,32 @@ var send = (destination, event) => {
22
34
  reportFailure("Destination", destination.name, error);
23
35
  }
24
36
  };
25
- var startTracking = (broker, consentProvider, destinations, { sources = [], consentSinks = [], limit = 100 } = {}) => {
37
+ var startTracking = (broker, consentProvider, destinations, { sources = [], consentSinks = [] } = {}) => {
26
38
  if (typeof window === "undefined") return () => {
27
39
  };
28
40
  const flowGlobal = globalThis;
29
41
  flowGlobal[CURRENT_FLOW]?.();
30
- const held = new Map(destinations.mapped.map((destination) => [destination, []]));
42
+ const held = new Map(destinations.map((destination) => [destination, []]));
31
43
  const sinks = consentSinks.filter(
32
44
  (sink) => sink.name !== consentProvider.name
33
45
  );
34
- const applyConsent = (answer) => {
35
- if (!answer) return;
46
+ const applyConsent = (answer, previous) => {
47
+ if (!answer && !previous) return;
36
48
  for (const sink of sinks) {
37
49
  try {
38
- sink.apply(answer);
50
+ if (answer) sink.apply(answer);
51
+ else sink.clear?.();
39
52
  } catch (error) {
40
53
  reportFailure("Consent sink", sink.name, error);
41
54
  }
42
55
  }
43
56
  };
44
57
  let consent = consentProvider.get();
45
- applyConsent(consent);
58
+ applyConsent(consent, null);
46
59
  const unsubscribeConsent = consentProvider.subscribe((next) => {
60
+ const previous = consent;
47
61
  consent = next;
48
- applyConsent(consent);
62
+ applyConsent(consent, previous);
49
63
  for (const [destination, events] of held) {
50
64
  const allowed = isAllowed(destination, consent);
51
65
  if (allowed === void 0) continue;
@@ -60,7 +74,7 @@ var startTracking = (broker, consentProvider, destinations, { sources = [], cons
60
74
  if (allowed) send(destination, event);
61
75
  else if (allowed === void 0) {
62
76
  events.push(event);
63
- if (events.length > limit) events.shift();
77
+ if (events.length > LIMIT) events.shift();
64
78
  }
65
79
  }
66
80
  },
@@ -77,6 +91,6 @@ var startTracking = (broker, consentProvider, destinations, { sources = [], cons
77
91
  return stop;
78
92
  };
79
93
 
80
- export { startTracking };
94
+ export { map, startTracking };
81
95
  //# sourceMappingURL=index.js.map
82
96
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/flow/start-tracking.ts"],"names":[],"mappings":";;;AAeA,IAAM,YAAA,GAAe,MAAA,CAAO,GAAA,CAAI,2BAA2B,CAAA;AAM3D,IAAM,SAAA,GAAY,CAAC,WAAA,EAA8B,OAAA,KAA4B;AAC5E,EAAA,IAAI,WAAA,CAAY,QAAA,KAAa,MAAA,EAAQ,OAAO,IAAA;AAC5C,EAAA,IAAI,CAAC,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AAA;AAC9C,QAAA,IAAI,OAAA,EAAS,IAAA,CAAK,WAAA,EAAa,KAAK,CAAA;AAAA,aAAA,IAC3B,YAAY,MAAA,EAAW;AAC/B,UAAA,MAAA,CAAO,KAAK,KAAK,CAAA;AACjB,UAAA,IAAI,MAAA,CAAO,MAAA,GAAS,KAAA,EAAO,MAAA,CAAO,KAAA,EAAM;AAAA,QACzC;AAAA,MACD;AAAA,IACD,CAAA;AAAA,IACA,EAAE,QAAQ,IAAA;AAAK,GAChB;AAEA,EAAA,MAAM,cAAc,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAA,KAAW,MAAA,CAAO,OAAO,CAAA;AAE1D,EAAA,MAAM,OAAO,MAAM;AAClB,IAAA,iBAAA,EAAkB;AAClB,IAAA,kBAAA,EAAmB;AACnB,IAAA,KAAA,MAAW,UAAA,IAAc,aAAa,UAAA,EAAW;AACjD,IAAA,IAAI,WAAW,YAAY,CAAA,KAAM,IAAA,EAAM,OAAO,WAAW,YAAY,CAAA;AAAA,EACtE,CAAA;AACA,EAAA,UAAA,CAAW,YAAY,CAAA,GAAI,IAAA;AAC3B,EAAA,OAAO,IAAA;AACR","file":"index.js","sourcesContent":["import { IS_DEVELOPMENT } from \"../config\";\nimport type { Consent, ConsentProvider, ConsentSink } from \"../consent\";\nimport type { Destinations, MappedDestination } from \"../destinations\";\nimport type { Catalog, EventBroker, EventName, TrackingEvent } from \"../events\";\nimport type { Source } from \"../sources\";\n\nexport type TrackingOptions = {\n\t/** Started with the Flow and stopped with it. */\n\tsources?: Source[];\n\t/** Told every consent answer before Destinations receive Events under it. */\n\tconsentSinks?: ConsentSink[];\n\t/** Events held per Destination while consent is unanswered. */\n\tlimit?: number;\n};\n\nconst CURRENT_FLOW = Symbol.for(\"@buildinams/tracking/flow\");\n\ntype FlowGlobal = { [CURRENT_FLOW]?: () => void };\n\ntype DestinationInfo = Pick<MappedDestination<Catalog>, \"name\" | \"requires\">;\n\nconst isAllowed = (destination: DestinationInfo, consent: Consent | null) => {\n\tif (destination.requires === \"none\") return true;\n\tif (!consent) return undefined;\n\treturn destination.requires.every((category) => consent[category]);\n};\n\nconst reportFailure = (\n\tkind: \"Destination\" | \"Consent sink\",\n\tname: string,\n\terror: unknown,\n) => {\n\tif (IS_DEVELOPMENT)\n\t\tconsole.error(`[tracking] ${kind} \"${name}\" failed`, error);\n};\n\nconst send = <C extends Catalog, Cx>(\n\tdestination: MappedDestination<C, Cx>,\n\tevent: TrackingEvent<C, EventName<C>, Cx>,\n) => {\n\ttry {\n\t\tconst result = destination.deliver(event);\n\t\tif (result instanceof Promise)\n\t\t\tresult.catch((error: unknown) =>\n\t\t\t\treportFailure(\"Destination\", destination.name, error),\n\t\t\t);\n\t} catch (error) {\n\t\treportFailure(\"Destination\", destination.name, error);\n\t}\n};\n\nexport const startTracking = <C extends Catalog, Cx>(\n\tbroker: EventBroker<C, Cx>,\n\tconsentProvider: ConsentProvider,\n\tdestinations: Destinations<C, Cx>,\n\t{ sources = [], consentSinks = [], limit = 100 }: TrackingOptions = {},\n): (() => void) => {\n\tif (typeof window === \"undefined\") return () => {};\n\n\t// A module re-run by HMR starts a new Flow; the previous one must stop or every Event is sent twice.\n\tconst flowGlobal = globalThis as FlowGlobal;\n\tflowGlobal[CURRENT_FLOW]?.();\n\n\tconst held = new Map<\n\t\tMappedDestination<C, Cx>,\n\t\tTrackingEvent<C, EventName<C>, Cx>[]\n\t>(destinations.mapped.map((destination) => [destination, []]));\n\tconst sinks = consentSinks.filter(\n\t\t(sink) => sink.name !== consentProvider.name,\n\t);\n\tconst applyConsent = (answer: Consent | null) => {\n\t\tif (!answer) return;\n\t\tfor (const sink of sinks) {\n\t\t\ttry {\n\t\t\t\tsink.apply(answer);\n\t\t\t} catch (error) {\n\t\t\t\treportFailure(\"Consent sink\", sink.name, error);\n\t\t\t}\n\t\t}\n\t};\n\n\tlet consent = consentProvider.get();\n\tapplyConsent(consent);\n\n\tconst unsubscribeConsent = consentProvider.subscribe((next) => {\n\t\tconsent = next;\n\t\tapplyConsent(consent);\n\t\tfor (const [destination, events] of held) {\n\t\t\tconst allowed = isAllowed(destination, consent);\n\t\t\tif (allowed === undefined) continue;\n\t\t\tconst pending = events.splice(0);\n\t\t\tif (allowed) for (const event of pending) send(destination, event);\n\t\t}\n\t});\n\n\tconst unsubscribeBroker = broker.subscribe(\n\t\t(event) => {\n\t\t\tfor (const [destination, events] of held) {\n\t\t\t\tconst allowed = isAllowed(destination, consent);\n\t\t\t\tif (allowed) send(destination, event);\n\t\t\t\telse if (allowed === undefined) {\n\t\t\t\t\tevents.push(event);\n\t\t\t\t\tif (events.length > limit) events.shift();\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{ replay: true },\n\t);\n\n\tconst stopSources = sources.map((source) => source.start());\n\n\tconst stop = () => {\n\t\tunsubscribeBroker();\n\t\tunsubscribeConsent();\n\t\tfor (const stopSource of stopSources) stopSource();\n\t\tif (flowGlobal[CURRENT_FLOW] === stop) delete flowGlobal[CURRENT_FLOW];\n\t};\n\tflowGlobal[CURRENT_FLOW] = stop;\n\treturn stop;\n};\n"]}
1
+ {"version":3,"sources":["../../src/flow/map.ts","../../src/flow/start-tracking.ts"],"names":[],"mappings":";;;AAUO,IAAM,GAAA,GAAM,CAElB,OAAA,EACA,WAAA,EACA,UACA,OAAA,MAC+B;AAAA,EAC/B,MAAM,WAAA,CAAY,IAAA;AAAA,EAClB,QAAA;AAAA,EACA,QAAQ,KAAA,EAAO;AACd,IAAA,MAAM,OAAA,GAAU,OAAA,CAAQ,KAAA,CAAM,IAAI,CAAA;AAGlC,IAAA,MAAM,MAAA,GAAS,UAAU,KAAK,CAAA;AAC9B,IAAA,IAAI,MAAA,EAAQ,OAAO,WAAA,CAAY,IAAA,CAAK,MAAM,CAAA;AAAA,EAC3C;AACD,CAAA;;;ACZA,IAAM,KAAA,GAAQ,GAAA;AAEd,IAAM,YAAA,GAAe,MAAA,CAAO,GAAA,CAAI,2BAA2B,CAAA;AAM3D,IAAM,SAAA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;AAAA,EACD,CAAC,CAAA;AAED,EAAA,MAAM,oBAAoB,MAAA,CAAO,SAAA;AAAA,IAChC,CAAC,KAAA,KAAU;AACV,MAAA,KAAA,MAAW,CAAC,WAAA,EAAa,MAAM,CAAA,IAAK,IAAA,EAAM;AACzC,QAAA,MAAM,OAAA,GAAU,SAAA,CAAU,WAAA,EAAa,OAAO,CAAA;AAC9C,QAAA,IAAI,OAAA,EAAS,IAAA,CAAK,WAAA,EAAa,KAAK,CAAA;AAAA,aAAA,IAC3B,YAAY,MAAA,EAAW;AAC/B,UAAA,MAAA,CAAO,KAAK,KAAK,CAAA;AACjB,UAAA,IAAI,MAAA,CAAO,MAAA,GAAS,KAAA,EAAO,MAAA,CAAO,KAAA,EAAM;AAAA,QACzC;AAAA,MACD;AAAA,IACD,CAAA;AAAA,IACA,EAAE,QAAQ,IAAA;AAAK,GAChB;AAEA,EAAA,MAAM,cAAc,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAA,KAAW,MAAA,CAAO,OAAO,CAAA;AAE1D,EAAA,MAAM,OAAO,MAAM;AAClB,IAAA,iBAAA,EAAkB;AAClB,IAAA,kBAAA,EAAmB;AACnB,IAAA,KAAA,MAAW,UAAA,IAAc,aAAa,UAAA,EAAW;AACjD,IAAA,IAAI,WAAW,YAAY,CAAA,KAAM,IAAA,EAAM,OAAO,WAAW,YAAY,CAAA;AAAA,EACtE,CAAA;AACA,EAAA,UAAA,CAAW,YAAY,CAAA,GAAI,IAAA;AAC3B,EAAA,OAAO,IAAA;AACR","file":"index.js","sourcesContent":["import type { Catalog, EventBroker, EventName, TrackingEvent } from \"../events\";\nimport type { ConsentRequirement } from \"./consent-types\";\nimport type {\n\tDestination,\n\tDestinationEvent,\n\tMappedDestination,\n\tMapping,\n} from \"./destination-types\";\n\n/** A Destination for `startTracking()`: receives what `mapping` makes of the broker's Events, once `requires` is consented to. */\nexport const map = <C extends Catalog, Cx, E extends DestinationEvent>(\n\t// Types the Mapping only.\n\t_broker: EventBroker<C, Cx>,\n\tdestination: Destination<E>,\n\trequires: ConsentRequirement,\n\tmapping: NoInfer<Mapping<C, E, Cx>>,\n): MappedDestination<C, Cx> => ({\n\tname: destination.name,\n\trequires,\n\tdeliver(event) {\n\t\tconst toEvent = mapping[event.name] as\n\t\t\t| ((event: TrackingEvent<C, EventName<C>, Cx>) => E | null | undefined)\n\t\t\t| undefined;\n\t\tconst mapped = toEvent?.(event);\n\t\tif (mapped) return destination.send(mapped);\n\t},\n});\n","import { IS_DEVELOPMENT } from \"../config\";\nimport type { Catalog, EventBroker, EventName, TrackingEvent } from \"../events\";\nimport type { Consent, ConsentProvider, ConsentSink } from \"./consent-types\";\nimport type { MappedDestination } from \"./destination-types\";\nimport type { Source } from \"./source-types\";\n\nexport type TrackingOptions = {\n\t/** Started with the Flow and stopped with it. */\n\tsources?: Source[];\n\t/** Told every consent answer before Destinations receive Events under it. */\n\tconsentSinks?: ConsentSink[];\n};\n\n/** Events held per Destination while consent is unanswered. */\nconst LIMIT = 100;\n\nconst CURRENT_FLOW = Symbol.for(\"@buildinams/tracking/flow\");\n\ntype FlowGlobal = { [CURRENT_FLOW]?: () => void };\n\ntype DestinationInfo = Pick<MappedDestination<Catalog>, \"name\" | \"requires\">;\n\nconst isAllowed = (destination: DestinationInfo, consent: Consent | null) => {\n\tif (destination.requires === \"none\") return true;\n\tif (!consent) return undefined;\n\treturn destination.requires.every((category) => consent[category]);\n};\n\nconst reportFailure = (\n\tkind: \"Destination\" | \"Consent sink\",\n\tname: string,\n\terror: unknown,\n) => {\n\tif (IS_DEVELOPMENT)\n\t\tconsole.error(`[tracking] ${kind} \"${name}\" failed`, error);\n};\n\nconst send = <C extends Catalog, Cx>(\n\tdestination: MappedDestination<C, Cx>,\n\tevent: TrackingEvent<C, EventName<C>, Cx>,\n) => {\n\ttry {\n\t\tconst result = destination.deliver(event);\n\t\tif (result instanceof Promise)\n\t\t\tresult.catch((error: unknown) =>\n\t\t\t\treportFailure(\"Destination\", destination.name, error),\n\t\t\t);\n\t} catch (error) {\n\t\treportFailure(\"Destination\", destination.name, error);\n\t}\n};\n\nexport const startTracking = <C extends Catalog, Cx>(\n\tbroker: EventBroker<C, Cx>,\n\tconsentProvider: ConsentProvider,\n\tdestinations: readonly MappedDestination<C, Cx>[],\n\t{ sources = [], consentSinks = [] }: TrackingOptions = {},\n): (() => void) => {\n\tif (typeof window === \"undefined\") return () => {};\n\n\t// A module re-run by HMR starts a new Flow; the previous one must stop or every Event is sent twice.\n\tconst flowGlobal = globalThis as FlowGlobal;\n\tflowGlobal[CURRENT_FLOW]?.();\n\n\tconst held = new Map<\n\t\tMappedDestination<C, Cx>,\n\t\tTrackingEvent<C, EventName<C>, Cx>[]\n\t>(destinations.map((destination) => [destination, []]));\n\tconst sinks = consentSinks.filter(\n\t\t(sink) => sink.name !== consentProvider.name,\n\t);\n\tconst applyConsent = (answer: Consent | null, previous: Consent | null) => {\n\t\tif (!answer && !previous) return;\n\t\tfor (const sink of sinks) {\n\t\t\ttry {\n\t\t\t\tif (answer) sink.apply(answer);\n\t\t\t\telse sink.clear?.();\n\t\t\t} catch (error) {\n\t\t\t\treportFailure(\"Consent sink\", sink.name, error);\n\t\t\t}\n\t\t}\n\t};\n\n\tlet consent = consentProvider.get();\n\tapplyConsent(consent, null);\n\n\tconst unsubscribeConsent = consentProvider.subscribe((next) => {\n\t\tconst previous = consent;\n\t\tconsent = next;\n\t\tapplyConsent(consent, previous);\n\t\tfor (const [destination, events] of held) {\n\t\t\tconst allowed = isAllowed(destination, consent);\n\t\t\tif (allowed === undefined) continue;\n\t\t\tconst pending = events.splice(0);\n\t\t\tif (allowed) for (const event of pending) send(destination, event);\n\t\t}\n\t});\n\n\tconst unsubscribeBroker = broker.subscribe(\n\t\t(event) => {\n\t\t\tfor (const [destination, events] of held) {\n\t\t\t\tconst allowed = isAllowed(destination, consent);\n\t\t\t\tif (allowed) send(destination, event);\n\t\t\t\telse if (allowed === undefined) {\n\t\t\t\t\tevents.push(event);\n\t\t\t\t\tif (events.length > LIMIT) events.shift();\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{ replay: true },\n\t);\n\n\tconst stopSources = sources.map((source) => source.start());\n\n\tconst stop = () => {\n\t\tunsubscribeBroker();\n\t\tunsubscribeConsent();\n\t\tfor (const stopSource of stopSources) stopSource();\n\t\tif (flowGlobal[CURRENT_FLOW] === stop) delete flowGlobal[CURRENT_FLOW];\n\t};\n\tflowGlobal[CURRENT_FLOW] = stop;\n\treturn stop;\n};\n"]}
@@ -0,0 +1,32 @@
1
+ import { e as ConsentMapping, c as ConsentSink } from '../consent-types-DgKtGapr.js';
2
+ import { a as Destination } from '../destination-types-DNMBOW_e.js';
3
+ import '../types-CZEg03xW.js';
4
+
5
+ type GoogleConsentType = "ad_personalization" | "ad_storage" | "ad_user_data" | "analytics_storage" | "functionality_storage" | "personalization_storage" | "security_storage";
6
+ type GoogleConsentState = Record<GoogleConsentType, "granted" | "denied">;
7
+ type GoogleConsentModeOptions = {
8
+ /** The GTM data layer's global name. */
9
+ dataLayerName?: string;
10
+ /** Also maps the unanswered default, so a type granted regardless of the answer is granted from the start. */
11
+ mapConsent?: ConsentMapping<GoogleConsentState>;
12
+ /** How long Google's tags wait for the answer before firing under the default, in milliseconds. */
13
+ waitForUpdate?: number;
14
+ };
15
+ /**
16
+ * Forwards consent to Google Consent Mode. The first one created for a data layer denies every
17
+ * category by default, so create it before GTM loads or anything is pushed to the data layer.
18
+ */
19
+ declare const googleConsentMode: ({ dataLayerName, mapConsent, waitForUpdate, }?: GoogleConsentModeOptions) => ConsentSink;
20
+
21
+ type GtmEvent = {
22
+ name: string;
23
+ payload: Record<string, unknown>;
24
+ };
25
+ type GtmOptions = {
26
+ /** The GTM data layer's global name. */
27
+ dataLayerName?: string;
28
+ };
29
+ /** Pushes to GTM's data layer, e.g. for GA4; Consent Mode in the container gates it. */
30
+ declare const gtm: ({ dataLayerName, }?: GtmOptions) => Destination<GtmEvent>;
31
+
32
+ export { type GoogleConsentModeOptions, type GoogleConsentState, type GoogleConsentType, type GtmEvent, type GtmOptions, googleConsentMode, gtm };
@@ -0,0 +1,66 @@
1
+ // src/google/data-layer.ts
2
+ var getDataLayer = (name = "dataLayer") => window[name] ??= [];
3
+
4
+ // src/google/google-consent-mode.ts
5
+ var toGoogleConsent = ({
6
+ analytics,
7
+ marketing,
8
+ preferences
9
+ }) => {
10
+ const state = (allowed) => allowed ? "granted" : "denied";
11
+ return {
12
+ ad_personalization: state(marketing),
13
+ ad_storage: state(marketing),
14
+ ad_user_data: state(marketing),
15
+ analytics_storage: state(analytics),
16
+ functionality_storage: state(preferences),
17
+ personalization_storage: state(preferences),
18
+ security_storage: "granted"
19
+ };
20
+ };
21
+ var UNANSWERED = {
22
+ necessary: true,
23
+ preferences: false,
24
+ analytics: false,
25
+ marketing: false
26
+ };
27
+ var defaulted = /* @__PURE__ */ new WeakSet();
28
+ var googleConsentMode = ({
29
+ dataLayerName = "dataLayer",
30
+ mapConsent = (_consent, defaults) => defaults,
31
+ // Leaves room for consent loaded after GTM, e.g. Shopify's Customer Privacy API on a headless store.
32
+ waitForUpdate = 2e3
33
+ } = {}) => {
34
+ const toConsentMode = (consent) => mapConsent(consent, toGoogleConsent(consent));
35
+ function gtag(..._args) {
36
+ getDataLayer(dataLayerName).push(arguments);
37
+ }
38
+ if (typeof window !== "undefined" && !defaulted.has(getDataLayer(dataLayerName))) {
39
+ defaulted.add(getDataLayer(dataLayerName));
40
+ gtag("consent", "default", {
41
+ ...toConsentMode(UNANSWERED),
42
+ wait_for_update: waitForUpdate
43
+ });
44
+ }
45
+ return {
46
+ name: "google",
47
+ apply: (consent) => gtag("consent", "update", toConsentMode(consent)),
48
+ clear: () => gtag("consent", "update", toConsentMode(UNANSWERED))
49
+ };
50
+ };
51
+
52
+ // src/google/gtm.ts
53
+ var gtm = ({
54
+ dataLayerName = "dataLayer"
55
+ } = {}) => ({
56
+ name: "gtm",
57
+ send({ name, payload }) {
58
+ const target = getDataLayer(dataLayerName);
59
+ if ("ecommerce" in payload) target.push({ ecommerce: null });
60
+ target.push({ event: name, ...payload });
61
+ }
62
+ });
63
+
64
+ export { googleConsentMode, gtm };
65
+ //# sourceMappingURL=index.js.map
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/google/data-layer.ts","../../src/google/google-consent-mode.ts","../../src/google/gtm.ts"],"names":[],"mappings":";AACO,IAAM,eAAe,CAAC,IAAA,GAAO,gBACjC,MAAA,CAA4D,IAAI,MAAM,EAAC;;;ACwB1E,IAAM,kBAAkB,CAAC;AAAA,EACxB,SAAA;AAAA,EACA,SAAA;AAAA,EACA;AACD,CAAA,KAAmC;AAClC,EAAA,MAAM,KAAA,GAAQ,CAAC,OAAA,KAAsB,OAAA,GAAU,SAAA,GAAY,QAAA;AAC3D,EAAA,OAAO;AAAA,IACN,kBAAA,EAAoB,MAAM,SAAS,CAAA;AAAA,IACnC,UAAA,EAAY,MAAM,SAAS,CAAA;AAAA,IAC3B,YAAA,EAAc,MAAM,SAAS,CAAA;AAAA,IAC7B,iBAAA,EAAmB,MAAM,SAAS,CAAA;AAAA,IAClC,qBAAA,EAAuB,MAAM,WAAW,CAAA;AAAA,IACxC,uBAAA,EAAyB,MAAM,WAAW,CAAA;AAAA,IAC1C,gBAAA,EAAkB;AAAA,GACnB;AACD,CAAA;AAEA,IAAM,UAAA,GAAsB;AAAA,EAC3B,SAAA,EAAW,IAAA;AAAA,EACX,WAAA,EAAa,KAAA;AAAA,EACb,SAAA,EAAW,KAAA;AAAA,EACX,SAAA,EAAW;AACZ,CAAA;AAGA,IAAM,SAAA,uBAAgB,OAAA,EAAmB;AAMlC,IAAM,oBAAoB,CAAC;AAAA,EACjC,aAAA,GAAgB,WAAA;AAAA,EAChB,UAAA,GAAa,CAAC,QAAA,EAAU,QAAA,KAAa,QAAA;AAAA;AAAA,EAErC,aAAA,GAAgB;AACjB,CAAA,GAA8B,EAAC,KAAmB;AACjD,EAAA,MAAM,gBAAgB,CAAC,OAAA,KACtB,WAAW,OAAA,EAAS,eAAA,CAAgB,OAAO,CAAC,CAAA;AAE7C,EAAA,SAAS,QAAQ,KAAA,EAAkB;AAGlC,IAAA,YAAA,CAAa,aAAa,CAAA,CAAE,IAAA,CAAK,SAAS,CAAA;AAAA,EAC3C;AAEA,EAAA,IACC,OAAO,WAAW,WAAA,IAClB,CAAC,UAAU,GAAA,CAAI,YAAA,CAAa,aAAa,CAAC,CAAA,EACzC;AACD,IAAA,SAAA,CAAU,GAAA,CAAI,YAAA,CAAa,aAAa,CAAC,CAAA;AACzC,IAAA,IAAA,CAAK,WAAW,SAAA,EAAW;AAAA,MAC1B,GAAG,cAAc,UAAU,CAAA;AAAA,MAC3B,eAAA,EAAiB;AAAA,KACjB,CAAA;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACN,IAAA,EAAM,QAAA;AAAA,IACN,KAAA,EAAO,CAAC,OAAA,KAAY,IAAA,CAAK,WAAW,QAAA,EAAU,aAAA,CAAc,OAAO,CAAC,CAAA;AAAA,IACpE,OAAO,MAAM,IAAA,CAAK,WAAW,QAAA,EAAU,aAAA,CAAc,UAAU,CAAC;AAAA,GACjE;AACD;;;AC7EO,IAAM,MAAM,CAAC;AAAA,EACnB,aAAA,GAAgB;AACjB,CAAA,GAAgB,EAAC,MAA8B;AAAA,EAC9C,IAAA,EAAM,KAAA;AAAA,EACN,IAAA,CAAK,EAAE,IAAA,EAAM,OAAA,EAAQ,EAAG;AACvB,IAAA,MAAM,MAAA,GAAS,aAAa,aAAa,CAAA;AAEzC,IAAA,IAAI,eAAe,OAAA,EAAS,MAAA,CAAO,KAAK,EAAE,SAAA,EAAW,MAAM,CAAA;AAC3D,IAAA,MAAA,CAAO,KAAK,EAAE,KAAA,EAAO,IAAA,EAAM,GAAG,SAAS,CAAA;AAAA,EACxC;AACD,CAAA","file":"index.js","sourcesContent":["/** GTM's data layer, created if GTM hasn't loaded yet. */\nexport const getDataLayer = (name = \"dataLayer\"): unknown[] =>\n\t((window as unknown as Record<string, unknown[] | undefined>)[name] ??= []);\n","import type { Consent, ConsentMapping, ConsentSink } from \"../flow\";\nimport { getDataLayer } from \"./data-layer\";\n\nexport type GoogleConsentType =\n\t| \"ad_personalization\"\n\t| \"ad_storage\"\n\t| \"ad_user_data\"\n\t| \"analytics_storage\"\n\t| \"functionality_storage\"\n\t| \"personalization_storage\"\n\t| \"security_storage\";\n\nexport type GoogleConsentState = Record<\n\tGoogleConsentType,\n\t\"granted\" | \"denied\"\n>;\n\nexport type GoogleConsentModeOptions = {\n\t/** The GTM data layer's global name. */\n\tdataLayerName?: string;\n\t/** Also maps the unanswered default, so a type granted regardless of the answer is granted from the start. */\n\tmapConsent?: ConsentMapping<GoogleConsentState>;\n\t/** How long Google's tags wait for the answer before firing under the default, in milliseconds. */\n\twaitForUpdate?: number;\n};\n\nconst toGoogleConsent = ({\n\tanalytics,\n\tmarketing,\n\tpreferences,\n}: Consent): GoogleConsentState => {\n\tconst state = (allowed: boolean) => (allowed ? \"granted\" : \"denied\");\n\treturn {\n\t\tad_personalization: state(marketing),\n\t\tad_storage: state(marketing),\n\t\tad_user_data: state(marketing),\n\t\tanalytics_storage: state(analytics),\n\t\tfunctionality_storage: state(preferences),\n\t\tpersonalization_storage: state(preferences),\n\t\tsecurity_storage: \"granted\",\n\t};\n};\n\nconst UNANSWERED: Consent = {\n\tnecessary: true,\n\tpreferences: false,\n\tanalytics: false,\n\tmarketing: false,\n};\n\n// A default after an update would override the answer.\nconst defaulted = new WeakSet<unknown[]>();\n\n/**\n * Forwards consent to Google Consent Mode. The first one created for a data layer denies every\n * category by default, so create it before GTM loads or anything is pushed to the data layer.\n */\nexport const googleConsentMode = ({\n\tdataLayerName = \"dataLayer\",\n\tmapConsent = (_consent, defaults) => defaults,\n\t// Leaves room for consent loaded after GTM, e.g. Shopify's Customer Privacy API on a headless store.\n\twaitForUpdate = 2000,\n}: GoogleConsentModeOptions = {}): ConsentSink => {\n\tconst toConsentMode = (consent: Consent) =>\n\t\tmapConsent(consent, toGoogleConsent(consent));\n\n\tfunction gtag(..._args: unknown[]) {\n\t\t// GTM reads consent commands only as an `arguments` object, not an array.\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\tgetDataLayer(dataLayerName).push(arguments);\n\t}\n\n\tif (\n\t\ttypeof window !== \"undefined\" &&\n\t\t!defaulted.has(getDataLayer(dataLayerName))\n\t) {\n\t\tdefaulted.add(getDataLayer(dataLayerName));\n\t\tgtag(\"consent\", \"default\", {\n\t\t\t...toConsentMode(UNANSWERED),\n\t\t\twait_for_update: waitForUpdate,\n\t\t});\n\t}\n\n\treturn {\n\t\tname: \"google\",\n\t\tapply: (consent) => gtag(\"consent\", \"update\", toConsentMode(consent)),\n\t\tclear: () => gtag(\"consent\", \"update\", toConsentMode(UNANSWERED)),\n\t};\n};\n","import type { Destination } from \"../flow\";\nimport { getDataLayer } from \"./data-layer\";\n\nexport type GtmEvent = { name: string; payload: Record<string, unknown> };\n\nexport type GtmOptions = {\n\t/** The GTM data layer's global name. */\n\tdataLayerName?: string;\n};\n\n/** Pushes to GTM's data layer, e.g. for GA4; Consent Mode in the container gates it. */\nexport const gtm = ({\n\tdataLayerName = \"dataLayer\",\n}: GtmOptions = {}): Destination<GtmEvent> => ({\n\tname: \"gtm\",\n\tsend({ name, payload }) {\n\t\tconst target = getDataLayer(dataLayerName);\n\t\t// GTM merges every push into one data model, so the previous event's `ecommerce` would carry over.\n\t\tif (\"ecommerce\" in payload) target.push({ ecommerce: null });\n\t\ttarget.push({ event: name, ...payload });\n\t},\n});\n"]}
@@ -1,27 +1,22 @@
1
- type PageFacts = {
2
- url: string;
3
- path: string;
4
- title: string;
5
- referrer: string;
6
- language: string;
7
- };
8
1
  type PageListener = {
9
2
  /** The Page is ending; still the current one. */
10
3
  leave?(): void;
11
4
  /** The next Page has started. */
12
5
  enter?(): void;
13
6
  };
14
- type CurrentPage = {
15
- read(): PageFacts;
7
+ /** Follows Pages across client-side navigations; a site that only does full page loads doesn't need it. */
8
+ type ClientNavigation = {
9
+ /** The previous Page's last URL, or `document.referrer` on the first. */
10
+ referrer(): string;
16
11
  /** Starts the next Page if the URL's key changed since the last call; call it after every client-side navigation. */
17
12
  sync(): void;
18
13
  /** Every listener's `leave()` runs before the Page changes, every `enter()` after. */
19
14
  subscribe(listener: PageListener): () => void;
20
15
  };
21
- type CurrentPageOptions = {
16
+ type ClientNavigationOptions = {
22
17
  /** What makes a URL another Page; by default its pathname, so query and hash changes aren't. */
23
18
  key?: (url: URL) => string;
24
19
  };
25
- declare const createCurrentPage: ({ key, }?: CurrentPageOptions) => CurrentPage;
20
+ declare const createClientNavigation: ({ key, }?: ClientNavigationOptions) => ClientNavigation;
26
21
 
27
- export { type CurrentPage, type CurrentPageOptions, type PageFacts, type PageListener, createCurrentPage };
22
+ export { type ClientNavigation, type ClientNavigationOptions, type PageListener, createClientNavigation };
@@ -1,7 +1,7 @@
1
1
  import { IS_DEVELOPMENT } from '../chunk-KLN5K6PR.js';
2
2
 
3
- // src/page/create-current-page.ts
4
- var createCurrentPage = ({
3
+ // src/navigation/create-client-navigation.ts
4
+ var createClientNavigation = ({
5
5
  key = (url) => url.pathname
6
6
  } = {}) => {
7
7
  const listeners = /* @__PURE__ */ new Set();
@@ -22,13 +22,7 @@ var createCurrentPage = ({
22
22
  };
23
23
  if (typeof window !== "undefined") current();
24
24
  return {
25
- read: () => ({
26
- url: location.href,
27
- path: location.pathname,
28
- title: document.title,
29
- referrer: current().referrer,
30
- language: document.documentElement.lang || navigator.language
31
- }),
25
+ referrer: () => current().referrer,
32
26
  sync() {
33
27
  if (typeof window === "undefined") return;
34
28
  const previous = current();
@@ -51,6 +45,6 @@ var createCurrentPage = ({
51
45
  };
52
46
  };
53
47
 
54
- export { createCurrentPage };
48
+ export { createClientNavigation };
55
49
  //# sourceMappingURL=index.js.map
56
50
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/navigation/create-client-navigation.ts"],"names":[],"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A;AAC1B,MAAA,IAAA,GAAO,EAAE,KAAK,IAAA,EAAM,GAAA,EAAK,SAAS,IAAA,EAAM,QAAA,EAAU,SAAS,GAAA,EAAI;AAC/D,MAAA,MAAA,CAAO,SAAS,UAAU,CAAA;AAAA,IAC3B,CAAA;AAAA,IACA,UAAU,QAAA,EAAU;AACnB,MAAA,SAAA,CAAU,IAAI,QAAQ,CAAA;AACtB,MAAA,OAAO,MAAM;AACZ,QAAA,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,MAC1B,CAAA;AAAA,IACD;AAAA,GACD;AACD","file":"index.js","sourcesContent":["import { IS_DEVELOPMENT } from \"../config\";\n\nexport type PageListener = {\n\t/** The Page is ending; still the current one. */\n\tleave?(): void;\n\t/** The next Page has started. */\n\tenter?(): void;\n};\n\n/** Follows Pages across client-side navigations; a site that only does full page loads doesn't need it. */\nexport type ClientNavigation = {\n\t/** The previous Page's last URL, or `document.referrer` on the first. */\n\treferrer(): string;\n\t/** Starts the next Page if the URL's key changed since the last call; call it after every client-side navigation. */\n\tsync(): void;\n\t/** Every listener's `leave()` runs before the Page changes, every `enter()` after. */\n\tsubscribe(listener: PageListener): () => void;\n};\n\nexport type ClientNavigationOptions = {\n\t/** What makes a URL another Page; by default its pathname, so query and hash changes aren't. */\n\tkey?: (url: URL) => string;\n};\n\nexport const createClientNavigation = ({\n\tkey = (url) => url.pathname,\n}: ClientNavigationOptions = {}): ClientNavigation => {\n\tconst listeners = new Set<PageListener>();\n\tconst notify = (step: \"leave\" | \"enter\", subscribed: PageListener[]) => {\n\t\tfor (const listener of subscribed) {\n\t\t\ttry {\n\t\t\t\tlistener[step]?.();\n\t\t\t} catch (error) {\n\t\t\t\tif (IS_DEVELOPMENT) console.error(error);\n\t\t\t}\n\t\t}\n\t};\n\tlet page: { key: string; url: string; referrer: string } | undefined;\n\n\tconst current = () =>\n\t\t(page ??= {\n\t\t\tkey: key(new URL(location.href)),\n\t\t\turl: location.href,\n\t\t\treferrer: document.referrer,\n\t\t});\n\t// The URL it was created on is the first Page, even if the first `sync()` comes after a navigation.\n\tif (typeof window !== \"undefined\") current();\n\n\treturn {\n\t\treferrer: () => current().referrer,\n\t\tsync() {\n\t\t\tif (typeof window === \"undefined\") return;\n\t\t\tconst previous = current();\n\t\t\tconst next = key(new URL(location.href));\n\t\t\tif (next === previous.key) {\n\t\t\t\tprevious.url = location.href;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst subscribed = [...listeners];\n\t\t\tnotify(\"leave\", subscribed);\n\t\t\tpage = { key: next, url: location.href, referrer: previous.url };\n\t\t\tnotify(\"enter\", subscribed);\n\t\t},\n\t\tsubscribe(listener) {\n\t\t\tlisteners.add(listener);\n\t\t\treturn () => {\n\t\t\t\tlisteners.delete(listener);\n\t\t\t};\n\t\t},\n\t};\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { ConsentCategory, ConsentProvider } from '../index.js';
1
+ import { b as ConsentCategory, C as ConsentProvider } from '../consent-types-DgKtGapr.js';
2
2
 
3
3
  type OneTrustOptions = {
4
4
  /** OneTrust category ID per consent category; defaults to OneTrust's standard IDs. */
@@ -1,4 +1,4 @@
1
- // src/consent/onetrust/onetrust.ts
1
+ // src/onetrust/onetrust.ts
2
2
  var DEFAULT_GROUPS = {
3
3
  necessary: "C0001",
4
4
  analytics: "C0002",
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/onetrust/onetrust.ts"],"names":[],"mappings":";AAYA,IAAM,cAAA,GAAkD;AAAA,EACvD,SAAA,EAAW,OAAA;AAAA,EACX,SAAA,EAAW,OAAA;AAAA,EACX,WAAA,EAAa,OAAA;AAAA,EACb,SAAA,EAAW;AACZ,CAAA;AAEO,IAAM,WAAW,CAAC,EAAE,MAAA,EAAO,GAAqB,EAAC,KAAuB;AAC9E,EAAA,MAAM,GAAA,GAAM,EAAE,GAAG,cAAA,EAAgB,GAAG,MAAA,EAAO;AAE3C,EAAA,MAAM,OAAO,MAAsB;AAClC,IAAA,MAAM,EAAE,QAAA,EAAU,oBAAA,EAAqB,GAAI,MAAA;AAC3C,IAAA,IAAI,CAAC,QAAA,EAAU,gBAAA,IAAmB,IAAK,oBAAA,KAAyB,MAAA;AAC/D,MAAA,OAAO,IAAA;AACR,IAAA,MAAM,MAAA,GAAS,IAAI,GAAA,CAAI,oBAAA,CAAqB,MAAM,GAAG,CAAA,CAAE,MAAA,CAAO,OAAO,CAAC,CAAA;AACtE,IAAA,OAAO;AAAA,MACN,SAAA,EAAW,IAAA;AAAA,MACX,WAAA,EAAa,MAAA,CAAO,GAAA,CAAI,GAAA,CAAI,WAAW,CAAA;AAAA,MACvC,SAAA,EAAW,MAAA,CAAO,GAAA,CAAI,GAAA,CAAI,SAAS,CAAA;AAAA,MACnC,SAAA,EAAW,MAAA,CAAO,GAAA,CAAI,GAAA,CAAI,SAAS;AAAA,KACpC;AAAA,EACD,CAAA;AAEA,EAAA,OAAO;AAAA,IACN,IAAA,EAAM,UAAA;AAAA,IACN,GAAA,EAAK,IAAA;AAAA,IACL,UAAU,QAAA,EAAU;AACnB,MAAA,MAAM,QAAA,GAAW,MAAM,QAAA,CAAS,IAAA,EAAM,CAAA;AACtC,MAAA,MAAA,CAAO,gBAAA,CAAiB,yBAAyB,QAAQ,CAAA;AACzD,MAAA,OAAO,MACN,MAAA,CAAO,mBAAA,CAAoB,uBAAA,EAAyB,QAAQ,CAAA;AAAA,IAC9D;AAAA,GACD;AACD","file":"index.js","sourcesContent":["import type { Consent, ConsentCategory, ConsentProvider } from \"../flow\";\n\nexport type OneTrustOptions = {\n\t/** OneTrust category ID per consent category; defaults to OneTrust's standard IDs. */\n\tgroups?: Partial<Record<ConsentCategory, string>>;\n};\n\ntype OneTrustGlobal = {\n\tOnetrustActiveGroups?: string;\n\tOneTrust?: { IsAlertBoxClosed?(): boolean };\n};\n\nconst DEFAULT_GROUPS: Record<ConsentCategory, string> = {\n\tnecessary: \"C0001\",\n\tanalytics: \"C0002\",\n\tpreferences: \"C0003\",\n\tmarketing: \"C0004\",\n};\n\nexport const onetrust = ({ groups }: OneTrustOptions = {}): ConsentProvider => {\n\tconst ids = { ...DEFAULT_GROUPS, ...groups };\n\n\tconst read = (): Consent | null => {\n\t\tconst { OneTrust, OnetrustActiveGroups } = window as OneTrustGlobal;\n\t\tif (!OneTrust?.IsAlertBoxClosed?.() || OnetrustActiveGroups === undefined)\n\t\t\treturn null;\n\t\tconst active = new Set(OnetrustActiveGroups.split(\",\").filter(Boolean));\n\t\treturn {\n\t\t\tnecessary: true,\n\t\t\tpreferences: active.has(ids.preferences),\n\t\t\tanalytics: active.has(ids.analytics),\n\t\t\tmarketing: active.has(ids.marketing),\n\t\t};\n\t};\n\n\treturn {\n\t\tname: \"onetrust\",\n\t\tget: read,\n\t\tsubscribe(listener) {\n\t\t\tconst onChange = () => listener(read());\n\t\t\twindow.addEventListener(\"OneTrustGroupsUpdated\", onChange);\n\t\t\treturn () =>\n\t\t\t\twindow.removeEventListener(\"OneTrustGroupsUpdated\", onChange);\n\t\t},\n\t};\n};\n"]}
@@ -0,0 +1,45 @@
1
+ import { CartAdapter } from '../cart/index.js';
2
+ import { C as ConsentProvider, e as ConsentMapping, c as ConsentSink } from '../consent-types-DgKtGapr.js';
3
+ import '../types-CZEg03xW.js';
4
+ import '../compatibility-wHn2I_ws.js';
5
+ import '../source-types-fJXZeF2Q.js';
6
+
7
+ type ShopifyCartLine = {
8
+ id: string;
9
+ quantity: number;
10
+ merchandise?: {
11
+ id: string;
12
+ };
13
+ };
14
+ /** Storefront API connections and Hydrogen's flattened arrays both fit. */
15
+ type Lines<Line> = readonly Line[] | {
16
+ nodes: readonly Line[];
17
+ } | {
18
+ edges: readonly {
19
+ node: Line;
20
+ }[];
21
+ };
22
+ type ShopifyCart = {
23
+ lines?: Lines<ShopifyCartLine> | null;
24
+ };
25
+ type ShopifyCartLineOf<Cart extends ShopifyCart> = (NonNullable<Cart["lines"]> extends Lines<infer Line> ? Line : never) & ShopifyCartLine;
26
+ /** Reads Storefront API and Hydrogen carts, keying lines by variant. */
27
+ declare const shopifyCart: <Cart extends ShopifyCart = ShopifyCart>() => CartAdapter<Cart, ShopifyCartLineOf<Cart>>;
28
+
29
+ /** Reads consent from Shopify's Customer Privacy API, e.g. its privacy banner. */
30
+ declare const shopifyConsent: () => ConsentProvider;
31
+
32
+ type ShopifyTrackingConsent = {
33
+ analytics: boolean;
34
+ marketing: boolean;
35
+ preferences: boolean;
36
+ sale_of_data: boolean;
37
+ };
38
+ type ShopifyCustomerPrivacyOptions = {
39
+ /** By default `sale_of_data` follows `marketing`. */
40
+ mapConsent?: ConsentMapping<ShopifyTrackingConsent>;
41
+ };
42
+ /** Forwards consent to Shopify's Customer Privacy API. */
43
+ declare const shopifyCustomerPrivacy: ({ mapConsent, }?: ShopifyCustomerPrivacyOptions) => ConsentSink;
44
+
45
+ export { type ShopifyCart, type ShopifyCartLine, type ShopifyCartLineOf, type ShopifyCustomerPrivacyOptions, type ShopifyTrackingConsent, shopifyCart, shopifyConsent, shopifyCustomerPrivacy };