@kk-forge/artel-collector 0.4.0 → 0.5.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.
@@ -1,37 +1,37 @@
1
- import type { Browser } from './browser.js';
2
- import type { Clock } from './clock.js';
3
- import type { EventParams, Platform } from './envelope.js';
4
- import type { Lock } from './lock.js';
5
- import type { ProductFields } from './stateFields.js';
6
- import type { StorageAdapter } from './storage.js';
7
- import type { Transport } from './transport.js';
1
+ import type { Browser } from "./browser.js";
2
+ import type { Clock } from "./clock.js";
3
+ import type { EventParams, Platform } from "./envelope.js";
4
+ import type { Lock } from "./lock.js";
5
+ import type { ProductFields } from "./stateFields.js";
6
+ import type { StorageAdapter } from "./storage.js";
7
+ import type { Transport } from "./transport.js";
8
8
  /**
9
9
  * What a channel may collect at most, as set in the intake's admin. The collector's mode matches its channel's. Each
10
10
  * mode takes the states up to its own: a pseudonymous channel adds the install id, and an identified one the account
11
11
  * id.
12
12
  */
13
13
  export declare const Mode: {
14
- readonly Anonymous: 'anonymous';
15
- readonly Pseudonymous: 'pseudonymous';
16
- readonly Identified: 'identified';
14
+ readonly Anonymous: "anonymous";
15
+ readonly Pseudonymous: "pseudonymous";
16
+ readonly Identified: "identified";
17
17
  };
18
18
  export type Mode = (typeof Mode)[keyof typeof Mode];
19
19
  /** The user's analytics state, which the collector stores and which decides what it sends. Users start anonymous. */
20
20
  export declare const AnalyticsState: {
21
21
  /** Sends nothing. Switching to it sends one `opted_out`, with no id or browser, and drops what was not sent. */
22
- readonly OptedOut: 'opted_out';
22
+ readonly OptedOut: "opted_out";
23
23
  /** Sends events with no id or browser, the primary languages only and coarse ages. Needs no consent. */
24
- readonly Anonymous: 'anonymous';
24
+ readonly Anonymous: "anonymous";
25
25
  /**
26
26
  * Sends a random install id the collector makes and stores, the browser, the full languages and exact ages. Needs
27
27
  * consent. A pseudonymous or identified channel takes it.
28
28
  */
29
- readonly Pseudonymous: 'pseudonymous';
29
+ readonly Pseudonymous: "pseudonymous";
30
30
  /**
31
31
  * Sends what the pseudonymous state sends, with the id from `getId` in place of the install id. Needs consent. Only
32
32
  * an identified channel takes it.
33
33
  */
34
- readonly Identified: 'identified';
34
+ readonly Identified: "identified";
35
35
  };
36
36
  export type AnalyticsState = (typeof AnalyticsState)[keyof typeof AnalyticsState];
37
37
  /** The states a collector of channel mode `M` takes: those up to its mode. */
@@ -145,11 +145,11 @@ export interface PageFields {
145
145
  }
146
146
  /** Bucket for the number of days with at least one event. */
147
147
  export declare const ActiveDaysBucket: {
148
- readonly None: '0';
149
- readonly One: '1';
150
- readonly TwoToFive: '2-5';
151
- readonly SixToTwenty: '6-20';
152
- readonly TwentyOneOrMore: '21+';
148
+ readonly None: "0";
149
+ readonly One: "1";
150
+ readonly TwoToFive: "2-5";
151
+ readonly SixToTwenty: "6-20";
152
+ readonly TwentyOneOrMore: "21+";
153
153
  };
154
154
  export type ActiveDaysBucket = (typeof ActiveDaysBucket)[keyof typeof ActiveDaysBucket];
155
155
  /** What an uninstall page gets in its query string, shaped by the state as an envelope is. */
@@ -159,15 +159,24 @@ export interface UninstallParams extends ProductFields {
159
159
  /** The bucket of the number of local days with an event. */
160
160
  active_days: ActiveDaysBucket;
161
161
  }
162
+ export interface TrackOptions {
163
+ /**
164
+ * Drops this call while a call of the same name with `throttleMs` went less than this many milliseconds before, as
165
+ * for a held key that repeats. The first call of a series goes. A call without `throttleMs` opens no window. The
166
+ * collector keeps the time in memory, so each collector keeps its own.
167
+ */
168
+ throttleMs?: number | undefined;
169
+ }
162
170
  /** Every method resolves and never rejects. A failure goes only to `onError`. */
163
171
  export interface Collector<M extends Mode = Mode> {
164
172
  /**
165
173
  * Queues the event for the current state. Refuses and reports an event the intake would drop for its form or a system
166
174
  * event's params, and `installed`, `updated` and `opted_out`, which only the collector's own methods send. The intake
167
175
  * drops an event whose string param looks like an address, and the product's allowlist, which the collector does not
168
- * know, decides the rest. `onError` hears of neither drop.
176
+ * know, decides the rest. `onError` hears of neither drop, nor of a call that `throttleMs` drops. A `throttleMs` that
177
+ * is no finite number from 0 refuses the event and reports it to `onError`.
169
178
  */
170
- track(name: string, params?: EventParams): Promise<void>;
179
+ track(name: string, params?: EventParams, options?: TrackOptions): Promise<void>;
171
180
  /** Sends `installed` once per install. In the opted_out state it sends nothing and marks nothing. */
172
181
  installed(): Promise<void>;
173
182
  /**
@@ -4,32 +4,32 @@
4
4
  * id.
5
5
  */
6
6
  export const Mode = {
7
- Anonymous: 'anonymous',
8
- Pseudonymous: 'pseudonymous',
9
- Identified: 'identified',
7
+ Anonymous: "anonymous",
8
+ Pseudonymous: "pseudonymous",
9
+ Identified: "identified",
10
10
  };
11
11
  /** The user's analytics state, which the collector stores and which decides what it sends. Users start anonymous. */
12
12
  export const AnalyticsState = {
13
13
  /** Sends nothing. Switching to it sends one `opted_out`, with no id or browser, and drops what was not sent. */
14
- OptedOut: 'opted_out',
14
+ OptedOut: "opted_out",
15
15
  /** Sends events with no id or browser, the primary languages only and coarse ages. Needs no consent. */
16
- Anonymous: 'anonymous',
16
+ Anonymous: "anonymous",
17
17
  /**
18
18
  * Sends a random install id the collector makes and stores, the browser, the full languages and exact ages. Needs
19
19
  * consent. A pseudonymous or identified channel takes it.
20
20
  */
21
- Pseudonymous: 'pseudonymous',
21
+ Pseudonymous: "pseudonymous",
22
22
  /**
23
23
  * Sends what the pseudonymous state sends, with the id from `getId` in place of the install id. Needs consent. Only
24
24
  * an identified channel takes it.
25
25
  */
26
- Identified: 'identified',
26
+ Identified: "identified",
27
27
  };
28
28
  /** Bucket for the number of days with at least one event. */
29
29
  export const ActiveDaysBucket = {
30
- None: '0',
31
- One: '1',
32
- TwoToFive: '2-5',
33
- SixToTwenty: '6-20',
34
- TwentyOneOrMore: '21+',
30
+ None: "0",
31
+ One: "1",
32
+ TwoToFive: "2-5",
33
+ SixToTwenty: "6-20",
34
+ TwentyOneOrMore: "21+",
35
35
  };
package/dist/desktop.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { Collector, CommonOptions, Delivery, Mode, ModeOptions } from './collectorTypes.js';
2
- import type { Platform } from './envelope.js';
3
- import type { StorageAdapter } from './storage.js';
1
+ import type { Collector, CommonOptions, Delivery, Mode, ModeOptions } from "./collectorTypes.js";
2
+ import type { Platform } from "./envelope.js";
3
+ import type { StorageAdapter } from "./storage.js";
4
4
  /**
5
5
  * The options of `newDesktopCollector`: those of `newCollector` with `storage` optional and a desktop `platform`. An
6
6
  * option left out or `undefined` takes its default.
7
7
  */
8
- export type DesktopCollectorOptions = Omit<CommonOptions, 'storage'> & {
8
+ export type DesktopCollectorOptions = Omit<CommonOptions, "storage"> & {
9
9
  /** The operating system the app runs on, as the intake names it. */
10
10
  platform: typeof Platform.MacOs | typeof Platform.Windows | typeof Platform.Linux;
11
11
  /** The storage, the webview's `localStorage` by default. */
package/dist/desktop.js CHANGED
@@ -1,5 +1,5 @@
1
- import { newCollector } from './collector.js';
2
- import { newLocalStorageAdapter, newWebLock } from './web.js';
1
+ import { newCollector } from "./collector.js";
2
+ import { newLocalStorageAdapter, newWebLock } from "./web.js";
3
3
  export function newDesktopCollector(options) {
4
4
  const collector = newCollector({
5
5
  ...options,
@@ -1,12 +1,12 @@
1
- import type { Browser } from './browser.js';
2
- import type { Period } from './calendar.js';
1
+ import type { Browser } from "./browser.js";
2
+ import type { Period } from "./calendar.js";
3
3
  /** The platform the product runs on, as the intake names it. */
4
4
  export declare const Platform: {
5
- readonly Extension: 'extension';
6
- readonly MacOs: 'macos';
7
- readonly Windows: 'windows';
8
- readonly Linux: 'linux';
9
- readonly Web: 'web';
5
+ readonly Extension: "extension";
6
+ readonly MacOs: "macos";
7
+ readonly Windows: "windows";
8
+ readonly Linux: "linux";
9
+ readonly Web: "web";
10
10
  };
11
11
  export type Platform = (typeof Platform)[keyof typeof Platform];
12
12
  /**
@@ -14,9 +14,9 @@ export type Platform = (typeof Platform)[keyof typeof Platform];
14
14
  * user turns analytics off.
15
15
  */
16
16
  export declare const LifecycleEvent: {
17
- readonly Installed: 'installed';
18
- readonly Updated: 'updated';
19
- readonly OptedOut: 'opted_out';
17
+ readonly Installed: "installed";
18
+ readonly Updated: "updated";
19
+ readonly OptedOut: "opted_out";
20
20
  };
21
21
  export type LifecycleEvent = (typeof LifecycleEvent)[keyof typeof LifecycleEvent];
22
22
  /** The system event of a page view. Only the first one that a collector records carries the referrer. */
@@ -48,7 +48,7 @@ export interface UsageEvent {
48
48
  referrer?: string;
49
49
  }
50
50
  /** Where an envelope's `id` comes from: the install id the collector makes, or the account id from `getId`. */
51
- export type IdKind = 'pseudonymous' | 'identified';
51
+ export type IdKind = "pseudonymous" | "identified";
52
52
  /** What one request to the intake carries. */
53
53
  export interface Envelope {
54
54
  key: string;
package/dist/envelope.js CHANGED
@@ -1,23 +1,23 @@
1
1
  /** The platform the product runs on, as the intake names it. */
2
2
  export const Platform = {
3
- Extension: 'extension',
4
- MacOs: 'macos',
5
- Windows: 'windows',
6
- Linux: 'linux',
7
- Web: 'web',
3
+ Extension: "extension",
4
+ MacOs: "macos",
5
+ Windows: "windows",
6
+ Linux: "linux",
7
+ Web: "web",
8
8
  };
9
9
  /**
10
10
  * The events that only the collector sends: `installed` and `updated` from its own methods, and `opted_out` when the
11
11
  * user turns analytics off.
12
12
  */
13
13
  export const LifecycleEvent = {
14
- Installed: 'installed',
15
- Updated: 'updated',
16
- OptedOut: 'opted_out',
14
+ Installed: "installed",
15
+ Updated: "updated",
16
+ OptedOut: "opted_out",
17
17
  };
18
18
  /** The system event of a page view. Only the first one that a collector records carries the referrer. */
19
- export const PAGE_VIEW = 'page_view';
20
- export const UNINSTALLED = 'uninstalled';
19
+ export const PAGE_VIEW = "page_view";
20
+ export const UNINSTALLED = "uninstalled";
21
21
  /**
22
22
  * The intake's `system_events`: the events it takes from every product without the product's allowlist. The collector
23
23
  * sends the lifecycle ones, and the product's own pages and site send the rest.
@@ -25,7 +25,7 @@ export const UNINSTALLED = 'uninstalled';
25
25
  export const SYSTEM_EVENTS = [
26
26
  ...Object.values(LifecycleEvent),
27
27
  UNINSTALLED,
28
- 'welcome_opened',
28
+ "welcome_opened",
29
29
  PAGE_VIEW,
30
- 'install_click',
30
+ "install_click",
31
31
  ];
@@ -1,13 +1,22 @@
1
- import { type EventParams } from './envelope.js';
1
+ import { type TrackOptions } from "./collectorTypes.js";
2
+ import { type EventParams } from "./envelope.js";
2
3
  /**
3
4
  * Tells why the intake would drop the event, or returns undefined when its form passes. The check refuses `installed`,
4
- * `updated` and `opted_out`, because only the collector's own methods send them.
5
+ * `updated` and `opted_out`, because only the collector's own methods send them. It never throws: for params whose
6
+ * getter or proxy throws, it returns that it could not read them.
5
7
  */
6
8
  export declare function checkEvent(name: unknown, params: unknown): string | undefined;
7
9
  /**
8
- * Returns a copy of the params of an event `track` takes, or reports why it refuses the event and returns undefined.
9
- * The copy is taken once, so a later change the host makes to its object reaches neither the check nor the event.
10
+ * Returns a copy of the params of an event `track` takes, with the `throttleMs` of its options, or reports why it
11
+ * refuses the event and returns undefined. The copy is taken once, so a later change the host makes to its object
12
+ * reaches neither the check nor the event.
10
13
  */
11
- export declare function acceptedEvent(name: string, given: EventParams | undefined, reportError: (error: unknown) => void): {
14
+ export declare function acceptedEvent({ name, given, options, reportError, }: {
15
+ name: string;
16
+ given: EventParams | undefined;
17
+ options: TrackOptions | undefined;
18
+ reportError: (error: unknown) => void;
19
+ }): {
12
20
  params: EventParams | undefined;
21
+ throttleMs: number | undefined;
13
22
  } | undefined;
@@ -1,11 +1,13 @@
1
- import { ActiveDaysBucket } from './collectorTypes.js';
2
- import { LifecycleEvent, SYSTEM_EVENTS } from './envelope.js';
3
- import { quoted } from './hostInput.js';
1
+ import { ActiveDaysBucket } from "./collectorTypes.js";
2
+ import { LifecycleEvent, SYSTEM_EVENTS } from "./envelope.js";
3
+ import { quoted } from "./hostInput.js";
4
+ import { throttleOf } from "./throttle.js";
4
5
  /** The form the intake takes for an event name and a param name. */
5
6
  const NAME_FORMAT = /^[a-z][a-z\d_]{0,39}$/;
6
7
  const MAX_PARAMS = 16;
7
8
  /** The length of a string param the intake takes, in characters. */
8
9
  const MAX_PARAM_STRING_LENGTH = 64;
10
+ const UNREADABLE_PARAMS = "has params that could not be read";
9
11
  const LIFECYCLE_NAMES = new Set(Object.values(LifecycleEvent));
10
12
  const ACTIVE_DAYS = Object.values(ActiveDaysBucket);
11
13
  /**
@@ -14,49 +16,67 @@ const ACTIVE_DAYS = Object.values(ActiveDaysBucket);
14
16
  */
15
17
  const SYSTEM_EVENT_PARAMS = new Map([
16
18
  [
17
- 'uninstalled',
19
+ "uninstalled",
18
20
  {
19
21
  // The intake reads the value as whole days from 0. It drops the event when the value has another form.
20
- age_days: (value) => typeof value === 'number' && Number.isSafeInteger(value) && value >= 0
22
+ age_days: (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0
21
23
  ? undefined
22
- : 'that is not a whole number from 0',
23
- active_days: (value) => ACTIVE_DAYS.includes(value) ? undefined : `that is not one of ${ACTIVE_DAYS.join(', ')}`,
24
+ : "that is not a whole number from 0",
25
+ active_days: (value) => ACTIVE_DAYS.includes(value) ? undefined : `that is not one of ${ACTIVE_DAYS.join(", ")}`,
26
+ },
27
+ ],
28
+ [
29
+ "install_click",
30
+ {
31
+ product: (value) => (typeof value === "string" ? undefined : "that is not a string"),
24
32
  },
25
33
  ],
26
- ['install_click', { product: (value) => (typeof value === 'string' ? undefined : 'that is not a string') }],
27
34
  ]);
28
35
  /**
29
36
  * Tells why the intake would drop the event, or returns undefined when its form passes. The check refuses `installed`,
30
- * `updated` and `opted_out`, because only the collector's own methods send them.
37
+ * `updated` and `opted_out`, because only the collector's own methods send them. It never throws: for params whose
38
+ * getter or proxy throws, it returns that it could not read them.
31
39
  */
32
40
  export function checkEvent(name, params) {
33
- if (typeof name !== 'string' || !NAME_FORMAT.test(name)) {
34
- return 'has a name the intake does not take';
41
+ if (typeof name !== "string" || !NAME_FORMAT.test(name)) {
42
+ return "has a name the intake does not take";
35
43
  }
36
44
  if (LIFECYCLE_NAMES.has(name)) {
37
- return 'is one only the collector sends';
45
+ return "is one only the collector sends";
46
+ }
47
+ try {
48
+ return paramsProblem(name, params);
49
+ }
50
+ catch {
51
+ return UNREADABLE_PARAMS;
38
52
  }
39
- return paramsProblem(name, params);
40
53
  }
41
54
  /**
42
- * Returns a copy of the params of an event `track` takes, or reports why it refuses the event and returns undefined.
43
- * The copy is taken once, so a later change the host makes to its object reaches neither the check nor the event.
55
+ * Returns a copy of the params of an event `track` takes, with the `throttleMs` of its options, or reports why it
56
+ * refuses the event and returns undefined. The copy is taken once, so a later change the host makes to its object
57
+ * reaches neither the check nor the event.
44
58
  */
45
- export function acceptedEvent(name, given, reportError) {
59
+ export function acceptedEvent({ name, given, options, reportError, }) {
60
+ const refuse = (problem, cause) => {
61
+ const message = `artel: event ${quoted(name)} ${problem}, so it was not tracked`;
62
+ reportError(cause === undefined ? new Error(message) : new Error(message, { cause }));
63
+ return undefined;
64
+ };
46
65
  let params;
47
66
  try {
48
67
  params = copyOfParams(given);
49
68
  }
50
69
  catch (error) {
51
- reportError(error);
52
- return undefined;
70
+ return refuse(UNREADABLE_PARAMS, error);
53
71
  }
54
72
  const problem = checkEvent(name, params);
55
73
  if (problem !== undefined) {
56
- reportError(new Error(`artel: event ${quoted(name)} ${problem}, so it was not tracked`));
57
- return undefined;
74
+ return refuse(problem);
58
75
  }
59
- return { params };
76
+ const throttle = throttleOf(options);
77
+ return throttle === undefined
78
+ ? refuse("has a throttleMs that is not a finite number from 0")
79
+ : { params, throttleMs: throttle.throttleMs };
60
80
  }
61
81
  /**
62
82
  * Returns a shallow copy of the own enumerable entries of object params, and other params as they are. The collector
@@ -66,7 +86,7 @@ export function acceptedEvent(name, given, reportError) {
66
86
  function copyOfParams(params) {
67
87
  // An untyped host can pass null or a list. The function returns such params as they are, so the check refuses them.
68
88
  const value = params;
69
- return typeof value === 'object' && value !== null && !Array.isArray(value)
89
+ return typeof value === "object" && value !== null && !Array.isArray(value)
70
90
  ? Object.fromEntries(Object.entries(value))
71
91
  : params;
72
92
  }
@@ -78,8 +98,8 @@ function paramsProblem(name, params) {
78
98
  if (params === undefined) {
79
99
  return undefined;
80
100
  }
81
- if (typeof params !== 'object' || params === null || Array.isArray(params)) {
82
- return 'has params that are not an object';
101
+ if (typeof params !== "object" || params === null || Array.isArray(params)) {
102
+ return "has params that are not an object";
83
103
  }
84
104
  // The check counts the keys before it reads any value. A content script can send params with many keys, and this
85
105
  // order keeps their cost low.
@@ -101,7 +121,7 @@ function paramsProblem(name, params) {
101
121
  */
102
122
  function paramRule(name, key, value) {
103
123
  if (!NAME_FORMAT.test(key)) {
104
- return 'whose name is not a lowercase letter, then lowercase letters, digits and _, up to 40 characters';
124
+ return "whose name is not a lowercase letter, then lowercase letters, digits and _, up to 40 characters";
105
125
  }
106
126
  if (SYSTEM_EVENTS.includes(name)) {
107
127
  const rule = SYSTEM_EVENT_PARAMS.get(name)?.[key];
@@ -117,14 +137,15 @@ function paramRule(name, key, value) {
117
137
  * that is not finite, because JSON sends it as null.
118
138
  */
119
139
  function valueRule(value) {
120
- if (typeof value === 'string') {
140
+ if (typeof value === "string") {
121
141
  // A string longer than twice the limit in UTF-16 units has more characters than the limit, so the check does not
122
142
  // count its characters.
123
- return value.length > 2 * MAX_PARAM_STRING_LENGTH || Array.from(value).length > MAX_PARAM_STRING_LENGTH
143
+ return value.length > 2 * MAX_PARAM_STRING_LENGTH ||
144
+ Array.from(value).length > MAX_PARAM_STRING_LENGTH
124
145
  ? `past ${MAX_PARAM_STRING_LENGTH} characters`
125
146
  : undefined;
126
147
  }
127
- return typeof value === 'boolean' || Number.isFinite(value)
148
+ return typeof value === "boolean" || Number.isFinite(value)
128
149
  ? undefined
129
- : 'that is not a string, a boolean or a finite number';
150
+ : "that is not a string, a boolean or a finite number";
130
151
  }
package/dist/exports.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export { detectBrowser, BrowserName, type Browser, type NavigatorFields } from './browser.js';
2
- export { newCollector } from './collector.js';
3
- export { ActiveDaysBucket, AnalyticsState, Mode, type Collector, type CollectorOptions, type CommonOptions, type Delivery, type GetId, type ModeOptions, type PageFields, type PageOptions, type StateOf, type UninstallParams, } from './collectorTypes.js';
4
- export { Platform, type EventParams } from './envelope.js';
5
- export { checkEvent } from './eventCheck.js';
6
- export { checkOptions, isTestKey } from './hostInput.js';
7
- export { newMemoryStorage, type StorageAdapter } from './storage.js';
8
- export { newHttpTransport, type Transport, type TransportResult } from './transport.js';
9
- export type { Lock } from './lock.js';
10
- export { systemClock, type Clock, type TimerHandle } from './clock.js';
1
+ export { detectBrowser, BrowserName, type Browser, type NavigatorFields } from "./browser.js";
2
+ export { newCollector } from "./collector.js";
3
+ export { ActiveDaysBucket, AnalyticsState, Mode, type Collector, type CollectorOptions, type CommonOptions, type Delivery, type GetId, type ModeOptions, type PageFields, type PageOptions, type StateOf, type TrackOptions, type UninstallParams, } from "./collectorTypes.js";
4
+ export { Platform, type EventParams } from "./envelope.js";
5
+ export { checkEvent } from "./eventCheck.js";
6
+ export { checkOptions, isTestKey } from "./hostInput.js";
7
+ export { newMemoryStorage, type StorageAdapter } from "./storage.js";
8
+ export { newHttpTransport, type Transport, type TransportResult } from "./transport.js";
9
+ export type { Lock } from "./lock.js";
10
+ export { systemClock, type Clock } from "./clock.js";
package/dist/exports.js CHANGED
@@ -1,9 +1,9 @@
1
- export { detectBrowser, BrowserName } from './browser.js';
2
- export { newCollector } from './collector.js';
3
- export { ActiveDaysBucket, AnalyticsState, Mode, } from './collectorTypes.js';
4
- export { Platform } from './envelope.js';
5
- export { checkEvent } from './eventCheck.js';
6
- export { checkOptions, isTestKey } from './hostInput.js';
7
- export { newMemoryStorage } from './storage.js';
8
- export { newHttpTransport } from './transport.js';
9
- export { systemClock } from './clock.js';
1
+ export { detectBrowser, BrowserName } from "./browser.js";
2
+ export { newCollector } from "./collector.js";
3
+ export { ActiveDaysBucket, AnalyticsState, Mode, } from "./collectorTypes.js";
4
+ export { Platform } from "./envelope.js";
5
+ export { checkEvent } from "./eventCheck.js";
6
+ export { checkOptions, isTestKey } from "./hostInput.js";
7
+ export { newMemoryStorage } from "./storage.js";
8
+ export { newHttpTransport } from "./transport.js";
9
+ export { systemClock } from "./clock.js";
@@ -1,18 +1,20 @@
1
- import { Mode, type Collector, type CommonOptions, type Delivery, type ModeOptions } from './collectorTypes.js';
2
- import { type EventParams } from './envelope.js';
3
- import type { StorageAdapter } from './storage.js';
1
+ import { type Clock } from "./clock.js";
2
+ import { Mode, type Collector, type CommonOptions, type Delivery, type ModeOptions } from "./collectorTypes.js";
3
+ import { type EventParams } from "./envelope.js";
4
+ import type { StorageAdapter } from "./storage.js";
4
5
  /**
5
6
  * The options of `newExtensionCollector`: those of `newCollector` without `platform`, with `storage` and `version`
6
7
  * optional. An option left out or `undefined` takes its default.
7
8
  */
8
- export type ExtensionCollectorOptions = Omit<CommonOptions, 'storage' | 'version'> & {
9
+ export type ExtensionCollectorOptions = Omit<CommonOptions, "storage" | "version"> & {
9
10
  /** The storage, `chrome.storage.local` by default. */
10
11
  storage?: StorageAdapter | undefined;
11
12
  /** The product version, the manifest's by default. */
12
13
  version?: string | undefined;
13
14
  /**
14
15
  * The address of the page Chrome opens when the user removes the extension. The collector sets it with the fields of
15
- * `uninstallParams()` in its query at construction and after each `setState`. Left out, the collector sets none.
16
+ * `uninstallParams()` in its query at construction, after each `setState` and after the first event of a local day.
17
+ * Left out, the collector sets none.
16
18
  */
17
19
  uninstallPage?: string | undefined;
18
20
  /** An extension sends no page. */
@@ -40,11 +42,13 @@ export declare function newChromeStorageAdapter(): StorageAdapter;
40
42
  */
41
43
  export declare function forwardTrack(name: string, params?: EventParams): Promise<void>;
42
44
  /** The part of the collector a content script uses: it tracks events, and the worker keeps the analytics state. */
43
- export type ContentScriptCollector = Pick<Collector, 'track'>;
45
+ export type ContentScriptCollector = Pick<Collector, "track">;
44
46
  /**
45
- * Returns the collector of a content script. Its `track` hands each event to the service worker with `forwardTrack`,
46
- * and the worker's collector checks, queues and sends it under the user's analytics state. The state lives in the
47
- * worker and the extension pages, so a content script can neither read nor change it. It reads no storage, needs no
48
- * key, version or endpoint, and never throws.
47
+ * Returns the collector of a content script. Its `track` applies a call's `throttleMs` in the script's memory, by
48
+ * `clock`, then hands the event to the worker with `forwardTrack`. The worker checks, queues and sends it under the
49
+ * user's analytics state, which a content script can neither read nor change. It reads no storage, needs no key,
50
+ * version or endpoint, never throws, and drops a call with a bad `throttleMs` without a report, having no `onError`.
49
51
  */
50
- export declare function newContentScriptCollector(): ContentScriptCollector;
52
+ export declare function newContentScriptCollector({ clock, }?: {
53
+ clock?: Clock;
54
+ }): ContentScriptCollector;