@10x-media/analytics 1.0.0-beta.7 → 1.0.0-beta.9
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 +118 -0
- package/LICENSE +21 -21
- package/README.md +10 -4
- package/dist/adapters/ga4/eventName.d.ts +15 -0
- package/dist/adapters/ga4/eventName.js +19 -0
- package/dist/adapters/ga4/eventName.js.map +1 -0
- package/dist/adapters/ga4/ga4.d.ts +5 -0
- package/dist/adapters/ga4/ga4.js +179 -70
- package/dist/adapters/ga4/ga4.js.map +1 -1
- package/dist/adapters/ga4/measurementId.js +15 -0
- package/dist/adapters/ga4/measurementId.js.map +1 -0
- package/dist/adapters/goalRead.js +126 -0
- package/dist/adapters/goalRead.js.map +1 -0
- package/dist/adapters/plausible/plausible.d.ts +15 -0
- package/dist/adapters/plausible/plausible.js +112 -43
- package/dist/adapters/plausible/plausible.js.map +1 -1
- package/dist/adapters/posthog/posthog.js +47 -25
- package/dist/adapters/posthog/posthog.js.map +1 -1
- package/dist/adapters/umami/umami.d.ts +8 -0
- package/dist/adapters/umami/umami.js +237 -28
- package/dist/adapters/umami/umami.js.map +1 -1
- package/dist/capture/slots.js +16 -5
- package/dist/capture/slots.js.map +1 -1
- package/dist/capture/trackerConfig.d.ts +1 -0
- package/dist/capture/trackerConfig.js +28 -3
- package/dist/capture/trackerConfig.js.map +1 -1
- package/dist/charts/BarList.d.ts +15 -1
- package/dist/charts/BarList.js +41 -19
- package/dist/charts/BarList.js.map +1 -1
- package/dist/charts/TrendChart.d.ts +16 -3
- package/dist/charts/TrendChart.js +172 -106
- package/dist/charts/TrendChart.js.map +1 -1
- package/dist/charts/bars.d.ts +2 -0
- package/dist/charts/bars.js +2 -1
- package/dist/charts/bars.js.map +1 -1
- package/dist/charts/bucket.js +10 -1
- package/dist/charts/bucket.js.map +1 -1
- package/dist/charts/spline.js +2 -2
- package/dist/charts/spline.js.map +1 -1
- package/dist/charts/styles.js +18 -1
- package/dist/charts/styles.js.map +1 -1
- package/dist/core/cacheKey.js +24 -2
- package/dist/core/cacheKey.js.map +1 -1
- package/dist/core/capabilities.js +7 -2
- package/dist/core/capabilities.js.map +1 -1
- package/dist/core/capture.d.ts +1 -1
- package/dist/core/contract.d.ts +46 -9
- package/dist/core/contract.js +29 -1
- package/dist/core/contract.js.map +1 -1
- package/dist/core/granularity.js +1 -1
- package/dist/core/options.d.ts +62 -7
- package/dist/core/options.js +63 -4
- package/dist/core/options.js.map +1 -1
- package/dist/core/scopedRead.js +33 -23
- package/dist/core/scopedRead.js.map +1 -1
- package/dist/core/serverEvent.d.ts +44 -0
- package/dist/core/serverEvent.js +12 -0
- package/dist/core/serverEvent.js.map +1 -0
- package/dist/exports/adapters/ga4.d.ts +2 -1
- package/dist/exports/adapters/ga4.js +2 -1
- package/dist/exports/client.d.ts +12 -3
- package/dist/exports/client.js +9 -1
- package/dist/exports/rsc.d.ts +7 -2
- package/dist/exports/rsc.js +6 -3
- package/dist/exports/tracker.d.ts +3 -2
- package/dist/exports/tracker.js +2 -1
- package/dist/exports/types.d.ts +13 -4
- package/dist/exports/types.js +3 -2
- package/dist/fields/AnalyticsPanelClient.js +1 -1
- package/dist/fields/AnalyticsPanelField.js +1 -1
- package/dist/fields/AnalyticsStatField.js +2 -2
- package/dist/fields/config/FilterDimensionSelectField.d.ts +14 -0
- package/dist/fields/config/FilterDimensionSelectField.js +77 -0
- package/dist/fields/config/FilterDimensionSelectField.js.map +1 -0
- package/dist/fields/config/FilterOperatorSelectField.d.ts +14 -0
- package/dist/fields/config/FilterOperatorSelectField.js +75 -0
- package/dist/fields/config/FilterOperatorSelectField.js.map +1 -0
- package/dist/fields/config/MetricSelectField.js +3 -3
- package/dist/fields/config/MetricSelectField.js.map +1 -1
- package/dist/fields/config/SourceSelectField.js +3 -3
- package/dist/fields/config/SourceSelectField.js.map +1 -1
- package/dist/fields/config/fetchSources.d.ts +5 -1
- package/dist/fields/config/sourcesState.js +19 -3
- package/dist/fields/config/sourcesState.js.map +1 -1
- package/dist/fields/config/useAnalyticsSources.d.ts +8 -3
- package/dist/fields/config/useAnalyticsSources.js +9 -6
- package/dist/fields/config/useAnalyticsSources.js.map +1 -1
- package/dist/fields/config/useFilterCapabilities.d.ts +28 -0
- package/dist/fields/config/useFilterCapabilities.js +52 -0
- package/dist/fields/config/useFilterCapabilities.js.map +1 -0
- package/dist/fields/readForDocument.d.ts +5 -0
- package/dist/fields/readForDocument.js +21 -9
- package/dist/fields/readForDocument.js.map +1 -1
- package/dist/goals/GoalSelectField.d.ts +7 -0
- package/dist/goals/GoalSelectField.js +77 -0
- package/dist/goals/GoalSelectField.js.map +1 -0
- package/dist/goals/collection.js +250 -0
- package/dist/goals/collection.js.map +1 -0
- package/dist/goals/currency.js +14 -0
- package/dist/goals/currency.js.map +1 -0
- package/dist/goals/fetchGoals.d.ts +18 -0
- package/dist/goals/fetchGoals.js +29 -0
- package/dist/goals/fetchGoals.js.map +1 -0
- package/dist/goals/goalField.d.ts +31 -0
- package/dist/goals/goalField.js +56 -0
- package/dist/goals/goalField.js.map +1 -0
- package/dist/goals/goalsEndpoint.d.ts +1 -0
- package/dist/goals/goalsEndpoint.js +55 -0
- package/dist/goals/goalsEndpoint.js.map +1 -0
- package/dist/goals/resolver.d.ts +8 -0
- package/dist/goals/resolver.js +147 -0
- package/dist/goals/resolver.js.map +1 -0
- package/dist/goals/trackGoalAction.d.ts +74 -0
- package/dist/goals/trackGoalAction.js +139 -0
- package/dist/goals/trackGoalAction.js.map +1 -0
- package/dist/goals/useAnalyticsGoals.d.ts +20 -0
- package/dist/goals/useAnalyticsGoals.js +67 -0
- package/dist/goals/useAnalyticsGoals.js.map +1 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.js +75 -11
- package/dist/index.js.map +1 -1
- package/dist/native/collections/events.js +36 -0
- package/dist/native/collections/events.js.map +1 -1
- package/dist/native/eventScan.js +25 -0
- package/dist/native/eventScan.js.map +1 -0
- package/dist/native/ingest/browser.js +47 -0
- package/dist/native/ingest/browser.js.map +1 -0
- package/dist/native/ingest/device.js +11 -3
- package/dist/native/ingest/device.js.map +1 -1
- package/dist/native/ingest/endpoint.d.ts +1 -0
- package/dist/native/ingest/endpoint.js +2 -17
- package/dist/native/ingest/endpoint.js.map +1 -1
- package/dist/native/ingest/flushBatch.js +26 -26
- package/dist/native/ingest/flushBatch.js.map +1 -1
- package/dist/native/ingest/language.js +14 -0
- package/dist/native/ingest/language.js.map +1 -0
- package/dist/native/ingest/normalizeEvent.d.ts +26 -0
- package/dist/native/ingest/normalizeEvent.js +35 -7
- package/dist/native/ingest/normalizeEvent.js.map +1 -1
- package/dist/native/ingest/referrer.js +48 -0
- package/dist/native/ingest/referrer.js.map +1 -0
- package/dist/native/ingest/serverTrack.d.ts +20 -0
- package/dist/native/ingest/serverTrack.js +100 -0
- package/dist/native/ingest/serverTrack.js.map +1 -0
- package/dist/native/ingest/source.d.ts +7 -0
- package/dist/native/ingest/source.js +139 -14
- package/dist/native/ingest/source.js.map +1 -1
- package/dist/native/ingest/utm.js +33 -0
- package/dist/native/ingest/utm.js.map +1 -0
- package/dist/native/ingest/validate.js +27 -0
- package/dist/native/ingest/validate.js.map +1 -0
- package/dist/native/nativeAdapter.d.ts +1 -1
- package/dist/native/nativeAdapter.js +53 -36
- package/dist/native/nativeAdapter.js.map +1 -1
- package/dist/native/query/eventAgg.js +14 -1
- package/dist/native/query/eventAgg.js.map +1 -1
- package/dist/native/retention/pruneTask.js +1 -1
- package/dist/native/rollups/bucketKey.js +15 -0
- package/dist/native/rollups/bucketKey.js.map +1 -0
- package/dist/native/rollups/bumpRollups.js +116 -0
- package/dist/native/rollups/bumpRollups.js.map +1 -0
- package/dist/native/rollups/deltas.js +30 -15
- package/dist/native/rollups/deltas.js.map +1 -1
- package/dist/native/rollups/insertManyIfNew.js +93 -0
- package/dist/native/rollups/insertManyIfNew.js.map +1 -0
- package/dist/next/captureRewrites.d.ts +3 -2
- package/dist/next/captureRewrites.js +3 -2
- package/dist/next/captureRewrites.js.map +1 -1
- package/dist/plugin/documentEndpoint.js +52 -15
- package/dist/plugin/documentEndpoint.js.map +1 -1
- package/dist/plugin/goalHint.d.ts +1 -0
- package/dist/plugin/goalHint.js +24 -0
- package/dist/plugin/goalHint.js.map +1 -0
- package/dist/plugin/paths.js +5 -1
- package/dist/plugin/paths.js.map +1 -1
- package/dist/plugin/queryEndpoint.js +120 -0
- package/dist/plugin/queryEndpoint.js.map +1 -0
- package/dist/plugin/readContextForRequest.js +71 -0
- package/dist/plugin/readContextForRequest.js.map +1 -0
- package/dist/plugin/realtimeEndpoint.js +43 -15
- package/dist/plugin/realtimeEndpoint.js.map +1 -1
- package/dist/plugin/responses.js +17 -0
- package/dist/plugin/responses.js.map +1 -0
- package/dist/plugin/runtime.js +31 -1
- package/dist/plugin/runtime.js.map +1 -1
- package/dist/plugin/scopeFieldBoot.js +22 -0
- package/dist/plugin/scopeFieldBoot.js.map +1 -0
- package/dist/plugin/sourcesEndpoint.js +21 -52
- 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 +29 -13
- package/dist/providers/collection.js.map +1 -1
- package/dist/providers/factory.js +4 -2
- package/dist/providers/factory.js.map +1 -1
- package/dist/providers/resolver.js.map +1 -1
- package/dist/query/dates.js +64 -0
- package/dist/query/dates.js.map +1 -0
- package/dist/query/errors.d.ts +17 -0
- package/dist/query/errors.js +10 -0
- package/dist/query/errors.js.map +1 -0
- package/dist/query/fetchQuery.d.ts +59 -0
- package/dist/query/fetchQuery.js +110 -0
- package/dist/query/fetchQuery.js.map +1 -0
- package/dist/query/parse.d.ts +22 -0
- package/dist/query/parse.js +168 -0
- package/dist/query/parse.js.map +1 -0
- package/dist/query/response.d.ts +39 -0
- package/dist/query/response.js +11 -0
- package/dist/query/response.js.map +1 -0
- package/dist/surfacing/engine.js +1 -1
- package/dist/surfacing/engine.js.map +1 -1
- package/dist/testing/memoryAdapter.js +0 -1
- package/dist/testing/memoryAdapter.js.map +1 -1
- package/dist/timeframe/tz.js +17 -6
- package/dist/timeframe/tz.js.map +1 -1
- package/dist/tracker/createTracker.js +13 -1
- package/dist/tracker/createTracker.js.map +1 -1
- package/dist/tracker/sinks/ga4.d.ts +21 -0
- package/dist/tracker/sinks/ga4.js +26 -0
- package/dist/tracker/sinks/ga4.js.map +1 -0
- package/dist/tracker/types.d.ts +5 -0
- package/dist/translations/ar.js +127 -1
- package/dist/translations/ar.js.map +1 -1
- package/dist/translations/de.js +127 -1
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +127 -1
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +127 -1
- package/dist/translations/es.js.map +1 -1
- package/dist/translations/fr.js +127 -1
- package/dist/translations/fr.js.map +1 -1
- package/dist/translations/id.js +127 -1
- package/dist/translations/id.js.map +1 -1
- package/dist/translations/keys.d.ts +126 -0
- package/dist/translations/keys.js +127 -1
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +127 -1
- package/dist/translations/ko.js.map +1 -1
- package/dist/translations/metricKeys.js +8 -2
- package/dist/translations/metricKeys.js.map +1 -1
- package/dist/translations/pt.js +127 -1
- package/dist/translations/pt.js.map +1 -1
- package/dist/translations/ru.js +127 -1
- package/dist/translations/ru.js.map +1 -1
- package/dist/translations/server.js.map +1 -1
- package/dist/translations/uk.js +127 -1
- package/dist/translations/uk.js.map +1 -1
- package/dist/translations/zh.js +127 -1
- package/dist/translations/zh.js.map +1 -1
- package/dist/view/AnalyticsNavLink.d.ts +19 -0
- package/dist/view/AnalyticsNavLink.js +40 -0
- package/dist/view/AnalyticsNavLink.js.map +1 -0
- package/dist/view/AnalyticsView.d.ts +23 -0
- package/dist/view/AnalyticsView.js +45 -0
- package/dist/view/AnalyticsView.js.map +1 -0
- package/dist/view/AnalyticsViewClient.d.ts +15 -0
- package/dist/view/AnalyticsViewClient.js +200 -0
- package/dist/view/AnalyticsViewClient.js.map +1 -0
- package/dist/view/authRedirect.js +32 -0
- package/dist/view/authRedirect.js.map +1 -0
- package/dist/view/conversionRate.js +18 -0
- package/dist/view/conversionRate.js.map +1 -0
- package/dist/view/dayRange.js +68 -0
- package/dist/view/dayRange.js.map +1 -0
- package/dist/view/gating.d.ts +1 -0
- package/dist/view/gating.js +142 -0
- package/dist/view/gating.js.map +1 -0
- package/dist/view/labels.js +64 -0
- package/dist/view/labels.js.map +1 -0
- package/dist/view/registerView.js +48 -0
- package/dist/view/registerView.js.map +1 -0
- package/dist/view/sections/Breakdowns.js +197 -0
- package/dist/view/sections/Breakdowns.js.map +1 -0
- package/dist/view/sections/EmptyStates.js +92 -0
- package/dist/view/sections/EmptyStates.js.map +1 -0
- package/dist/view/sections/FilterChips.js +46 -0
- package/dist/view/sections/FilterChips.js.map +1 -0
- package/dist/view/sections/GoalsPanel.js +82 -0
- package/dist/view/sections/GoalsPanel.js.map +1 -0
- package/dist/view/sections/OverviewCards.js +65 -0
- package/dist/view/sections/OverviewCards.js.map +1 -0
- package/dist/view/sections/RealtimeStrip.js +80 -0
- package/dist/view/sections/RealtimeStrip.js.map +1 -0
- package/dist/view/sections/Toolbar.js +186 -0
- package/dist/view/sections/Toolbar.js.map +1 -0
- package/dist/view/sections/Trend.js +125 -0
- package/dist/view/sections/Trend.js.map +1 -0
- package/dist/view/sections/styles.js +74 -0
- package/dist/view/sections/styles.js.map +1 -0
- package/dist/view/state.js +211 -0
- package/dist/view/state.js.map +1 -0
- package/dist/view/useViewQueries.js +153 -0
- package/dist/view/useViewQueries.js.map +1 -0
- package/dist/view/viewProps.d.ts +40 -0
- package/dist/view/viewProps.js +90 -0
- package/dist/view/viewProps.js.map +1 -0
- package/dist/widgets/AnalyticsBreakdownWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsBreakdownWidget.js +78 -11
- package/dist/widgets/AnalyticsBreakdownWidget.js.map +1 -1
- package/dist/widgets/AnalyticsGoalsWidget.d.ts +14 -0
- package/dist/widgets/AnalyticsGoalsWidget.js +196 -0
- package/dist/widgets/AnalyticsGoalsWidget.js.map +1 -0
- package/dist/widgets/AnalyticsMetricWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsMetricWidget.js +63 -13
- package/dist/widgets/AnalyticsMetricWidget.js.map +1 -1
- package/dist/widgets/AnalyticsRealtimeWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsRealtimeWidget.js +44 -22
- package/dist/widgets/AnalyticsRealtimeWidget.js.map +1 -1
- package/dist/widgets/AnalyticsTrendWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsTrendWidget.js +79 -16
- package/dist/widgets/AnalyticsTrendWidget.js.map +1 -1
- package/dist/widgets/RealtimeCounter.d.ts +4 -0
- package/dist/widgets/RealtimeCounter.js +10 -1
- package/dist/widgets/RealtimeCounter.js.map +1 -1
- package/dist/widgets/WidgetViewLink.js +17 -0
- package/dist/widgets/WidgetViewLink.js.map +1 -0
- package/dist/widgets/breakdownTypes.js +28 -1
- package/dist/widgets/breakdownTypes.js.map +1 -1
- package/dist/widgets/cardChrome.js +31 -7
- package/dist/widgets/cardChrome.js.map +1 -1
- package/dist/widgets/comparison.js +15 -1
- package/dist/widgets/comparison.js.map +1 -1
- package/dist/widgets/defaults.d.ts +6 -2
- package/dist/widgets/defaults.js +72 -25
- package/dist/widgets/defaults.js.map +1 -1
- package/dist/widgets/filterCaption.js +27 -0
- package/dist/widgets/filterCaption.js.map +1 -0
- package/dist/widgets/filterField.d.ts +19 -0
- package/dist/widgets/filterField.js +75 -0
- package/dist/widgets/filterField.js.map +1 -0
- package/dist/widgets/prepareWidgetRead.d.ts +7 -0
- package/dist/widgets/prepareWidgetRead.js +74 -0
- package/dist/widgets/prepareWidgetRead.js.map +1 -0
- package/dist/widgets/range.js +43 -12
- package/dist/widgets/range.js.map +1 -1
- package/dist/widgets/readForWidget.d.ts +24 -2
- package/dist/widgets/readForWidget.js +34 -48
- package/dist/widgets/readForWidget.js.map +1 -1
- package/dist/widgets/readForWidgetBreakdown.d.ts +32 -1
- package/dist/widgets/readForWidgetBreakdown.js +32 -42
- package/dist/widgets/readForWidgetBreakdown.js.map +1 -1
- package/dist/widgets/readForWidgetGoals.d.ts +67 -0
- package/dist/widgets/readForWidgetGoals.js +140 -0
- package/dist/widgets/readForWidgetGoals.js.map +1 -0
- package/dist/widgets/readForWidgetRealtime.d.ts +8 -0
- package/dist/widgets/readForWidgetRealtime.js +21 -20
- package/dist/widgets/readForWidgetRealtime.js.map +1 -1
- package/dist/widgets/readForWidgetSeries.d.ts +24 -1
- package/dist/widgets/readForWidgetSeries.js +63 -56
- package/dist/widgets/readForWidgetSeries.js.map +1 -1
- package/dist/widgets/readMeta.js +18 -0
- package/dist/widgets/readMeta.js.map +1 -0
- package/dist/widgets/registerWidgets.js +53 -7
- package/dist/widgets/registerWidgets.js.map +1 -1
- package/dist/widgets/types.d.ts +15 -0
- package/dist/widgets/types.js +12 -1
- package/dist/widgets/types.js.map +1 -1
- package/dist/widgets/viewLink.d.ts +22 -0
- package/dist/widgets/viewLink.js +86 -0
- package/dist/widgets/viewLink.js.map +1 -0
- package/package.json +9 -4
- package/dist/native/rollups/applyDistinctDeltas.js +0 -9
- package/dist/native/rollups/applyDistinctDeltas.js.map +0 -1
- package/dist/native/rollups/bumpRollup.js +0 -73
- package/dist/native/rollups/bumpRollup.js.map +0 -1
- package/dist/native/rollups/insertIfNew.js +0 -19
- package/dist/native/rollups/insertIfNew.js.map +0 -1
package/dist/core/options.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import "../capture/proxyEndpoint.js";
|
|
2
2
|
import { GOAL_SLUG_PATTERN } from "../goals/types.js";
|
|
3
|
+
import { GOALS_SLUG } from "../goals/collection.js";
|
|
3
4
|
import { PROVIDERS_SLUG } from "../providers/collection.js";
|
|
5
|
+
import { TIMEFRAME_PRESETS } from "../timeframe/presets.js";
|
|
6
|
+
import { METRIC_KEYS } from "../translations/metricKeys.js";
|
|
4
7
|
//#region src/core/options.ts
|
|
5
8
|
const DEFAULT_WARM_CRON = "*/30 * * * *";
|
|
6
9
|
const DEFAULT_SYNC_CRON = "0 */6 * * *";
|
|
@@ -13,13 +16,15 @@ const DEFAULT_AUTO_CAPTURE = {
|
|
|
13
16
|
scrollDepth: false,
|
|
14
17
|
outboundLinks: true,
|
|
15
18
|
fileDownloads: true,
|
|
16
|
-
goalAttribute: true
|
|
19
|
+
goalAttribute: true,
|
|
20
|
+
query: true
|
|
17
21
|
};
|
|
18
22
|
const resolveAutoCapture = (option) => ({
|
|
19
23
|
scrollDepth: option?.scrollDepth ?? DEFAULT_AUTO_CAPTURE.scrollDepth,
|
|
20
24
|
outboundLinks: option?.outboundLinks ?? DEFAULT_AUTO_CAPTURE.outboundLinks,
|
|
21
25
|
fileDownloads: option?.fileDownloads ?? DEFAULT_AUTO_CAPTURE.fileDownloads,
|
|
22
|
-
goalAttribute: option?.goalAttribute ?? DEFAULT_AUTO_CAPTURE.goalAttribute
|
|
26
|
+
goalAttribute: option?.goalAttribute ?? DEFAULT_AUTO_CAPTURE.goalAttribute,
|
|
27
|
+
query: option?.query ?? DEFAULT_AUTO_CAPTURE.query
|
|
23
28
|
});
|
|
24
29
|
/** Cookieless native capture needs no consent gate; a vendor's tracker does. */
|
|
25
30
|
const defaultConsentFor = (kind) => kind === "native" ? "none" : "required";
|
|
@@ -44,6 +49,53 @@ const resolveGoals = (option) => {
|
|
|
44
49
|
}
|
|
45
50
|
return goals;
|
|
46
51
|
};
|
|
52
|
+
const resolveGoalsCollection = (option) => {
|
|
53
|
+
const off = {
|
|
54
|
+
enabled: false,
|
|
55
|
+
slug: GOALS_SLUG,
|
|
56
|
+
scopeField: DEFAULT_SCOPE_FIELD
|
|
57
|
+
};
|
|
58
|
+
const collection = Array.isArray(option) ? void 0 : option?.collection;
|
|
59
|
+
if (!collection) return off;
|
|
60
|
+
const resolved = collection === true ? {
|
|
61
|
+
...off,
|
|
62
|
+
enabled: true
|
|
63
|
+
} : {
|
|
64
|
+
enabled: collection.enabled ?? true,
|
|
65
|
+
slug: collection.slug ?? "analytics-goals",
|
|
66
|
+
scopeField: collection.scopeField ?? DEFAULT_SCOPE_FIELD,
|
|
67
|
+
overrides: collection.overrides,
|
|
68
|
+
access: collection.access
|
|
69
|
+
};
|
|
70
|
+
if (!resolved.enabled) return off;
|
|
71
|
+
if (typeof resolved.slug !== "string" || resolved.slug.trim() === "") throw new Error("analytics: goals.collection.slug must be a non-empty collection slug");
|
|
72
|
+
if (resolved.scopeField.trim() === "") throw new Error("analytics: goals.collection.scopeField must be a non-empty field name");
|
|
73
|
+
if (resolved.scopeField.includes(".")) throw new Error("analytics: goals.collection.scopeField must be a top-level field name (no dots); the scope stamp writes it as a flat key");
|
|
74
|
+
return {
|
|
75
|
+
...resolved,
|
|
76
|
+
slug: resolved.slug.trim()
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const DEFAULT_VIEW = {
|
|
80
|
+
path: "/analytics",
|
|
81
|
+
defaultRange: "last30days",
|
|
82
|
+
defaultMetric: "pageviews"
|
|
83
|
+
};
|
|
84
|
+
const resolveView = (option) => {
|
|
85
|
+
if (option === false) return false;
|
|
86
|
+
const path = option?.path ?? DEFAULT_VIEW.path;
|
|
87
|
+
if (typeof path !== "string" || !path.startsWith("/")) throw new Error(`analytics: view.path must start with "/", got "${String(path)}"`);
|
|
88
|
+
const defaultRange = option?.defaultRange ?? DEFAULT_VIEW.defaultRange;
|
|
89
|
+
if (!TIMEFRAME_PRESETS.includes(defaultRange)) throw new Error(`analytics: unknown view.defaultRange "${String(defaultRange)}"`);
|
|
90
|
+
const defaultMetric = option?.defaultMetric ?? DEFAULT_VIEW.defaultMetric;
|
|
91
|
+
if (!(defaultMetric in METRIC_KEYS)) throw new Error(`analytics: unknown view.defaultMetric "${String(defaultMetric)}"`);
|
|
92
|
+
return {
|
|
93
|
+
path,
|
|
94
|
+
defaultRange,
|
|
95
|
+
defaultMetric,
|
|
96
|
+
...option?.navLabel !== void 0 ? { navLabel: option.navLabel } : {}
|
|
97
|
+
};
|
|
98
|
+
};
|
|
47
99
|
const resolveBindings = (collections) => {
|
|
48
100
|
const out = {};
|
|
49
101
|
for (const [slug, binding] of Object.entries(collections ?? {})) {
|
|
@@ -135,6 +187,7 @@ function resolveOptions(options) {
|
|
|
135
187
|
hidden: true
|
|
136
188
|
};
|
|
137
189
|
const scoped = options.scopeResolver !== void 0;
|
|
190
|
+
const read = options.access?.read ?? (({ req }) => Boolean(req.user));
|
|
138
191
|
return {
|
|
139
192
|
adapters: options.adapters,
|
|
140
193
|
defaultAdapter: options.defaultAdapter,
|
|
@@ -143,7 +196,12 @@ function resolveOptions(options) {
|
|
|
143
196
|
scopes: options.scopes,
|
|
144
197
|
reportingTimezone: options.reportingTimezone,
|
|
145
198
|
platformAdapter: options.platformAdapter,
|
|
146
|
-
access: {
|
|
199
|
+
access: {
|
|
200
|
+
platformRead: options.access?.platformRead ?? (scoped ? () => false : ({ req }) => Boolean(req.user)),
|
|
201
|
+
read,
|
|
202
|
+
view: options.access?.view ?? read
|
|
203
|
+
},
|
|
204
|
+
view: resolveView(options.view),
|
|
147
205
|
capture: {
|
|
148
206
|
slots: {
|
|
149
207
|
global: options.capture?.slots?.global,
|
|
@@ -161,6 +219,7 @@ function resolveOptions(options) {
|
|
|
161
219
|
}
|
|
162
220
|
},
|
|
163
221
|
goals: resolveGoals(options.goals),
|
|
222
|
+
goalsCollection: resolveGoalsCollection(options.goals),
|
|
164
223
|
providers,
|
|
165
224
|
bindings: resolveBindings(options.collections),
|
|
166
225
|
cache: {
|
|
@@ -176,6 +235,6 @@ function resolveOptions(options) {
|
|
|
176
235
|
};
|
|
177
236
|
}
|
|
178
237
|
//#endregion
|
|
179
|
-
export { DEFAULT_AUTO_CAPTURE, defaultConsentFor, resolveOptions };
|
|
238
|
+
export { DEFAULT_AUTO_CAPTURE, DEFAULT_VIEW, defaultConsentFor, resolveOptions };
|
|
180
239
|
|
|
181
240
|
//# sourceMappingURL=options.js.map
|
package/dist/core/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","names":[],"sources":["../../src/core/options.ts"],"sourcesContent":["import type { KeysConfig } from '@10x-media/fields/encrypted'\nimport type { CollectionConfig, CollectionSlug, Payload, PayloadRequest } from 'payload'\nimport type { AnalyticsBinding, ResolvedBinding } from '../binding/types'\nimport { DEFAULT_PROXY_MAX_BODY_BYTES, DEFAULT_PROXY_TIMEOUT_MS } from '../capture/proxyEndpoint'\nimport type { CaptureSlot } from '../capture/slots'\nimport { GOAL_SLUG_PATTERN, type Goal } from '../goals/types'\nimport { PROVIDERS_SLUG } from '../providers/collection'\nimport type { TranslationsOption } from '../translations'\nimport type { CustomWidgetDef } from '../widgets/customWidget'\nimport type { CaptureClientKind } from './capture'\nimport type { AnalyticsAdapter } from './contract'\n\nconst DEFAULT_WARM_CRON = '*/30 * * * *'\nconst DEFAULT_SYNC_CRON = '0 */6 * * *'\nconst DEFAULT_SYNC_COLLECTION = 'analytics-daily'\nconst DEFAULT_SYNC_LOOKBACK = 3\nconst DEFAULT_SCOPE_FIELD = 'scope'\nconst DEFAULT_TIMEOUT_MS = 15_000\n\n/**\n * Maps a request to its analytics boundary (tenant id, site key). Null means the\n * whole install, which is the default single-site behavior. With a multi-tenant\n * plugin, return the request's tenant id here.\n */\nexport type ScopeResolver = (args: {\n\treq: PayloadRequest\n}) => string | null | Promise<string | null>\n\n/**\n * Resolves the IANA reporting timezone a read's (or ingest's) day boundaries align\n * to. Receives the request and its already-resolved scope, so per-tenant, per-user\n * (`req.user`), and selector (cookie/preference) strategies are all expressible.\n * Return `null` to fall back to UTC.\n */\nexport type TimezoneResolver = (args: {\n\treq: PayloadRequest\n\tscope: string | null\n}) => string | null | Promise<string | null>\n\n/**\n * Enumerates the tenant scopes the cron tiers (cache warming, sync) fan out over.\n * Absent, each tier runs once for the install-wide scope.\n */\nexport type ScopesResolver = (args: { payload: Payload }) => string[] | Promise<string[]>\n\n/**\n * Escape hatch replacing the provider-collection lookup: return the runtime\n * adapters for a scope yourself (any store, any shape). Results are layered onto\n * the static config adapters exactly like collection-resolved ones, but are not\n * cached; memoize inside the function if lookups are expensive.\n */\nexport type ProvidersResolve = (args: {\n\tpayload: Payload\n\treq?: PayloadRequest\n\tscope: string | null\n}) => AnalyticsAdapter[] | Promise<AnalyticsAdapter[]>\n\nexport type ProvidersCollectionOptions = {\n\tslug?: string\n\t/**\n\t * Field matched against the resolved scope when looking up a scope's providers.\n\t * Point it at a tenant plugin's field (e.g. 'tenant') when that plugin manages\n\t * scoping for the collection.\n\t */\n\tscopeField?: string\n\toverrides?: (collection: CollectionConfig) => CollectionConfig\n\taccess?: Partial<CollectionConfig['access']>\n\t/**\n\t * Dedicated key ring for the stored provider credentials. Unset, the\n\t * fields plugin's global `encrypted.keys` applies, and with neither the\n\t * ring derives from the Payload secret. Configure a dedicated key for\n\t * anything beyond a dev install.\n\t */\n\tencryption?: { keys?: KeysConfig }\n}\n\nexport type ProvidersOptions = {\n\t/** Opt-in admin collection storing runtime provider configurations. */\n\tcollection?: boolean | ProvidersCollectionOptions\n\tresolve?: ProvidersResolve\n}\n\n/** Access checker for cross-scope (platform) analytics reads. */\nexport type PlatformReadAccess = (args: { req: PayloadRequest }) => boolean | Promise<boolean>\n\nexport type AnalyticsAccessOptions = {\n\t/**\n\t * Gates cross-scope reads: explicit `scope: '*'` reads, and scoped reads through\n\t * a shared config adapter that cannot filter by scope. Scoped installs\n\t * (`scopeResolver` configured) default to deny; configure it, for example a role\n\t * check, so platform admins can read cross-scope and manage every tenant's\n\t * providers. Unscoped installs default to any authenticated admin-panel user.\n\t */\n\tplatformRead?: PlatformReadAccess\n}\n\nexport type ConsentMode = 'none' | 'required'\n\n/** Per-slot consent decision, evaluated against the slot's resolved adapter. */\nexport type ConsentResolver = (args: { slot: CaptureSlot; adapterId: string }) => ConsentMode\n\n/** An adapter id to fill a capture slot with, or `false` to leave it deliberately empty. */\nexport type CaptureSlotOption = string | false\n\n/**\n * A bare mode applies to every slot; a resolver decides per request-resolved adapter; the\n * object form maps ids and slots, with an adapter entry winning over a slot entry. Every\n * form overrides the default, which is `none` for the cookieless native tracker and\n * `required` for a vendor's.\n */\nexport type CaptureConsentOption =\n\t| ConsentMode\n\t| ConsentResolver\n\t| {\n\t\t\tslots?: Partial<Record<CaptureSlot, ConsentMode>>\n\t\t\t/**\n\t\t\t * Keyed by adapter id. A bare id must name a config adapter; a runtime provider\n\t\t\t * instance id (`<provider>:<instance>`) is taken on trust, since the providers it\n\t\t\t * comes from are only resolved per request.\n\t\t\t */\n\t\t\tadapters?: Record<string, ConsentMode>\n\t }\n\n/** The normalized policy the runtime evaluates; `kind` carries the adapter's tracker family. */\nexport type ConsentPolicy = (\n\tslot: CaptureSlot,\n\tadapterId: string,\n\tkind: CaptureClientKind\n) => ConsentMode\n\nexport type AutoCaptureOptions = {\n\tscrollDepth?: boolean\n\toutboundLinks?: boolean\n\tfileDownloads?: boolean\n\tgoalAttribute?: boolean\n}\n\nexport type ResolvedAutoCapture = Required<AutoCaptureOptions>\n\n/** Goals as config: the array form, or the object form 1b grows a collection source on. */\nexport type AnalyticsGoalsOptions = { defaults?: Goal[] }\n\nexport type AnalyticsCaptureOptions = {\n\t/**\n\t * Which adapter fills each capture slot, overriding the defaults: `global` is the\n\t * designated `platformAdapter`, or the single config adapter when only one is\n\t * configured; `tenant` is the resolved scope's default adapter. A `global` id must\n\t * name a config adapter; a `tenant` id may also name a runtime provider instance,\n\t * so it is resolved per request rather than validated at config time.\n\t *\n\t * `false` disables a slot outright: it fills with nothing, its proxy mount 404s, and\n\t * the tracker config omits it. Use it to keep a default from filling a slot at all.\n\t */\n\tslots?: { global?: CaptureSlotOption; tenant?: CaptureSlotOption }\n\t/**\n\t * Mount each slot's snippet points at. Defaults to the runtime proxy endpoint\n\t * (`<routes.api>/analytics/p/<slot>`); set it when the slot is served through Next\n\t * rewrites instead, passing the same path `captureRewrites` was mounted at.\n\t */\n\tpaths?: { global?: string; tenant?: string }\n\t/** Whether a slot's tracker waits for consent. Native defaults to no gate, vendors to one. */\n\tconsent?: CaptureConsentOption\n\t/** Browser auto-capture listeners, all on by default except `scrollDepth`. */\n\tautoCapture?: AutoCaptureOptions\n\t/** Limits for the public runtime capture proxy, separate from the read-path `cache`. */\n\tproxy?: {\n\t\t/**\n\t\t * Deadline for the upstream response headers, in ms. Default 10000. The body\n\t\t * download is not on the clock, so a large tracker bundle streams to completion.\n\t\t */\n\t\ttimeoutMs?: number\n\t\t/**\n\t\t * Largest proxied request body, in bytes. Default 1 MiB, which clears a PostHog\n\t\t * batch carrying session-replay data. Anything larger is refused with 413.\n\t\t */\n\t\tmaxBodyBytes?: number\n\t}\n}\n\nexport type AnalyticsPluginOptions = {\n\tdisabled?: boolean\n\t/**\n\t * Per-locale overrides for this plugin's UI strings, keyed by the typed\n\t * translation keys exported from `@10x-media/analytics/i18n`. Values win over\n\t * the built-in locales key-by-key; locales the plugin does not ship are added\n\t * whole. App-level `i18n.translations` still wins over both.\n\t */\n\ttranslations?: TranslationsOption\n\tadapters?: AnalyticsAdapter[]\n\tdefaultAdapter?: string\n\tscopeResolver?: ScopeResolver\n\t/**\n\t * Enumerates the tenant scopes the cache-warming and sync cron tiers fan out\n\t * over, in addition to the install-wide (null) scope every tier already runs.\n\t * Unset, those tiers run once for the whole install, same as before.\n\t */\n\tscopes?: ScopesResolver\n\t/**\n\t * IANA reporting timezone that day boundaries (timeframe windows, series axes,\n\t * native rollup buckets) align to. Defaults to UTC. A string forces one timezone\n\t * (the single-tenant / no-multi-tenancy case); a resolver derives it per request\n\t * from the scope, user, or a selector. Native rollups bucket at ingest in the\n\t * resolved timezone, so changing it does not re-bucket existing history.\n\t */\n\treportingTimezone?: string | TimezoneResolver\n\tproviders?: ProvidersOptions\n\t/**\n\t * Id of one config adapter shared by every scope (the platform's own analytics,\n\t * e.g. a PostHog project capturing all tenants). Included in each scope's\n\t * registry like any config adapter; reads through it are scope-filtered only\n\t * when the adapter supports scoped queries, otherwise they are cross-scope and\n\t * require `access.platformRead`.\n\t */\n\tplatformAdapter?: string\n\taccess?: AnalyticsAccessOptions\n\tcapture?: AnalyticsCaptureOptions\n\t/**\n\t * Conversion goals the tracker and the native ingest match events against. Slugs must\n\t * be unique and kebab-case; only the slug and its match reach the browser.\n\t */\n\tgoals?: Goal[] | AnalyticsGoalsOptions\n\t/**\n\t * Per-collection bindings, keyed by collection slug. With generated types\n\t * augmented, each slug's resolvers receive that collection's typed document.\n\t */\n\tcollections?: { [TSlug in CollectionSlug]?: AnalyticsBinding<TSlug> }\n\tcache?: {\n\t\tttl?: { aggregate?: number; realtime?: number }\n\t\twarm?: boolean | { cron?: string }\n\t\t/** Per-read provider timeout in ms, spanning retries and limiter waits. Default 15000. */\n\t\ttimeoutMs?: number\n\t}\n\twidgets?:\n\t\t| boolean\n\t\t| {\n\t\t\t\tdisabled?: string[]\n\t\t\t\tregister?: CustomWidgetDef[]\n\t\t\t\t/**\n\t\t\t\t * Marks the free-text widget config fields (each widget's Title) as\n\t\t\t\t * `localized`. Off by default; takes effect only when the Payload config\n\t\t\t\t * enables localization (Payload strips the flag otherwise).\n\t\t\t\t */\n\t\t\t\tlocalizeText?: boolean\n\t\t\t\t/**\n\t\t\t\t * Period-over-period comparison on the metric and trend widgets. On by\n\t\t\t\t * default for adapters that declare `capabilities.comparison`; set false\n\t\t\t\t * to skip the second (previous-window) read entirely.\n\t\t\t\t */\n\t\t\t\tcomparison?: boolean\n\t\t }\n\t/**\n\t * Opt-in sync tier: a cron job that persists each provider's daily metrics into a\n\t * queryable collection. Reads go through the surfacing cache, so persisted rows reflect\n\t * cached values up to `cache.ttl.aggregate` old; keep that TTL below the sync interval\n\t * for the freshest data.\n\t */\n\tsync?:\n\t\t| boolean\n\t\t| {\n\t\t\t\tcollectionSlug?: CollectionSlug\n\t\t\t\tcron?: string\n\t\t\t\tlookbackDays?: number\n\t\t\t\tadapters?: string[]\n\t\t\t\t/** Surface the analytics-daily collection in the admin nav. Default false (hidden). */\n\t\t\t\thidden?: boolean\n\t\t }\n}\n\nexport interface ResolvedCapture {\n\tslots: { global?: CaptureSlotOption; tenant?: CaptureSlotOption }\n\tpaths: { global?: string; tenant?: string }\n\tconsent: ConsentPolicy\n\tautoCapture: ResolvedAutoCapture\n\tproxy: { timeoutMs: number; maxBodyBytes: number }\n}\n\nexport interface ResolvedOptions {\n\tadapters: AnalyticsAdapter[]\n\tdefaultAdapter?: string\n\tscopeResolver: ScopeResolver\n\t/** True when the app configured a scopeResolver (scoped install). */\n\tscoped: boolean\n\t/** Raw scopes option; undefined runs the cron tiers install-wide only. */\n\tscopes?: ScopesResolver\n\t/** Raw reportingTimezone option; normalized into a resolver at init. */\n\treportingTimezone?: string | TimezoneResolver\n\tplatformAdapter?: string\n\taccess: { platformRead: PlatformReadAccess }\n\tcapture: ResolvedCapture\n\t/** Config goals, validated; 1b layers collection-sourced goals on top of these. */\n\tgoals: Goal[]\n\tproviders: {\n\t\tcollection: {\n\t\t\tenabled: boolean\n\t\t\tslug: string\n\t\t\tscopeField: string\n\t\t\toverrides?: (collection: CollectionConfig) => CollectionConfig\n\t\t\taccess?: Partial<CollectionConfig['access']>\n\t\t\tencryption?: { keys?: KeysConfig }\n\t\t}\n\t\tresolve?: ProvidersResolve\n\t}\n\tbindings: Record<string, ResolvedBinding>\n\tcache: {\n\t\t/** Undefined when unset: adapter recommendedTtl is the fallback, an explicit value wins. */\n\t\tttl: { aggregate?: number; realtime?: number }\n\t\twarm: { enabled: boolean; cron: string }\n\t\ttimeoutMs: number\n\t}\n\twidgets: {\n\t\tenabled: boolean\n\t\tdisabled: string[]\n\t\tregister: CustomWidgetDef[]\n\t\tlocalizeText: boolean\n\t\tcomparison: boolean\n\t}\n\tsync: {\n\t\tenabled: boolean\n\t\tcollectionSlug: string\n\t\tcron: string\n\t\tlookbackDays: number\n\t\tadapters?: string[]\n\t\t/** True hides the analytics-daily collection from the admin nav (default). */\n\t\thidden: boolean\n\t}\n}\n\n/** Scroll depth is the one listener off by default: it fires on every page, for every visitor. */\nexport const DEFAULT_AUTO_CAPTURE: ResolvedAutoCapture = {\n\tscrollDepth: false,\n\toutboundLinks: true,\n\tfileDownloads: true,\n\tgoalAttribute: true,\n}\n\nconst resolveAutoCapture = (option: AutoCaptureOptions | undefined): ResolvedAutoCapture => ({\n\tscrollDepth: option?.scrollDepth ?? DEFAULT_AUTO_CAPTURE.scrollDepth,\n\toutboundLinks: option?.outboundLinks ?? DEFAULT_AUTO_CAPTURE.outboundLinks,\n\tfileDownloads: option?.fileDownloads ?? DEFAULT_AUTO_CAPTURE.fileDownloads,\n\tgoalAttribute: option?.goalAttribute ?? DEFAULT_AUTO_CAPTURE.goalAttribute,\n})\n\n/** Cookieless native capture needs no consent gate; a vendor's tracker does. */\nexport const defaultConsentFor = (kind: CaptureClientKind): ConsentMode =>\n\tkind === 'native' ? 'none' : 'required'\n\nconst resolveConsent = (\n\toption: CaptureConsentOption | undefined,\n\tadapters: AnalyticsAdapter[]\n): ConsentPolicy => {\n\tif (option === 'none' || option === 'required') {\n\t\treturn () => option\n\t}\n\tif (typeof option === 'function') {\n\t\treturn (slot, adapterId) => option({ slot, adapterId })\n\t}\n\tfor (const id of Object.keys(option?.adapters ?? {})) {\n\t\t// A runtime provider instance id is `<provider>:<instance>` and only exists once a\n\t\t// scope resolves, so it cannot be checked here; a bare id must name a config adapter.\n\t\tif (!id.includes(':') && !adapters.some((a) => a.id === id)) {\n\t\t\tthrow new Error(`analytics: unknown consent adapter \"${id}\"`)\n\t\t}\n\t}\n\treturn (slot, adapterId, kind) =>\n\t\toption?.adapters?.[adapterId] ?? option?.slots?.[slot] ?? defaultConsentFor(kind)\n}\n\nconst resolveGoals = (option: AnalyticsPluginOptions['goals']): Goal[] => {\n\tconst goals = Array.isArray(option) ? option : (option?.defaults ?? [])\n\tconst seen = new Set<string>()\n\tfor (const goal of goals) {\n\t\tif (!GOAL_SLUG_PATTERN.test(goal.slug)) {\n\t\t\tthrow new Error(`analytics: goal slug \"${goal.slug}\" must be kebab-case`)\n\t\t}\n\t\tif (seen.has(goal.slug)) {\n\t\t\tthrow new Error(`analytics: duplicate goal slug \"${goal.slug}\"`)\n\t\t}\n\t\tconst fixed = goal.value?.fixed\n\t\t// Revenue is money: a negative or non-finite fixed value would be silently ignored at\n\t\t// ingest, so it fails the boot instead.\n\t\tif (fixed !== undefined && (!Number.isFinite(fixed) || fixed < 0)) {\n\t\t\tthrow new Error(\n\t\t\t\t`analytics: goal \"${goal.slug}\" value.fixed must be a finite number >= 0, got ${String(fixed)}`\n\t\t\t)\n\t\t}\n\t\tseen.add(goal.slug)\n\t}\n\treturn goals\n}\n\nconst resolveBindings = (\n\tcollections: AnalyticsPluginOptions['collections']\n): Record<string, ResolvedBinding> => {\n\tconst out: Record<string, ResolvedBinding> = {}\n\tfor (const [slug, binding] of Object.entries(collections ?? {})) {\n\t\tif (!binding) continue\n\t\tif (!binding.path && !binding.pathField) {\n\t\t\tthrow new Error(`analytics: binding for \"${slug}\" needs a path resolver or a pathField`)\n\t\t}\n\t\t// Erases the per-slug doc generic; safe because the runtime only ever hands\n\t\t// a binding documents from its own collection.\n\t\tout[slug] = binding as ResolvedBinding\n\t}\n\treturn out\n}\n\nexport function resolveOptions(options: AnalyticsPluginOptions): ResolvedOptions {\n\tif (!options.adapters || options.adapters.length === 0) {\n\t\tthrow new Error('analytics: at least one adapter is required')\n\t}\n\tif (\n\t\toptions.platformAdapter !== undefined &&\n\t\t!options.adapters.some((a) => a.id === options.platformAdapter)\n\t) {\n\t\tthrow new Error(`analytics: unknown platform adapter \"${options.platformAdapter}\"`)\n\t}\n\tfor (const [slot, value] of Object.entries(options.capture?.slots ?? {})) {\n\t\tif (value !== false && typeof value !== 'string' && value !== undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`analytics: capture slot \"${slot}\" must be an adapter id or false, got ${typeof value}`\n\t\t\t)\n\t\t}\n\t}\n\tconst globalSlot = options.capture?.slots?.global\n\t// A tenant id may name a runtime provider instance, which only exists once a scope\n\t// resolves; a global one can only come from the config registry, so it is checked here.\n\tif (typeof globalSlot === 'string' && !options.adapters.some((a) => a.id === globalSlot)) {\n\t\tthrow new Error(`analytics: unknown global capture slot adapter \"${globalSlot}\"`)\n\t}\n\tconst widgets =\n\t\toptions.widgets === false\n\t\t\t? {\n\t\t\t\t\tenabled: false,\n\t\t\t\t\tdisabled: [] as string[],\n\t\t\t\t\tregister: [] as CustomWidgetDef[],\n\t\t\t\t\tlocalizeText: false,\n\t\t\t\t\tcomparison: true,\n\t\t\t\t}\n\t\t\t: options.widgets === undefined || options.widgets === true\n\t\t\t\t? {\n\t\t\t\t\t\tenabled: true,\n\t\t\t\t\t\tdisabled: [] as string[],\n\t\t\t\t\t\tregister: [] as CustomWidgetDef[],\n\t\t\t\t\t\tlocalizeText: false,\n\t\t\t\t\t\tcomparison: true,\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\tenabled: true,\n\t\t\t\t\t\tdisabled: options.widgets.disabled ?? [],\n\t\t\t\t\t\tregister: options.widgets.register ?? [],\n\t\t\t\t\t\tlocalizeText: options.widgets.localizeText ?? false,\n\t\t\t\t\t\tcomparison: options.widgets.comparison ?? true,\n\t\t\t\t\t}\n\tconst warmOpt = options.cache?.warm\n\tconst warm =\n\t\twarmOpt === true\n\t\t\t? { enabled: true, cron: DEFAULT_WARM_CRON }\n\t\t\t: warmOpt && typeof warmOpt === 'object'\n\t\t\t\t? { enabled: true, cron: warmOpt.cron ?? DEFAULT_WARM_CRON }\n\t\t\t\t: { enabled: false, cron: DEFAULT_WARM_CRON }\n\tconst collectionOpt = options.providers?.collection\n\tconst providers = {\n\t\tcollection:\n\t\t\tcollectionOpt === true\n\t\t\t\t? { enabled: true, slug: PROVIDERS_SLUG, scopeField: DEFAULT_SCOPE_FIELD }\n\t\t\t\t: collectionOpt && typeof collectionOpt === 'object'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tenabled: true,\n\t\t\t\t\t\t\tslug: collectionOpt.slug ?? PROVIDERS_SLUG,\n\t\t\t\t\t\t\tscopeField: collectionOpt.scopeField ?? DEFAULT_SCOPE_FIELD,\n\t\t\t\t\t\t\toverrides: collectionOpt.overrides,\n\t\t\t\t\t\t\taccess: collectionOpt.access,\n\t\t\t\t\t\t\tencryption: collectionOpt.encryption,\n\t\t\t\t\t\t}\n\t\t\t\t\t: { enabled: false, slug: PROVIDERS_SLUG, scopeField: DEFAULT_SCOPE_FIELD },\n\t\tresolve: options.providers?.resolve,\n\t}\n\tif (providers.collection.enabled) {\n\t\tif (providers.collection.scopeField.trim() === '') {\n\t\t\tthrow new Error('analytics: providers.collection.scopeField must be a non-empty field name')\n\t\t}\n\t\tif (providers.collection.scopeField.includes('.')) {\n\t\t\tthrow new Error(\n\t\t\t\t'analytics: providers.collection.scopeField must be a top-level field name (no dots); the scope stamp writes it as a flat key'\n\t\t\t)\n\t\t}\n\t}\n\tconst syncOpt = options.sync\n\tconst sync =\n\t\tsyncOpt === true\n\t\t\t? {\n\t\t\t\t\tenabled: true,\n\t\t\t\t\tcollectionSlug: DEFAULT_SYNC_COLLECTION,\n\t\t\t\t\tcron: DEFAULT_SYNC_CRON,\n\t\t\t\t\tlookbackDays: DEFAULT_SYNC_LOOKBACK,\n\t\t\t\t\thidden: true,\n\t\t\t\t}\n\t\t\t: syncOpt && typeof syncOpt === 'object'\n\t\t\t\t? {\n\t\t\t\t\t\tenabled: true,\n\t\t\t\t\t\tcollectionSlug: syncOpt.collectionSlug ?? DEFAULT_SYNC_COLLECTION,\n\t\t\t\t\t\tcron: syncOpt.cron ?? DEFAULT_SYNC_CRON,\n\t\t\t\t\t\tlookbackDays: syncOpt.lookbackDays ?? DEFAULT_SYNC_LOOKBACK,\n\t\t\t\t\t\tadapters: syncOpt.adapters,\n\t\t\t\t\t\thidden: syncOpt.hidden ?? true,\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\tenabled: false,\n\t\t\t\t\t\tcollectionSlug: DEFAULT_SYNC_COLLECTION,\n\t\t\t\t\t\tcron: DEFAULT_SYNC_CRON,\n\t\t\t\t\t\tlookbackDays: DEFAULT_SYNC_LOOKBACK,\n\t\t\t\t\t\thidden: true,\n\t\t\t\t\t}\n\tconst scoped = options.scopeResolver !== undefined\n\treturn {\n\t\tadapters: options.adapters,\n\t\tdefaultAdapter: options.defaultAdapter,\n\t\tscopeResolver: options.scopeResolver ?? (() => null),\n\t\tscoped,\n\t\tscopes: options.scopes,\n\t\treportingTimezone: options.reportingTimezone,\n\t\tplatformAdapter: options.platformAdapter,\n\t\taccess: {\n\t\t\tplatformRead:\n\t\t\t\toptions.access?.platformRead ?? (scoped ? () => false : ({ req }) => Boolean(req.user)),\n\t\t},\n\t\tcapture: {\n\t\t\tslots: {\n\t\t\t\tglobal: options.capture?.slots?.global,\n\t\t\t\ttenant: options.capture?.slots?.tenant,\n\t\t\t},\n\t\t\tpaths: {\n\t\t\t\tglobal: options.capture?.paths?.global,\n\t\t\t\ttenant: options.capture?.paths?.tenant,\n\t\t\t},\n\t\t\tconsent: resolveConsent(options.capture?.consent, options.adapters),\n\t\t\tautoCapture: resolveAutoCapture(options.capture?.autoCapture),\n\t\t\tproxy: {\n\t\t\t\ttimeoutMs: options.capture?.proxy?.timeoutMs ?? DEFAULT_PROXY_TIMEOUT_MS,\n\t\t\t\tmaxBodyBytes: options.capture?.proxy?.maxBodyBytes ?? DEFAULT_PROXY_MAX_BODY_BYTES,\n\t\t\t},\n\t\t},\n\t\tgoals: resolveGoals(options.goals),\n\t\tproviders,\n\t\tbindings: resolveBindings(options.collections),\n\t\tcache: {\n\t\t\t// Left undefined when the app did not set them so the adapter's recommendedTtl\n\t\t\t// applies as the default; an explicit value overrides the adapter recommendation.\n\t\t\tttl: {\n\t\t\t\taggregate: options.cache?.ttl?.aggregate,\n\t\t\t\trealtime: options.cache?.ttl?.realtime,\n\t\t\t},\n\t\t\twarm,\n\t\t\ttimeoutMs: options.cache?.timeoutMs ?? DEFAULT_TI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EACA,SAAS;EACT,gBAAgB,QAAQ,kBAAkB;EAC1C,MAAM,QAAQ,QAAQ;EACtB,cAAc,QAAQ,gBAAgB;EACtC,UAAU,QAAQ;EAClB,QAAQ,QAAQ,UAAU;CAC3B,IACC;EACA,SAAS;EACT,gBAAgB;EAChB,MAAM;EACN,cAAc;EACd,QAAQ;CACT;CACJ,MAAM,SAAS,QAAQ,kBAAkB,KAAA;CACzC,OAAO;EACN,UAAU,QAAQ;EAClB,gBAAgB,QAAQ;EACxB,eAAe,QAAQ,wBAAwB;EAC/C;EACA,QAAQ,QAAQ;EAChB,mBAAmB,QAAQ;EAC3B,iBAAiB,QAAQ;EACzB,QAAQ,EACP,cACC,QAAQ,QAAQ,iBAAiB,eAAe,SAAS,EAAE,UAAU,QAAQ,IAAI,IAAI,GACvF;EACA,SAAS;GACR,OAAO;IACN,QAAQ,QAAQ,SAAS,OAAO;IAChC,QAAQ,QAAQ,SAAS,OAAO;GACjC;GACA,OAAO;IACN,QAAQ,QAAQ,SAAS,OAAO;IAChC,QAAQ,QAAQ,SAAS,OAAO;GACjC;GACA,SAAS,eAAe,QAAQ,SAAS,SAAS,QAAQ,QAAQ;GAClE,aAAa,mBAAmB,QAAQ,SAAS,WAAW;GAC5D,OAAO;IACN,WAAW,QAAQ,SAAS,OAAO,aAAA;IACnC,cAAc,QAAQ,SAAS,OAAO,gBAAA;GACvC;EACD;EACA,OAAO,aAAa,QAAQ,KAAK;EACjC;EACA,UAAU,gBAAgB,QAAQ,WAAW;EAC7C,OAAO;GAGN,KAAK;IACJ,WAAW,QAAQ,OAAO,KAAK;IAC/B,UAAU,QAAQ,OAAO,KAAK;GAC/B;GACA;GACA,WAAW,QAAQ,OAAO,aAAa;EACxC;EACA;EACA;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"options.js","names":[],"sources":["../../src/core/options.ts"],"sourcesContent":["import type { KeysConfig } from '@10x-media/fields/encrypted'\nimport type { CollectionConfig, CollectionSlug, Payload, PayloadRequest } from 'payload'\nimport type { AnalyticsBinding, ResolvedBinding } from '../binding/types'\nimport { DEFAULT_PROXY_MAX_BODY_BYTES, DEFAULT_PROXY_TIMEOUT_MS } from '../capture/proxyEndpoint'\nimport type { CaptureSlot } from '../capture/slots'\nimport { GOALS_SLUG } from '../goals/collection'\nimport { GOAL_SLUG_PATTERN, type Goal } from '../goals/types'\nimport { PROVIDERS_SLUG } from '../providers/collection'\nimport { TIMEFRAME_PRESETS, type TimeframePreset } from '../timeframe/presets'\nimport type { TranslationsOption } from '../translations'\nimport { METRIC_KEYS } from '../translations/metricKeys'\nimport type { CustomWidgetDef } from '../widgets/customWidget'\nimport type { CaptureClientKind } from './capture'\nimport type { AnalyticsAdapter, MetricKey } from './contract'\n\nconst DEFAULT_WARM_CRON = '*/30 * * * *'\nconst DEFAULT_SYNC_CRON = '0 */6 * * *'\nconst DEFAULT_SYNC_COLLECTION = 'analytics-daily'\nconst DEFAULT_SYNC_LOOKBACK = 3\nconst DEFAULT_SCOPE_FIELD = 'scope'\nconst DEFAULT_TIMEOUT_MS = 15_000\n\n/**\n * Maps a request to its analytics boundary (tenant id, site key). Null means the\n * whole install, which is the default single-site behavior. With a multi-tenant\n * plugin, return the request's tenant id here.\n */\nexport type ScopeResolver = (args: {\n\treq: PayloadRequest\n}) => string | null | Promise<string | null>\n\n/**\n * Resolves the IANA reporting timezone a read's (or ingest's) day boundaries align\n * to. Receives the request and its already-resolved scope, so per-tenant, per-user\n * (`req.user`), and selector (cookie/preference) strategies are all expressible.\n * Return `null` to fall back to UTC.\n */\nexport type TimezoneResolver = (args: {\n\treq: PayloadRequest\n\tscope: string | null\n}) => string | null | Promise<string | null>\n\n/**\n * Enumerates the tenant scopes the cron tiers (cache warming, sync) fan out over.\n * Absent, each tier runs once for the install-wide scope.\n */\nexport type ScopesResolver = (args: { payload: Payload }) => string[] | Promise<string[]>\n\n/**\n * Escape hatch replacing the provider-collection lookup: return the runtime\n * adapters for a scope yourself (any store, any shape). Results are layered onto\n * the static config adapters exactly like collection-resolved ones, but are not\n * cached; memoize inside the function if lookups are expensive.\n */\nexport type ProvidersResolve = (args: {\n\tpayload: Payload\n\treq?: PayloadRequest\n\tscope: string | null\n}) => AnalyticsAdapter[] | Promise<AnalyticsAdapter[]>\n\nexport type ProvidersCollectionOptions = {\n\tslug?: string\n\t/**\n\t * Field matched against the resolved scope when looking up a scope's providers.\n\t * Point it at a tenant plugin's field (e.g. 'tenant') when that plugin manages\n\t * scoping for the collection.\n\t */\n\tscopeField?: string\n\toverrides?: (collection: CollectionConfig) => CollectionConfig\n\taccess?: Partial<CollectionConfig['access']>\n\t/**\n\t * Dedicated key ring for the stored provider credentials. Unset, the\n\t * fields plugin's global `encrypted.keys` applies, and with neither the\n\t * ring derives from the Payload secret. Configure a dedicated key for\n\t * anything beyond a dev install.\n\t */\n\tencryption?: { keys?: KeysConfig }\n}\n\nexport type ProvidersOptions = {\n\t/** Opt-in admin collection storing runtime provider configurations. */\n\tcollection?: boolean | ProvidersCollectionOptions\n\tresolve?: ProvidersResolve\n}\n\n/** Access checker for cross-scope (platform) analytics reads. */\nexport type PlatformReadAccess = (args: { req: PayloadRequest }) => boolean | Promise<boolean>\n\n/** Access checker for authenticated analytics reads. */\nexport type AnalyticsReadAccess = (args: { req: PayloadRequest }) => boolean | Promise<boolean>\n\n/** Access checker for the analytics admin view. */\nexport type AnalyticsViewAccess = (args: { req: PayloadRequest }) => boolean | Promise<boolean>\n\nexport type AnalyticsAccessOptions = {\n\t/**\n\t * Gates every authenticated read endpoint: query, document panel, realtime, sources\n\t * and goals. Defaults to any authenticated user; narrow it to a role check to keep\n\t * analytics away from admins who should not see them. Scope gating is separate and\n\t * always applies: granting `read` never widens which scope a user reads.\n\t */\n\tread?: AnalyticsReadAccess\n\t/**\n\t * Gates cross-scope reads: explicit `scope: '*'` reads, and scoped reads through\n\t * a shared config adapter that cannot filter by scope. Scoped installs\n\t * (`scopeResolver` configured) default to deny; configure it, for example a role\n\t * check, so platform admins can read cross-scope and manage every tenant's\n\t * providers. Unscoped installs default to any authenticated admin-panel user.\n\t */\n\tplatformRead?: PlatformReadAccess\n\t/**\n\t * Gates the analytics admin view. Defaults to `read`, so one gate covers the view and\n\t * the endpoints behind it. A reader this denies still sees the nav link (it is a client\n\t * component with no access context) and lands on the view's no-access message.\n\t */\n\tview?: AnalyticsViewAccess\n}\n\nexport type ConsentMode = 'none' | 'required'\n\n/** Per-slot consent decision, evaluated against the slot's resolved adapter. */\nexport type ConsentResolver = (args: { slot: CaptureSlot; adapterId: string }) => ConsentMode\n\n/** An adapter id to fill a capture slot with, or `false` to leave it deliberately empty. */\nexport type CaptureSlotOption = string | false\n\n/**\n * A bare mode applies to every slot; a resolver decides per request-resolved adapter; the\n * object form maps ids and slots, with an adapter entry winning over a slot entry. Every\n * form overrides the default, which is `none` for the cookieless native tracker and\n * `required` for a vendor's.\n */\nexport type CaptureConsentOption =\n\t| ConsentMode\n\t| ConsentResolver\n\t| {\n\t\t\tslots?: Partial<Record<CaptureSlot, ConsentMode>>\n\t\t\t/**\n\t\t\t * Keyed by adapter id. A bare id must name a config adapter; a runtime provider\n\t\t\t * instance id (`<provider>:<instance>`) is taken on trust, since the providers it\n\t\t\t * comes from are only resolved per request.\n\t\t\t */\n\t\t\tadapters?: Record<string, ConsentMode>\n\t }\n\n/** The normalized policy the runtime evaluates; `kind` carries the adapter's tracker family. */\nexport type ConsentPolicy = (\n\tslot: CaptureSlot,\n\tadapterId: string,\n\tkind: CaptureClientKind\n) => ConsentMode\n\nexport type AutoCaptureOptions = {\n\tscrollDepth?: boolean\n\toutboundLinks?: boolean\n\tfileDownloads?: boolean\n\tgoalAttribute?: boolean\n\t/**\n\t * Send each pageview's query string so ingest can extract its utm keys. The raw query is\n\t * never stored, only the five campaign values; set false to stop sending it at all.\n\t */\n\tquery?: boolean\n}\n\nexport type ResolvedAutoCapture = Required<AutoCaptureOptions>\n\nexport type AnalyticsGoalsCollectionOptions = {\n\t/** Set false to keep the object form's other settings while leaving the collection off. */\n\tenabled?: boolean\n\tslug?: string\n\t/**\n\t * Field matched against the resolved scope when looking up a scope's goals. Point it at\n\t * a tenant plugin's field (e.g. 'tenant') when that plugin manages scoping.\n\t */\n\tscopeField?: string\n\toverrides?: (collection: CollectionConfig) => CollectionConfig\n\taccess?: Partial<CollectionConfig['access']>\n}\n\n/** Goals as config, plus the opt-in collection editors manage their own goals through. */\nexport type AnalyticsGoalsOptions = {\n\tdefaults?: Goal[]\n\t/** Opt-in admin collection whose goals merge over `defaults`, by slug, per scope. */\n\tcollection?: boolean | AnalyticsGoalsCollectionOptions\n}\n\nexport type AnalyticsCaptureOptions = {\n\t/**\n\t * Which adapter fills each capture slot, overriding the defaults: `global` is the\n\t * designated `platformAdapter`, or the single config adapter when only one is\n\t * configured; `tenant` is the resolved scope's default adapter. A `global` id must\n\t * name a config adapter; a `tenant` id may also name a runtime provider instance,\n\t * so it is resolved per request rather than validated at config time.\n\t *\n\t * `false` disables a slot outright: it fills with nothing, its proxy mount 404s, and\n\t * the tracker config omits it. Use it to keep a default from filling a slot at all.\n\t */\n\tslots?: { global?: CaptureSlotOption; tenant?: CaptureSlotOption }\n\t/**\n\t * Mount each slot's snippet points at. Defaults to the runtime proxy endpoint\n\t * (`<routes.api>/analytics/p/<slot>`); set it when the slot is served through Next\n\t * rewrites instead, passing the same path `captureRewrites` was mounted at.\n\t */\n\tpaths?: { global?: string; tenant?: string }\n\t/** Whether a slot's tracker waits for consent. Native defaults to no gate, vendors to one. */\n\tconsent?: CaptureConsentOption\n\t/** Browser auto-capture listeners, all on by default except `scrollDepth`. */\n\tautoCapture?: AutoCaptureOptions\n\t/** Limits for the public runtime capture proxy, separate from the read-path `cache`. */\n\tproxy?: {\n\t\t/**\n\t\t * Deadline for the upstream response headers, in ms. Default 10000. The body\n\t\t * download is not on the clock, so a large tracker bundle streams to completion.\n\t\t */\n\t\ttimeoutMs?: number\n\t\t/**\n\t\t * Largest proxied request body, in bytes. Default 1 MiB, which clears a PostHog\n\t\t * batch carrying session-replay data. Anything larger is refused with 413.\n\t\t */\n\t\tmaxBodyBytes?: number\n\t}\n}\n\nexport type AnalyticsViewOptions = {\n\t/** Admin path the view mounts at, under `routes.admin`. Default `/analytics`. */\n\tpath?: `/${string}`\n\t/** Timeframe the view opens on before the URL says otherwise. Default `last30days`. */\n\tdefaultRange?: TimeframePreset\n\t/** Metric the cards and the trend open on. Default `pageviews`. */\n\tdefaultMetric?: MetricKey\n\t/**\n\t * Nav link label. A string is used as-is; a map is keyed by admin language code and\n\t * falls back to `en`. Unset, the plugin's own translated label applies.\n\t */\n\tnavLabel?: string | Record<string, string>\n}\n\nexport interface ResolvedView {\n\tpath: `/${string}`\n\tdefaultRange: TimeframePreset\n\tdefaultMetric: MetricKey\n\tnavLabel?: string | Record<string, string>\n}\n\nexport type AnalyticsPluginOptions = {\n\tdisabled?: boolean\n\t/**\n\t * Per-locale overrides for this plugin's UI strings, keyed by the typed\n\t * translation keys exported from `@10x-media/analytics/i18n`. Values win over\n\t * the built-in locales key-by-key; locales the plugin does not ship are added\n\t * whole. App-level `i18n.translations` still wins over both.\n\t */\n\ttranslations?: TranslationsOption\n\tadapters?: AnalyticsAdapter[]\n\tdefaultAdapter?: string\n\tscopeResolver?: ScopeResolver\n\t/**\n\t * Enumerates the tenant scopes the cache-warming and sync cron tiers fan out\n\t * over, in addition to the install-wide (null) scope every tier already runs.\n\t * Unset, those tiers run once for the whole install, same as before.\n\t */\n\tscopes?: ScopesResolver\n\t/**\n\t * IANA reporting timezone that day boundaries (timeframe windows, series axes,\n\t * native rollup buckets) align to. Defaults to UTC. A string forces one timezone\n\t * (the single-tenant / no-multi-tenancy case); a resolver derives it per request\n\t * from the scope, user, or a selector. Native rollups bucket at ingest in the\n\t * resolved timezone, so changing it does not re-bucket existing history.\n\t */\n\treportingTimezone?: string | TimezoneResolver\n\tproviders?: ProvidersOptions\n\t/**\n\t * Id of one config adapter shared by every scope (the platform's own analytics,\n\t * e.g. a PostHog project capturing all tenants). Included in each scope's\n\t * registry like any config adapter; reads through it are scope-filtered only\n\t * when the adapter supports scoped queries, otherwise they are cross-scope and\n\t * require `access.platformRead`.\n\t */\n\tplatformAdapter?: string\n\taccess?: AnalyticsAccessOptions\n\t/**\n\t * The analytics admin view and its nav link, on by default. `false` registers neither;\n\t * the read endpoints stay mounted either way, so a custom surface keeps working.\n\t */\n\tview?: false | AnalyticsViewOptions\n\tcapture?: AnalyticsCaptureOptions\n\t/**\n\t * Conversion goals the tracker and the native ingest match events against. Slugs must\n\t * be unique and kebab-case; only the slug and its match reach the browser.\n\t */\n\tgoals?: Goal[] | AnalyticsGoalsOptions\n\t/**\n\t * Per-collection bindings, keyed by collection slug. With generated types\n\t * augmented, each slug's resolvers receive that collection's typed document.\n\t */\n\tcollections?: { [TSlug in CollectionSlug]?: AnalyticsBinding<TSlug> }\n\tcache?: {\n\t\tttl?: { aggregate?: number; realtime?: number }\n\t\twarm?: boolean | { cron?: string }\n\t\t/** Per-read provider timeout in ms, spanning retries and limiter waits. Default 15000. */\n\t\ttimeoutMs?: number\n\t}\n\twidgets?:\n\t\t| boolean\n\t\t| {\n\t\t\t\tdisabled?: string[]\n\t\t\t\tregister?: CustomWidgetDef[]\n\t\t\t\t/**\n\t\t\t\t * Marks the free-text widget config fields (each widget's Title) as\n\t\t\t\t * `localized`. Off by default; takes effect only when the Payload config\n\t\t\t\t * enables localization (Payload strips the flag otherwise).\n\t\t\t\t */\n\t\t\t\tlocalizeText?: boolean\n\t\t\t\t/**\n\t\t\t\t * Period-over-period comparison on the metric and trend widgets. On by\n\t\t\t\t * default for every source except one whose adapter sets\n\t\t\t\t * `capabilities.comparison` false; set false to skip the second\n\t\t\t\t * (previous-window) read entirely.\n\t\t\t\t */\n\t\t\t\tcomparison?: boolean\n\t\t }\n\t/**\n\t * Opt-in sync tier: a cron job that persists each provider's daily metrics into a\n\t * queryable collection. Reads go through the surfacing cache, so persisted rows reflect\n\t * cached values up to `cache.ttl.aggregate` old; keep that TTL below the sync interval\n\t * for the freshest data.\n\t */\n\tsync?:\n\t\t| boolean\n\t\t| {\n\t\t\t\tcollectionSlug?: CollectionSlug\n\t\t\t\tcron?: string\n\t\t\t\tlookbackDays?: number\n\t\t\t\tadapters?: string[]\n\t\t\t\t/** Surface the analytics-daily collection in the admin nav. Default false (hidden). */\n\t\t\t\thidden?: boolean\n\t\t }\n}\n\nexport interface ResolvedCapture {\n\tslots: { global?: CaptureSlotOption; tenant?: CaptureSlotOption }\n\tpaths: { global?: string; tenant?: string }\n\tconsent: ConsentPolicy\n\tautoCapture: ResolvedAutoCapture\n\tproxy: { timeoutMs: number; maxBodyBytes: number }\n}\n\nexport interface ResolvedOptions {\n\tadapters: AnalyticsAdapter[]\n\tdefaultAdapter?: string\n\tscopeResolver: ScopeResolver\n\t/** True when the app configured a scopeResolver (scoped install). */\n\tscoped: boolean\n\t/** Raw scopes option; undefined runs the cron tiers install-wide only. */\n\tscopes?: ScopesResolver\n\t/** Raw reportingTimezone option; normalized into a resolver at init. */\n\treportingTimezone?: string | TimezoneResolver\n\tplatformAdapter?: string\n\taccess: {\n\t\tplatformRead: PlatformReadAccess\n\t\tread: AnalyticsReadAccess\n\t\tview: AnalyticsViewAccess\n\t}\n\t/** The admin view, filled with its defaults, or false when the app turned it off. */\n\tview: false | ResolvedView\n\tcapture: ResolvedCapture\n\t/** Config goals, validated; the goals collection layers its own on top of these. */\n\tgoals: Goal[]\n\tgoalsCollection: {\n\t\tenabled: boolean\n\t\tslug: string\n\t\tscopeField: string\n\t\toverrides?: (collection: CollectionConfig) => CollectionConfig\n\t\taccess?: Partial<CollectionConfig['access']>\n\t}\n\tproviders: {\n\t\tcollection: {\n\t\t\tenabled: boolean\n\t\t\tslug: string\n\t\t\tscopeField: string\n\t\t\toverrides?: (collection: CollectionConfig) => CollectionConfig\n\t\t\taccess?: Partial<CollectionConfig['access']>\n\t\t\tencryption?: { keys?: KeysConfig }\n\t\t}\n\t\tresolve?: ProvidersResolve\n\t}\n\tbindings: Record<string, ResolvedBinding>\n\tcache: {\n\t\t/** Undefined when unset: adapter recommendedTtl is the fallback, an explicit value wins. */\n\t\tttl: { aggregate?: number; realtime?: number }\n\t\twarm: { enabled: boolean; cron: string }\n\t\ttimeoutMs: number\n\t}\n\twidgets: {\n\t\tenabled: boolean\n\t\tdisabled: string[]\n\t\tregister: CustomWidgetDef[]\n\t\tlocalizeText: boolean\n\t\tcomparison: boolean\n\t}\n\tsync: {\n\t\tenabled: boolean\n\t\tcollectionSlug: string\n\t\tcron: string\n\t\tlookbackDays: number\n\t\tadapters?: string[]\n\t\t/** True hides the analytics-daily collection from the admin nav (default). */\n\t\thidden: boolean\n\t}\n}\n\n/** Scroll depth is the one listener off by default: it fires on every page, for every visitor. */\nexport const DEFAULT_AUTO_CAPTURE: ResolvedAutoCapture = {\n\tscrollDepth: false,\n\toutboundLinks: true,\n\tfileDownloads: true,\n\tgoalAttribute: true,\n\tquery: true,\n}\n\nconst resolveAutoCapture = (option: AutoCaptureOptions | undefined): ResolvedAutoCapture => ({\n\tscrollDepth: option?.scrollDepth ?? DEFAULT_AUTO_CAPTURE.scrollDepth,\n\toutboundLinks: option?.outboundLinks ?? DEFAULT_AUTO_CAPTURE.outboundLinks,\n\tfileDownloads: option?.fileDownloads ?? DEFAULT_AUTO_CAPTURE.fileDownloads,\n\tgoalAttribute: option?.goalAttribute ?? DEFAULT_AUTO_CAPTURE.goalAttribute,\n\tquery: option?.query ?? DEFAULT_AUTO_CAPTURE.query,\n})\n\n/** Cookieless native capture needs no consent gate; a vendor's tracker does. */\nexport const defaultConsentFor = (kind: CaptureClientKind): ConsentMode =>\n\tkind === 'native' ? 'none' : 'required'\n\nconst resolveConsent = (\n\toption: CaptureConsentOption | undefined,\n\tadapters: AnalyticsAdapter[]\n): ConsentPolicy => {\n\tif (option === 'none' || option === 'required') {\n\t\treturn () => option\n\t}\n\tif (typeof option === 'function') {\n\t\treturn (slot, adapterId) => option({ slot, adapterId })\n\t}\n\tfor (const id of Object.keys(option?.adapters ?? {})) {\n\t\t// A runtime provider instance id is `<provider>:<instance>` and only exists once a\n\t\t// scope resolves, so it cannot be checked here; a bare id must name a config adapter.\n\t\tif (!id.includes(':') && !adapters.some((a) => a.id === id)) {\n\t\t\tthrow new Error(`analytics: unknown consent adapter \"${id}\"`)\n\t\t}\n\t}\n\treturn (slot, adapterId, kind) =>\n\t\toption?.adapters?.[adapterId] ?? option?.slots?.[slot] ?? defaultConsentFor(kind)\n}\n\nconst resolveGoals = (option: AnalyticsPluginOptions['goals']): Goal[] => {\n\tconst goals = Array.isArray(option) ? option : (option?.defaults ?? [])\n\tconst seen = new Set<string>()\n\tfor (const goal of goals) {\n\t\tif (!GOAL_SLUG_PATTERN.test(goal.slug)) {\n\t\t\tthrow new Error(`analytics: goal slug \"${goal.slug}\" must be kebab-case`)\n\t\t}\n\t\tif (seen.has(goal.slug)) {\n\t\t\tthrow new Error(`analytics: duplicate goal slug \"${goal.slug}\"`)\n\t\t}\n\t\tconst fixed = goal.value?.fixed\n\t\t// Revenue is money: a negative or non-finite fixed value would be silently ignored at\n\t\t// ingest, so it fails the boot instead.\n\t\tif (fixed !== undefined && (!Number.isFinite(fixed) || fixed < 0)) {\n\t\t\tthrow new Error(\n\t\t\t\t`analytics: goal \"${goal.slug}\" value.fixed must be a finite number >= 0, got ${String(fixed)}`\n\t\t\t)\n\t\t}\n\t\tseen.add(goal.slug)\n\t}\n\treturn goals\n}\n\nconst resolveGoalsCollection = (\n\toption: AnalyticsPluginOptions['goals']\n): ResolvedOptions['goalsCollection'] => {\n\tconst off = { enabled: false, slug: GOALS_SLUG, scopeField: DEFAULT_SCOPE_FIELD }\n\tconst collection = Array.isArray(option) ? undefined : option?.collection\n\tif (!collection) {\n\t\treturn off\n\t}\n\tconst resolved =\n\t\tcollection === true\n\t\t\t? { ...off, enabled: true }\n\t\t\t: {\n\t\t\t\t\tenabled: collection.enabled ?? true,\n\t\t\t\t\tslug: collection.slug ?? GOALS_SLUG,\n\t\t\t\t\tscopeField: collection.scopeField ?? DEFAULT_SCOPE_FIELD,\n\t\t\t\t\toverrides: collection.overrides,\n\t\t\t\t\taccess: collection.access,\n\t\t\t\t}\n\tif (!resolved.enabled) {\n\t\treturn off\n\t}\n\tif (typeof resolved.slug !== 'string' || resolved.slug.trim() === '') {\n\t\tthrow new Error('analytics: goals.collection.slug must be a non-empty collection slug')\n\t}\n\tif (resolved.scopeField.trim() === '') {\n\t\tthrow new Error('analytics: goals.collection.scopeField must be a non-empty field name')\n\t}\n\tif (resolved.scopeField.includes('.')) {\n\t\tthrow new Error(\n\t\t\t'analytics: goals.collection.scopeField must be a top-level field name (no dots); the scope stamp writes it as a flat key'\n\t\t)\n\t}\n\treturn { ...resolved, slug: resolved.slug.trim() }\n}\n\nexport const DEFAULT_VIEW: ResolvedView = {\n\tpath: '/analytics',\n\tdefaultRange: 'last30days',\n\tdefaultMetric: 'pageviews',\n}\n\nconst resolveView = (option: AnalyticsPluginOptions['view']): false | ResolvedView => {\n\tif (option === false) {\n\t\treturn false\n\t}\n\tconst path = option?.path ?? DEFAULT_VIEW.path\n\tif (typeof path !== 'string' || !path.startsWith('/')) {\n\t\tthrow new Error(`analytics: view.path must start with \"/\", got \"${String(path)}\"`)\n\t}\n\tconst defaultRange = option?.defaultRange ?? DEFAULT_VIEW.defaultRange\n\tif (!TIMEFRAME_PRESETS.includes(defaultRange)) {\n\t\tthrow new Error(`analytics: unknown view.defaultRange \"${String(defaultRange)}\"`)\n\t}\n\tconst defaultMetric = option?.defaultMetric ?? DEFAULT_VIEW.defaultMetric\n\tif (!(defaultMetric in METRIC_KEYS)) {\n\t\tthrow new Error(`analytics: unknown view.defaultMetric \"${String(defaultMetric)}\"`)\n\t}\n\treturn {\n\t\tpath,\n\t\tdefaultRange,\n\t\tdefaultMetric,\n\t\t...(option?.navLabel !== undefined ? { navLabel: option.navLabel } : {}),\n\t}\n}\n\nconst resolveBindings = (\n\tcollections: AnalyticsPluginOptions['collections']\n): Record<string, ResolvedBinding> => {\n\tconst out: Record<string, ResolvedBinding> = {}\n\tfor (const [slug, binding] of Object.entries(collections ?? {})) {\n\t\tif (!binding) continue\n\t\tif (!binding.path && !binding.pathField) {\n\t\t\tthrow new Error(`analytics: binding for \"${slug}\" needs a path resolver or a pathField`)\n\t\t}\n\t\t// Erases the per-slug doc generic; safe because the runtime only ever hands\n\t\t// a binding documents from its own collection.\n\t\tout[slug] = binding as ResolvedBinding\n\t}\n\treturn out\n}\n\nexport function resolveOptions(options: AnalyticsPluginOptions): ResolvedOptions {\n\tif (!options.adapters || options.adapters.length === 0) {\n\t\tthrow new Error('analytics: at least one adapter is required')\n\t}\n\tif (\n\t\toptions.platformAdapter !== undefined &&\n\t\t!options.adapters.some((a) => a.id === options.platformAdapter)\n\t) {\n\t\tthrow new Error(`analytics: unknown platform adapter \"${options.platformAdapter}\"`)\n\t}\n\tfor (const [slot, value] of Object.entries(options.capture?.slots ?? {})) {\n\t\tif (value !== false && typeof value !== 'string' && value !== undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`analytics: capture slot \"${slot}\" must be an adapter id or false, got ${typeof value}`\n\t\t\t)\n\t\t}\n\t}\n\tconst globalSlot = options.capture?.slots?.global\n\t// A tenant id may name a runtime provider instance, which only exists once a scope\n\t// resolves; a global one can only come from the config registry, so it is checked here.\n\tif (typeof globalSlot === 'string' && !options.adapters.some((a) => a.id === globalSlot)) {\n\t\tthrow new Error(`analytics: unknown global capture slot adapter \"${globalSlot}\"`)\n\t}\n\tconst widgets =\n\t\toptions.widgets === false\n\t\t\t? {\n\t\t\t\t\tenabled: false,\n\t\t\t\t\tdisabled: [] as string[],\n\t\t\t\t\tregister: [] as CustomWidgetDef[],\n\t\t\t\t\tlocalizeText: false,\n\t\t\t\t\tcomparison: true,\n\t\t\t\t}\n\t\t\t: options.widgets === undefined || options.widgets === true\n\t\t\t\t? {\n\t\t\t\t\t\tenabled: true,\n\t\t\t\t\t\tdisabled: [] as string[],\n\t\t\t\t\t\tregister: [] as CustomWidgetDef[],\n\t\t\t\t\t\tlocalizeText: false,\n\t\t\t\t\t\tcomparison: true,\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\tenabled: true,\n\t\t\t\t\t\tdisabled: options.widgets.disabled ?? [],\n\t\t\t\t\t\tregister: options.widgets.register ?? [],\n\t\t\t\t\t\tlocalizeText: options.widgets.localizeText ?? false,\n\t\t\t\t\t\tcomparison: options.widgets.comparison ?? true,\n\t\t\t\t\t}\n\tconst warmOpt = options.cache?.warm\n\tconst warm =\n\t\twarmOpt === true\n\t\t\t? { enabled: true, cron: DEFAULT_WARM_CRON }\n\t\t\t: warmOpt && typeof warmOpt === 'object'\n\t\t\t\t? { enabled: true, cron: warmOpt.cron ?? DEFAULT_WARM_CRON }\n\t\t\t\t: { enabled: false, cron: DEFAULT_WARM_CRON }\n\tconst collectionOpt = options.providers?.collection\n\tconst providers = {\n\t\tcollection:\n\t\t\tcollectionOpt === true\n\t\t\t\t? { enabled: true, slug: PROVIDERS_SLUG, scopeField: DEFAULT_SCOPE_FIELD }\n\t\t\t\t: collectionOpt && typeof collectionOpt === 'object'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tenabled: true,\n\t\t\t\t\t\t\tslug: collectionOpt.slug ?? PROVIDERS_SLUG,\n\t\t\t\t\t\t\tscopeField: collectionOpt.scopeField ?? DEFAULT_SCOPE_FIELD,\n\t\t\t\t\t\t\toverrides: collectionOpt.overrides,\n\t\t\t\t\t\t\taccess: collectionOpt.access,\n\t\t\t\t\t\t\tencryption: collectionOpt.encryption,\n\t\t\t\t\t\t}\n\t\t\t\t\t: { enabled: false, slug: PROVIDERS_SLUG, scopeField: DEFAULT_SCOPE_FIELD },\n\t\tresolve: options.providers?.resolve,\n\t}\n\tif (providers.collection.enabled) {\n\t\tif (providers.collection.scopeField.trim() === '') {\n\t\t\tthrow new Error('analytics: providers.collection.scopeField must be a non-empty field name')\n\t\t}\n\t\tif (providers.collection.scopeField.includes('.')) {\n\t\t\tthrow new Error(\n\t\t\t\t'analytics: providers.collection.scopeField must be a top-level field name (no dots); the scope stamp writes it as a flat key'\n\t\t\t)\n\t\t}\n\t}\n\tconst syncOpt = options.sync\n\tconst sync =\n\t\tsyncOpt === true\n\t\t\t? {\n\t\t\t\t\tenabled: true,\n\t\t\t\t\tcollectionSlug: DEFAULT_SYNC_COLLECTION,\n\t\t\t\t\tcron: DEFAULT_SYNC_CRON,\n\t\t\t\t\tlookbackDays: DEFAULT_SYNC_LOOKBACK,\n\t\t\t\t\thidden: true,\n\t\t\t\t}\n\t\t\t: syncOpt && typeof syncOpt === 'object'\n\t\t\t\t? {\n\t\t\t\t\t\tenabled: true,\n\t\t\t\t\t\tcollectionSlug: syncOpt.collectionSlug ?? DEFAULT_SYNC_COLLECTION,\n\t\t\t\t\t\tcron: syncOpt.cron ?? DEFAULT_SYNC_CRON,\n\t\t\t\t\t\tlookbackDays: syncOpt.lookbackDays ?? DEFAULT_SYNC_LOOKBACK,\n\t\t\t\t\t\tadapters: syncOpt.adapters,\n\t\t\t\t\t\thidden: syncOpt.hidden ?? true,\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\tenabled: false,\n\t\t\t\t\t\tcollectionSlug: DEFAULT_SYNC_COLLECTION,\n\t\t\t\t\t\tcron: DEFAULT_SYNC_CRON,\n\t\t\t\t\t\tlookbackDays: DEFAULT_SYNC_LOOKBACK,\n\t\t\t\t\t\thidden: true,\n\t\t\t\t\t}\n\tconst scoped = options.scopeResolver !== undefined\n\t// The view gate defaults to this exact function, so one `access.read` covers both.\n\tconst read: AnalyticsReadAccess = options.access?.read ?? (({ req }) => Boolean(req.user))\n\treturn {\n\t\tadapters: options.adapters,\n\t\tdefaultAdapter: options.defaultAdapter,\n\t\tscopeResolver: options.scopeResolver ?? (() => null),\n\t\tscoped,\n\t\tscopes: options.scopes,\n\t\treportingTimezone: options.reportingTimezone,\n\t\tplatformAdapter: options.platformAdapter,\n\t\taccess: {\n\t\t\tplatformRead:\n\t\t\t\toptions.access?.platformRead ?? (scoped ? () => false : ({ req }) => Boolean(req.user)),\n\t\t\tread,\n\t\t\tview: options.access?.view ?? read,\n\t\t},\n\t\tview: resolveView(options.view),\n\t\tcapture: {\n\t\t\tslots: {\n\t\t\t\tglobal: options.capture?.slots?.global,\n\t\t\t\ttenant: options.capture?.slots?.tenant,\n\t\t\t},\n\t\t\tpaths: {\n\t\t\t\tglobal: options.capture?.paths?.global,\n\t\t\t\ttenant: options.capture?.paths?.tenant,\n\t\t\t},\n\t\t\tconsent: resolveConsent(options.capture?.consent, options.adapters),\n\t\t\tautoCapture: resolveAutoCapture(options.capture?.autoCapture),\n\t\t\tproxy: {\n\t\t\t\ttimeoutMs: options.capture?.proxy?.timeoutMs ?? DEFAULT_PROXY_TIMEOUT_MS,\n\t\t\t\tmaxBodyBytes: options.capture?.proxy?.maxBodyBytes ?? DEFAULT_PROXY_MAX_BODY_BYTES,\n\t\t\t},\n\t\t},\n\t\tgoals: resolveGoals(options.goals),\n\t\tgoalsCollection: resolveGoalsCollection(options.goals),\n\t\tproviders,\n\t\tbindings: resolveBindings(options.collections),\n\t\tcache: {\n\t\t\t// Left undefined when the app did not set them so the adapter's recommendedTtl\n\t\t\t// applies as the default; an explicit value overrides the adapter recommendation.\n\t\t\tttl: {\n\t\t\t\taggregate: options.cache?.ttl?.aggregate,\n\t\t\t\trealtime: options.cache?.ttl?.realtime,\n\t\t\t},\n\t\t\twarm,\n\t\t\ttimeoutMs: options.cache?.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n\t\t},\n\t\twidgets,\n\t\tsync,\n\t}\n}\n"],"mappings":";;;;;;;AAeA,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAC1B,MAAM,0BAA0B;AAChC,MAAM,wBAAwB;AAC9B,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;;AAwY3B,MAAa,uBAA4C;CACxD,aAAa;CACb,eAAe;CACf,eAAe;CACf,eAAe;CACf,OAAO;AACR;AAEA,MAAM,sBAAsB,YAAi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.js";
|
|
2
|
+
import { platformReadGate, resolveRegistryFor, resolveScopeFor } from "../plugin/runtime.js";
|
|
3
3
|
//#region src/core/scopedRead.ts
|
|
4
4
|
/**
|
|
5
|
+
* The scope to stamp on one adapter query, or a refusal. Cross-scope reads fail closed
|
|
6
|
+
* behind `platformRead`: the `'*'` marker, and any scoped read through a shared config
|
|
7
|
+
* adapter that cannot narrow the query to one scope (whether or not it is the designated
|
|
8
|
+
* platform adapter), which would otherwise answer with every scope's data. A tenant's own
|
|
9
|
+
* runtime adapters are never gated. Every read path decides this here, so the widgets and
|
|
10
|
+
* the query endpoint cannot drift apart on what counts as cross-scope.
|
|
11
|
+
*/
|
|
12
|
+
const resolveQueryScope = async (args) => {
|
|
13
|
+
const { runtime, req, scope, adapter } = args;
|
|
14
|
+
const allowed = args.platformRead ?? platformReadGate(runtime, req);
|
|
15
|
+
if (scope === "*") return await allowed() ? { ok: true } : { ok: false };
|
|
16
|
+
if (scope === null) return { ok: true };
|
|
17
|
+
if (runtime.configAdapterIds.has(adapter.id) && !adapter.capabilities.scopedQueries) return await allowed() ? { ok: true } : { ok: false };
|
|
18
|
+
return {
|
|
19
|
+
ok: true,
|
|
20
|
+
queryScope: scope
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
5
24
|
* Resolve one read's scope and adapter: explicit scope wins over the request's
|
|
6
25
|
* resolved scope, the registry is resolved per scope, then the adapter is picked
|
|
7
26
|
* by id (or the registry default). Cross-scope reads fail closed behind
|
|
@@ -20,9 +39,10 @@ import "./contract.js";
|
|
|
20
39
|
*/
|
|
21
40
|
const resolveReadContext = async (args) => {
|
|
22
41
|
const { runtime, req, adapterId } = args;
|
|
42
|
+
const allowed = platformReadGate(runtime, req);
|
|
23
43
|
try {
|
|
24
44
|
const scope = args.scope !== void 0 ? args.scope : await resolveScopeFor(runtime, req);
|
|
25
|
-
if (runtime.scoped && args.scope === void 0 && scope === null && !await
|
|
45
|
+
if (runtime.scoped && args.scope === void 0 && scope === null && !await allowed()) return { ok: false };
|
|
26
46
|
const registryScope = scope === "*" ? null : scope;
|
|
27
47
|
const registry = await resolveRegistryFor(runtime, {
|
|
28
48
|
payload: req.payload,
|
|
@@ -30,29 +50,19 @@ const resolveReadContext = async (args) => {
|
|
|
30
50
|
scope: registryScope
|
|
31
51
|
});
|
|
32
52
|
const adapter = adapterId ? registry.get(adapterId) : registry.default();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
if (scope !== null && runtime.configAdapterIds.has(adapter.id) && !adapter.capabilities.scopedQueries) {
|
|
43
|
-
if (!await platformReadFor(runtime, req)) return { ok: false };
|
|
44
|
-
return {
|
|
45
|
-
ok: true,
|
|
46
|
-
adapter,
|
|
47
|
-
scope,
|
|
48
|
-
queryScope: void 0
|
|
49
|
-
};
|
|
50
|
-
}
|
|
53
|
+
const decision = await resolveQueryScope({
|
|
54
|
+
runtime,
|
|
55
|
+
req,
|
|
56
|
+
scope,
|
|
57
|
+
adapter,
|
|
58
|
+
platformRead: allowed
|
|
59
|
+
});
|
|
60
|
+
if (!decision.ok) return { ok: false };
|
|
51
61
|
return {
|
|
52
62
|
ok: true,
|
|
53
63
|
adapter,
|
|
54
|
-
scope,
|
|
55
|
-
queryScope:
|
|
64
|
+
scope: registryScope,
|
|
65
|
+
queryScope: decision.queryScope
|
|
56
66
|
};
|
|
57
67
|
} catch (err) {
|
|
58
68
|
req.payload.logger?.warn(`analytics: read context resolution failed: ${String(err)}`);
|
|
@@ -60,6 +70,6 @@ const resolveReadContext = async (args) => {
|
|
|
60
70
|
}
|
|
61
71
|
};
|
|
62
72
|
//#endregion
|
|
63
|
-
export { resolveReadContext };
|
|
73
|
+
export { resolveQueryScope, resolveReadContext };
|
|
64
74
|
|
|
65
75
|
//# sourceMappingURL=scopedRead.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scopedRead.js","names":[],"sources":["../../src/core/scopedRead.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport {\n\ttype AnalyticsRuntime,\n\
|
|
1
|
+
{"version":3,"file":"scopedRead.js","names":[],"sources":["../../src/core/scopedRead.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport {\n\ttype AnalyticsRuntime,\n\ttype PlatformReadGate,\n\tplatformReadGate,\n\tresolveRegistryFor,\n\tresolveScopeFor,\n} from '../plugin/runtime'\nimport { type AnalyticsAdapter, PLATFORM_SCOPE } from './contract'\n\nexport type ReadContext =\n\t| {\n\t\t\tok: true\n\t\t\tadapter: AnalyticsAdapter\n\t\t\tscope: string | null\n\t\t\t/** The scope to stamp on the adapter query; undefined for install-wide reads. */\n\t\t\tqueryScope?: string\n\t }\n\t| { ok: false }\n\nexport interface ResolveReadContextArgs {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\tadapterId?: string\n\t/** Explicit scope override; undefined resolves via the plugin's scopeResolver. */\n\tscope?: string | null\n}\n\nexport interface QueryScopeArgs {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\t/** The read's resolved scope; `'*'` is the explicit cross-scope marker. */\n\tscope: string | null\n\tadapter: AnalyticsAdapter\n\t/** Shared `platformRead` decision; one is created per call when omitted. */\n\tplatformRead?: PlatformReadGate\n}\n\n/**\n * The scope to stamp on one adapter query, or a refusal. Cross-scope reads fail closed\n * behind `platformRead`: the `'*'` marker, and any scoped read through a shared config\n * adapter that cannot narrow the query to one scope (whether or not it is the designated\n * platform adapter), which would otherwise answer with every scope's data. A tenant's own\n * runtime adapters are never gated. Every read path decides this here, so the widgets and\n * the query endpoint cannot drift apart on what counts as cross-scope.\n */\nexport const resolveQueryScope = async (\n\targs: QueryScopeArgs\n): Promise<{ ok: true; queryScope?: string } | { ok: false }> => {\n\tconst { runtime, req, scope, adapter } = args\n\tconst allowed = args.platformRead ?? platformReadGate(runtime, req)\n\tif (scope === PLATFORM_SCOPE) {\n\t\treturn (await allowed()) ? { ok: true } : { ok: false }\n\t}\n\tif (scope === null) {\n\t\treturn { ok: true }\n\t}\n\tif (runtime.configAdapterIds.has(adapter.id) && !adapter.capabilities.scopedQueries) {\n\t\treturn (await allowed()) ? { ok: true } : { ok: false }\n\t}\n\treturn { ok: true, queryScope: scope }\n}\n\n/**\n * Resolve one read's scope and adapter: explicit scope wins over the request's\n * resolved scope, the registry is resolved per scope, then the adapter is picked\n * by id (or the registry default). Cross-scope reads fail closed behind\n * `platformRead`: an explicit `'*'` scope always, any scoped read through a\n * shared config adapter that cannot narrow the query to one scope (whether or\n * not it is the designated platform adapter), and, on a scoped install, a\n * request that resolves no scope at all. That last case is ambiguous rather\n * than intentionally install-wide (a tenant's scopeResolver returning null\n * usually means \"no tenant selected\", not \"read everything\"), so it fails\n * closed the same way. An explicit `scope: null` override bypasses that gate:\n * it is the trusted server-side caller's path (cron passes, tests), never a\n * request's own resolution. A tenant's own runtime adapters are never gated.\n * Any resolution failure (unknown adapter id, a throwing scopeResolver or\n * provider lookup) degrades to `{ ok: false }` so read paths render their\n * unavailable state instead of throwing.\n */\nexport const resolveReadContext = async (args: ResolveReadContextArgs): Promise<ReadContext> => {\n\tconst { runtime, req, adapterId } = args\n\tconst allowed = platformReadGate(runtime, req)\n\ttry {\n\t\tconst scope = args.scope !== undefined ? args.scope : await resolveScopeFor(runtime, req)\n\t\tif (runtime.scoped && args.scope === undefined && scope === null && !(await allowed())) {\n\t\t\treturn { ok: false }\n\t\t}\n\t\tconst registryScope = scope === PLATFORM_SCOPE ? null : scope\n\t\tconst registry = await resolveRegistryFor(runtime, {\n\t\t\tpayload: req.payload,\n\t\t\treq,\n\t\t\tscope: registryScope,\n\t\t})\n\t\tconst adapter = adapterId ? registry.get(adapterId) : registry.default()\n\t\tconst decision = await resolveQueryScope({\n\t\t\truntime,\n\t\t\treq,\n\t\t\tscope,\n\t\t\tadapter,\n\t\t\tplatformRead: allowed,\n\t\t})\n\t\tif (!decision.ok) {\n\t\t\treturn { ok: false }\n\t\t}\n\t\treturn { ok: true, adapter, scope: registryScope, queryScope: decision.queryScope }\n\t} catch (err) {\n\t\treq.payload.logger?.warn(`analytics: read context resolution failed: ${String(err)}`)\n\t\treturn { ok: false }\n\t}\n}\n"],"mappings":";;;;;;;;;;;AA8CA,MAAa,oBAAoB,OAChC,SACgE;CAChE,MAAM,EAAE,SAAS,KAAK,OAAO,YAAY;CACzC,MAAM,UAAU,KAAK,gBAAgB,iBAAiB,SAAS,GAAG;CAClE,IAAI,UAAA,KACH,OAAQ,MAAM,QAAQ,IAAK,EAAE,IAAI,KAAK,IAAI,EAAE,IAAI,MAAM;CAEvD,IAAI,UAAU,MACb,OAAO,EAAE,IAAI,KAAK;CAEnB,IAAI,QAAQ,iBAAiB,IAAI,QAAQ,EAAE,KAAK,CAAC,QAAQ,aAAa,eACrE,OAAQ,MAAM,QAAQ,IAAK,EAAE,IAAI,KAAK,IAAI,EAAE,IAAI,MAAM;CAEvD,OAAO;EAAE,IAAI;EAAM,YAAY;CAAM;AACtC;;;;;;;;;;;;;;;;;;AAmBA,MAAa,qBAAqB,OAAO,SAAuD;CAC/F,MAAM,EAAE,SAAS,KAAK,cAAc;CACpC,MAAM,UAAU,iBAAiB,SAAS,GAAG;CAC7C,IAAI;EACH,MAAM,QAAQ,KAAK,UAAU,KAAA,IAAY,KAAK,QAAQ,MAAM,gBAAgB,SAAS,GAAG;EACxF,IAAI,QAAQ,UAAU,KAAK,UAAU,KAAA,KAAa,UAAU,QAAQ,CAAE,MAAM,QAAQ,GACnF,OAAO,EAAE,IAAI,MAAM;EAEpB,MAAM,gBAAgB,UAAA,MAA2B,OAAO;EACxD,MAAM,WAAW,MAAM,mBAAmB,SAAS;GAClD,SAAS,IAAI;GACb;GACA,OAAO;EACR,CAAC;EACD,MAAM,UAAU,YAAY,SAAS,IAAI,SAAS,IAAI,SAAS,QAAQ;EACvE,MAAM,WAAW,MAAM,kBAAkB;GACxC;GACA;GACA;GACA;GACA,cAAc;EACf,CAAC;EACD,IAAI,CAAC,SAAS,IACb,OAAO,EAAE,IAAI,MAAM;EAEpB,OAAO;GAAE,IAAI;GAAM;GAAS,OAAO;GAAe,YAAY,SAAS;EAAW;CACnF,SAAS,KAAK;EACb,IAAI,QAAQ,QAAQ,KAAK,8CAA8C,OAAO,GAAG,GAAG;EACpF,OAAO,EAAE,IAAI,MAAM;CACpB;AACD"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { RawEventInput } from "../native/ingest/normalizeEvent.js";
|
|
2
|
+
import { PayloadRequest } from "payload";
|
|
3
|
+
|
|
4
|
+
//#region src/core/serverEvent.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* One event recorded from server code. The fields a browser event carries mean exactly what
|
|
7
|
+
* they mean on the wire (and go through the same sanitizers); the rest say what the server
|
|
8
|
+
* knows that a browser request would otherwise have said for itself.
|
|
9
|
+
*/
|
|
10
|
+
type ServerEventInput = Pick<RawEventInput, 'type' | 'name' | 'path' | 'hostname' | 'referrer' | 'query' | 'props' | 'value' | 'currency'> & {
|
|
11
|
+
/**
|
|
12
|
+
* Attribution inputs, overlaid on `opts.req`'s own headers when there is a request.
|
|
13
|
+
* With neither, the event is attributed to the day's synthetic server visitor and
|
|
14
|
+
* reports no device, browser, OS or language: those are read off the request's headers,
|
|
15
|
+
* and inventing them would put a fabricated visitor in every breakdown. No IP is ever
|
|
16
|
+
* fabricated either.
|
|
17
|
+
*/
|
|
18
|
+
ip?: string;
|
|
19
|
+
userAgent?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Analytics boundary to stamp; null is install-wide. Unset resolves from `opts.req`.
|
|
22
|
+
* Ignored on an unscoped install, and never validated against the scopes that exist.
|
|
23
|
+
*/
|
|
24
|
+
scope?: string | null; /** IANA reporting timezone the rollup day bucket is computed in. */
|
|
25
|
+
timezone?: string; /** Event time; defaults to now. */
|
|
26
|
+
now?: Date;
|
|
27
|
+
};
|
|
28
|
+
interface ServerTrackOptions {
|
|
29
|
+
/** The request the event belongs to: attribution, scope and timezone all come from it. */
|
|
30
|
+
req?: PayloadRequest;
|
|
31
|
+
/**
|
|
32
|
+
* Wait for the write to land. On an install with a write buffer the call otherwise
|
|
33
|
+
* resolves as soon as the event is queued, and a failed flush only reaches the logger.
|
|
34
|
+
*/
|
|
35
|
+
flush?: boolean;
|
|
36
|
+
}
|
|
37
|
+
type ServerTrack = (event: ServerEventInput, opts?: ServerTrackOptions) => Promise<void>;
|
|
38
|
+
/** Thrown instead of dropping the event: a server caller can handle a rejected promise. */
|
|
39
|
+
declare class AnalyticsTrackError extends Error {
|
|
40
|
+
constructor(message: string);
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { AnalyticsTrackError, ServerEventInput, ServerTrack, ServerTrackOptions };
|
|
44
|
+
//# sourceMappingURL=serverEvent.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/core/serverEvent.ts
|
|
2
|
+
/** Thrown instead of dropping the event: a server caller can handle a rejected promise. */
|
|
3
|
+
var AnalyticsTrackError = class extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "AnalyticsTrackError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { AnalyticsTrackError };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=serverEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverEvent.js","names":[],"sources":["../../src/core/serverEvent.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport type { RawEventInput } from '../native/ingest/normalizeEvent'\n\n/**\n * One event recorded from server code. The fields a browser event carries mean exactly what\n * they mean on the wire (and go through the same sanitizers); the rest say what the server\n * knows that a browser request would otherwise have said for itself.\n */\nexport type ServerEventInput = Pick<\n\tRawEventInput,\n\t'type' | 'name' | 'path' | 'hostname' | 'referrer' | 'query' | 'props' | 'value' | 'currency'\n> & {\n\t/**\n\t * Attribution inputs, overlaid on `opts.req`'s own headers when there is a request.\n\t * With neither, the event is attributed to the day's synthetic server visitor and\n\t * reports no device, browser, OS or language: those are read off the request's headers,\n\t * and inventing them would put a fabricated visitor in every breakdown. No IP is ever\n\t * fabricated either.\n\t */\n\tip?: string\n\tuserAgent?: string\n\t/**\n\t * Analytics boundary to stamp; null is install-wide. Unset resolves from `opts.req`.\n\t * Ignored on an unscoped install, and never validated against the scopes that exist.\n\t */\n\tscope?: string | null\n\t/** IANA reporting timezone the rollup day bucket is computed in. */\n\ttimezone?: string\n\t/** Event time; defaults to now. */\n\tnow?: Date\n}\n\nexport interface ServerTrackOptions {\n\t/** The request the event belongs to: attribution, scope and timezone all come from it. */\n\treq?: PayloadRequest\n\t/**\n\t * Wait for the write to land. On an install with a write buffer the call otherwise\n\t * resolves as soon as the event is queued, and a failed flush only reaches the logger.\n\t */\n\tflush?: boolean\n}\n\nexport type ServerTrack = (event: ServerEventInput, opts?: ServerTrackOptions) => Promise<void>\n\n/** Thrown instead of dropping the event: a server caller can handle a rejected promise. */\nexport class AnalyticsTrackError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'AnalyticsTrackError'\n\t}\n}\n"],"mappings":";;AA6CA,IAAa,sBAAb,cAAyC,MAAM;CAC9C,YAAY,SAAiB;EAC5B,MAAM,OAAO;EACb,KAAK,OAAO;CACb;AACD"}
|
package/dist/exports/client.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { BarList, BarListProps } from "../charts/BarList.js";
|
|
2
|
-
import { TrendChart, TrendChartProps } from "../charts/TrendChart.js";
|
|
2
|
+
import { TrendChart, TrendChartProps, TrendPoint } from "../charts/TrendChart.js";
|
|
3
|
+
import { FilterDimensionSelectField, FilterDimensionSelectFieldProps } from "../fields/config/FilterDimensionSelectField.js";
|
|
4
|
+
import { FilterOperatorSelectField, FilterOperatorSelectFieldProps } from "../fields/config/FilterOperatorSelectField.js";
|
|
3
5
|
import { WireSource } from "../fields/config/fetchSources.js";
|
|
4
6
|
import { MetricSelectField, MetricSelectFieldProps } from "../fields/config/MetricSelectField.js";
|
|
5
7
|
import { SourceSelectField } from "../fields/config/SourceSelectField.js";
|
|
6
|
-
import { useAnalyticsSources } from "../fields/config/useAnalyticsSources.js";
|
|
8
|
+
import { AnalyticsSources, useAnalyticsSources } from "../fields/config/useAnalyticsSources.js";
|
|
9
|
+
import { FilterCapabilities, useFilterCapabilities } from "../fields/config/useFilterCapabilities.js";
|
|
7
10
|
import { DateRangeField } from "../fields/dateRange/ui.js";
|
|
11
|
+
import { GoalsResponse, WireGoal } from "../goals/fetchGoals.js";
|
|
12
|
+
import { GoalSelectField } from "../goals/GoalSelectField.js";
|
|
13
|
+
import { useAnalyticsGoals } from "../goals/useAnalyticsGoals.js";
|
|
14
|
+
import { QueryFetchError, QueryRequest, buildQueryUrl, fetchQuery } from "../query/fetchQuery.js";
|
|
15
|
+
import { AnalyticsNavLink, AnalyticsNavLinkProps } from "../view/AnalyticsNavLink.js";
|
|
16
|
+
import { AnalyticsViewClient } from "../view/AnalyticsViewClient.js";
|
|
8
17
|
import { RealtimeCounter } from "../widgets/RealtimeCounter.js";
|
|
9
|
-
export { BarList, type BarListProps, DateRangeField, MetricSelectField, type MetricSelectFieldProps, RealtimeCounter, SourceSelectField, TrendChart, type TrendChartProps, type WireSource, useAnalyticsSources };
|
|
18
|
+
export { AnalyticsNavLink, type AnalyticsNavLinkProps, type AnalyticsSources, AnalyticsViewClient, BarList, type BarListProps, DateRangeField, type FilterCapabilities, FilterDimensionSelectField, type FilterDimensionSelectFieldProps, FilterOperatorSelectField, type FilterOperatorSelectFieldProps, GoalSelectField, type GoalsResponse, MetricSelectField, type MetricSelectFieldProps, QueryFetchError, type QueryRequest, RealtimeCounter, SourceSelectField, TrendChart, type TrendChartProps, type TrendPoint, type WireGoal, type WireSource, buildQueryUrl, fetchQuery, useAnalyticsGoals, useAnalyticsSources, useFilterCapabilities };
|
package/dist/exports/client.js
CHANGED
|
@@ -2,8 +2,16 @@
|
|
|
2
2
|
import { BarList } from "../charts/BarList.js";
|
|
3
3
|
import { TrendChart } from "../charts/TrendChart.js";
|
|
4
4
|
import { useAnalyticsSources } from "../fields/config/useAnalyticsSources.js";
|
|
5
|
+
import { useFilterCapabilities } from "../fields/config/useFilterCapabilities.js";
|
|
6
|
+
import { FilterDimensionSelectField } from "../fields/config/FilterDimensionSelectField.js";
|
|
7
|
+
import { FilterOperatorSelectField } from "../fields/config/FilterOperatorSelectField.js";
|
|
5
8
|
import { MetricSelectField } from "../fields/config/MetricSelectField.js";
|
|
6
9
|
import { SourceSelectField } from "../fields/config/SourceSelectField.js";
|
|
7
10
|
import { DateRangeField } from "../fields/dateRange/ui.js";
|
|
11
|
+
import { useAnalyticsGoals } from "../goals/useAnalyticsGoals.js";
|
|
12
|
+
import { GoalSelectField } from "../goals/GoalSelectField.js";
|
|
13
|
+
import { QueryFetchError, buildQueryUrl, fetchQuery } from "../query/fetchQuery.js";
|
|
14
|
+
import { AnalyticsNavLink } from "../view/AnalyticsNavLink.js";
|
|
8
15
|
import { RealtimeCounter } from "../widgets/RealtimeCounter.js";
|
|
9
|
-
|
|
16
|
+
import { AnalyticsViewClient } from "../view/AnalyticsViewClient.js";
|
|
17
|
+
export { AnalyticsNavLink, AnalyticsViewClient, BarList, DateRangeField, FilterDimensionSelectField, FilterOperatorSelectField, GoalSelectField, MetricSelectField, QueryFetchError, RealtimeCounter, SourceSelectField, TrendChart, buildQueryUrl, fetchQuery, useAnalyticsGoals, useAnalyticsSources, useFilterCapabilities };
|
package/dist/exports/rsc.d.ts
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { AnalyticsFilter, DateRange, DimensionKey, MetricKey } from "../core/contract.js";
|
|
2
2
|
import { CapabilityRequirement } from "../core/capabilities.js";
|
|
3
|
+
import { AnalyticsViewClientProps, ViewGoal } from "../view/viewProps.js";
|
|
3
4
|
import { ReadForWidgetRealtimeArgs, RealtimePoint, WidgetRealtimeResult, WidgetRealtimeStatus, readForWidgetRealtime } from "../widgets/readForWidgetRealtime.js";
|
|
4
5
|
import { TrackerConfig, TrackerSlotConfig } from "../capture/trackerConfig.js";
|
|
5
6
|
import { getTrackerConfig } from "../capture/getTrackerConfig.js";
|
|
6
7
|
import { AnalyticsStatField } from "../fields/AnalyticsStatField.js";
|
|
7
8
|
import { AnalyticsPanelField } from "../fields/AnalyticsPanelField.js";
|
|
8
9
|
import { formatMetricValue } from "../fields/format.js";
|
|
9
|
-
import {
|
|
10
|
+
import { WidgetReadStatus } from "../widgets/prepareWidgetRead.js";
|
|
10
11
|
import { ReadForWidgetSeriesArgs, SeriesPoint, WidgetSeriesResult, readForWidgetSeries } from "../widgets/readForWidgetSeries.js";
|
|
11
12
|
import { FieldReadResult, FieldReadStatus, ReadForFieldArgs, readForField } from "../fields/readForDocument.js";
|
|
12
13
|
import { AnalyticsScripts, AnalyticsScriptsProps } from "../rsc/AnalyticsScripts.js";
|
|
14
|
+
import { AnalyticsView, AnalyticsViewProps } from "../view/AnalyticsView.js";
|
|
13
15
|
import { AnalyticsBreakdownWidget } from "../widgets/AnalyticsBreakdownWidget.js";
|
|
16
|
+
import { AnalyticsGoalsWidget } from "../widgets/AnalyticsGoalsWidget.js";
|
|
14
17
|
import { AnalyticsMetricWidget } from "../widgets/AnalyticsMetricWidget.js";
|
|
15
18
|
import { AnalyticsRealtimeWidget } from "../widgets/AnalyticsRealtimeWidget.js";
|
|
16
19
|
import { AnalyticsTrendWidget } from "../widgets/AnalyticsTrendWidget.js";
|
|
17
20
|
import { cardStyle, labelStyle } from "../widgets/cardChrome.js";
|
|
21
|
+
import { ReadForWidgetArgs, WidgetReadResult, readForWidget } from "../widgets/readForWidget.js";
|
|
18
22
|
import { BreakdownRow, ReadForWidgetBreakdownArgs, WidgetBreakdownResult, readForWidgetBreakdown } from "../widgets/readForWidgetBreakdown.js";
|
|
19
|
-
|
|
23
|
+
import { GoalRow, ReadForWidgetGoalsArgs, WidgetGoalsResult, readForWidgetGoals } from "../widgets/readForWidgetGoals.js";
|
|
24
|
+
export { AnalyticsBreakdownWidget, type AnalyticsFilter, AnalyticsGoalsWidget, AnalyticsMetricWidget, AnalyticsPanelField, AnalyticsRealtimeWidget, AnalyticsScripts, type AnalyticsScriptsProps, AnalyticsStatField, AnalyticsTrendWidget, AnalyticsView, type AnalyticsViewClientProps, type AnalyticsViewProps, type BreakdownRow, type CapabilityRequirement, type DateRange, type DimensionKey, type FieldReadResult, type FieldReadStatus, type GoalRow, type MetricKey, type ReadForFieldArgs, type ReadForWidgetArgs, type ReadForWidgetBreakdownArgs, type ReadForWidgetGoalsArgs, type ReadForWidgetRealtimeArgs, type ReadForWidgetSeriesArgs, type RealtimePoint, type SeriesPoint, type TrackerConfig, type TrackerSlotConfig, type ViewGoal, type WidgetBreakdownResult, type WidgetGoalsResult, type WidgetReadResult, type WidgetReadStatus, type WidgetRealtimeResult, type WidgetRealtimeStatus, type WidgetSeriesResult, formatMetricValue, getTrackerConfig, readForField, readForWidget, readForWidgetBreakdown, readForWidgetGoals, readForWidgetRealtime, readForWidgetSeries, cardStyle as widgetCardStyle, labelStyle as widgetLabelStyle };
|
package/dist/exports/rsc.js
CHANGED
|
@@ -3,14 +3,17 @@ import { readForField } from "../fields/readForDocument.js";
|
|
|
3
3
|
import { readForWidgetRealtime } from "../widgets/readForWidgetRealtime.js";
|
|
4
4
|
import { readForWidget } from "../widgets/readForWidget.js";
|
|
5
5
|
import { readForWidgetBreakdown } from "../widgets/readForWidgetBreakdown.js";
|
|
6
|
-
import { getTrackerConfig } from "../capture/getTrackerConfig.js";
|
|
7
6
|
import { formatMetricValue } from "../fields/format.js";
|
|
7
|
+
import { cardStyle, labelStyle } from "../widgets/cardChrome.js";
|
|
8
|
+
import { getTrackerConfig } from "../capture/getTrackerConfig.js";
|
|
8
9
|
import { AnalyticsStatField } from "../fields/AnalyticsStatField.js";
|
|
9
10
|
import { AnalyticsPanelField } from "../fields/AnalyticsPanelField.js";
|
|
10
11
|
import { AnalyticsScripts } from "../rsc/AnalyticsScripts.js";
|
|
11
|
-
import {
|
|
12
|
+
import { AnalyticsView } from "../view/AnalyticsView.js";
|
|
12
13
|
import AnalyticsBreakdownWidget from "../widgets/AnalyticsBreakdownWidget.js";
|
|
14
|
+
import { readForWidgetGoals } from "../widgets/readForWidgetGoals.js";
|
|
15
|
+
import AnalyticsGoalsWidget from "../widgets/AnalyticsGoalsWidget.js";
|
|
13
16
|
import AnalyticsMetricWidget from "../widgets/AnalyticsMetricWidget.js";
|
|
14
17
|
import AnalyticsRealtimeWidget from "../widgets/AnalyticsRealtimeWidget.js";
|
|
15
18
|
import AnalyticsTrendWidget from "../widgets/AnalyticsTrendWidget.js";
|
|
16
|
-
export { AnalyticsBreakdownWidget, AnalyticsMetricWidget, AnalyticsPanelField, AnalyticsRealtimeWidget, AnalyticsScripts, AnalyticsStatField, AnalyticsTrendWidget, formatMetricValue, getTrackerConfig, readForField, readForWidget, readForWidgetBreakdown, readForWidgetRealtime, readForWidgetSeries, cardStyle as widgetCardStyle, labelStyle as widgetLabelStyle };
|
|
19
|
+
export { AnalyticsBreakdownWidget, AnalyticsGoalsWidget, AnalyticsMetricWidget, AnalyticsPanelField, AnalyticsRealtimeWidget, AnalyticsScripts, AnalyticsStatField, AnalyticsTrendWidget, AnalyticsView, formatMetricValue, getTrackerConfig, readForField, readForWidget, readForWidgetBreakdown, readForWidgetGoals, readForWidgetRealtime, readForWidgetSeries, cardStyle as widgetCardStyle, labelStyle as widgetLabelStyle };
|
|
@@ -10,9 +10,10 @@ import { DEFAULT_TRACKER_ENDPOINT, InitTrackerArgs, initTracker } from "../track
|
|
|
10
10
|
import { createScriptLoader } from "../tracker/loadScript.js";
|
|
11
11
|
import { PageTracking, createPageTracking } from "../tracker/pageTracking.js";
|
|
12
12
|
import { TrackerLease, acquireTracker } from "../tracker/registry.js";
|
|
13
|
-
import { PAGEVIEW_BUFFER_MS, createNativeSink } from "../tracker/sinks/native.js";
|
|
14
13
|
import { VendorSinkArgs } from "../tracker/sinks/vendor.js";
|
|
14
|
+
import { createGa4Sink } from "../tracker/sinks/ga4.js";
|
|
15
|
+
import { PAGEVIEW_BUFFER_MS, createNativeSink } from "../tracker/sinks/native.js";
|
|
15
16
|
import { createPlausibleSink } from "../tracker/sinks/plausible.js";
|
|
16
17
|
import { createPosthogSink } from "../tracker/sinks/posthog.js";
|
|
17
18
|
import { createUmamiSink } from "../tracker/sinks/umami.js";
|
|
18
|
-
export { type AutoCapture, type AutoCaptureHandlers, CONSENT_QUEUE_LIMIT, CONSENT_STORAGE_KEY, type CaptureSnippet, type ConsentState, DEFAULT_TRACKER_ENDPOINT, DOWNLOAD_EVENT, GOAL_ATTRIBUTE, type InitTrackerArgs, type LoadScript, OUTBOUND_EVENT, PAGEVIEW_BUFFER_MS, type PageTracking, type ResolvedAutoCapture, SCROLL_EVENT, type Sink, type SnippetScript, type Tracker, type TrackerConfig, type TrackerEvent, type TrackerGoal, type TrackerLease, type TrackerOptions, type TrackerSlotConfig, type TrackerWindow, type VendorSinkArgs, acquireTracker, createAutoCapture, createConsentQueue, createNativeSink, createNoopTracker, createPageTracking, createPlausibleSink, createPosthogSink, createScriptLoader, createTracker, createUmamiSink, initTracker, readConsent, writeConsent };
|
|
19
|
+
export { type AutoCapture, type AutoCaptureHandlers, CONSENT_QUEUE_LIMIT, CONSENT_STORAGE_KEY, type CaptureSnippet, type ConsentState, DEFAULT_TRACKER_ENDPOINT, DOWNLOAD_EVENT, GOAL_ATTRIBUTE, type InitTrackerArgs, type LoadScript, OUTBOUND_EVENT, PAGEVIEW_BUFFER_MS, type PageTracking, type ResolvedAutoCapture, SCROLL_EVENT, type Sink, type SnippetScript, type Tracker, type TrackerConfig, type TrackerEvent, type TrackerGoal, type TrackerLease, type TrackerOptions, type TrackerSlotConfig, type TrackerWindow, type VendorSinkArgs, acquireTracker, createAutoCapture, createConsentQueue, createGa4Sink, createNativeSink, createNoopTracker, createPageTracking, createPlausibleSink, createPosthogSink, createScriptLoader, createTracker, createUmamiSink, initTracker, readConsent, writeConsent };
|
package/dist/exports/tracker.js
CHANGED
|
@@ -2,6 +2,7 @@ import { DOWNLOAD_EVENT, GOAL_ATTRIBUTE, OUTBOUND_EVENT, SCROLL_EVENT, createAut
|
|
|
2
2
|
import { CONSENT_QUEUE_LIMIT, CONSENT_STORAGE_KEY, createConsentQueue, readConsent, writeConsent } from "../tracker/consent.js";
|
|
3
3
|
import { createScriptLoader } from "../tracker/loadScript.js";
|
|
4
4
|
import { createPageTracking } from "../tracker/pageTracking.js";
|
|
5
|
+
import { createGa4Sink } from "../tracker/sinks/ga4.js";
|
|
5
6
|
import { PAGEVIEW_BUFFER_MS, createNativeSink } from "../tracker/sinks/native.js";
|
|
6
7
|
import { createPlausibleSink } from "../tracker/sinks/plausible.js";
|
|
7
8
|
import { createPosthogSink } from "../tracker/sinks/posthog.js";
|
|
@@ -9,4 +10,4 @@ import { createUmamiSink } from "../tracker/sinks/umami.js";
|
|
|
9
10
|
import { createNoopTracker, createTracker } from "../tracker/createTracker.js";
|
|
10
11
|
import { acquireTracker } from "../tracker/registry.js";
|
|
11
12
|
import { DEFAULT_TRACKER_ENDPOINT, initTracker } from "../tracker/initTracker.js";
|
|
12
|
-
export { CONSENT_QUEUE_LIMIT, CONSENT_STORAGE_KEY, DEFAULT_TRACKER_ENDPOINT, DOWNLOAD_EVENT, GOAL_ATTRIBUTE, OUTBOUND_EVENT, PAGEVIEW_BUFFER_MS, SCROLL_EVENT, acquireTracker, createAutoCapture, createConsentQueue, createNativeSink, createNoopTracker, createPageTracking, createPlausibleSink, createPosthogSink, createScriptLoader, createTracker, createUmamiSink, initTracker, readConsent, writeConsent };
|
|
13
|
+
export { CONSENT_QUEUE_LIMIT, CONSENT_STORAGE_KEY, DEFAULT_TRACKER_ENDPOINT, DOWNLOAD_EVENT, GOAL_ATTRIBUTE, OUTBOUND_EVENT, PAGEVIEW_BUFFER_MS, SCROLL_EVENT, acquireTracker, createAutoCapture, createConsentQueue, createGa4Sink, createNativeSink, createNoopTracker, createPageTracking, createPlausibleSink, createPosthogSink, createScriptLoader, createTracker, createUmamiSink, initTracker, readConsent, writeConsent };
|