@10x-media/analytics 0.1.0-beta.5 → 1.0.0-beta.7
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 +40 -0
- package/LICENSE +21 -21
- package/README.md +5 -1
- package/dist/adapters/ga4/ga4.js +13 -0
- package/dist/adapters/ga4/ga4.js.map +1 -1
- package/dist/adapters/http/fetchJson.js +1 -1
- package/dist/adapters/plausible/plausible.d.ts +10 -0
- package/dist/adapters/plausible/plausible.js +51 -0
- package/dist/adapters/plausible/plausible.js.map +1 -1
- package/dist/adapters/posthog/posthog.d.ts +10 -1
- package/dist/adapters/posthog/posthog.js +84 -3
- package/dist/adapters/posthog/posthog.js.map +1 -1
- package/dist/adapters/series.js +11 -1
- package/dist/adapters/series.js.map +1 -1
- package/dist/adapters/umami/umami.d.ts +5 -1
- package/dist/adapters/umami/umami.js +28 -0
- package/dist/adapters/umami/umami.js.map +1 -1
- package/dist/capture/getTrackerConfig.d.ts +20 -0
- package/dist/capture/getTrackerConfig.js +31 -0
- package/dist/capture/getTrackerConfig.js.map +1 -0
- package/dist/capture/mountPath.js +14 -0
- package/dist/capture/mountPath.js.map +1 -0
- package/dist/capture/proxyEndpoint.js +123 -0
- package/dist/capture/proxyEndpoint.js.map +1 -0
- package/dist/capture/proxyRoutes.js +108 -0
- package/dist/capture/proxyRoutes.js.map +1 -0
- package/dist/capture/requestBody.js +68 -0
- package/dist/capture/requestBody.js.map +1 -0
- package/dist/capture/slots.d.ts +8 -0
- package/dist/capture/slots.js +43 -0
- package/dist/capture/slots.js.map +1 -0
- package/dist/capture/trackerConfig.d.ts +32 -0
- package/dist/capture/trackerConfig.js +70 -0
- package/dist/capture/trackerConfig.js.map +1 -0
- package/dist/capture/trackerEndpoint.js +35 -0
- package/dist/capture/trackerEndpoint.js.map +1 -0
- package/dist/core/capabilities.d.ts +5 -1
- package/dist/core/capabilities.js +4 -0
- package/dist/core/capabilities.js.map +1 -1
- package/dist/core/capture.d.ts +49 -0
- package/dist/core/contract.d.ts +33 -4
- package/dist/core/contract.js.map +1 -1
- package/dist/core/options.d.ts +97 -2
- package/dist/core/options.js +63 -2
- package/dist/core/options.js.map +1 -1
- package/dist/core/registry.d.ts +1 -0
- package/dist/core/scopeList.js +32 -0
- package/dist/core/scopeList.js.map +1 -0
- package/dist/core/scopedRead.js +13 -6
- package/dist/core/scopedRead.js.map +1 -1
- package/dist/exports/next.d.ts +2 -1
- package/dist/exports/next.js +2 -1
- package/dist/exports/react.d.ts +4 -0
- package/dist/exports/react.js +5 -0
- package/dist/exports/rsc.d.ts +5 -2
- package/dist/exports/rsc.js +3 -1
- package/dist/exports/tracker.d.ts +18 -0
- package/dist/exports/tracker.js +12 -0
- package/dist/exports/types.d.ts +6 -3
- package/dist/fields/AnalyticsPanelClient.js +1 -1
- package/dist/fields/config/narrow.js +2 -0
- package/dist/fields/config/narrow.js.map +1 -1
- package/dist/fields/readForDocument.js +1 -1
- package/dist/goals/match.js +64 -0
- package/dist/goals/match.js.map +1 -0
- package/dist/goals/types.d.ts +33 -0
- package/dist/goals/types.js +7 -0
- package/dist/goals/types.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +39 -10
- package/dist/index.js.map +1 -1
- package/dist/native/collections/events.js +21 -1
- package/dist/native/collections/events.js.map +1 -1
- package/dist/native/collections/rollups.js +39 -3
- package/dist/native/collections/rollups.js.map +1 -1
- package/dist/native/geo/maxmindResolver.js +2 -4
- package/dist/native/geo/maxmindResolver.js.map +1 -1
- package/dist/native/ingest/clientIp.js +15 -0
- package/dist/native/ingest/clientIp.js.map +1 -0
- package/dist/native/ingest/endpoint.js +40 -4
- package/dist/native/ingest/endpoint.js.map +1 -1
- package/dist/native/ingest/flushBatch.js +4 -13
- package/dist/native/ingest/flushBatch.js.map +1 -1
- package/dist/native/ingest/normalizeEvent.js +76 -9
- package/dist/native/ingest/normalizeEvent.js.map +1 -1
- package/dist/native/nativeAdapter.js +100 -5
- package/dist/native/nativeAdapter.js.map +1 -1
- package/dist/native/query/eventAgg.js +161 -0
- package/dist/native/query/eventAgg.js.map +1 -0
- package/dist/native/rollupAcc.js +12 -1
- package/dist/native/rollupAcc.js.map +1 -1
- package/dist/native/rollups/applyDistinctDeltas.js +1 -1
- package/dist/native/rollups/applyDistinctDeltas.js.map +1 -1
- package/dist/native/rollups/bumpRollup.js +7 -2
- package/dist/native/rollups/bumpRollup.js.map +1 -1
- package/dist/native/rollups/deltas.js +70 -11
- package/dist/native/rollups/deltas.js.map +1 -1
- package/dist/next/captureRewrites.d.ts +41 -0
- package/dist/next/captureRewrites.js +56 -0
- package/dist/next/captureRewrites.js.map +1 -0
- package/dist/next/posthogProxyRewrites.d.ts +5 -0
- package/dist/next/posthogProxyRewrites.js +16 -21
- package/dist/next/posthogProxyRewrites.js.map +1 -1
- package/dist/plugin/documentEndpoint.js +1 -1
- package/dist/plugin/paths.js +11 -1
- package/dist/plugin/paths.js.map +1 -1
- package/dist/plugin/runtime.d.ts +1 -0
- package/dist/plugin/runtime.js.map +1 -1
- package/dist/plugin/sourcesEndpoint.js +16 -4
- package/dist/plugin/sourcesEndpoint.js.map +1 -1
- package/dist/plugin/warmTask.js +0 -0
- package/dist/plugin/warmTask.js.map +1 -1
- package/dist/providers/collection.js +56 -16
- package/dist/providers/collection.js.map +1 -1
- package/dist/providers/factory.js +8 -2
- package/dist/providers/factory.js.map +1 -1
- package/dist/react/AnalyticsProvider.d.ts +43 -0
- package/dist/react/AnalyticsProvider.js +66 -0
- package/dist/react/AnalyticsProvider.js.map +1 -0
- package/dist/react/TrackerBoot.d.ts +22 -0
- package/dist/react/TrackerBoot.js +30 -0
- package/dist/react/TrackerBoot.js.map +1 -0
- package/dist/react/useAnalytics.d.ts +17 -0
- package/dist/react/useAnalytics.js +36 -0
- package/dist/react/useAnalytics.js.map +1 -0
- package/dist/rsc/AnalyticsScripts.d.ts +30 -0
- package/dist/rsc/AnalyticsScripts.js +41 -0
- package/dist/rsc/AnalyticsScripts.js.map +1 -0
- package/dist/surfacing/cacheStore.d.ts +1 -0
- package/dist/surfacing/cacheStore.js +18 -2
- package/dist/surfacing/cacheStore.js.map +1 -1
- package/dist/surfacing/engine.d.ts +1 -0
- package/dist/surfacing/engine.js +44 -4
- package/dist/surfacing/engine.js.map +1 -1
- package/dist/surfacing/queue.js +22 -6
- package/dist/surfacing/queue.js.map +1 -1
- package/dist/surfacing/rateLimiter.js +130 -0
- package/dist/surfacing/rateLimiter.js.map +1 -0
- package/dist/surfacing/retryPolicy.js +15 -0
- package/dist/surfacing/retryPolicy.js.map +1 -0
- package/dist/sync/collection.js +23 -7
- package/dist/sync/collection.js.map +1 -1
- package/dist/sync/syncTask.js +68 -33
- package/dist/sync/syncTask.js.map +1 -1
- package/dist/testing/memoryAdapter.d.ts +2 -0
- package/dist/testing/memoryAdapter.js +17 -0
- package/dist/testing/memoryAdapter.js.map +1 -1
- package/dist/tracker/autoCapture.d.ts +48 -0
- package/dist/tracker/autoCapture.js +129 -0
- package/dist/tracker/autoCapture.js.map +1 -0
- package/dist/tracker/consent.d.ts +24 -0
- package/dist/tracker/consent.js +48 -0
- package/dist/tracker/consent.js.map +1 -0
- package/dist/tracker/createTracker.d.ts +18 -0
- package/dist/tracker/createTracker.js +163 -0
- package/dist/tracker/createTracker.js.map +1 -0
- package/dist/tracker/initTracker.d.ts +22 -0
- package/dist/tracker/initTracker.js +33 -0
- package/dist/tracker/initTracker.js.map +1 -0
- package/dist/tracker/loadScript.d.ts +14 -0
- package/dist/tracker/loadScript.js +41 -0
- package/dist/tracker/loadScript.js.map +1 -0
- package/dist/tracker/pageTracking.d.ts +17 -0
- package/dist/tracker/pageTracking.js +38 -0
- package/dist/tracker/pageTracking.js.map +1 -0
- package/dist/tracker/registry.d.ts +27 -0
- package/dist/tracker/registry.js +73 -0
- package/dist/tracker/registry.js.map +1 -0
- package/dist/tracker/sinks/native.d.ts +22 -0
- package/dist/tracker/sinks/native.js +56 -0
- package/dist/tracker/sinks/native.js.map +1 -0
- package/dist/tracker/sinks/plausible.d.ts +14 -0
- package/dist/tracker/sinks/plausible.js +25 -0
- package/dist/tracker/sinks/plausible.js.map +1 -0
- package/dist/tracker/sinks/posthog.d.ts +14 -0
- package/dist/tracker/sinks/posthog.js +18 -0
- package/dist/tracker/sinks/posthog.js.map +1 -0
- package/dist/tracker/sinks/umami.d.ts +13 -0
- package/dist/tracker/sinks/umami.js +17 -0
- package/dist/tracker/sinks/umami.js.map +1 -0
- package/dist/tracker/sinks/vendor.d.ts +14 -0
- package/dist/tracker/sinks/vendor.js +66 -0
- package/dist/tracker/sinks/vendor.js.map +1 -0
- package/dist/tracker/transport.js +28 -0
- package/dist/tracker/transport.js.map +1 -0
- package/dist/tracker/types.d.ts +66 -0
- package/dist/translations/ar.js +83 -0
- package/dist/translations/ar.js.map +1 -0
- package/dist/translations/de.js +6 -0
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +6 -0
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +83 -0
- package/dist/translations/es.js.map +1 -0
- package/dist/translations/fr.js +83 -0
- package/dist/translations/fr.js.map +1 -0
- package/dist/translations/id.js +83 -0
- package/dist/translations/id.js.map +1 -0
- package/dist/translations/index.d.ts +10 -1
- package/dist/translations/index.js +19 -1
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/keys.d.ts +6 -0
- package/dist/translations/keys.js +6 -0
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +83 -0
- package/dist/translations/ko.js.map +1 -0
- package/dist/translations/pt.js +83 -0
- package/dist/translations/pt.js.map +1 -0
- package/dist/translations/ru.js +83 -0
- package/dist/translations/ru.js.map +1 -0
- package/dist/translations/uk.js +83 -0
- package/dist/translations/uk.js.map +1 -0
- package/dist/translations/zh.js +83 -0
- package/dist/translations/zh.js.map +1 -0
- package/dist/widgets/breakdownTypes.js +5 -0
- package/dist/widgets/breakdownTypes.js.map +1 -1
- package/dist/widgets/readForWidget.d.ts +2 -1
- package/dist/widgets/readForWidget.js +32 -14
- package/dist/widgets/readForWidget.js.map +1 -1
- package/dist/widgets/readForWidgetBreakdown.d.ts +2 -1
- package/dist/widgets/readForWidgetBreakdown.js +29 -15
- package/dist/widgets/readForWidgetBreakdown.js.map +1 -1
- package/dist/widgets/readForWidgetRealtime.js +1 -1
- package/dist/widgets/readForWidgetSeries.d.ts +2 -1
- package/dist/widgets/readForWidgetSeries.js +34 -16
- package/dist/widgets/readForWidgetSeries.js.map +1 -1
- package/dist/widgets/registerWidgets.js +10 -4
- package/dist/widgets/registerWidgets.js.map +1 -1
- package/dist/widgets/types.js +4 -1
- package/dist/widgets/types.js.map +1 -1
- package/package.json +20 -5
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TrackerGoal } from "../goals/types.js";
|
|
2
|
+
import { CaptureClientKind, CaptureSnippet, CaptureSupport } from "../core/capture.js";
|
|
3
|
+
import { CaptureSlot } from "./slots.js";
|
|
4
|
+
import { ResolvedAutoCapture } from "../core/options.js";
|
|
5
|
+
import { PayloadRequest } from "payload";
|
|
6
|
+
|
|
7
|
+
//#region src/capture/trackerConfig.d.ts
|
|
8
|
+
interface TrackerSlotConfig {
|
|
9
|
+
slot: CaptureSlot;
|
|
10
|
+
kind: CaptureClientKind;
|
|
11
|
+
adapterId: string;
|
|
12
|
+
/** Mount the snippet and the sink talk to: the runtime proxy, or a `capture.paths` override. */
|
|
13
|
+
path: string;
|
|
14
|
+
snippet: CaptureSnippet;
|
|
15
|
+
client: CaptureSupport['client'];
|
|
16
|
+
requiresConsent: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Everything the browser tracker needs, and nothing else. Serialized to any visitor by the
|
|
20
|
+
* public tracker endpoint, so it carries only what an adapter puts in `capture.client` and
|
|
21
|
+
* `capture.snippet`: never a query credential, never a goal's admin-facing name.
|
|
22
|
+
*/
|
|
23
|
+
interface TrackerConfig {
|
|
24
|
+
slots: TrackerSlotConfig[];
|
|
25
|
+
autoCapture: ResolvedAutoCapture;
|
|
26
|
+
goals: TrackerGoal[];
|
|
27
|
+
/** Where the native sink posts events, derived from the app's own `routes.api`. */
|
|
28
|
+
ingestPath: string;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { TrackerConfig, TrackerSlotConfig };
|
|
32
|
+
//# sourceMappingURL=trackerConfig.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { INGEST_PATH, PROXY_PATH } from "../plugin/paths.js";
|
|
2
|
+
import { CAPTURE_SLOTS, resolveSlotAdapter } from "./slots.js";
|
|
3
|
+
import { DEFAULT_AUTO_CAPTURE, defaultConsentFor } from "../core/options.js";
|
|
4
|
+
import { normalizeMountPath } from "./mountPath.js";
|
|
5
|
+
//#region src/capture/trackerConfig.ts
|
|
6
|
+
const apiRoute = (req) => req.payload?.config?.routes?.api ?? "/api";
|
|
7
|
+
const trackerGoals = (goals) => (goals ?? []).map(({ slug, match, value, currency }) => ({
|
|
8
|
+
slug,
|
|
9
|
+
match,
|
|
10
|
+
...value ? { value } : {},
|
|
11
|
+
...currency ? { currency } : {}
|
|
12
|
+
}));
|
|
13
|
+
/** The config for an install with no runtime yet: no slots, but still a usable ingest path. */
|
|
14
|
+
const emptyTrackerConfig = (req) => ({
|
|
15
|
+
slots: [],
|
|
16
|
+
autoCapture: DEFAULT_AUTO_CAPTURE,
|
|
17
|
+
goals: [],
|
|
18
|
+
ingestPath: `${apiRoute(req)}${INGEST_PATH}`
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* The per-request tracker config: one entry per capture slot that resolves to an adapter
|
|
22
|
+
* declaring `capture`, in slot order. A slot whose adapter does not resolve (no scope, an
|
|
23
|
+
* unknown id, a throwing scope resolver) is simply absent, as is one whose snippet throws;
|
|
24
|
+
* this runs on a public, unauthenticated path, so every failure degrades a slot away
|
|
25
|
+
* rather than surfacing an error.
|
|
26
|
+
*
|
|
27
|
+
* One adapter fills at most one slot. A scoped install whose tenant registry defaults to
|
|
28
|
+
* the same adapter the global slot names would otherwise hand the tracker two sinks for
|
|
29
|
+
* it and send every event twice; the native adapter in particular resolves its scope from
|
|
30
|
+
* the request, so one sink already covers both. The global slot iterates first and keeps
|
|
31
|
+
* the entry.
|
|
32
|
+
*/
|
|
33
|
+
const resolveTrackerConfig = async (args) => {
|
|
34
|
+
const { runtime, req } = args;
|
|
35
|
+
const base = apiRoute(req);
|
|
36
|
+
const slots = [];
|
|
37
|
+
const filled = /* @__PURE__ */ new Set();
|
|
38
|
+
for (const slot of CAPTURE_SLOTS) {
|
|
39
|
+
const adapter = await resolveSlotAdapter(runtime, req, slot);
|
|
40
|
+
const capture = adapter?.capture;
|
|
41
|
+
if (!adapter || !capture || filled.has(adapter.id)) continue;
|
|
42
|
+
const override = runtime.capturePaths?.[slot];
|
|
43
|
+
const path = override ? normalizeMountPath(override) : `${base}${PROXY_PATH}/${slot}`;
|
|
44
|
+
const kind = capture.client.kind;
|
|
45
|
+
try {
|
|
46
|
+
slots.push({
|
|
47
|
+
slot,
|
|
48
|
+
kind,
|
|
49
|
+
adapterId: adapter.id,
|
|
50
|
+
path,
|
|
51
|
+
snippet: capture.snippet({ path }),
|
|
52
|
+
client: capture.client,
|
|
53
|
+
requiresConsent: (runtime.consentFor?.(slot, adapter.id, kind) ?? defaultConsentFor(kind)) === "required"
|
|
54
|
+
});
|
|
55
|
+
filled.add(adapter.id);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
req.payload?.logger?.warn(`analytics: capture snippet for "${adapter.id}" failed, dropping the ${slot} slot: ${String(err)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
slots,
|
|
62
|
+
autoCapture: runtime.autoCapture ?? DEFAULT_AUTO_CAPTURE,
|
|
63
|
+
goals: trackerGoals(runtime.goals),
|
|
64
|
+
ingestPath: `${base}${runtime.ingestPath ?? "/analytics/ingest"}`
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { emptyTrackerConfig, resolveTrackerConfig };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=trackerConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trackerConfig.js","names":[],"sources":["../../src/capture/trackerConfig.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport type { CaptureClientKind, CaptureSnippet, CaptureSupport } from '../core/capture'\nimport { DEFAULT_AUTO_CAPTURE, defaultConsentFor, type ResolvedAutoCapture } from '../core/options'\nimport type { Goal, TrackerGoal } from '../goals/types'\nimport { INGEST_PATH, PROXY_PATH } from '../plugin/paths'\nimport type { AnalyticsRuntime } from '../plugin/runtime'\nimport { normalizeMountPath } from './mountPath'\nimport { CAPTURE_SLOTS, type CaptureSlot, resolveSlotAdapter } from './slots'\n\nexport interface TrackerSlotConfig {\n\tslot: CaptureSlot\n\tkind: CaptureClientKind\n\tadapterId: string\n\t/** Mount the snippet and the sink talk to: the runtime proxy, or a `capture.paths` override. */\n\tpath: string\n\tsnippet: CaptureSnippet\n\tclient: CaptureSupport['client']\n\trequiresConsent: boolean\n}\n\n/**\n * Everything the browser tracker needs, and nothing else. Serialized to any visitor by the\n * public tracker endpoint, so it carries only what an adapter puts in `capture.client` and\n * `capture.snippet`: never a query credential, never a goal's admin-facing name.\n */\nexport interface TrackerConfig {\n\tslots: TrackerSlotConfig[]\n\tautoCapture: ResolvedAutoCapture\n\tgoals: TrackerGoal[]\n\t/** Where the native sink posts events, derived from the app's own `routes.api`. */\n\tingestPath: string\n}\n\nconst apiRoute = (req: PayloadRequest): string => req.payload?.config?.routes?.api ?? '/api'\n\nconst trackerGoals = (goals: Goal[] | undefined): TrackerGoal[] =>\n\t(goals ?? []).map(({ slug, match, value, currency }) => ({\n\t\tslug,\n\t\tmatch,\n\t\t...(value ? { value } : {}),\n\t\t...(currency ? { currency } : {}),\n\t}))\n\n/** The config for an install with no runtime yet: no slots, but still a usable ingest path. */\nexport const emptyTrackerConfig = (req: PayloadRequest): TrackerConfig => ({\n\tslots: [],\n\tautoCapture: DEFAULT_AUTO_CAPTURE,\n\tgoals: [],\n\tingestPath: `${apiRoute(req)}${INGEST_PATH}`,\n})\n\n/**\n * The per-request tracker config: one entry per capture slot that resolves to an adapter\n * declaring `capture`, in slot order. A slot whose adapter does not resolve (no scope, an\n * unknown id, a throwing scope resolver) is simply absent, as is one whose snippet throws;\n * this runs on a public, unauthenticated path, so every failure degrades a slot away\n * rather than surfacing an error.\n *\n * One adapter fills at most one slot. A scoped install whose tenant registry defaults to\n * the same adapter the global slot names would otherwise hand the tracker two sinks for\n * it and send every event twice; the native adapter in particular resolves its scope from\n * the request, so one sink already covers both. The global slot iterates first and keeps\n * the entry.\n */\nexport const resolveTrackerConfig = async (args: {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n}): Promise<TrackerConfig> => {\n\tconst { runtime, req } = args\n\tconst base = apiRoute(req)\n\tconst slots: TrackerSlotConfig[] = []\n\tconst filled = new Set<string>()\n\tfor (const slot of CAPTURE_SLOTS) {\n\t\tconst adapter = await resolveSlotAdapter(runtime, req, slot)\n\t\tconst capture = adapter?.capture\n\t\tif (!adapter || !capture || filled.has(adapter.id)) {\n\t\t\tcontinue\n\t\t}\n\t\tconst override = runtime.capturePaths?.[slot]\n\t\tconst path = override ? normalizeMountPath(override) : `${base}${PROXY_PATH}/${slot}`\n\t\tconst kind = capture.client.kind\n\t\ttry {\n\t\t\tslots.push({\n\t\t\t\tslot,\n\t\t\t\tkind,\n\t\t\t\tadapterId: adapter.id,\n\t\t\t\tpath,\n\t\t\t\tsnippet: capture.snippet({ path }),\n\t\t\t\tclient: capture.client,\n\t\t\t\trequiresConsent:\n\t\t\t\t\t(runtime.consentFor?.(slot, adapter.id, kind) ?? defaultConsentFor(kind)) === 'required',\n\t\t\t})\n\t\t\tfilled.add(adapter.id)\n\t\t} catch (err) {\n\t\t\treq.payload?.logger?.warn(\n\t\t\t\t`analytics: capture snippet for \"${adapter.id}\" failed, dropping the ${slot} slot: ${String(err)}`\n\t\t\t)\n\t\t}\n\t}\n\treturn {\n\t\tslots,\n\t\tautoCapture: runtime.autoCapture ?? DEFAULT_AUTO_CAPTURE,\n\t\tgoals: trackerGoals(runtime.goals),\n\t\tingestPath: `${base}${runtime.ingestPath ?? INGEST_PATH}`,\n\t}\n}\n"],"mappings":";;;;;AAiCA,MAAM,YAAY,QAAgC,IAAI,SAAS,QAAQ,QAAQ,OAAO;AAEtF,MAAM,gBAAgB,WACpB,SAAS,CAAC,GAAG,KAAK,EAAE,MAAM,OAAO,OAAO,gBAAgB;CACxD;CACA;CACA,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;CACzB,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;AAChC,EAAE;;AAGH,MAAa,sBAAsB,SAAwC;CAC1E,OAAO,CAAC;CACR,aAAa;CACb,OAAO,CAAC;CACR,YAAY,GAAG,SAAS,GAAG,IAAI;AAChC;;;;;;;;;;;;;;AAeA,MAAa,uBAAuB,OAAO,SAGb;CAC7B,MAAM,EAAE,SAAS,QAAQ;CACzB,MAAM,OAAO,SAAS,GAAG;CACzB,MAAM,QAA6B,CAAC;CACpC,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,QAAQ,eAAe;EACjC,MAAM,UAAU,MAAM,mBAAmB,SAAS,KAAK,IAAI;EAC3D,MAAM,UAAU,SAAS;EACzB,IAAI,CAAC,WAAW,CAAC,WAAW,OAAO,IAAI,QAAQ,EAAE,GAChD;EAED,MAAM,WAAW,QAAQ,eAAe;EACxC,MAAM,OAAO,WAAW,mBAAmB,QAAQ,IAAI,GAAG,OAAO,WAAW,GAAG;EAC/E,MAAM,OAAO,QAAQ,OAAO;EAC5B,IAAI;GACH,MAAM,KAAK;IACV;IACA;IACA,WAAW,QAAQ;IACnB;IACA,SAAS,QAAQ,QAAQ,EAAE,KAAK,CAAC;IACjC,QAAQ,QAAQ;IAChB,kBACE,QAAQ,aAAa,MAAM,QAAQ,IAAI,IAAI,KAAK,kBAAkB,IAAI,OAAO;GAChF,CAAC;GACD,OAAO,IAAI,QAAQ,EAAE;EACtB,SAAS,KAAK;GACb,IAAI,SAAS,QAAQ,KACpB,mCAAmC,QAAQ,GAAG,yBAAyB,KAAK,SAAS,OAAO,GAAG,GAChG;EACD;CACD;CACA,OAAO;EACN;EACA,aAAa,QAAQ,eAAe;EACpC,OAAO,aAAa,QAAQ,KAAK;EACjC,YAAY,GAAG,OAAO,QAAQ,cAAA;CAC/B;AACD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { TRACKER_PATH } from "../plugin/paths.js";
|
|
2
|
+
import { getRuntime } from "../plugin/runtime.js";
|
|
3
|
+
import { emptyTrackerConfig, resolveTrackerConfig } from "./trackerConfig.js";
|
|
4
|
+
//#region src/capture/trackerEndpoint.ts
|
|
5
|
+
/**
|
|
6
|
+
* Public GET serving the browser tracker its per-request configuration. Like the capture
|
|
7
|
+
* proxy, it runs with no `req.user` and calls the host's `scopeResolver` on behalf of an
|
|
8
|
+
* anonymous visitor: a resolver that throws or resolves nothing leaves the tenant slot
|
|
9
|
+
* absent rather than failing the request, so a broken resolver degrades capture instead of
|
|
10
|
+
* breaking the page.
|
|
11
|
+
*
|
|
12
|
+
* The response is per-visitor and hostname-derived, never shared: `private` with a short
|
|
13
|
+
* max-age, `Vary: Host, Cookie` (a `scopeResolver` may read `req.user` or a tenant cookie,
|
|
14
|
+
* which makes the body cookie-dependent), and no cookie of its own.
|
|
15
|
+
*/
|
|
16
|
+
const makeTrackerHandler = () => async (req) => {
|
|
17
|
+
const runtime = getRuntime(req.payload);
|
|
18
|
+
const config = runtime ? await resolveTrackerConfig({
|
|
19
|
+
runtime,
|
|
20
|
+
req
|
|
21
|
+
}) : emptyTrackerConfig(req);
|
|
22
|
+
return Response.json(config, { headers: {
|
|
23
|
+
"cache-control": "private, max-age=60",
|
|
24
|
+
vary: "Host, Cookie"
|
|
25
|
+
} });
|
|
26
|
+
};
|
|
27
|
+
const trackerEndpoint = () => ({
|
|
28
|
+
method: "get",
|
|
29
|
+
path: TRACKER_PATH,
|
|
30
|
+
handler: makeTrackerHandler()
|
|
31
|
+
});
|
|
32
|
+
//#endregion
|
|
33
|
+
export { trackerEndpoint };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=trackerEndpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trackerEndpoint.js","names":[],"sources":["../../src/capture/trackerEndpoint.ts"],"sourcesContent":["import type { Endpoint, PayloadHandler } from 'payload'\nimport { TRACKER_PATH } from '../plugin/paths'\nimport { getRuntime } from '../plugin/runtime'\nimport { emptyTrackerConfig, resolveTrackerConfig } from './trackerConfig'\n\nexport { TRACKER_PATH }\n\n/**\n * Public GET serving the browser tracker its per-request configuration. Like the capture\n * proxy, it runs with no `req.user` and calls the host's `scopeResolver` on behalf of an\n * anonymous visitor: a resolver that throws or resolves nothing leaves the tenant slot\n * absent rather than failing the request, so a broken resolver degrades capture instead of\n * breaking the page.\n *\n * The response is per-visitor and hostname-derived, never shared: `private` with a short\n * max-age, `Vary: Host, Cookie` (a `scopeResolver` may read `req.user` or a tenant cookie,\n * which makes the body cookie-dependent), and no cookie of its own.\n */\nexport const makeTrackerHandler = (): PayloadHandler => async (req) => {\n\tconst runtime = getRuntime(req.payload)\n\tconst config = runtime ? await resolveTrackerConfig({ runtime, req }) : emptyTrackerConfig(req)\n\treturn Response.json(config, {\n\t\theaders: { 'cache-control': 'private, max-age=60', vary: 'Host, Cookie' },\n\t})\n}\n\nexport const trackerEndpoint = (): Endpoint => ({\n\tmethod: 'get',\n\tpath: TRACKER_PATH,\n\thandler: makeTrackerHandler(),\n})\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAa,2BAA2C,OAAO,QAAQ;CACtE,MAAM,UAAU,WAAW,IAAI,OAAO;CACtC,MAAM,SAAS,UAAU,MAAM,qBAAqB;EAAE;EAAS;CAAI,CAAC,IAAI,mBAAmB,GAAG;CAC9F,OAAO,SAAS,KAAK,QAAQ,EAC5B,SAAS;EAAE,iBAAiB;EAAuB,MAAM;CAAe,EACzE,CAAC;AACF;AAEA,MAAa,yBAAmC;CAC/C,QAAQ;CACR,MAAM;CACN,SAAS,mBAAmB;AAC7B"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { DimensionKey, Granularity, MetricKey } from "./contract.js";
|
|
1
|
+
import { DimensionKey, FilterOperator, Granularity, MetricKey } from "./contract.js";
|
|
2
2
|
|
|
3
3
|
//#region src/core/capabilities.d.ts
|
|
4
4
|
interface CapabilityRequirement {
|
|
5
5
|
metrics?: MetricKey[];
|
|
6
6
|
dimensions?: DimensionKey[];
|
|
7
|
+
filters?: DimensionKey[];
|
|
8
|
+
filterOperators?: FilterOperator[];
|
|
7
9
|
realtime?: boolean;
|
|
8
10
|
perPageQuery?: boolean;
|
|
9
11
|
}
|
|
@@ -11,6 +13,8 @@ interface CapabilityRequirement {
|
|
|
11
13
|
type SerializedCapabilities = {
|
|
12
14
|
metrics: MetricKey[];
|
|
13
15
|
dimensions: DimensionKey[];
|
|
16
|
+
filters: DimensionKey[];
|
|
17
|
+
filterOperators: FilterOperator[];
|
|
14
18
|
realtime: boolean;
|
|
15
19
|
realtimeWindowMinutes?: number;
|
|
16
20
|
perPageQuery: boolean;
|
|
@@ -4,11 +4,15 @@ function satisfiesCapabilities(caps, req) {
|
|
|
4
4
|
if (req.perPageQuery && !caps.perPageQuery) return false;
|
|
5
5
|
if (req.metrics?.some((m) => !caps.metrics.has(m))) return false;
|
|
6
6
|
if (req.dimensions?.some((d) => !caps.dimensions.has(d))) return false;
|
|
7
|
+
if (req.filters?.some((d) => !caps.filters.has(d))) return false;
|
|
8
|
+
if (req.filterOperators?.some((op) => !caps.filterOperators.has(op))) return false;
|
|
7
9
|
return true;
|
|
8
10
|
}
|
|
9
11
|
const serializeCapabilities = (caps) => ({
|
|
10
12
|
metrics: [...caps.metrics],
|
|
11
13
|
dimensions: [...caps.dimensions],
|
|
14
|
+
filters: [...caps.filters],
|
|
15
|
+
filterOperators: [...caps.filterOperators],
|
|
12
16
|
realtime: caps.realtime,
|
|
13
17
|
...caps.realtimeWindowMinutes !== void 0 ? { realtimeWindowMinutes: caps.realtimeWindowMinutes } : {},
|
|
14
18
|
perPageQuery: caps.perPageQuery,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.js","names":[],"sources":["../../src/core/capabilities.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"capabilities.js","names":[],"sources":["../../src/core/capabilities.ts"],"sourcesContent":["import type {\n\tAnalyticsCapabilities,\n\tDimensionKey,\n\tFilterOperator,\n\tGranularity,\n\tMetricKey,\n} from './contract'\n\nexport interface CapabilityRequirement {\n\tmetrics?: MetricKey[]\n\tdimensions?: DimensionKey[]\n\tfilters?: DimensionKey[]\n\tfilterOperators?: FilterOperator[]\n\trealtime?: boolean\n\tperPageQuery?: boolean\n}\n\nexport function satisfiesCapabilities(\n\tcaps: AnalyticsCapabilities,\n\treq: CapabilityRequirement\n): boolean {\n\tif (req.realtime && !caps.realtime) return false\n\tif (req.perPageQuery && !caps.perPageQuery) return false\n\tif (req.metrics?.some((m) => !caps.metrics.has(m))) return false\n\tif (req.dimensions?.some((d) => !caps.dimensions.has(d))) return false\n\tif (req.filters?.some((d) => !caps.filters.has(d))) return false\n\tif (req.filterOperators?.some((op) => !caps.filterOperators.has(op))) return false\n\treturn true\n}\n\n/** Wire form of AnalyticsCapabilities for client pickers: a deliberate allowlist, so adapter internals (rate limits, TTLs) never become client contract by accident. */\nexport type SerializedCapabilities = {\n\tmetrics: MetricKey[]\n\tdimensions: DimensionKey[]\n\tfilters: DimensionKey[]\n\tfilterOperators: FilterOperator[]\n\trealtime: boolean\n\trealtimeWindowMinutes?: number\n\tperPageQuery: boolean\n\tcomparison: boolean\n\tminGranularity: Granularity\n\tmaxLookbackDays: number | null\n}\n\nexport const serializeCapabilities = (caps: AnalyticsCapabilities): SerializedCapabilities => ({\n\tmetrics: [...caps.metrics],\n\tdimensions: [...caps.dimensions],\n\tfilters: [...caps.filters],\n\tfilterOperators: [...caps.filterOperators],\n\trealtime: caps.realtime,\n\t...(caps.realtimeWindowMinutes !== undefined\n\t\t? { realtimeWindowMinutes: caps.realtimeWindowMinutes }\n\t\t: {}),\n\tperPageQuery: caps.perPageQuery,\n\tcomparison: caps.comparison,\n\tminGranularity: caps.minGranularity,\n\tmaxLookbackDays: caps.maxLookbackDays,\n})\n"],"mappings":";AAiBA,SAAgB,sBACf,MACA,KACU;CACV,IAAI,IAAI,YAAY,CAAC,KAAK,UAAU,OAAO;CAC3C,IAAI,IAAI,gBAAgB,CAAC,KAAK,cAAc,OAAO;CACnD,IAAI,IAAI,SAAS,MAAM,MAAM,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,GAAG,OAAO;CAC3D,IAAI,IAAI,YAAY,MAAM,MAAM,CAAC,KAAK,WAAW,IAAI,CAAC,CAAC,GAAG,OAAO;CACjE,IAAI,IAAI,SAAS,MAAM,MAAM,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,GAAG,OAAO;CAC3D,IAAI,IAAI,iBAAiB,MAAM,OAAO,CAAC,KAAK,gBAAgB,IAAI,EAAE,CAAC,GAAG,OAAO;CAC7E,OAAO;AACR;AAgBA,MAAa,yBAAyB,UAAyD;CAC9F,SAAS,CAAC,GAAG,KAAK,OAAO;CACzB,YAAY,CAAC,GAAG,KAAK,UAAU;CAC/B,SAAS,CAAC,GAAG,KAAK,OAAO;CACzB,iBAAiB,CAAC,GAAG,KAAK,eAAe;CACzC,UAAU,KAAK;CACf,GAAI,KAAK,0BAA0B,KAAA,IAChC,EAAE,uBAAuB,KAAK,sBAAsB,IACpD,CAAC;CACJ,cAAc,KAAK;CACnB,YAAY,KAAK;CACjB,gBAAgB,KAAK;CACrB,iBAAiB,KAAK;AACvB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/core/capture.d.ts
|
|
2
|
+
/** One rewrite the runtime proxy endpoint answers, source pattern to vendor upstream. */
|
|
3
|
+
interface ProxyRoute {
|
|
4
|
+
source: string;
|
|
5
|
+
upstream: string;
|
|
6
|
+
}
|
|
7
|
+
/** Routes a Next rewrites helper and the runtime proxy endpoint both consume. */
|
|
8
|
+
interface ProxyDescriptor {
|
|
9
|
+
routes: ProxyRoute[];
|
|
10
|
+
forwardHeaders?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* The vendor serves some paths only with a trailing slash (PostHog's capture
|
|
13
|
+
* endpoints). Both slash forms always match; this decides what reaches the vendor:
|
|
14
|
+
* true keeps the request's trailing slash on the upstream path, absent or false
|
|
15
|
+
* normalizes it away. Next apps proxying such a vendor through rewrites also need
|
|
16
|
+
* `skipTrailingSlashRedirect: true`.
|
|
17
|
+
*/
|
|
18
|
+
trailingSlashes?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface SnippetScript {
|
|
21
|
+
src?: string;
|
|
22
|
+
inline?: string;
|
|
23
|
+
attrs?: Record<string, string>;
|
|
24
|
+
async?: boolean;
|
|
25
|
+
defer?: boolean;
|
|
26
|
+
type?: string;
|
|
27
|
+
}
|
|
28
|
+
interface CaptureSnippet {
|
|
29
|
+
scripts: SnippetScript[];
|
|
30
|
+
}
|
|
31
|
+
type CaptureClientKind = 'native' | 'posthog' | 'plausible' | 'umami';
|
|
32
|
+
/**
|
|
33
|
+
* Pure descriptor of how a vendor's browser tracker is proxied and booted, consumed by
|
|
34
|
+
* a later runtime proxy endpoint, a Next rewrites helper, and a snippet renderer. Never
|
|
35
|
+
* carries private/secret credentials (e.g. PostHog's Query API key); only what the
|
|
36
|
+
* browser is allowed to see.
|
|
37
|
+
*/
|
|
38
|
+
interface CaptureSupport {
|
|
39
|
+
proxy: ProxyDescriptor;
|
|
40
|
+
snippet(args: {
|
|
41
|
+
path: string;
|
|
42
|
+
}): CaptureSnippet;
|
|
43
|
+
client: {
|
|
44
|
+
kind: CaptureClientKind;
|
|
45
|
+
} & Record<string, string | number | boolean>;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { CaptureClientKind, CaptureSnippet, CaptureSupport, ProxyDescriptor, ProxyRoute, SnippetScript };
|
|
49
|
+
//# sourceMappingURL=capture.d.ts.map
|
package/dist/core/contract.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Goal } from "../goals/types.js";
|
|
2
|
+
import { CaptureSupport } from "./capture.js";
|
|
1
3
|
import { Config, PayloadRequest } from "payload";
|
|
2
4
|
|
|
3
5
|
//#region src/core/contract.d.ts
|
|
@@ -7,15 +9,16 @@ import { Config, PayloadRequest } from "payload";
|
|
|
7
9
|
*/
|
|
8
10
|
declare const PLATFORM_SCOPE = "*";
|
|
9
11
|
type MetricKey = 'pageviews' | 'visitors' | 'visits' | 'sessions' | 'bounceRate' | 'avgDuration' | 'scrollDepth' | 'events' | 'conversions' | 'revenue';
|
|
10
|
-
type DimensionKey = 'page' | 'referrer' | 'source' | 'medium' | 'campaign' | 'utmSource' | 'utmMedium' | 'utmCampaign' | 'utmContent' | 'utmTerm' | 'device' | 'browser' | 'os' | 'country' | 'region' | 'city' | 'language' | 'event';
|
|
12
|
+
type DimensionKey = 'page' | 'referrer' | 'source' | 'medium' | 'campaign' | 'utmSource' | 'utmMedium' | 'utmCampaign' | 'utmContent' | 'utmTerm' | 'device' | 'browser' | 'os' | 'country' | 'region' | 'city' | 'language' | 'event' | 'goal';
|
|
11
13
|
type Granularity = 'minute' | 'hour' | 'day' | 'week' | 'month';
|
|
12
14
|
interface DateRange {
|
|
13
15
|
start: Date;
|
|
14
16
|
end: Date;
|
|
15
17
|
}
|
|
18
|
+
type FilterOperator = 'eq' | 'contains' | 'matches';
|
|
16
19
|
interface AnalyticsFilter {
|
|
17
20
|
dimension: DimensionKey;
|
|
18
|
-
operator:
|
|
21
|
+
operator: FilterOperator;
|
|
19
22
|
value: string;
|
|
20
23
|
}
|
|
21
24
|
interface AnalyticsQuery {
|
|
@@ -57,14 +60,20 @@ interface AnalyticsResult {
|
|
|
57
60
|
provider: string;
|
|
58
61
|
sampled?: boolean;
|
|
59
62
|
clamped?: boolean;
|
|
60
|
-
fetchedAt: string;
|
|
63
|
+
fetchedAt: string; /** Served from an expired cache entry because the live refresh failed. */
|
|
64
|
+
stale?: boolean;
|
|
61
65
|
};
|
|
62
66
|
}
|
|
63
67
|
interface RateLimitDescriptor {
|
|
64
68
|
requestsPerMinute?: number;
|
|
65
69
|
requestsPerHour?: number;
|
|
66
70
|
maxConcurrent?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Describes the provider's quota model for documentation; the limiter always
|
|
73
|
+
* throttles by request count regardless of this value.
|
|
74
|
+
*/
|
|
67
75
|
quotaModel?: 'requests' | 'tokens';
|
|
76
|
+
/** Documents whether reads consume the provider's write/ingest quota too. */
|
|
68
77
|
readsCountAsUsage?: boolean;
|
|
69
78
|
}
|
|
70
79
|
interface AnalyticsCapabilities {
|
|
@@ -76,6 +85,10 @@ interface AnalyticsCapabilities {
|
|
|
76
85
|
maxLookbackDays: number | null;
|
|
77
86
|
metrics: ReadonlySet<MetricKey>;
|
|
78
87
|
dimensions: ReadonlySet<DimensionKey>;
|
|
88
|
+
/** Dimensions the adapter can apply AnalyticsQuery.filters on; empty = filters unsupported. */
|
|
89
|
+
filters: ReadonlySet<DimensionKey>;
|
|
90
|
+
/** Operators the adapter honors in filters; adapters ignore filters whose operator they lack. */
|
|
91
|
+
filterOperators: ReadonlySet<FilterOperator>;
|
|
79
92
|
batchPageReport: boolean;
|
|
80
93
|
rateLimit: RateLimitDescriptor | null;
|
|
81
94
|
recommendedTtl: {
|
|
@@ -104,11 +117,27 @@ interface AdapterRegisterContext {
|
|
|
104
117
|
* rollups at ingest). Resolves to `'UTC'` when no reportingTimezone is set.
|
|
105
118
|
*/
|
|
106
119
|
resolveTimezone: (req: PayloadRequest, scope?: string | null) => Promise<string>;
|
|
120
|
+
/**
|
|
121
|
+
* The install's goals for a request's scope, for adapters that match completions
|
|
122
|
+
* themselves (the native engine, at ingest). Config goals today; a collection source
|
|
123
|
+
* merges in behind the same call.
|
|
124
|
+
*/
|
|
125
|
+
resolveGoals: (req: PayloadRequest, scope?: string | null) => Promise<Goal[]>;
|
|
107
126
|
}
|
|
108
127
|
interface AnalyticsAdapter {
|
|
109
128
|
readonly id: string;
|
|
110
129
|
readonly label: string;
|
|
111
130
|
readonly capabilities: AnalyticsCapabilities;
|
|
131
|
+
/** Browser-tracker proxying/boot descriptor. Absent when the adapter has no client-side script (GA4). */
|
|
132
|
+
readonly capture?: CaptureSupport;
|
|
133
|
+
/**
|
|
134
|
+
* Where this adapter's own ingest endpoint listens, relative to `routes.api`, for the
|
|
135
|
+
* adapters that register one (the native engine). Server-side only: the tracker learns
|
|
136
|
+
* the path from `TrackerConfig.ingestPath`, and this object is never serialized.
|
|
137
|
+
*/
|
|
138
|
+
readonly ingest?: {
|
|
139
|
+
path: string;
|
|
140
|
+
};
|
|
112
141
|
isConfigured(): boolean;
|
|
113
142
|
query(query: AnalyticsQuery, ctx: AdapterContext): Promise<AnalyticsResult>;
|
|
114
143
|
realtime?(query: AnalyticsQuery, ctx: AdapterContext): Promise<AnalyticsResult>;
|
|
@@ -116,5 +145,5 @@ interface AnalyticsAdapter {
|
|
|
116
145
|
}
|
|
117
146
|
type AnalyticsAdapterFactory<Config> = (config: Config) => AnalyticsAdapter;
|
|
118
147
|
//#endregion
|
|
119
|
-
export { AdapterContext, AdapterRegisterContext, AnalyticsAdapter, AnalyticsAdapterFactory, AnalyticsCapabilities, AnalyticsFilter, AnalyticsQuery, AnalyticsResult, AnalyticsRow, DateRange, DimensionKey, Granularity, MetricKey, PLATFORM_SCOPE, RateLimitDescriptor };
|
|
148
|
+
export { AdapterContext, AdapterRegisterContext, AnalyticsAdapter, AnalyticsAdapterFactory, AnalyticsCapabilities, AnalyticsFilter, AnalyticsQuery, AnalyticsResult, AnalyticsRow, DateRange, DimensionKey, FilterOperator, Granularity, MetricKey, PLATFORM_SCOPE, RateLimitDescriptor };
|
|
120
149
|
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","names":[],"sources":["../../src/core/contract.ts"],"sourcesContent":["import type { Config, PayloadRequest } from 'payload'\n\n/**\n * Explicit cross-scope read marker: pass as a read's `scope` to aggregate over every\n * scope. Gated by `access.platformRead`; the query reaches the adapter unscoped.\n */\nexport const PLATFORM_SCOPE = '*'\n\nexport type MetricKey =\n\t| 'pageviews'\n\t| 'visitors'\n\t| 'visits'\n\t| 'sessions'\n\t| 'bounceRate'\n\t| 'avgDuration'\n\t| 'scrollDepth'\n\t| 'events'\n\t| 'conversions'\n\t| 'revenue'\n\nexport type DimensionKey =\n\t| 'page'\n\t| 'referrer'\n\t| 'source'\n\t| 'medium'\n\t| 'campaign'\n\t| 'utmSource'\n\t| 'utmMedium'\n\t| 'utmCampaign'\n\t| 'utmContent'\n\t| 'utmTerm'\n\t| 'device'\n\t| 'browser'\n\t| 'os'\n\t| 'country'\n\t| 'region'\n\t| 'city'\n\t| 'language'\n\t| 'event'\n\nexport type Granularity = 'minute' | 'hour' | 'day' | 'week' | 'month'\n\nexport interface DateRange {\n\tstart: Date\n\tend: Date\n}\n\nexport
|
|
1
|
+
{"version":3,"file":"contract.js","names":[],"sources":["../../src/core/contract.ts"],"sourcesContent":["import type { Config, PayloadRequest } from 'payload'\nimport type { Goal } from '../goals/types'\nimport type { CaptureSupport } from './capture'\n\n/**\n * Explicit cross-scope read marker: pass as a read's `scope` to aggregate over every\n * scope. Gated by `access.platformRead`; the query reaches the adapter unscoped.\n */\nexport const PLATFORM_SCOPE = '*'\n\nexport type MetricKey =\n\t| 'pageviews'\n\t| 'visitors'\n\t| 'visits'\n\t| 'sessions'\n\t| 'bounceRate'\n\t| 'avgDuration'\n\t| 'scrollDepth'\n\t| 'events'\n\t| 'conversions'\n\t| 'revenue'\n\nexport type DimensionKey =\n\t| 'page'\n\t| 'referrer'\n\t| 'source'\n\t| 'medium'\n\t| 'campaign'\n\t| 'utmSource'\n\t| 'utmMedium'\n\t| 'utmCampaign'\n\t| 'utmContent'\n\t| 'utmTerm'\n\t| 'device'\n\t| 'browser'\n\t| 'os'\n\t| 'country'\n\t| 'region'\n\t| 'city'\n\t| 'language'\n\t| 'event'\n\t| 'goal'\n\nexport type Granularity = 'minute' | 'hour' | 'day' | 'week' | 'month'\n\nexport interface DateRange {\n\tstart: Date\n\tend: Date\n}\n\nexport type FilterOperator = 'eq' | 'contains' | 'matches'\n\nexport interface AnalyticsFilter {\n\tdimension: DimensionKey\n\toperator: FilterOperator\n\tvalue: string\n}\n\nexport interface AnalyticsQuery {\n\tpath?: string\n\thostname?: string\n\tmetrics: MetricKey[]\n\tdimensions?: DimensionKey[]\n\tdateRange: DateRange\n\tgranularity?: Granularity\n\tfilters?: AnalyticsFilter[]\n\tlimit?: number\n\torder?: { metric: MetricKey; direction: 'asc' | 'desc' }\n\t/**\n\t * Analytics boundary this read belongs to (tenant id, site key). Undefined means\n\t * install-wide (the default). Adapters that can filter by scope apply it; others\n\t * ignore it. Always part of the surfacing cache key, so per-scope adapter\n\t * instances sharing an id never share cached results.\n\t */\n\tscope?: string\n\t/**\n\t * IANA reporting timezone the read's day boundaries are aligned to. Undefined\n\t * means UTC. Adapters that can bucket in a timezone apply it (PostHog, Umami);\n\t * others report in their own account timezone. Part of the cache key when set.\n\t */\n\ttimezone?: string\n}\n\nexport interface AnalyticsRow {\n\tdimensions?: Partial<Record<DimensionKey, string>>\n\tmetrics: Partial<Record<MetricKey, number>>\n\ttimestamp?: string\n}\n\nexport interface AnalyticsResult {\n\trows: AnalyticsRow[]\n\ttotals?: Partial<Record<MetricKey, number>>\n\tmeta: {\n\t\tprovider: string\n\t\tsampled?: boolean\n\t\tclamped?: boolean\n\t\tfetchedAt: string\n\t\t/** Served from an expired cache entry because the live refresh failed. */\n\t\tstale?: boolean\n\t}\n}\n\nexport interface RateLimitDescriptor {\n\trequestsPerMinute?: number\n\trequestsPerHour?: number\n\tmaxConcurrent?: number\n\t/**\n\t * Describes the provider's quota model for documentation; the limiter always\n\t * throttles by request count regardless of this value.\n\t */\n\tquotaModel?: 'requests' | 'tokens'\n\t/** Documents whether reads consume the provider's write/ingest quota too. */\n\treadsCountAsUsage?: boolean\n}\n\nexport interface AnalyticsCapabilities {\n\tperPageQuery: boolean\n\trealtime: boolean\n\trealtimeWindowMinutes?: number\n\tcomparison: boolean\n\tminGranularity: Granularity\n\tmaxLookbackDays: number | null\n\tmetrics: ReadonlySet<MetricKey>\n\tdimensions: ReadonlySet<DimensionKey>\n\t/** Dimensions the adapter can apply AnalyticsQuery.filters on; empty = filters unsupported. */\n\tfilters: ReadonlySet<DimensionKey>\n\t/** Operators the adapter honors in filters; adapters ignore filters whose operator they lack. */\n\tfilterOperators: ReadonlySet<FilterOperator>\n\tbatchPageReport: boolean\n\trateLimit: RateLimitDescriptor | null\n\trecommendedTtl: { realtime: number; aggregate: number }\n\t/**\n\t * The adapter applies `AnalyticsQuery.scope` as a provider-native filter (native\n\t * scope column, PostHog `scopeProperty`, ...). Without it, a scoped read through\n\t * a shared platform adapter would expose cross-scope data, so such reads are\n\t * gated by `access.platformRead`.\n\t */\n\tscopedQueries?: boolean\n}\n\nexport interface AdapterContext {\n\tsignal?: AbortSignal\n}\n\n/** Extra context the plugin hands adapters when they register config surface. */\nexport interface AdapterRegisterContext {\n\t/** True when the plugin has a scopeResolver configured. */\n\tscoped: boolean\n\t/** The plugin's scopeResolver bound for adapter use (e.g. ingest stamping). */\n\tresolveScope: (req: PayloadRequest) => Promise<string | null>\n\t/**\n\t * The plugin's reportingTimezone bound for adapter use (e.g. bucketing native\n\t * rollups at ingest). Resolves to `'UTC'` when no reportingTimezone is set.\n\t */\n\tresolveTimezone: (req: PayloadRequest, scope?: string | null) => Promise<string>\n\t/**\n\t * The install's goals for a request's scope, for adapters that match completions\n\t * themselves (the native engine, at ingest). Config goals today; a collection source\n\t * merges in behind the same call.\n\t */\n\tresolveGoals: (req: PayloadRequest, scope?: string | null) => Promise<Goal[]>\n}\n\nexport interface AnalyticsAdapter {\n\treadonly id: string\n\treadonly label: string\n\treadonly capabilities: AnalyticsCapabilities\n\t/** Browser-tracker proxying/boot descriptor. Absent when the adapter has no client-side script (GA4). */\n\treadonly capture?: CaptureSupport\n\t/**\n\t * Where this adapter's own ingest endpoint listens, relative to `routes.api`, for the\n\t * adapters that register one (the native engine). Server-side only: the tracker learns\n\t * the path from `TrackerConfig.ingestPath`, and this object is never serialized.\n\t */\n\treadonly ingest?: { path: string }\n\tisConfigured(): boolean\n\tquery(query: AnalyticsQuery, ctx: AdapterContext): Promise<AnalyticsResult>\n\trealtime?(query: AnalyticsQuery, ctx: AdapterContext): Promise<AnalyticsResult>\n\tregister?(config: Config, context?: AdapterRegisterContext): void\n}\n\nexport type AnalyticsAdapterFactory<Config> = (config: Config) => AnalyticsAdapter\n"],"mappings":";;;;;AAQA,MAAa,iBAAiB"}
|
package/dist/core/options.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { Goal } from "../goals/types.js";
|
|
1
2
|
import { AnalyticsAdapter } from "./contract.js";
|
|
2
3
|
import { TranslationsOption } from "../translations/index.js";
|
|
3
4
|
import { AnalyticsBinding } from "../binding/types.js";
|
|
5
|
+
import { CaptureSlot } from "../capture/slots.js";
|
|
4
6
|
import { CustomWidgetDef } from "../widgets/customWidget.js";
|
|
5
7
|
import { CollectionConfig, CollectionSlug, Payload, PayloadRequest } from "payload";
|
|
6
8
|
import { KeysConfig } from "@10x-media/fields/encrypted";
|
|
@@ -24,6 +26,13 @@ type TimezoneResolver = (args: {
|
|
|
24
26
|
req: PayloadRequest;
|
|
25
27
|
scope: string | null;
|
|
26
28
|
}) => string | null | Promise<string | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Enumerates the tenant scopes the cron tiers (cache warming, sync) fan out over.
|
|
31
|
+
* Absent, each tier runs once for the install-wide scope.
|
|
32
|
+
*/
|
|
33
|
+
type ScopesResolver = (args: {
|
|
34
|
+
payload: Payload;
|
|
35
|
+
}) => string[] | Promise<string[]>;
|
|
27
36
|
/**
|
|
28
37
|
* Escape hatch replacing the provider-collection lookup: return the runtime
|
|
29
38
|
* adapters for a scope yourself (any store, any shape). Results are layered onto
|
|
@@ -73,6 +82,79 @@ type AnalyticsAccessOptions = {
|
|
|
73
82
|
*/
|
|
74
83
|
platformRead?: PlatformReadAccess;
|
|
75
84
|
};
|
|
85
|
+
type ConsentMode = 'none' | 'required';
|
|
86
|
+
/** Per-slot consent decision, evaluated against the slot's resolved adapter. */
|
|
87
|
+
type ConsentResolver = (args: {
|
|
88
|
+
slot: CaptureSlot;
|
|
89
|
+
adapterId: string;
|
|
90
|
+
}) => ConsentMode;
|
|
91
|
+
/** An adapter id to fill a capture slot with, or `false` to leave it deliberately empty. */
|
|
92
|
+
type CaptureSlotOption = string | false;
|
|
93
|
+
/**
|
|
94
|
+
* A bare mode applies to every slot; a resolver decides per request-resolved adapter; the
|
|
95
|
+
* object form maps ids and slots, with an adapter entry winning over a slot entry. Every
|
|
96
|
+
* form overrides the default, which is `none` for the cookieless native tracker and
|
|
97
|
+
* `required` for a vendor's.
|
|
98
|
+
*/
|
|
99
|
+
type CaptureConsentOption = ConsentMode | ConsentResolver | {
|
|
100
|
+
slots?: Partial<Record<CaptureSlot, ConsentMode>>;
|
|
101
|
+
/**
|
|
102
|
+
* Keyed by adapter id. A bare id must name a config adapter; a runtime provider
|
|
103
|
+
* instance id (`<provider>:<instance>`) is taken on trust, since the providers it
|
|
104
|
+
* comes from are only resolved per request.
|
|
105
|
+
*/
|
|
106
|
+
adapters?: Record<string, ConsentMode>;
|
|
107
|
+
};
|
|
108
|
+
type AutoCaptureOptions = {
|
|
109
|
+
scrollDepth?: boolean;
|
|
110
|
+
outboundLinks?: boolean;
|
|
111
|
+
fileDownloads?: boolean;
|
|
112
|
+
goalAttribute?: boolean;
|
|
113
|
+
};
|
|
114
|
+
type ResolvedAutoCapture = Required<AutoCaptureOptions>;
|
|
115
|
+
/** Goals as config: the array form, or the object form 1b grows a collection source on. */
|
|
116
|
+
type AnalyticsGoalsOptions = {
|
|
117
|
+
defaults?: Goal[];
|
|
118
|
+
};
|
|
119
|
+
type AnalyticsCaptureOptions = {
|
|
120
|
+
/**
|
|
121
|
+
* Which adapter fills each capture slot, overriding the defaults: `global` is the
|
|
122
|
+
* designated `platformAdapter`, or the single config adapter when only one is
|
|
123
|
+
* configured; `tenant` is the resolved scope's default adapter. A `global` id must
|
|
124
|
+
* name a config adapter; a `tenant` id may also name a runtime provider instance,
|
|
125
|
+
* so it is resolved per request rather than validated at config time.
|
|
126
|
+
*
|
|
127
|
+
* `false` disables a slot outright: it fills with nothing, its proxy mount 404s, and
|
|
128
|
+
* the tracker config omits it. Use it to keep a default from filling a slot at all.
|
|
129
|
+
*/
|
|
130
|
+
slots?: {
|
|
131
|
+
global?: CaptureSlotOption;
|
|
132
|
+
tenant?: CaptureSlotOption;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Mount each slot's snippet points at. Defaults to the runtime proxy endpoint
|
|
136
|
+
* (`<routes.api>/analytics/p/<slot>`); set it when the slot is served through Next
|
|
137
|
+
* rewrites instead, passing the same path `captureRewrites` was mounted at.
|
|
138
|
+
*/
|
|
139
|
+
paths?: {
|
|
140
|
+
global?: string;
|
|
141
|
+
tenant?: string;
|
|
142
|
+
}; /** Whether a slot's tracker waits for consent. Native defaults to no gate, vendors to one. */
|
|
143
|
+
consent?: CaptureConsentOption; /** Browser auto-capture listeners, all on by default except `scrollDepth`. */
|
|
144
|
+
autoCapture?: AutoCaptureOptions; /** Limits for the public runtime capture proxy, separate from the read-path `cache`. */
|
|
145
|
+
proxy?: {
|
|
146
|
+
/**
|
|
147
|
+
* Deadline for the upstream response headers, in ms. Default 10000. The body
|
|
148
|
+
* download is not on the clock, so a large tracker bundle streams to completion.
|
|
149
|
+
*/
|
|
150
|
+
timeoutMs?: number;
|
|
151
|
+
/**
|
|
152
|
+
* Largest proxied request body, in bytes. Default 1 MiB, which clears a PostHog
|
|
153
|
+
* batch carrying session-replay data. Anything larger is refused with 413.
|
|
154
|
+
*/
|
|
155
|
+
maxBodyBytes?: number;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
76
158
|
type AnalyticsPluginOptions = {
|
|
77
159
|
disabled?: boolean;
|
|
78
160
|
/**
|
|
@@ -85,6 +167,12 @@ type AnalyticsPluginOptions = {
|
|
|
85
167
|
adapters?: AnalyticsAdapter[];
|
|
86
168
|
defaultAdapter?: string;
|
|
87
169
|
scopeResolver?: ScopeResolver;
|
|
170
|
+
/**
|
|
171
|
+
* Enumerates the tenant scopes the cache-warming and sync cron tiers fan out
|
|
172
|
+
* over, in addition to the install-wide (null) scope every tier already runs.
|
|
173
|
+
* Unset, those tiers run once for the whole install, same as before.
|
|
174
|
+
*/
|
|
175
|
+
scopes?: ScopesResolver;
|
|
88
176
|
/**
|
|
89
177
|
* IANA reporting timezone that day boundaries (timeframe windows, series axes,
|
|
90
178
|
* native rollup buckets) align to. Defaults to UTC. A string forces one timezone
|
|
@@ -103,6 +191,12 @@ type AnalyticsPluginOptions = {
|
|
|
103
191
|
*/
|
|
104
192
|
platformAdapter?: string;
|
|
105
193
|
access?: AnalyticsAccessOptions;
|
|
194
|
+
capture?: AnalyticsCaptureOptions;
|
|
195
|
+
/**
|
|
196
|
+
* Conversion goals the tracker and the native ingest match events against. Slugs must
|
|
197
|
+
* be unique and kebab-case; only the slug and its match reach the browser.
|
|
198
|
+
*/
|
|
199
|
+
goals?: Goal[] | AnalyticsGoalsOptions;
|
|
106
200
|
/**
|
|
107
201
|
* Per-collection bindings, keyed by collection slug. With generated types
|
|
108
202
|
* augmented, each slug's resolvers receive that collection's typed document.
|
|
@@ -115,7 +209,8 @@ type AnalyticsPluginOptions = {
|
|
|
115
209
|
};
|
|
116
210
|
warm?: boolean | {
|
|
117
211
|
cron?: string;
|
|
118
|
-
};
|
|
212
|
+
}; /** Per-read provider timeout in ms, spanning retries and limiter waits. Default 15000. */
|
|
213
|
+
timeoutMs?: number;
|
|
119
214
|
};
|
|
120
215
|
widgets?: boolean | {
|
|
121
216
|
disabled?: string[];
|
|
@@ -148,5 +243,5 @@ type AnalyticsPluginOptions = {
|
|
|
148
243
|
};
|
|
149
244
|
};
|
|
150
245
|
//#endregion
|
|
151
|
-
export { AnalyticsAccessOptions, AnalyticsPluginOptions, PlatformReadAccess, ProvidersCollectionOptions, ProvidersOptions, ProvidersResolve, ScopeResolver, TimezoneResolver };
|
|
246
|
+
export { AnalyticsAccessOptions, AnalyticsCaptureOptions, AnalyticsGoalsOptions, AnalyticsPluginOptions, AutoCaptureOptions, CaptureConsentOption, ConsentMode, ConsentResolver, PlatformReadAccess, ProvidersCollectionOptions, ProvidersOptions, ProvidersResolve, ResolvedAutoCapture, ScopeResolver, ScopesResolver, TimezoneResolver };
|
|
152
247
|
//# sourceMappingURL=options.d.ts.map
|
package/dist/core/options.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import "../capture/proxyEndpoint.js";
|
|
2
|
+
import { GOAL_SLUG_PATTERN } from "../goals/types.js";
|
|
1
3
|
import { PROVIDERS_SLUG } from "../providers/collection.js";
|
|
2
4
|
//#region src/core/options.ts
|
|
3
5
|
const DEFAULT_WARM_CRON = "*/30 * * * *";
|
|
@@ -5,6 +7,43 @@ const DEFAULT_SYNC_CRON = "0 */6 * * *";
|
|
|
5
7
|
const DEFAULT_SYNC_COLLECTION = "analytics-daily";
|
|
6
8
|
const DEFAULT_SYNC_LOOKBACK = 3;
|
|
7
9
|
const DEFAULT_SCOPE_FIELD = "scope";
|
|
10
|
+
const DEFAULT_TIMEOUT_MS = 15e3;
|
|
11
|
+
/** Scroll depth is the one listener off by default: it fires on every page, for every visitor. */
|
|
12
|
+
const DEFAULT_AUTO_CAPTURE = {
|
|
13
|
+
scrollDepth: false,
|
|
14
|
+
outboundLinks: true,
|
|
15
|
+
fileDownloads: true,
|
|
16
|
+
goalAttribute: true
|
|
17
|
+
};
|
|
18
|
+
const resolveAutoCapture = (option) => ({
|
|
19
|
+
scrollDepth: option?.scrollDepth ?? DEFAULT_AUTO_CAPTURE.scrollDepth,
|
|
20
|
+
outboundLinks: option?.outboundLinks ?? DEFAULT_AUTO_CAPTURE.outboundLinks,
|
|
21
|
+
fileDownloads: option?.fileDownloads ?? DEFAULT_AUTO_CAPTURE.fileDownloads,
|
|
22
|
+
goalAttribute: option?.goalAttribute ?? DEFAULT_AUTO_CAPTURE.goalAttribute
|
|
23
|
+
});
|
|
24
|
+
/** Cookieless native capture needs no consent gate; a vendor's tracker does. */
|
|
25
|
+
const defaultConsentFor = (kind) => kind === "native" ? "none" : "required";
|
|
26
|
+
const resolveConsent = (option, adapters) => {
|
|
27
|
+
if (option === "none" || option === "required") return () => option;
|
|
28
|
+
if (typeof option === "function") return (slot, adapterId) => option({
|
|
29
|
+
slot,
|
|
30
|
+
adapterId
|
|
31
|
+
});
|
|
32
|
+
for (const id of Object.keys(option?.adapters ?? {})) if (!id.includes(":") && !adapters.some((a) => a.id === id)) throw new Error(`analytics: unknown consent adapter "${id}"`);
|
|
33
|
+
return (slot, adapterId, kind) => option?.adapters?.[adapterId] ?? option?.slots?.[slot] ?? defaultConsentFor(kind);
|
|
34
|
+
};
|
|
35
|
+
const resolveGoals = (option) => {
|
|
36
|
+
const goals = Array.isArray(option) ? option : option?.defaults ?? [];
|
|
37
|
+
const seen = /* @__PURE__ */ new Set();
|
|
38
|
+
for (const goal of goals) {
|
|
39
|
+
if (!GOAL_SLUG_PATTERN.test(goal.slug)) throw new Error(`analytics: goal slug "${goal.slug}" must be kebab-case`);
|
|
40
|
+
if (seen.has(goal.slug)) throw new Error(`analytics: duplicate goal slug "${goal.slug}"`);
|
|
41
|
+
const fixed = goal.value?.fixed;
|
|
42
|
+
if (fixed !== void 0 && (!Number.isFinite(fixed) || fixed < 0)) throw new Error(`analytics: goal "${goal.slug}" value.fixed must be a finite number >= 0, got ${String(fixed)}`);
|
|
43
|
+
seen.add(goal.slug);
|
|
44
|
+
}
|
|
45
|
+
return goals;
|
|
46
|
+
};
|
|
8
47
|
const resolveBindings = (collections) => {
|
|
9
48
|
const out = {};
|
|
10
49
|
for (const [slug, binding] of Object.entries(collections ?? {})) {
|
|
@@ -17,6 +56,9 @@ const resolveBindings = (collections) => {
|
|
|
17
56
|
function resolveOptions(options) {
|
|
18
57
|
if (!options.adapters || options.adapters.length === 0) throw new Error("analytics: at least one adapter is required");
|
|
19
58
|
if (options.platformAdapter !== void 0 && !options.adapters.some((a) => a.id === options.platformAdapter)) throw new Error(`analytics: unknown platform adapter "${options.platformAdapter}"`);
|
|
59
|
+
for (const [slot, value] of Object.entries(options.capture?.slots ?? {})) if (value !== false && typeof value !== "string" && value !== void 0) throw new Error(`analytics: capture slot "${slot}" must be an adapter id or false, got ${typeof value}`);
|
|
60
|
+
const globalSlot = options.capture?.slots?.global;
|
|
61
|
+
if (typeof globalSlot === "string" && !options.adapters.some((a) => a.id === globalSlot)) throw new Error(`analytics: unknown global capture slot adapter "${globalSlot}"`);
|
|
20
62
|
const widgets = options.widgets === false ? {
|
|
21
63
|
enabled: false,
|
|
22
64
|
disabled: [],
|
|
@@ -98,9 +140,27 @@ function resolveOptions(options) {
|
|
|
98
140
|
defaultAdapter: options.defaultAdapter,
|
|
99
141
|
scopeResolver: options.scopeResolver ?? (() => null),
|
|
100
142
|
scoped,
|
|
143
|
+
scopes: options.scopes,
|
|
101
144
|
reportingTimezone: options.reportingTimezone,
|
|
102
145
|
platformAdapter: options.platformAdapter,
|
|
103
146
|
access: { platformRead: options.access?.platformRead ?? (scoped ? () => false : ({ req }) => Boolean(req.user)) },
|
|
147
|
+
capture: {
|
|
148
|
+
slots: {
|
|
149
|
+
global: options.capture?.slots?.global,
|
|
150
|
+
tenant: options.capture?.slots?.tenant
|
|
151
|
+
},
|
|
152
|
+
paths: {
|
|
153
|
+
global: options.capture?.paths?.global,
|
|
154
|
+
tenant: options.capture?.paths?.tenant
|
|
155
|
+
},
|
|
156
|
+
consent: resolveConsent(options.capture?.consent, options.adapters),
|
|
157
|
+
autoCapture: resolveAutoCapture(options.capture?.autoCapture),
|
|
158
|
+
proxy: {
|
|
159
|
+
timeoutMs: options.capture?.proxy?.timeoutMs ?? 1e4,
|
|
160
|
+
maxBodyBytes: options.capture?.proxy?.maxBodyBytes ?? 1048576
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
goals: resolveGoals(options.goals),
|
|
104
164
|
providers,
|
|
105
165
|
bindings: resolveBindings(options.collections),
|
|
106
166
|
cache: {
|
|
@@ -108,13 +168,14 @@ function resolveOptions(options) {
|
|
|
108
168
|
aggregate: options.cache?.ttl?.aggregate,
|
|
109
169
|
realtime: options.cache?.ttl?.realtime
|
|
110
170
|
},
|
|
111
|
-
warm
|
|
171
|
+
warm,
|
|
172
|
+
timeoutMs: options.cache?.timeoutMs ?? DEFAULT_TIMEOUT_MS
|
|
112
173
|
},
|
|
113
174
|
widgets,
|
|
114
175
|
sync
|
|
115
176
|
};
|
|
116
177
|
}
|
|
117
178
|
//#endregion
|
|
118
|
-
export { resolveOptions };
|
|
179
|
+
export { DEFAULT_AUTO_CAPTURE, defaultConsentFor, resolveOptions };
|
|
119
180
|
|
|
120
181
|
//# sourceMappingURL=options.js.map
|