@walkeros/web-core 4.8.1 → 4.8.3-next-1793115089237
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.
- package/CHANGELOG.md +57 -3
- package/README.md +3 -3
- package/dist/dev.d.mts +28 -0
- package/dist/dev.d.ts +28 -0
- package/dist/dev.js +1 -0
- package/dist/dev.js.map +1 -0
- package/dist/dev.mjs +1 -0
- package/dist/dev.mjs.map +1 -0
- package/dist/index.d.mts +137 -2
- package/dist/index.d.ts +137 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,62 @@
|
|
|
1
1
|
# @walkeros/web-core
|
|
2
2
|
|
|
3
|
+
## 4.8.3-next-1793115089237
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 29d2218: The gtag and d8a destinations now set `analytics_storage` from
|
|
8
|
+
`analytics` consent instead of `functional` by default, matching what the
|
|
9
|
+
Cookiebot, CookieFirst and CookiePro sources report. With the Usercentrics
|
|
10
|
+
source, map your measurement category to `analytics` in its `categoryMap`. If
|
|
11
|
+
your consent commands report measurement consent as `functional`, map it
|
|
12
|
+
yourself, like
|
|
13
|
+
`como: { functional: 'analytics_storage', marketing: ['ad_storage', 'ad_user_data', 'ad_personalization'] }`.
|
|
14
|
+
When several consent keys map to one parameter, the parameter is granted only
|
|
15
|
+
if all of them are granted in the current consent state; before, the key that
|
|
16
|
+
came last won.
|
|
17
|
+
- 5313635: The test page `page` from `@walkeros/web-core/dev` now answers each
|
|
18
|
+
vendor script a step inserts with `load`, as a browser does, so a destination
|
|
19
|
+
that waits for its script delivers in the examples runner and the conformance
|
|
20
|
+
kit instead of timing out. `failScripts` still fails those scripts on demand.
|
|
21
|
+
- Updated dependencies [34fd225]
|
|
22
|
+
- Updated dependencies [5313635]
|
|
23
|
+
- Updated dependencies [5313635]
|
|
24
|
+
- Updated dependencies [5313635]
|
|
25
|
+
- Updated dependencies [5313635]
|
|
26
|
+
- Updated dependencies [5313635]
|
|
27
|
+
- Updated dependencies [34fd225]
|
|
28
|
+
- Updated dependencies [5313635]
|
|
29
|
+
- @walkeros/core@4.8.3-next-1793115089237
|
|
30
|
+
|
|
31
|
+
## 4.8.2
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- b1d65e2: `loadVendor` injects the script into the document that `env`
|
|
36
|
+
provides, falling back to the page's own, and fails with `vendor-not-ready`
|
|
37
|
+
when there is no document at all. The new `@walkeros/web-core/dev` entry
|
|
38
|
+
exports `mockScriptDocument()` for examples and tests that run without a
|
|
39
|
+
browser.
|
|
40
|
+
- 964590a: `@walkeros/web-core` exports `moin`, `browserSwapActivator` and
|
|
41
|
+
`pageObserveSlot`, and `@walkeros/web-core/dev` exports `page` for the
|
|
42
|
+
conformance tests of web steps.
|
|
43
|
+
- 2374f54: `sendWeb` now throws a `StepError` instead of resolving
|
|
44
|
+
`{ ok: false }`: `transport` with the status for an error answer or a network
|
|
45
|
+
error, `timeout`, or `beacon-rejected`. A fetch skips `keepalive` past the
|
|
46
|
+
browser's 64 KiB limit. New `loadVendor` loads a vendor script once per page
|
|
47
|
+
and reports `vendor-not-loaded`, `vendor-not-ready` or `vendor-timeout`.
|
|
48
|
+
- Updated dependencies [2374f54]
|
|
49
|
+
- Updated dependencies [7e5fc27]
|
|
50
|
+
- Updated dependencies [2374f54]
|
|
51
|
+
- Updated dependencies [964590a]
|
|
52
|
+
- Updated dependencies [4100ede]
|
|
53
|
+
- Updated dependencies [2374f54]
|
|
54
|
+
- Updated dependencies [2374f54]
|
|
55
|
+
- Updated dependencies [15eb7b2]
|
|
56
|
+
- Updated dependencies [33a2779]
|
|
57
|
+
- Updated dependencies [33a2779]
|
|
58
|
+
- @walkeros/core@4.8.2
|
|
59
|
+
|
|
3
60
|
## 4.8.1
|
|
4
61
|
|
|
5
62
|
### Patch Changes
|
|
@@ -275,9 +332,6 @@
|
|
|
275
332
|
and `event.context` remain required.
|
|
276
333
|
- Each source self-registers via TypeScript module augmentation of `SourceMap`
|
|
277
334
|
in `@walkeros/core`.
|
|
278
|
-
- App-side coordination (`/workspaces/developer/app`) is a follow-up plan, not
|
|
279
|
-
part of this release. Telemetry from v4 CLI/MCP will not validate against
|
|
280
|
-
the existing app schema until that follow-up ships.
|
|
281
335
|
- `Mapping.Rule.skip` is renamed to `Mapping.Rule.silent`. Customer flow.json
|
|
282
336
|
configs using `skip: true` in mapping rules must rename to `silent: true`.
|
|
283
337
|
Hard cut: no legacy alias, the field is gone.
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Browser-specific utilities for client-side walkerOS implementations, covering
|
|
|
10
10
|
DOM interactions, browser information, storage, element visibility, web hashing,
|
|
11
11
|
and web-based communication.
|
|
12
12
|
|
|
13
|
-
[Documentation](https://www.walkeros.io/docs) •
|
|
13
|
+
[Documentation](https://www.walkeros.io/docs/core/web) •
|
|
14
14
|
[NPM Package](https://www.npmjs.com/package/@walkeros/web-core) •
|
|
15
15
|
[Source Code](https://github.com/elbwalker/walkerOS/tree/main/packages/web/core)
|
|
16
16
|
|
|
@@ -28,7 +28,7 @@ import { getAttribute, isVisible, sendWeb } from '@walkeros/web-core';
|
|
|
28
28
|
const element = document.querySelector('[data-elb="product"]');
|
|
29
29
|
const entity = getAttribute(element, 'data-elb');
|
|
30
30
|
|
|
31
|
-
if (isVisible(element)) {
|
|
31
|
+
if (isVisible(element, window, document)) {
|
|
32
32
|
await sendWeb('https://api.example.com/events', { entity });
|
|
33
33
|
}
|
|
34
34
|
```
|
|
@@ -36,7 +36,7 @@ if (isVisible(element)) {
|
|
|
36
36
|
## Documentation
|
|
37
37
|
|
|
38
38
|
Full configuration, mapping, and examples live in the docs:
|
|
39
|
-
**https://www.walkeros.io/docs**
|
|
39
|
+
**https://www.walkeros.io/docs/core/web**
|
|
40
40
|
|
|
41
41
|
## Contribute
|
|
42
42
|
|
package/dist/dev.d.mts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Flow } from '@walkeros/core';
|
|
2
|
+
|
|
3
|
+
/** A script element, as far as `loadVendor` uses one. */
|
|
4
|
+
type MockScript = {
|
|
5
|
+
src: string;
|
|
6
|
+
async: boolean;
|
|
7
|
+
getAttribute(name: string): string | null;
|
|
8
|
+
setAttribute(name: string, value: string): void;
|
|
9
|
+
addEventListener(type: string, listener: () => void): void;
|
|
10
|
+
};
|
|
11
|
+
/** A document, as far as `loadVendor` injects into one. */
|
|
12
|
+
type MockScriptDocument = {
|
|
13
|
+
querySelectorAll(selector: string): MockScript[];
|
|
14
|
+
createElement(tagName: string): MockScript;
|
|
15
|
+
head: {
|
|
16
|
+
appendChild(script: MockScript): void;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A document without a DOM for `loadVendor` to inject into, for an examples
|
|
21
|
+
* env (tests, simulation in Node). It keeps the scripts appended to its head,
|
|
22
|
+
* so each src goes in once, and an appended script loads at once.
|
|
23
|
+
*/
|
|
24
|
+
declare function mockScriptDocument(): MockScriptDocument;
|
|
25
|
+
|
|
26
|
+
declare const page: Flow.StepPage;
|
|
27
|
+
|
|
28
|
+
export { type MockScript, type MockScriptDocument, mockScriptDocument, page };
|
package/dist/dev.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Flow } from '@walkeros/core';
|
|
2
|
+
|
|
3
|
+
/** A script element, as far as `loadVendor` uses one. */
|
|
4
|
+
type MockScript = {
|
|
5
|
+
src: string;
|
|
6
|
+
async: boolean;
|
|
7
|
+
getAttribute(name: string): string | null;
|
|
8
|
+
setAttribute(name: string, value: string): void;
|
|
9
|
+
addEventListener(type: string, listener: () => void): void;
|
|
10
|
+
};
|
|
11
|
+
/** A document, as far as `loadVendor` injects into one. */
|
|
12
|
+
type MockScriptDocument = {
|
|
13
|
+
querySelectorAll(selector: string): MockScript[];
|
|
14
|
+
createElement(tagName: string): MockScript;
|
|
15
|
+
head: {
|
|
16
|
+
appendChild(script: MockScript): void;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A document without a DOM for `loadVendor` to inject into, for an examples
|
|
21
|
+
* env (tests, simulation in Node). It keeps the scripts appended to its head,
|
|
22
|
+
* so each src goes in once, and an appended script loads at once.
|
|
23
|
+
*/
|
|
24
|
+
declare function mockScriptDocument(): MockScriptDocument;
|
|
25
|
+
|
|
26
|
+
declare const page: Flow.StepPage;
|
|
27
|
+
|
|
28
|
+
export { type MockScript, type MockScriptDocument, mockScriptDocument, page };
|
package/dist/dev.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,o={};function a(){const e=[],t=new WeakMap;return{querySelectorAll:()=>[...e],createElement:()=>{const e=new Map,r={src:"",async:!1,getAttribute:t=>{var n;return"src"===t?r.src:null!=(n=e.get(t))?n:null},setAttribute:(t,r)=>{e.set(t,r)},addEventListener:(e,n)=>{var s;"load"===e&&t.set(r,[...null!=(s=t.get(r))?s:[],n])}};return r},head:{appendChild:r=>{var n;e.push(r),(null!=(n=t.get(r))?n:[]).forEach(e=>e())}}}}((e,r)=>{for(var n in r)t(e,n,{get:r[n],enumerable:!0})})(o,{mockScriptDocument:()=>a,page:()=>h}),module.exports=(e=o,((e,o,a,i)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let l of n(o))s.call(e,l)||l===a||t(e,l,{get:()=>o[l],enumerable:!(i=r(o,l))||i.enumerable});return e})(t({},"__esModule",{value:!0}),e));require("@walkeros/core");var i="data-walkeros-vendor";function l(e,t,r){const n=Object.getOwnPropertyDescriptor(e,t);return Object.defineProperty(e,t,{value:r,configurable:!0,writable:!0}),()=>{n?Object.defineProperty(e,t,n):Reflect.deleteProperty(e,t)}}function c(e){return Array.from(e.querySelectorAll("script"))}function u(e){return class{constructor(){this.status=0,this.statusText="",this.response="",this.responseText="",this.readyState=0,this.onload=null,this.onerror=null,this.onreadystatechange=null,this.method="GET",this.url="",this.async=!0}open(e,t,r=!0){this.method=e,this.url=t,this.async=r,this.readyState=1}setRequestHeader(){}addEventListener(e,t){"load"===e&&(this.onload=t),"error"===e&&(this.onerror=t)}send(t){const{answer:r,settle:n}=e(["XMLHttpRequest",this.method,this.url,t]),s=()=>{var e,t,s,o,a;if(n(),this.readyState=4,r.error){if(!this.async)throw new Error("NetworkError");null==(e=this.onerror)||e.call(this)}else this.status=null!=(t=r.status)?t:200,this.statusText=null!=(s=r.statusText)?s:"",this.responseText=function(e){return void 0===e?"":"string"==typeof e?e:JSON.stringify(e)}(r.body),this.response=this.responseText,null==(o=this.onreadystatechange)||o.call(this),null==(a=this.onload)||a.call(this)};this.async?new Promise(e=>setTimeout(e,0)).then(s):s()}}}var h={open(e){if("undefined"==typeof document)throw new Error("the web page needs a document: run it in a jsdom test environment");const t=document,r=new Set(c(t)),n=()=>c(t).filter(e=>!r.has(e)),s=[l(window,"XMLHttpRequest",u(e)),l(navigator,"sendBeacon",(t,r)=>{var n;const{answer:s,settle:o}=e(["sendBeacon",t,r]);return o(),!s.error&&(null!=(n=s.status)?n:200)<400})],o=new WeakSet,a=new MutationObserver(e=>{for(const{addedNodes:t}of e)t.forEach(e=>{e instanceof HTMLScriptElement&&e.hasAttribute(i)&&!o.has(e)&&(o.add(e),e.dispatchEvent(new Event("load")))})});return a.observe(t,{childList:!0,subtree:!0}),{globals:{document:t},scripts:()=>{const e=n(),t=e.filter(e=>e.hasAttribute(i)).length;return{marked:t,unmarked:e.length-t}},failScripts:()=>{t.querySelectorAll(`script[${i}]`).forEach(e=>e.dispatchEvent(new Event("error")))},close:()=>{a.disconnect(),s.splice(0).forEach(e=>e()),n().forEach(e=>e.remove())}}}};//# sourceMappingURL=dev.js.map
|
package/dist/dev.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dev.ts","../src/mockScriptDocument.ts","../src/loadVendor.ts","../src/dev/page.ts"],"sourcesContent":["export { mockScriptDocument } from './mockScriptDocument';\nexport type { MockScript, MockScriptDocument } from './mockScriptDocument';\nexport { page } from './dev/page';\n","/** A script element, as far as `loadVendor` uses one. */\nexport type MockScript = {\n src: string;\n async: boolean;\n getAttribute(name: string): string | null;\n setAttribute(name: string, value: string): void;\n addEventListener(type: string, listener: () => void): void;\n};\n\n/** A document, as far as `loadVendor` injects into one. */\nexport type MockScriptDocument = {\n querySelectorAll(selector: string): MockScript[];\n createElement(tagName: string): MockScript;\n head: { appendChild(script: MockScript): void };\n};\n\n/**\n * A document without a DOM for `loadVendor` to inject into, for an examples\n * env (tests, simulation in Node). It keeps the scripts appended to its head,\n * so each src goes in once, and an appended script loads at once.\n */\nexport function mockScriptDocument(): MockScriptDocument {\n const scripts: MockScript[] = [];\n const loads = new WeakMap<MockScript, Array<() => void>>();\n\n return {\n querySelectorAll: () => [...scripts],\n createElement: () => {\n const attributes = new Map<string, string>();\n const script: MockScript = {\n src: '',\n async: false,\n getAttribute: (name) =>\n name === 'src' ? script.src : (attributes.get(name) ?? null),\n setAttribute: (name, value) => {\n attributes.set(name, value);\n },\n addEventListener: (type, listener) => {\n if (type === 'load')\n loads.set(script, [...(loads.get(script) ?? []), listener]);\n },\n };\n return script;\n },\n head: {\n appendChild: (script) => {\n scripts.push(script);\n (loads.get(script) ?? []).forEach((listener) => listener());\n },\n },\n };\n}\n","import { resolveDestinationTimeout, StepError } from '@walkeros/core';\n\n/** Attribute on every script `loadVendor` injects. */\nexport const VENDOR_SCRIPT_MARKER = 'data-walkeros-vendor';\n\nexport interface LoadVendorOptions {\n /** The destination's timeout; the load deadline is its resolved value. */\n timeout?: number;\n /**\n * Attributes the vendor's tag needs (e.g. `data-domain`), set before the\n * script is inserted. `src` and the marker cannot be overwritten.\n */\n attributes?: Record<string, string>;\n /**\n * The document the script goes into, and whose scripts are the registry:\n * the destination's env one (`getEnv(env).document`). The global document\n * without it.\n */\n document?: Document;\n}\n\nexport interface Vendor<T> {\n /**\n * Resolves with the vendor once its script loaded and `get()` finds it.\n * Rejects `vendor-not-loaded` after the script's `error` (final for the\n * page), `vendor-not-ready` when the vendor is missing, `vendor-timeout`\n * when the script did not load by the deadline. Past the deadline, and\n * without a script, it checks `get()` on each call.\n */\n ready(): Promise<T>;\n /**\n * For vendors that replay their own stub (called synchronously): throws\n * `vendor-not-loaded` once the injected script fired `error`.\n */\n check(): void;\n}\n\ntype Outcome = 'loaded' | 'failed' | 'expired';\n\ninterface Injected {\n state: 'loading' | 'loaded' | 'failed';\n /** The deadline passed before the script loaded or failed. */\n expired: boolean;\n timeout: number;\n waiting: Array<(outcome: Outcome) => void>;\n}\n\n/** The state of each vendor script, kept with its element. */\nconst injected = new WeakMap<Element, Injected>();\n\n/**\n * The page's script for `src`. The page itself is the registry: its one\n * marked script with that src means the src was injected (once per page, a\n * failure is never re-injected), and another document has its own.\n */\nfunction scriptOf(doc: Document, src: string): HTMLScriptElement | undefined {\n const marked = doc.querySelectorAll<HTMLScriptElement>(\n `script[${VENDOR_SCRIPT_MARKER}]`,\n );\n return Array.from(marked).find(\n (script) => script.getAttribute('src') === src,\n );\n}\n\nfunction inject(\n doc: Document,\n src: string,\n timeout: number,\n attributes: Record<string, string>,\n available: () => boolean,\n): Injected {\n const existing = scriptOf(doc, src);\n const known = existing && injected.get(existing);\n if (known) return known;\n\n const entry: Injected = {\n state: 'loading',\n expired: false,\n timeout,\n waiting: [],\n };\n\n // A marked script without state (another bundle's) is adopted, not\n // doubled. Its `load` may have fired already: with the vendor there, it is\n // ready at once; otherwise it is watched like an own script.\n if (existing && available()) {\n entry.state = 'loaded';\n injected.set(existing, entry);\n return entry;\n }\n const script = existing ?? doc.createElement('script');\n\n const settle = (outcome: Outcome) => {\n const waiting = entry.waiting;\n entry.waiting = [];\n waiting.forEach((notify) => notify(outcome));\n };\n\n const timer = setTimeout(() => {\n entry.expired = true;\n settle('expired');\n }, timeout);\n\n injected.set(script, entry);\n script.addEventListener('load', () => {\n clearTimeout(timer);\n entry.state = 'loaded';\n settle('loaded');\n });\n script.addEventListener('error', () => {\n clearTimeout(timer);\n entry.state = 'failed';\n settle('failed');\n });\n\n if (!existing) {\n for (const [name, value] of Object.entries(attributes))\n script.setAttribute(name, value);\n // After the attributes, so they never replace the src or the marker.\n script.src = src;\n script.async = true;\n script.setAttribute(VENDOR_SCRIPT_MARKER, '');\n doc.head.appendChild(script);\n }\n\n return entry;\n}\n\nconst notLoaded = () =>\n new StepError('Vendor script failed to load', { code: 'vendor-not-loaded' });\n\nconst notReady = () =>\n new StepError('Vendor not ready: its global is missing', {\n code: 'vendor-not-ready',\n });\n\nconst timedOut = (timeout: number) =>\n new StepError(`Vendor script did not load within ${timeout}ms`, {\n code: 'vendor-timeout',\n });\n\n/**\n * Injects a vendor script once per `src` on the page (marked\n * `data-walkeros-vendor`, with the `attributes` its tag needs) and reports\n * its readiness. The deadline runs from the injection and equals the\n * destination's resolved timeout, so an awaited `ready()` settles before the\n * push's own timeout. Without `src` (the page loads the vendor) nothing is\n * injected and there is no deadline. A `src` with no document to inject\n * into (neither `options.document` nor a global one) throws\n * `vendor-not-ready`.\n */\nexport function loadVendor<T>(\n src: string | undefined,\n get: () => T | undefined,\n options: LoadVendorOptions = {},\n): Vendor<T> {\n const available = () => {\n const vendor = get();\n return vendor !== undefined && vendor !== null;\n };\n\n let script: Injected | undefined;\n if (src) {\n const doc =\n options.document ??\n (typeof document !== 'undefined' ? document : undefined);\n if (!doc)\n throw new StepError(`Vendor script ${src} has no document to go into`, {\n code: 'vendor-not-ready',\n });\n script = inject(\n doc,\n src,\n resolveDestinationTimeout(options.timeout),\n options.attributes ?? {},\n available,\n );\n }\n\n const present = (): Promise<T> => {\n const vendor = get();\n return vendor === undefined || vendor === null\n ? Promise.reject(notReady())\n : Promise.resolve(vendor);\n };\n\n return {\n ready() {\n if (!script) return present();\n if (script.state === 'failed') return Promise.reject(notLoaded());\n if (script.state === 'loaded' || script.expired) return present();\n\n return new Promise<T>((resolve, reject) => {\n script.waiting.push((outcome) => {\n if (outcome === 'failed') reject(notLoaded());\n else if (outcome === 'expired') reject(timedOut(script.timeout));\n else present().then(resolve, reject);\n });\n });\n },\n check() {\n if (script?.state === 'failed') throw notLoaded();\n },\n };\n}\n","import type { Flow } from '@walkeros/core';\nimport { VENDOR_SCRIPT_MARKER } from '../loadVendor';\n\n/**\n * The page a web step runs on in the conformance kit and the examples runner\n * of `@walkeros/collector/dev`. While a run is open, `navigator.sendBeacon`\n * and `XMLHttpRequest` answer through the kit's boundary (`sendWeb` runs on\n * them), and the scripts the run adds are tracked: a marked vendor script\n * loads unless `failScripts` fails it. Closing the run restores both and\n * removes those scripts, so the next run starts on the page it found (the\n * page is loadVendor's once-per-src registry).\n */\n\nconst macrotask = () => new Promise<void>((resolve) => setTimeout(resolve, 0));\n\nfunction bodyText(body: unknown): string {\n if (body === undefined) return '';\n return typeof body === 'string' ? body : JSON.stringify(body);\n}\n\n/**\n * Replace one property for a run; returns its restore. A property that did\n * not exist is deleted again.\n */\nfunction replace(target: object, key: string, value: unknown): () => void {\n const original = Object.getOwnPropertyDescriptor(target, key);\n Object.defineProperty(target, key, {\n value,\n configurable: true,\n writable: true,\n });\n return () => {\n if (original) Object.defineProperty(target, key, original);\n else Reflect.deleteProperty(target, key);\n };\n}\n\nfunction scriptsOf(doc: Document): HTMLScriptElement[] {\n return Array.from(doc.querySelectorAll('script'));\n}\n\n/**\n * `XMLHttpRequest` at the boundary: synchronous by default, as sendWeb opens\n * it; the async form answers late.\n */\nfunction kitXMLHttpRequest(record: Flow.StepRecord) {\n return class KitXMLHttpRequest {\n status = 0;\n statusText = '';\n response: unknown = '';\n responseText = '';\n readyState = 0;\n onload: (() => void) | null = null;\n onerror: (() => void) | null = null;\n onreadystatechange: (() => void) | null = null;\n private method = 'GET';\n private url = '';\n private async = true;\n\n open(method: string, url: string, async = true) {\n this.method = method;\n this.url = url;\n this.async = async;\n this.readyState = 1;\n }\n setRequestHeader() {}\n addEventListener(type: string, listener: () => void) {\n if (type === 'load') this.onload = listener;\n if (type === 'error') this.onerror = listener;\n }\n send(body?: unknown) {\n const { answer, settle } = record([\n 'XMLHttpRequest',\n this.method,\n this.url,\n body,\n ]);\n const done = () => {\n settle();\n this.readyState = 4;\n if (answer.error) {\n if (!this.async) throw new Error('NetworkError');\n this.onerror?.();\n return;\n }\n this.status = answer.status ?? 200;\n this.statusText = answer.statusText ?? '';\n this.responseText = bodyText(answer.body);\n this.response = this.responseText;\n this.onreadystatechange?.();\n this.onload?.();\n };\n if (this.async) macrotask().then(done);\n else done();\n }\n };\n}\n\nexport const page: Flow.StepPage = {\n open(record) {\n if (typeof document === 'undefined')\n throw new Error(\n 'the web page needs a document: run it in a jsdom test environment',\n );\n const doc = document;\n const before = new Set(scriptsOf(doc));\n const added = () => scriptsOf(doc).filter((script) => !before.has(script));\n\n const beacon = (url: string, data?: unknown): boolean => {\n const { answer, settle } = record(['sendBeacon', url, data]);\n settle();\n return !answer.error && (answer.status ?? 200) < 400;\n };\n const restores = [\n replace(window, 'XMLHttpRequest', kitXMLHttpRequest(record)),\n replace(navigator, 'sendBeacon', beacon),\n ];\n\n // A vendor script a run adds loads, as in a browser: once, right after\n // it is inserted (loadVendor listens before it inserts). jsdom fetches\n // no script, so without this answer every awaited script times out.\n const loaded = new WeakSet<Node>();\n const observer = new MutationObserver((mutations) => {\n for (const { addedNodes } of mutations)\n addedNodes.forEach((node) => {\n if (\n !(node instanceof HTMLScriptElement) ||\n !node.hasAttribute(VENDOR_SCRIPT_MARKER) ||\n loaded.has(node)\n )\n return;\n loaded.add(node);\n node.dispatchEvent(new Event('load'));\n });\n });\n observer.observe(doc, { childList: true, subtree: true });\n\n return {\n globals: { document: doc },\n scripts: () => {\n const scripts = added();\n const marked = scripts.filter((script) =>\n script.hasAttribute(VENDOR_SCRIPT_MARKER),\n ).length;\n return { marked, unmarked: scripts.length - marked };\n },\n failScripts: () => {\n doc\n .querySelectorAll(`script[${VENDOR_SCRIPT_MARKER}]`)\n .forEach((script) => script.dispatchEvent(new Event('error')));\n },\n close: () => {\n observer.disconnect();\n restores.splice(0).forEach((restore) => restore());\n added().forEach((script) => script.remove());\n },\n };\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACqBO,SAAS,qBAAyC;AACvD,QAAM,UAAwB,CAAC;AAC/B,QAAM,QAAQ,oBAAI,QAAuC;AAEzD,SAAO;AAAA,IACL,kBAAkB,MAAM,CAAC,GAAG,OAAO;AAAA,IACnC,eAAe,MAAM;AACnB,YAAM,aAAa,oBAAI,IAAoB;AAC3C,YAAM,SAAqB;AAAA,QACzB,KAAK;AAAA,QACL,OAAO;AAAA,QACP,cAAc,CAAC,SAAM;AAhC7B;AAiCU,0BAAS,QAAQ,OAAO,OAAO,gBAAW,IAAI,IAAI,MAAnB,YAAwB;AAAA;AAAA,QACzD,cAAc,CAAC,MAAM,UAAU;AAC7B,qBAAW,IAAI,MAAM,KAAK;AAAA,QAC5B;AAAA,QACA,kBAAkB,CAAC,MAAM,aAAa;AArC9C;AAsCU,cAAI,SAAS;AACX,kBAAM,IAAI,QAAQ,CAAC,IAAI,WAAM,IAAI,MAAM,MAAhB,YAAqB,CAAC,GAAI,QAAQ,CAAC;AAAA,QAC9D;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,IACA,MAAM;AAAA,MACJ,aAAa,CAAC,WAAW;AA7C/B;AA8CQ,gBAAQ,KAAK,MAAM;AACnB,UAAC,WAAM,IAAI,MAAM,MAAhB,YAAqB,CAAC,GAAG,QAAQ,CAAC,aAAa,SAAS,CAAC;AAAA,MAC5D;AAAA,IACF;AAAA,EACF;AACF;;;ACnDA,kBAAqD;AAG9C,IAAM,uBAAuB;;;ACUpC,IAAM,YAAY,MAAM,IAAI,QAAc,CAAC,YAAY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,iBAAO,IAAI,IAAI;AACf,eAAK,cAAc,IAAI,MAAM,MAAM,CAAC;AAAA,QACtC,CAAC;AAAA,IACL,CAAC;AACD,aAAS,QAAQ,KAAK,EAAE,WAAW,MAAM,SAAS,KAAK,CAAC;AAExD,WAAO;AAAA,MACL,SAAS,EAAE,UAAU,IAAI;AAAA,MACzB,SAAS,MAAM;AACb,cAAM,UAAU,MAAM;AACtB,cAAM,SAAS,QAAQ;AAAA,UAAO,CAAC,WAC7B,OAAO,aAAa,oBAAoB;AAAA,QAC1C,EAAE;AACF,eAAO,EAAE,QAAQ,UAAU,QAAQ,SAAS,OAAO;AAAA,MACrD;AAAA,MACA,aAAa,MAAM;AACjB,YACG,iBAAiB,UAAU,oBAAoB,GAAG,EAClD,QAAQ,CAAC,WAAW,OAAO,cAAc,IAAI,MAAM,OAAO,CAAC,CAAC;AAAA,MACjE;AAAA,MACA,OAAO,MAAM;AACX,iBAAS,WAAW;AACpB,iBAAS,OAAO,CAAC,EAAE,QAAQ,CAAC,YAAY,QAAQ,CAAC;AACjD,cAAM,EAAE,QAAQ,CAAC,WAAW,OAAO,OAAO,CAAC;AAAA,MAC7C;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/dev.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(){const e=[],t=new WeakMap;return{querySelectorAll:()=>[...e],createElement:()=>{const e=new Map,r={src:"",async:!1,getAttribute:t=>{var s;return"src"===t?r.src:null!=(s=e.get(t))?s:null},setAttribute:(t,r)=>{e.set(t,r)},addEventListener:(e,s)=>{var n;"load"===e&&t.set(r,[...null!=(n=t.get(r))?n:[],s])}};return r},head:{appendChild:r=>{var s;e.push(r),(null!=(s=t.get(r))?s:[]).forEach(e=>e())}}}}import{resolveDestinationTimeout as t,StepError as r}from"@walkeros/core";var s="data-walkeros-vendor";function n(e,t,r){const s=Object.getOwnPropertyDescriptor(e,t);return Object.defineProperty(e,t,{value:r,configurable:!0,writable:!0}),()=>{s?Object.defineProperty(e,t,s):Reflect.deleteProperty(e,t)}}function o(e){return Array.from(e.querySelectorAll("script"))}function a(e){return class{constructor(){this.status=0,this.statusText="",this.response="",this.responseText="",this.readyState=0,this.onload=null,this.onerror=null,this.onreadystatechange=null,this.method="GET",this.url="",this.async=!0}open(e,t,r=!0){this.method=e,this.url=t,this.async=r,this.readyState=1}setRequestHeader(){}addEventListener(e,t){"load"===e&&(this.onload=t),"error"===e&&(this.onerror=t)}send(t){const{answer:r,settle:s}=e(["XMLHttpRequest",this.method,this.url,t]),n=()=>{var e,t,n,o,a;if(s(),this.readyState=4,r.error){if(!this.async)throw new Error("NetworkError");null==(e=this.onerror)||e.call(this)}else this.status=null!=(t=r.status)?t:200,this.statusText=null!=(n=r.statusText)?n:"",this.responseText=function(e){return void 0===e?"":"string"==typeof e?e:JSON.stringify(e)}(r.body),this.response=this.responseText,null==(o=this.onreadystatechange)||o.call(this),null==(a=this.onload)||a.call(this)};this.async?new Promise(e=>setTimeout(e,0)).then(n):n()}}}var i={open(e){if("undefined"==typeof document)throw new Error("the web page needs a document: run it in a jsdom test environment");const t=document,r=new Set(o(t)),i=()=>o(t).filter(e=>!r.has(e)),l=[n(window,"XMLHttpRequest",a(e)),n(navigator,"sendBeacon",(t,r)=>{var s;const{answer:n,settle:o}=e(["sendBeacon",t,r]);return o(),!n.error&&(null!=(s=n.status)?s:200)<400})],c=new WeakSet,u=new MutationObserver(e=>{for(const{addedNodes:t}of e)t.forEach(e=>{e instanceof HTMLScriptElement&&e.hasAttribute(s)&&!c.has(e)&&(c.add(e),e.dispatchEvent(new Event("load")))})});return u.observe(t,{childList:!0,subtree:!0}),{globals:{document:t},scripts:()=>{const e=i(),t=e.filter(e=>e.hasAttribute(s)).length;return{marked:t,unmarked:e.length-t}},failScripts:()=>{t.querySelectorAll(`script[${s}]`).forEach(e=>e.dispatchEvent(new Event("error")))},close:()=>{u.disconnect(),l.splice(0).forEach(e=>e()),i().forEach(e=>e.remove())}}}};export{e as mockScriptDocument,i as page};//# sourceMappingURL=dev.mjs.map
|
package/dist/dev.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mockScriptDocument.ts","../src/loadVendor.ts","../src/dev/page.ts"],"sourcesContent":["/** A script element, as far as `loadVendor` uses one. */\nexport type MockScript = {\n src: string;\n async: boolean;\n getAttribute(name: string): string | null;\n setAttribute(name: string, value: string): void;\n addEventListener(type: string, listener: () => void): void;\n};\n\n/** A document, as far as `loadVendor` injects into one. */\nexport type MockScriptDocument = {\n querySelectorAll(selector: string): MockScript[];\n createElement(tagName: string): MockScript;\n head: { appendChild(script: MockScript): void };\n};\n\n/**\n * A document without a DOM for `loadVendor` to inject into, for an examples\n * env (tests, simulation in Node). It keeps the scripts appended to its head,\n * so each src goes in once, and an appended script loads at once.\n */\nexport function mockScriptDocument(): MockScriptDocument {\n const scripts: MockScript[] = [];\n const loads = new WeakMap<MockScript, Array<() => void>>();\n\n return {\n querySelectorAll: () => [...scripts],\n createElement: () => {\n const attributes = new Map<string, string>();\n const script: MockScript = {\n src: '',\n async: false,\n getAttribute: (name) =>\n name === 'src' ? script.src : (attributes.get(name) ?? null),\n setAttribute: (name, value) => {\n attributes.set(name, value);\n },\n addEventListener: (type, listener) => {\n if (type === 'load')\n loads.set(script, [...(loads.get(script) ?? []), listener]);\n },\n };\n return script;\n },\n head: {\n appendChild: (script) => {\n scripts.push(script);\n (loads.get(script) ?? []).forEach((listener) => listener());\n },\n },\n };\n}\n","import { resolveDestinationTimeout, StepError } from '@walkeros/core';\n\n/** Attribute on every script `loadVendor` injects. */\nexport const VENDOR_SCRIPT_MARKER = 'data-walkeros-vendor';\n\nexport interface LoadVendorOptions {\n /** The destination's timeout; the load deadline is its resolved value. */\n timeout?: number;\n /**\n * Attributes the vendor's tag needs (e.g. `data-domain`), set before the\n * script is inserted. `src` and the marker cannot be overwritten.\n */\n attributes?: Record<string, string>;\n /**\n * The document the script goes into, and whose scripts are the registry:\n * the destination's env one (`getEnv(env).document`). The global document\n * without it.\n */\n document?: Document;\n}\n\nexport interface Vendor<T> {\n /**\n * Resolves with the vendor once its script loaded and `get()` finds it.\n * Rejects `vendor-not-loaded` after the script's `error` (final for the\n * page), `vendor-not-ready` when the vendor is missing, `vendor-timeout`\n * when the script did not load by the deadline. Past the deadline, and\n * without a script, it checks `get()` on each call.\n */\n ready(): Promise<T>;\n /**\n * For vendors that replay their own stub (called synchronously): throws\n * `vendor-not-loaded` once the injected script fired `error`.\n */\n check(): void;\n}\n\ntype Outcome = 'loaded' | 'failed' | 'expired';\n\ninterface Injected {\n state: 'loading' | 'loaded' | 'failed';\n /** The deadline passed before the script loaded or failed. */\n expired: boolean;\n timeout: number;\n waiting: Array<(outcome: Outcome) => void>;\n}\n\n/** The state of each vendor script, kept with its element. */\nconst injected = new WeakMap<Element, Injected>();\n\n/**\n * The page's script for `src`. The page itself is the registry: its one\n * marked script with that src means the src was injected (once per page, a\n * failure is never re-injected), and another document has its own.\n */\nfunction scriptOf(doc: Document, src: string): HTMLScriptElement | undefined {\n const marked = doc.querySelectorAll<HTMLScriptElement>(\n `script[${VENDOR_SCRIPT_MARKER}]`,\n );\n return Array.from(marked).find(\n (script) => script.getAttribute('src') === src,\n );\n}\n\nfunction inject(\n doc: Document,\n src: string,\n timeout: number,\n attributes: Record<string, string>,\n available: () => boolean,\n): Injected {\n const existing = scriptOf(doc, src);\n const known = existing && injected.get(existing);\n if (known) return known;\n\n const entry: Injected = {\n state: 'loading',\n expired: false,\n timeout,\n waiting: [],\n };\n\n // A marked script without state (another bundle's) is adopted, not\n // doubled. Its `load` may have fired already: with the vendor there, it is\n // ready at once; otherwise it is watched like an own script.\n if (existing && available()) {\n entry.state = 'loaded';\n injected.set(existing, entry);\n return entry;\n }\n const script = existing ?? doc.createElement('script');\n\n const settle = (outcome: Outcome) => {\n const waiting = entry.waiting;\n entry.waiting = [];\n waiting.forEach((notify) => notify(outcome));\n };\n\n const timer = setTimeout(() => {\n entry.expired = true;\n settle('expired');\n }, timeout);\n\n injected.set(script, entry);\n script.addEventListener('load', () => {\n clearTimeout(timer);\n entry.state = 'loaded';\n settle('loaded');\n });\n script.addEventListener('error', () => {\n clearTimeout(timer);\n entry.state = 'failed';\n settle('failed');\n });\n\n if (!existing) {\n for (const [name, value] of Object.entries(attributes))\n script.setAttribute(name, value);\n // After the attributes, so they never replace the src or the marker.\n script.src = src;\n script.async = true;\n script.setAttribute(VENDOR_SCRIPT_MARKER, '');\n doc.head.appendChild(script);\n }\n\n return entry;\n}\n\nconst notLoaded = () =>\n new StepError('Vendor script failed to load', { code: 'vendor-not-loaded' });\n\nconst notReady = () =>\n new StepError('Vendor not ready: its global is missing', {\n code: 'vendor-not-ready',\n });\n\nconst timedOut = (timeout: number) =>\n new StepError(`Vendor script did not load within ${timeout}ms`, {\n code: 'vendor-timeout',\n });\n\n/**\n * Injects a vendor script once per `src` on the page (marked\n * `data-walkeros-vendor`, with the `attributes` its tag needs) and reports\n * its readiness. The deadline runs from the injection and equals the\n * destination's resolved timeout, so an awaited `ready()` settles before the\n * push's own timeout. Without `src` (the page loads the vendor) nothing is\n * injected and there is no deadline. A `src` with no document to inject\n * into (neither `options.document` nor a global one) throws\n * `vendor-not-ready`.\n */\nexport function loadVendor<T>(\n src: string | undefined,\n get: () => T | undefined,\n options: LoadVendorOptions = {},\n): Vendor<T> {\n const available = () => {\n const vendor = get();\n return vendor !== undefined && vendor !== null;\n };\n\n let script: Injected | undefined;\n if (src) {\n const doc =\n options.document ??\n (typeof document !== 'undefined' ? document : undefined);\n if (!doc)\n throw new StepError(`Vendor script ${src} has no document to go into`, {\n code: 'vendor-not-ready',\n });\n script = inject(\n doc,\n src,\n resolveDestinationTimeout(options.timeout),\n options.attributes ?? {},\n available,\n );\n }\n\n const present = (): Promise<T> => {\n const vendor = get();\n return vendor === undefined || vendor === null\n ? Promise.reject(notReady())\n : Promise.resolve(vendor);\n };\n\n return {\n ready() {\n if (!script) return present();\n if (script.state === 'failed') return Promise.reject(notLoaded());\n if (script.state === 'loaded' || script.expired) return present();\n\n return new Promise<T>((resolve, reject) => {\n script.waiting.push((outcome) => {\n if (outcome === 'failed') reject(notLoaded());\n else if (outcome === 'expired') reject(timedOut(script.timeout));\n else present().then(resolve, reject);\n });\n });\n },\n check() {\n if (script?.state === 'failed') throw notLoaded();\n },\n };\n}\n","import type { Flow } from '@walkeros/core';\nimport { VENDOR_SCRIPT_MARKER } from '../loadVendor';\n\n/**\n * The page a web step runs on in the conformance kit and the examples runner\n * of `@walkeros/collector/dev`. While a run is open, `navigator.sendBeacon`\n * and `XMLHttpRequest` answer through the kit's boundary (`sendWeb` runs on\n * them), and the scripts the run adds are tracked: a marked vendor script\n * loads unless `failScripts` fails it. Closing the run restores both and\n * removes those scripts, so the next run starts on the page it found (the\n * page is loadVendor's once-per-src registry).\n */\n\nconst macrotask = () => new Promise<void>((resolve) => setTimeout(resolve, 0));\n\nfunction bodyText(body: unknown): string {\n if (body === undefined) return '';\n return typeof body === 'string' ? body : JSON.stringify(body);\n}\n\n/**\n * Replace one property for a run; returns its restore. A property that did\n * not exist is deleted again.\n */\nfunction replace(target: object, key: string, value: unknown): () => void {\n const original = Object.getOwnPropertyDescriptor(target, key);\n Object.defineProperty(target, key, {\n value,\n configurable: true,\n writable: true,\n });\n return () => {\n if (original) Object.defineProperty(target, key, original);\n else Reflect.deleteProperty(target, key);\n };\n}\n\nfunction scriptsOf(doc: Document): HTMLScriptElement[] {\n return Array.from(doc.querySelectorAll('script'));\n}\n\n/**\n * `XMLHttpRequest` at the boundary: synchronous by default, as sendWeb opens\n * it; the async form answers late.\n */\nfunction kitXMLHttpRequest(record: Flow.StepRecord) {\n return class KitXMLHttpRequest {\n status = 0;\n statusText = '';\n response: unknown = '';\n responseText = '';\n readyState = 0;\n onload: (() => void) | null = null;\n onerror: (() => void) | null = null;\n onreadystatechange: (() => void) | null = null;\n private method = 'GET';\n private url = '';\n private async = true;\n\n open(method: string, url: string, async = true) {\n this.method = method;\n this.url = url;\n this.async = async;\n this.readyState = 1;\n }\n setRequestHeader() {}\n addEventListener(type: string, listener: () => void) {\n if (type === 'load') this.onload = listener;\n if (type === 'error') this.onerror = listener;\n }\n send(body?: unknown) {\n const { answer, settle } = record([\n 'XMLHttpRequest',\n this.method,\n this.url,\n body,\n ]);\n const done = () => {\n settle();\n this.readyState = 4;\n if (answer.error) {\n if (!this.async) throw new Error('NetworkError');\n this.onerror?.();\n return;\n }\n this.status = answer.status ?? 200;\n this.statusText = answer.statusText ?? '';\n this.responseText = bodyText(answer.body);\n this.response = this.responseText;\n this.onreadystatechange?.();\n this.onload?.();\n };\n if (this.async) macrotask().then(done);\n else done();\n }\n };\n}\n\nexport const page: Flow.StepPage = {\n open(record) {\n if (typeof document === 'undefined')\n throw new Error(\n 'the web page needs a document: run it in a jsdom test environment',\n );\n const doc = document;\n const before = new Set(scriptsOf(doc));\n const added = () => scriptsOf(doc).filter((script) => !before.has(script));\n\n const beacon = (url: string, data?: unknown): boolean => {\n const { answer, settle } = record(['sendBeacon', url, data]);\n settle();\n return !answer.error && (answer.status ?? 200) < 400;\n };\n const restores = [\n replace(window, 'XMLHttpRequest', kitXMLHttpRequest(record)),\n replace(navigator, 'sendBeacon', beacon),\n ];\n\n // A vendor script a run adds loads, as in a browser: once, right after\n // it is inserted (loadVendor listens before it inserts). jsdom fetches\n // no script, so without this answer every awaited script times out.\n const loaded = new WeakSet<Node>();\n const observer = new MutationObserver((mutations) => {\n for (const { addedNodes } of mutations)\n addedNodes.forEach((node) => {\n if (\n !(node instanceof HTMLScriptElement) ||\n !node.hasAttribute(VENDOR_SCRIPT_MARKER) ||\n loaded.has(node)\n )\n return;\n loaded.add(node);\n node.dispatchEvent(new Event('load'));\n });\n });\n observer.observe(doc, { childList: true, subtree: true });\n\n return {\n globals: { document: doc },\n scripts: () => {\n const scripts = added();\n const marked = scripts.filter((script) =>\n script.hasAttribute(VENDOR_SCRIPT_MARKER),\n ).length;\n return { marked, unmarked: scripts.length - marked };\n },\n failScripts: () => {\n doc\n .querySelectorAll(`script[${VENDOR_SCRIPT_MARKER}]`)\n .forEach((script) => script.dispatchEvent(new Event('error')));\n },\n close: () => {\n observer.disconnect();\n restores.splice(0).forEach((restore) => restore());\n added().forEach((script) => script.remove());\n },\n };\n },\n};\n"],"mappings":";AAqBO,SAAS,qBAAyC;AACvD,QAAM,UAAwB,CAAC;AAC/B,QAAM,QAAQ,oBAAI,QAAuC;AAEzD,SAAO;AAAA,IACL,kBAAkB,MAAM,CAAC,GAAG,OAAO;AAAA,IACnC,eAAe,MAAM;AACnB,YAAM,aAAa,oBAAI,IAAoB;AAC3C,YAAM,SAAqB;AAAA,QACzB,KAAK;AAAA,QACL,OAAO;AAAA,QACP,cAAc,CAAC,SAAM;AAhC7B;AAiCU,0BAAS,QAAQ,OAAO,OAAO,gBAAW,IAAI,IAAI,MAAnB,YAAwB;AAAA;AAAA,QACzD,cAAc,CAAC,MAAM,UAAU;AAC7B,qBAAW,IAAI,MAAM,KAAK;AAAA,QAC5B;AAAA,QACA,kBAAkB,CAAC,MAAM,aAAa;AArC9C;AAsCU,cAAI,SAAS;AACX,kBAAM,IAAI,QAAQ,CAAC,IAAI,WAAM,IAAI,MAAM,MAAhB,YAAqB,CAAC,GAAI,QAAQ,CAAC;AAAA,QAC9D;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,IACA,MAAM;AAAA,MACJ,aAAa,CAAC,WAAW;AA7C/B;AA8CQ,gBAAQ,KAAK,MAAM;AACnB,UAAC,WAAM,IAAI,MAAM,MAAhB,YAAqB,CAAC,GAAG,QAAQ,CAAC,aAAa,SAAS,CAAC;AAAA,MAC5D;AAAA,IACF;AAAA,EACF;AACF;;;ACnDA,SAAS,2BAA2B,iBAAiB;AAG9C,IAAM,uBAAuB;;;ACUpC,IAAM,YAAY,MAAM,IAAI,QAAc,CAAC,YAAY,WAAW,SAAS,CAAC,CAAC;AAE7E,SAAS,SAAS,MAAuB;AACvC,MAAI,SAAS,OAAW,QAA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AAAA,IACL,CAAC;AACD,aAAS,QAAQ,KAAK,EAAE,WAAW,MAAM,SAAS,KAAK,CAAC;AAExD,WAAO;AAAA,MACL,SAAS,EAAE,UAAU,IAAI;AAAA,MACzB,SAAS,MAAM;AACb,cAAM,UAAU,MAAM;AACtB,cAAM,SAAS,QAAQ;AAAA,UAAO,CAAC,WAC7B,OAAO,aAAa,oBAAoB;AAAA,QAC1C,EAAE;AACF,eAAO,EAAE,QAAQ,UAAU,QAAQ,SAAS,OAAO;AAAA,MACrD;AAAA,MACA,aAAa,MAAM;AACjB,YACG,iBAAiB,UAAU,oBAAoB,GAAG,EAClD,QAAQ,CAAC,WAAW,OAAO,cAAc,IAAI,MAAM,OAAO,CAAC,CAAC;AAAA,MACjE;AAAA,MACA,OAAO,MAAM;AACX,iBAAS,WAAW;AACpB,iBAAS,OAAO,CAAC,EAAE,QAAQ,CAAC,YAAY,QAAQ,CAAC;AACjD,cAAM,EAAE,QAAQ,CAAC,WAAW,OAAO,OAAO,CAAC;AAAA,MAC7C;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Elb, Destination as Destination$1, SendHeaders, SendResponse, SendDataValue, StorageType,
|
|
1
|
+
import { WalkerOS, Elb, Destination as Destination$1, MoinTarget, ObserveSlot, PreviewKey, PreviewCrypto, SendHeaders, SendResponse, SendDataValue, StorageType, Source as Source$1, Collector as Collector$1, Hooks, On } from '@walkeros/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Get attribute value from element
|
|
@@ -37,6 +37,32 @@ declare function getLanguage(navigatorRef: Navigator): string | undefined;
|
|
|
37
37
|
declare function getTimezone(): string | undefined;
|
|
38
38
|
declare function getScreenSize(windowRef: Window): string;
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* walkerOS consent groups mapped to consent mode parameters, as Google
|
|
42
|
+
* Consent Mode and the tools compatible with it (d8a) name them.
|
|
43
|
+
*/
|
|
44
|
+
interface ConsentMapping {
|
|
45
|
+
[walkerOSConsentGroup: string]: string | string[];
|
|
46
|
+
}
|
|
47
|
+
type ConsentModeValue = 'granted' | 'denied';
|
|
48
|
+
/**
|
|
49
|
+
* Default mapping: measurement storage follows `analytics`, the ad
|
|
50
|
+
* parameters follow `marketing`.
|
|
51
|
+
*/
|
|
52
|
+
declare const DEFAULT_CONSENT_MODE_MAPPING: ConsentMapping;
|
|
53
|
+
/** Every parameter a mapping names, once, in mapping order. */
|
|
54
|
+
declare function consentModeParameters(mapping: ConsentMapping): string[];
|
|
55
|
+
/**
|
|
56
|
+
* Resolve consent mode parameters from walkerOS consent.
|
|
57
|
+
*
|
|
58
|
+
* A parameter is granted only when every group that maps to it is granted in
|
|
59
|
+
* `state`, the whole consent state; a group missing from it counts as denied.
|
|
60
|
+
* With `changed`, the result holds only the parameters of those groups, as a
|
|
61
|
+
* consent update carries only what a consent command changed. Groups the
|
|
62
|
+
* mapping does not name resolve nothing.
|
|
63
|
+
*/
|
|
64
|
+
declare function resolveConsentMode(mapping: ConsentMapping, state: WalkerOS.Consent, changed?: WalkerOS.Consent): Record<string, ConsentModeValue>;
|
|
65
|
+
|
|
40
66
|
declare const elb$1: Elb.Fn<void>;
|
|
41
67
|
|
|
42
68
|
type TypesGeneric$1 = Destination$1.TypesGeneric;
|
|
@@ -161,6 +187,107 @@ declare function shadowHostsAbove(node: Element, win: Window): Element[];
|
|
|
161
187
|
*/
|
|
162
188
|
declare function isVisible(element: HTMLElement, win: Window, doc: Document): boolean;
|
|
163
189
|
|
|
190
|
+
/** Attribute on every script `loadVendor` injects. */
|
|
191
|
+
declare const VENDOR_SCRIPT_MARKER = "data-walkeros-vendor";
|
|
192
|
+
interface LoadVendorOptions {
|
|
193
|
+
/** The destination's timeout; the load deadline is its resolved value. */
|
|
194
|
+
timeout?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Attributes the vendor's tag needs (e.g. `data-domain`), set before the
|
|
197
|
+
* script is inserted. `src` and the marker cannot be overwritten.
|
|
198
|
+
*/
|
|
199
|
+
attributes?: Record<string, string>;
|
|
200
|
+
/**
|
|
201
|
+
* The document the script goes into, and whose scripts are the registry:
|
|
202
|
+
* the destination's env one (`getEnv(env).document`). The global document
|
|
203
|
+
* without it.
|
|
204
|
+
*/
|
|
205
|
+
document?: Document;
|
|
206
|
+
}
|
|
207
|
+
interface Vendor<T> {
|
|
208
|
+
/**
|
|
209
|
+
* Resolves with the vendor once its script loaded and `get()` finds it.
|
|
210
|
+
* Rejects `vendor-not-loaded` after the script's `error` (final for the
|
|
211
|
+
* page), `vendor-not-ready` when the vendor is missing, `vendor-timeout`
|
|
212
|
+
* when the script did not load by the deadline. Past the deadline, and
|
|
213
|
+
* without a script, it checks `get()` on each call.
|
|
214
|
+
*/
|
|
215
|
+
ready(): Promise<T>;
|
|
216
|
+
/**
|
|
217
|
+
* For vendors that replay their own stub (called synchronously): throws
|
|
218
|
+
* `vendor-not-loaded` once the injected script fired `error`.
|
|
219
|
+
*/
|
|
220
|
+
check(): void;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Injects a vendor script once per `src` on the page (marked
|
|
224
|
+
* `data-walkeros-vendor`, with the `attributes` its tag needs) and reports
|
|
225
|
+
* its readiness. The deadline runs from the injection and equals the
|
|
226
|
+
* destination's resolved timeout, so an awaited `ready()` settles before the
|
|
227
|
+
* push's own timeout. Without `src` (the page loads the vendor) nothing is
|
|
228
|
+
* injected and there is no deadline. A `src` with no document to inject
|
|
229
|
+
* into (neither `options.document` nor a global one) throws
|
|
230
|
+
* `vendor-not-ready`.
|
|
231
|
+
*/
|
|
232
|
+
declare function loadVendor<T>(src: string | undefined, get: () => T | undefined, options?: LoadVendorOptions): Vendor<T>;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* The Tag Mode loader. Armed only by `?elbMoin` or the tab flag it leaves in
|
|
236
|
+
* sessionStorage, and only in the top frame; it then waits for one message
|
|
237
|
+
* from `target.app` naming a script by its hash, and loads that script from
|
|
238
|
+
* `target.base` with the same hash as its integrity. Not armed, it adds no
|
|
239
|
+
* listener, makes no request and writes nothing.
|
|
240
|
+
*/
|
|
241
|
+
declare function moin(target?: MoinTarget): void;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The page's Observe credential slot, for a web `observe` config:
|
|
245
|
+
* `startFlow({ observe: { url, binding, slot: pageObserveSlot() } })`.
|
|
246
|
+
*
|
|
247
|
+
* The credential arrives out-of-band as the `elbObserve` URL param, or in
|
|
248
|
+
* the `localStorage` slot the preview activator ferries it into. A URL
|
|
249
|
+
* credential wins over a stored one. Once kept, a URL-borne copy is
|
|
250
|
+
* stripped from the address bar: it is a bearer credential and must not
|
|
251
|
+
* linger there. Every page access is guarded, so no method throws.
|
|
252
|
+
*/
|
|
253
|
+
declare function pageObserveSlot(): ObserveSlot;
|
|
254
|
+
|
|
255
|
+
interface SwapActivatorConfig {
|
|
256
|
+
keyring: PreviewKey[];
|
|
257
|
+
iss: string;
|
|
258
|
+
/** This bundle's project binding. Absent on demo hosts (see acceptForeign). */
|
|
259
|
+
pb?: string;
|
|
260
|
+
acceptForeign?: boolean;
|
|
261
|
+
demoAllowlist?: string[];
|
|
262
|
+
/** Bare CDN hostname, e.g. 'cdn.walkeros.io'. */
|
|
263
|
+
previewOrigin: string;
|
|
264
|
+
/** Injectable for tests. */
|
|
265
|
+
now?: () => number;
|
|
266
|
+
crypto?: PreviewCrypto;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Storage slot for the session-forwarding companion grant. The web arm never
|
|
270
|
+
* verifies it (it is session-bound by design; the session container is its
|
|
271
|
+
* verifier): the activator only ferries it from the activation URL into
|
|
272
|
+
* storage, where the seamed preview artifact reads it to stamp the
|
|
273
|
+
* `X-Walkeros-Preview` header. It lives and dies with the activation state:
|
|
274
|
+
* set (or cleared) whenever a URL activation succeeds, cleared whenever the
|
|
275
|
+
* stored activation clears.
|
|
276
|
+
*/
|
|
277
|
+
declare const SESSION_STORAGE_KEY = "elbPreviewSession";
|
|
278
|
+
/**
|
|
279
|
+
* Decide whether a preview bundle should boot in place of this bundle's own flow.
|
|
280
|
+
*
|
|
281
|
+
* Returns true iff a preview took over, in which case the caller must not boot
|
|
282
|
+
* the production flow. Every failure path deterministically returns false: the
|
|
283
|
+
* loader never throws, never retries, and never leaves a page without a walker.
|
|
284
|
+
*
|
|
285
|
+
* Anti-griefing invariant: a rejected URL grant never touches stored state,
|
|
286
|
+
* the activator falls back to the stored grant instead. Only a failing stored
|
|
287
|
+
* grant clears storage (self-heal), plus `off` and `swap-failed`.
|
|
288
|
+
*/
|
|
289
|
+
declare function browserSwapActivator(cfg: SwapActivatorConfig): Promise<boolean>;
|
|
290
|
+
|
|
164
291
|
type SendWebTransport = 'fetch' | 'beacon' | 'xhr';
|
|
165
292
|
interface SendWebOptions {
|
|
166
293
|
headers?: SendHeaders;
|
|
@@ -174,6 +301,14 @@ interface SendWebOptionsFetch extends SendWebOptions {
|
|
|
174
301
|
}
|
|
175
302
|
type SendWebOptionsDynamic<T extends SendWebTransport> = T extends 'fetch' ? SendWebOptionsFetch : SendWebOptions;
|
|
176
303
|
type SendWebReturn<T extends SendWebTransport> = T extends 'fetch' ? Promise<SendResponse> : SendResponse;
|
|
304
|
+
/**
|
|
305
|
+
* Send a request with `fetch` (default), `navigator.sendBeacon` or a
|
|
306
|
+
* synchronous XHR. Resolves (fetch) or returns (beacon, xhr) `{ data }` when
|
|
307
|
+
* the request was sent, and throws a `StepError` otherwise: `transport` with
|
|
308
|
+
* `status` and `body` for a non-2xx answer or a network error, `timeout` for
|
|
309
|
+
* a fetch past its timeout, `beacon-rejected` when the browser refuses a
|
|
310
|
+
* beacon. The body stays on the error, never in its message.
|
|
311
|
+
*/
|
|
177
312
|
declare function sendWeb<T extends SendWebTransport>(url: string, data?: SendDataValue, options?: SendWebOptionsDynamic<T> & {
|
|
178
313
|
transport?: T;
|
|
179
314
|
}): SendWebReturn<T>;
|
|
@@ -329,4 +464,4 @@ declare namespace collector {
|
|
|
329
464
|
export type { collector_Collector as Collector, collector_Config as Config, collector_Destinations as Destinations, collector_InitConfig as InitConfig, collector_Scope as Scope, collector_State as State };
|
|
330
465
|
}
|
|
331
466
|
|
|
332
|
-
export { destination as DestinationWeb, elb as Elb, type SendWebOptions, type SendWebOptionsFetch, type SendWebReturn, type SendWebTransport, source as SourceWeb, type StorageEnv, type StorageValue, walker as Walker, collector as WebCollector, composedAncestors, deepElementFromPoint, elb$1 as elb, getAttribute, getEnv, getHashWeb, getLanguage, getScreenSize, getTimezone, isVisible, parseInlineConfig, sendWeb, sendWebAsBeacon, sendWebAsFetch, sendWebAsXhr, shadowHostsAbove, splitAttribute, splitKeyVal, storageDelete, storageRead, storageWrite };
|
|
467
|
+
export { type ConsentMapping, type ConsentModeValue, DEFAULT_CONSENT_MODE_MAPPING, destination as DestinationWeb, elb as Elb, type LoadVendorOptions, SESSION_STORAGE_KEY, type SendWebOptions, type SendWebOptionsFetch, type SendWebReturn, type SendWebTransport, source as SourceWeb, type StorageEnv, type StorageValue, type SwapActivatorConfig, VENDOR_SCRIPT_MARKER, type Vendor, walker as Walker, collector as WebCollector, browserSwapActivator, composedAncestors, consentModeParameters, deepElementFromPoint, elb$1 as elb, getAttribute, getEnv, getHashWeb, getLanguage, getScreenSize, getTimezone, isVisible, loadVendor, moin, pageObserveSlot, parseInlineConfig, resolveConsentMode, sendWeb, sendWebAsBeacon, sendWebAsFetch, sendWebAsXhr, shadowHostsAbove, splitAttribute, splitKeyVal, storageDelete, storageRead, storageWrite };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Elb, Destination as Destination$1, SendHeaders, SendResponse, SendDataValue, StorageType,
|
|
1
|
+
import { WalkerOS, Elb, Destination as Destination$1, MoinTarget, ObserveSlot, PreviewKey, PreviewCrypto, SendHeaders, SendResponse, SendDataValue, StorageType, Source as Source$1, Collector as Collector$1, Hooks, On } from '@walkeros/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Get attribute value from element
|
|
@@ -37,6 +37,32 @@ declare function getLanguage(navigatorRef: Navigator): string | undefined;
|
|
|
37
37
|
declare function getTimezone(): string | undefined;
|
|
38
38
|
declare function getScreenSize(windowRef: Window): string;
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* walkerOS consent groups mapped to consent mode parameters, as Google
|
|
42
|
+
* Consent Mode and the tools compatible with it (d8a) name them.
|
|
43
|
+
*/
|
|
44
|
+
interface ConsentMapping {
|
|
45
|
+
[walkerOSConsentGroup: string]: string | string[];
|
|
46
|
+
}
|
|
47
|
+
type ConsentModeValue = 'granted' | 'denied';
|
|
48
|
+
/**
|
|
49
|
+
* Default mapping: measurement storage follows `analytics`, the ad
|
|
50
|
+
* parameters follow `marketing`.
|
|
51
|
+
*/
|
|
52
|
+
declare const DEFAULT_CONSENT_MODE_MAPPING: ConsentMapping;
|
|
53
|
+
/** Every parameter a mapping names, once, in mapping order. */
|
|
54
|
+
declare function consentModeParameters(mapping: ConsentMapping): string[];
|
|
55
|
+
/**
|
|
56
|
+
* Resolve consent mode parameters from walkerOS consent.
|
|
57
|
+
*
|
|
58
|
+
* A parameter is granted only when every group that maps to it is granted in
|
|
59
|
+
* `state`, the whole consent state; a group missing from it counts as denied.
|
|
60
|
+
* With `changed`, the result holds only the parameters of those groups, as a
|
|
61
|
+
* consent update carries only what a consent command changed. Groups the
|
|
62
|
+
* mapping does not name resolve nothing.
|
|
63
|
+
*/
|
|
64
|
+
declare function resolveConsentMode(mapping: ConsentMapping, state: WalkerOS.Consent, changed?: WalkerOS.Consent): Record<string, ConsentModeValue>;
|
|
65
|
+
|
|
40
66
|
declare const elb$1: Elb.Fn<void>;
|
|
41
67
|
|
|
42
68
|
type TypesGeneric$1 = Destination$1.TypesGeneric;
|
|
@@ -161,6 +187,107 @@ declare function shadowHostsAbove(node: Element, win: Window): Element[];
|
|
|
161
187
|
*/
|
|
162
188
|
declare function isVisible(element: HTMLElement, win: Window, doc: Document): boolean;
|
|
163
189
|
|
|
190
|
+
/** Attribute on every script `loadVendor` injects. */
|
|
191
|
+
declare const VENDOR_SCRIPT_MARKER = "data-walkeros-vendor";
|
|
192
|
+
interface LoadVendorOptions {
|
|
193
|
+
/** The destination's timeout; the load deadline is its resolved value. */
|
|
194
|
+
timeout?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Attributes the vendor's tag needs (e.g. `data-domain`), set before the
|
|
197
|
+
* script is inserted. `src` and the marker cannot be overwritten.
|
|
198
|
+
*/
|
|
199
|
+
attributes?: Record<string, string>;
|
|
200
|
+
/**
|
|
201
|
+
* The document the script goes into, and whose scripts are the registry:
|
|
202
|
+
* the destination's env one (`getEnv(env).document`). The global document
|
|
203
|
+
* without it.
|
|
204
|
+
*/
|
|
205
|
+
document?: Document;
|
|
206
|
+
}
|
|
207
|
+
interface Vendor<T> {
|
|
208
|
+
/**
|
|
209
|
+
* Resolves with the vendor once its script loaded and `get()` finds it.
|
|
210
|
+
* Rejects `vendor-not-loaded` after the script's `error` (final for the
|
|
211
|
+
* page), `vendor-not-ready` when the vendor is missing, `vendor-timeout`
|
|
212
|
+
* when the script did not load by the deadline. Past the deadline, and
|
|
213
|
+
* without a script, it checks `get()` on each call.
|
|
214
|
+
*/
|
|
215
|
+
ready(): Promise<T>;
|
|
216
|
+
/**
|
|
217
|
+
* For vendors that replay their own stub (called synchronously): throws
|
|
218
|
+
* `vendor-not-loaded` once the injected script fired `error`.
|
|
219
|
+
*/
|
|
220
|
+
check(): void;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Injects a vendor script once per `src` on the page (marked
|
|
224
|
+
* `data-walkeros-vendor`, with the `attributes` its tag needs) and reports
|
|
225
|
+
* its readiness. The deadline runs from the injection and equals the
|
|
226
|
+
* destination's resolved timeout, so an awaited `ready()` settles before the
|
|
227
|
+
* push's own timeout. Without `src` (the page loads the vendor) nothing is
|
|
228
|
+
* injected and there is no deadline. A `src` with no document to inject
|
|
229
|
+
* into (neither `options.document` nor a global one) throws
|
|
230
|
+
* `vendor-not-ready`.
|
|
231
|
+
*/
|
|
232
|
+
declare function loadVendor<T>(src: string | undefined, get: () => T | undefined, options?: LoadVendorOptions): Vendor<T>;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* The Tag Mode loader. Armed only by `?elbMoin` or the tab flag it leaves in
|
|
236
|
+
* sessionStorage, and only in the top frame; it then waits for one message
|
|
237
|
+
* from `target.app` naming a script by its hash, and loads that script from
|
|
238
|
+
* `target.base` with the same hash as its integrity. Not armed, it adds no
|
|
239
|
+
* listener, makes no request and writes nothing.
|
|
240
|
+
*/
|
|
241
|
+
declare function moin(target?: MoinTarget): void;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The page's Observe credential slot, for a web `observe` config:
|
|
245
|
+
* `startFlow({ observe: { url, binding, slot: pageObserveSlot() } })`.
|
|
246
|
+
*
|
|
247
|
+
* The credential arrives out-of-band as the `elbObserve` URL param, or in
|
|
248
|
+
* the `localStorage` slot the preview activator ferries it into. A URL
|
|
249
|
+
* credential wins over a stored one. Once kept, a URL-borne copy is
|
|
250
|
+
* stripped from the address bar: it is a bearer credential and must not
|
|
251
|
+
* linger there. Every page access is guarded, so no method throws.
|
|
252
|
+
*/
|
|
253
|
+
declare function pageObserveSlot(): ObserveSlot;
|
|
254
|
+
|
|
255
|
+
interface SwapActivatorConfig {
|
|
256
|
+
keyring: PreviewKey[];
|
|
257
|
+
iss: string;
|
|
258
|
+
/** This bundle's project binding. Absent on demo hosts (see acceptForeign). */
|
|
259
|
+
pb?: string;
|
|
260
|
+
acceptForeign?: boolean;
|
|
261
|
+
demoAllowlist?: string[];
|
|
262
|
+
/** Bare CDN hostname, e.g. 'cdn.walkeros.io'. */
|
|
263
|
+
previewOrigin: string;
|
|
264
|
+
/** Injectable for tests. */
|
|
265
|
+
now?: () => number;
|
|
266
|
+
crypto?: PreviewCrypto;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Storage slot for the session-forwarding companion grant. The web arm never
|
|
270
|
+
* verifies it (it is session-bound by design; the session container is its
|
|
271
|
+
* verifier): the activator only ferries it from the activation URL into
|
|
272
|
+
* storage, where the seamed preview artifact reads it to stamp the
|
|
273
|
+
* `X-Walkeros-Preview` header. It lives and dies with the activation state:
|
|
274
|
+
* set (or cleared) whenever a URL activation succeeds, cleared whenever the
|
|
275
|
+
* stored activation clears.
|
|
276
|
+
*/
|
|
277
|
+
declare const SESSION_STORAGE_KEY = "elbPreviewSession";
|
|
278
|
+
/**
|
|
279
|
+
* Decide whether a preview bundle should boot in place of this bundle's own flow.
|
|
280
|
+
*
|
|
281
|
+
* Returns true iff a preview took over, in which case the caller must not boot
|
|
282
|
+
* the production flow. Every failure path deterministically returns false: the
|
|
283
|
+
* loader never throws, never retries, and never leaves a page without a walker.
|
|
284
|
+
*
|
|
285
|
+
* Anti-griefing invariant: a rejected URL grant never touches stored state,
|
|
286
|
+
* the activator falls back to the stored grant instead. Only a failing stored
|
|
287
|
+
* grant clears storage (self-heal), plus `off` and `swap-failed`.
|
|
288
|
+
*/
|
|
289
|
+
declare function browserSwapActivator(cfg: SwapActivatorConfig): Promise<boolean>;
|
|
290
|
+
|
|
164
291
|
type SendWebTransport = 'fetch' | 'beacon' | 'xhr';
|
|
165
292
|
interface SendWebOptions {
|
|
166
293
|
headers?: SendHeaders;
|
|
@@ -174,6 +301,14 @@ interface SendWebOptionsFetch extends SendWebOptions {
|
|
|
174
301
|
}
|
|
175
302
|
type SendWebOptionsDynamic<T extends SendWebTransport> = T extends 'fetch' ? SendWebOptionsFetch : SendWebOptions;
|
|
176
303
|
type SendWebReturn<T extends SendWebTransport> = T extends 'fetch' ? Promise<SendResponse> : SendResponse;
|
|
304
|
+
/**
|
|
305
|
+
* Send a request with `fetch` (default), `navigator.sendBeacon` or a
|
|
306
|
+
* synchronous XHR. Resolves (fetch) or returns (beacon, xhr) `{ data }` when
|
|
307
|
+
* the request was sent, and throws a `StepError` otherwise: `transport` with
|
|
308
|
+
* `status` and `body` for a non-2xx answer or a network error, `timeout` for
|
|
309
|
+
* a fetch past its timeout, `beacon-rejected` when the browser refuses a
|
|
310
|
+
* beacon. The body stays on the error, never in its message.
|
|
311
|
+
*/
|
|
177
312
|
declare function sendWeb<T extends SendWebTransport>(url: string, data?: SendDataValue, options?: SendWebOptionsDynamic<T> & {
|
|
178
313
|
transport?: T;
|
|
179
314
|
}): SendWebReturn<T>;
|
|
@@ -329,4 +464,4 @@ declare namespace collector {
|
|
|
329
464
|
export type { collector_Collector as Collector, collector_Config as Config, collector_Destinations as Destinations, collector_InitConfig as InitConfig, collector_Scope as Scope, collector_State as State };
|
|
330
465
|
}
|
|
331
466
|
|
|
332
|
-
export { destination as DestinationWeb, elb as Elb, type SendWebOptions, type SendWebOptionsFetch, type SendWebReturn, type SendWebTransport, source as SourceWeb, type StorageEnv, type StorageValue, walker as Walker, collector as WebCollector, composedAncestors, deepElementFromPoint, elb$1 as elb, getAttribute, getEnv, getHashWeb, getLanguage, getScreenSize, getTimezone, isVisible, parseInlineConfig, sendWeb, sendWebAsBeacon, sendWebAsFetch, sendWebAsXhr, shadowHostsAbove, splitAttribute, splitKeyVal, storageDelete, storageRead, storageWrite };
|
|
467
|
+
export { type ConsentMapping, type ConsentModeValue, DEFAULT_CONSENT_MODE_MAPPING, destination as DestinationWeb, elb as Elb, type LoadVendorOptions, SESSION_STORAGE_KEY, type SendWebOptions, type SendWebOptionsFetch, type SendWebReturn, type SendWebTransport, source as SourceWeb, type StorageEnv, type StorageValue, type SwapActivatorConfig, VENDOR_SCRIPT_MARKER, type Vendor, walker as Walker, collector as WebCollector, browserSwapActivator, composedAncestors, consentModeParameters, deepElementFromPoint, elb$1 as elb, getAttribute, getEnv, getHashWeb, getLanguage, getScreenSize, getTimezone, isVisible, loadVendor, moin, pageObserveSlot, parseInlineConfig, resolveConsentMode, sendWeb, sendWebAsBeacon, sendWebAsFetch, sendWebAsXhr, shadowHostsAbove, splitAttribute, splitKeyVal, storageDelete, storageRead, storageWrite };
|