@getpinax/widget 1.0.0-beta.1 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,3 +4,6 @@ export declare function setEditorBase(_scriptSrc: string): void;
4
4
  export declare function loadEditor(): Promise<EditorModule>;
5
5
  /** AI-15: the session recorder, loaded only on sampled Pro and Agency visits. */
6
6
  export declare function loadRecorder(): Promise<RecorderModule>;
7
+ /** W-20: axe-core, loaded only when a visitor sends an accessibility report. */
8
+ export type ScannerModule = typeof import('./a11y/scan');
9
+ export declare function loadScanner(): Promise<ScannerModule>;
@@ -1,5 +1,6 @@
1
- import type { EditorModule, RecorderModule } from './editor-loader';
1
+ import type { EditorModule, RecorderModule, ScannerModule } from './editor-loader';
2
2
  /** Called by embed.ts with the script tag's own src. */
3
3
  export declare function setEditorBase(scriptSrc: string): void;
4
4
  export declare function loadEditor(): Promise<EditorModule>;
5
5
  export declare function loadRecorder(): Promise<RecorderModule>;
6
+ export declare function loadScanner(): Promise<ScannerModule>;
@@ -9,6 +9,9 @@ import type { FixCheck } from './types';
9
9
  * and failed requests (from the existing capture) and, if the same
10
10
  * signature shows up, says so once with `POST /fix-check`. Nothing else is
11
11
  * ever sent: no "all clear", no page views, no log contents.
12
+ *
13
+ * AI-20 / P-17 reuses this watcher for open reports (path `*`): each sampled
14
+ * page view where the same error shows up sends `POST /sighting` once.
12
15
  */
13
16
  export type FixCheckOptions = {
14
17
  checks: FixCheck[];
@@ -20,6 +23,12 @@ export type FixCheckOptions = {
20
23
  path?: () => string;
21
24
  random?: () => number;
22
25
  now?: () => number;
26
+ /**
27
+ * When the first page view's errors count from. Default: the page load,
28
+ * so errors from before the config arrived are found. A watcher started
29
+ * again after consent was withdrawn passes now, so nothing is sent twice.
30
+ */
31
+ since?: number;
23
32
  };
24
33
  /** The signature of a single entry, as if it were the report's only one. */
25
34
  export declare function consoleSignature(entry: ConsoleEntry): string | null;
@@ -29,3 +38,5 @@ export declare function watchFixChecks(options: FixCheckOptions): {
29
38
  navigated: () => void;
30
39
  stop: () => void;
31
40
  };
41
+ /** `/book` and `/book/` are the same page (known issues use this too). */
42
+ export declare function samePage(a: string, b: string): boolean;
package/dist/index.d.ts CHANGED
@@ -3,12 +3,19 @@ import { type ConsoleEntry } from './capture/console';
3
3
  import { type NetworkEntry } from './capture/network';
4
4
  import { RingBuffer } from './capture/ring';
5
5
  import type { Recorder } from './replay/recorder';
6
- import type { PinaxOptions, PinaxUser, WidgetConfig } from './types';
6
+ import { type ReportConsent } from './report';
7
+ import type { PinaxBasket, PinaxConsent, PinaxOptions, PinaxUser, WidgetConfig } from './types';
7
8
  import { WidgetUI } from './ui/widget';
8
- export type { PinaxOptions, PinaxUser } from './types';
9
+ export type { PinaxBasket, PinaxConsent, PinaxOptions, PinaxUser, } from './types';
10
+ type Watcher = {
11
+ navigated: () => void;
12
+ stop: () => void;
13
+ };
9
14
  type State = {
10
15
  options: PinaxOptions;
11
16
  api: string;
17
+ /** P-15: where settings (and, with consent, the page-view count) go. */
18
+ cdn: string | null;
12
19
  root: ShadowRoot;
13
20
  user?: PinaxUser;
14
21
  config?: WidgetConfig;
@@ -19,6 +26,23 @@ type State = {
19
26
  breadcrumbs: RingBuffer<Breadcrumb>;
20
27
  /** AI-15: only on sampled Pro and Agency visits, once loaded. */
21
28
  recorder?: Recorder;
29
+ /** AI-15: the recorder chunk is on its way. */
30
+ replayStarting: boolean;
31
+ /** AI-15: drawn once per page view, whenever consent comes. */
32
+ replaySampled: boolean;
33
+ /** Visitor consent so far (`consent()`); used only where the site waits. */
34
+ consent: ReportConsent;
35
+ /** The button is up: enabled site, allowed domain (W-18, S-15). */
36
+ running: boolean;
37
+ /** AI-17 fix checks and AI-20 sightings, while they run. */
38
+ watchers: {
39
+ fixChecks?: Watcher;
40
+ sightings?: Watcher;
41
+ };
42
+ /** When consent was last withdrawn: watchers started again count from here. */
43
+ watchersSince?: number;
44
+ /** B-16: this page load was counted after consent. */
45
+ counted: boolean;
22
46
  /** C-10: stops console or network capture when the site has it off. */
23
47
  stopCapture: {
24
48
  console?: () => void;
@@ -38,8 +62,23 @@ type State = {
38
62
  export declare function init(options: PinaxOptions): void;
39
63
  /** Opens the feedback panel from the site's own link or button (S-05). */
40
64
  export declare function open(): void;
65
+ /**
66
+ * Visitor consent from the site's cookie banner: `consent(true)` or
67
+ * `consent(false)` for everything, or `consent({ diagnostics, replay })`
68
+ * for only the parts given. Can be called before init(), any number of
69
+ * times; withdrawing stops what it covers straight away. Only matters where
70
+ * the page waits for consent (the site's setting or `data-consent="wait"`).
71
+ */
72
+ export declare function consent(choice: PinaxConsent): void;
41
73
  /** Attaches the signed-in visitor to future reports (C-09). Can be called before init(). */
42
74
  export declare function identify(user: PinaxUser | null): void;
75
+ /**
76
+ * AI-21: the visitor's basket total, e.g. `setBasket({ value: 42.5, currency:
77
+ * 'GBP' })`, or `null` once it's empty. Can be called before init(). Pinax
78
+ * only sends it alongside a sampled sighting of a known error (P-17).
79
+ */
80
+ export declare function setBasket(next: PinaxBasket | null): void;
81
+ export declare function cleanBasket(b: unknown): PinaxBasket | undefined;
43
82
  /** Removes the widget and stops all capture. Mainly for tests and SPA teardown. */
44
83
  export declare function destroy(): void;
45
84
  /** @internal */
@@ -0,0 +1,27 @@
1
+ import type { ConsoleEntry } from './capture/console';
2
+ import type { NetworkEntry } from './capture/network';
3
+ import type { RingBuffer } from './capture/ring';
4
+ import type { KnownIssue } from './types';
5
+ /** The card lists at most this many. */
6
+ export declare const MAX_KNOWN_SHOWN = 3;
7
+ /**
8
+ * Known issues: which of the site's public reports this visitor may be
9
+ * looking at. One matches when one of its `paths` is this page (`/a` and
10
+ * `/a/` are the same; `*` means nothing special here), or when its error
11
+ * signature showed up in this page view's console errors or failed requests.
12
+ * Every page view is watched (no sampling) and nothing is ever sent: the
13
+ * result is only used to show the card when the panel opens.
14
+ */
15
+ export declare function watchKnown(options: {
16
+ known: KnownIssue[];
17
+ console: RingBuffer<ConsoleEntry>;
18
+ network: RingBuffer<NetworkEntry>;
19
+ path?: () => string;
20
+ now?: () => number;
21
+ }): {
22
+ matches: () => KnownIssue[];
23
+ navigated: () => void;
24
+ stop: () => void;
25
+ };
26
+ /** The issues for this page, in the config's order (newest first), at most 3. */
27
+ export declare function matchKnown(known: KnownIssue[], path: string, seen?: ReadonlySet<string>): KnownIssue[];