@10x-media/analytics 0.1.0-beta.5 → 1.0.0-beta.10
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 +270 -0
- package/LICENSE +21 -21
- package/README.md +15 -4
- package/dist/adapters/ga4/disableKey.d.ts +9 -0
- package/dist/adapters/ga4/disableKey.js +21 -0
- package/dist/adapters/ga4/disableKey.js.map +1 -0
- 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 +186 -58
- 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/http/fetchJson.js +1 -1
- package/dist/adapters/plausible/plausible.d.ts +25 -0
- package/dist/adapters/plausible/plausible.js +159 -38
- package/dist/adapters/plausible/plausible.js.map +1 -1
- package/dist/adapters/posthog/posthog.d.ts +10 -1
- package/dist/adapters/posthog/posthog.js +130 -21
- package/dist/adapters/posthog/posthog.js.map +1 -1
- package/dist/adapters/series.js +11 -1
- package/dist/adapters/series.js.map +1 -1
- package/dist/adapters/umami/umami.d.ts +13 -1
- package/dist/adapters/umami/umami.js +278 -26
- package/dist/adapters/umami/umami.js.map +1 -1
- package/dist/binding/resolvePath.js +18 -2
- package/dist/binding/resolvePath.js.map +1 -1
- package/dist/capture/getTrackerConfig.d.ts +20 -0
- package/dist/capture/getTrackerConfig.js +31 -0
- package/dist/capture/getTrackerConfig.js.map +1 -0
- package/dist/capture/mountPath.js +14 -0
- package/dist/capture/mountPath.js.map +1 -0
- package/dist/capture/proxyEndpoint.js +127 -0
- package/dist/capture/proxyEndpoint.js.map +1 -0
- package/dist/capture/proxyRoutes.js +108 -0
- package/dist/capture/proxyRoutes.js.map +1 -0
- package/dist/capture/requestBody.js +68 -0
- package/dist/capture/requestBody.js.map +1 -0
- package/dist/capture/slots.d.ts +8 -0
- package/dist/capture/slots.js +54 -0
- package/dist/capture/slots.js.map +1 -0
- package/dist/capture/trackerConfig.d.ts +33 -0
- package/dist/capture/trackerConfig.js +95 -0
- package/dist/capture/trackerConfig.js.map +1 -0
- package/dist/capture/trackerEndpoint.js +35 -0
- package/dist/capture/trackerEndpoint.js.map +1 -0
- package/dist/charts/BarList.d.ts +16 -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 +4 -0
- package/dist/charts/bars.js +3 -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 +26 -3
- package/dist/core/cacheKey.js.map +1 -1
- package/dist/core/capabilities.d.ts +5 -1
- package/dist/core/capabilities.js +11 -2
- package/dist/core/capabilities.js.map +1 -1
- package/dist/core/capture.d.ts +49 -0
- package/dist/core/contract.d.ts +74 -5
- package/dist/core/contract.js +30 -1
- package/dist/core/contract.js.map +1 -1
- package/dist/core/granularity.js +1 -1
- package/dist/core/options.d.ts +164 -6
- package/dist/core/options.js +126 -3
- package/dist/core/options.js.map +1 -1
- package/dist/core/registry.d.ts +1 -0
- package/dist/core/scopeList.js +32 -0
- package/dist/core/scopeList.js.map +1 -0
- package/dist/core/scopedRead.js +101 -30
- package/dist/core/scopedRead.js.map +1 -1
- package/dist/core/serverEvent.d.ts +60 -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/adapters/native.d.ts +3 -1
- package/dist/exports/adapters/native.js +2 -1
- package/dist/exports/client.d.ts +13 -3
- package/dist/exports/client.js +10 -1
- package/dist/exports/geo.d.ts +2 -2
- package/dist/exports/next.d.ts +2 -1
- package/dist/exports/next.js +2 -1
- package/dist/exports/react.d.ts +4 -0
- package/dist/exports/react.js +5 -0
- package/dist/exports/rsc.d.ts +11 -3
- package/dist/exports/rsc.js +7 -2
- package/dist/exports/tracker.d.ts +21 -0
- package/dist/exports/tracker.js +15 -0
- package/dist/exports/types.d.ts +16 -3
- package/dist/exports/types.js +4 -2
- package/dist/fields/AnalyticsPanelClient.js +2 -2
- 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/fetchSources.js +7 -3
- package/dist/fields/config/fetchSources.js.map +1 -1
- package/dist/fields/config/narrow.js +2 -0
- package/dist/fields/config/narrow.js.map +1 -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 +22 -10
- 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 +254 -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 +33 -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 +58 -0
- package/dist/goals/goalsEndpoint.js.map +1 -0
- package/dist/goals/match.js +64 -0
- package/dist/goals/match.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 +76 -0
- package/dist/goals/trackGoalAction.js +158 -0
- package/dist/goals/trackGoalAction.js.map +1 -0
- package/dist/goals/types.d.ts +33 -0
- package/dist/goals/types.js +7 -0
- package/dist/goals/types.js.map +1 -0
- package/dist/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 +14 -3
- package/dist/index.js +174 -19
- package/dist/index.js.map +1 -1
- package/dist/native/collections/events.js +65 -1
- package/dist/native/collections/events.js.map +1 -1
- package/dist/native/collections/rollups.js +39 -3
- package/dist/native/collections/rollups.js.map +1 -1
- package/dist/native/eventScan.js +25 -0
- package/dist/native/eventScan.js.map +1 -0
- package/dist/native/geo/composeGeoResolvers.js +2 -2
- package/dist/native/geo/composeGeoResolvers.js.map +1 -1
- package/dist/native/geo/geoResolver.d.ts +9 -2
- package/dist/native/geo/geoResolver.js.map +1 -1
- package/dist/native/geo/maxmindResolver.js +3 -5
- package/dist/native/geo/maxmindResolver.js.map +1 -1
- package/dist/native/ingest/bots.d.ts +11 -0
- package/dist/native/ingest/bots.js +71 -0
- package/dist/native/ingest/bots.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/clientIp.js +20 -0
- package/dist/native/ingest/clientIp.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 +107 -21
- package/dist/native/ingest/endpoint.js.map +1 -1
- package/dist/native/ingest/flushBatch.js +29 -38
- 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 +30 -0
- package/dist/native/ingest/normalizeEvent.js +115 -16
- 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/requestHost.js +57 -0
- package/dist/native/ingest/requestHost.js.map +1 -0
- package/dist/native/ingest/resolveHostname.d.ts +29 -0
- package/dist/native/ingest/resolveHostname.js +52 -0
- package/dist/native/ingest/resolveHostname.js.map +1 -0
- package/dist/native/ingest/salt.js +27 -2
- package/dist/native/ingest/salt.js.map +1 -1
- package/dist/native/ingest/serverTrack.d.ts +20 -0
- package/dist/native/ingest/serverTrack.js +109 -0
- package/dist/native/ingest/serverTrack.js.map +1 -0
- package/dist/native/ingest/source.d.ts +11 -0
- package/dist/native/ingest/source.js +264 -16
- 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 +26 -0
- package/dist/native/ingest/validate.js.map +1 -0
- package/dist/native/nativeAdapter.d.ts +37 -1
- package/dist/native/nativeAdapter.js +175 -22
- package/dist/native/nativeAdapter.js.map +1 -1
- package/dist/native/query/eventAgg.js +175 -0
- package/dist/native/query/eventAgg.js.map +1 -0
- package/dist/native/retention/pruneTask.js +53 -13
- package/dist/native/retention/pruneTask.js.map +1 -1
- package/dist/native/rollupAcc.js +12 -1
- package/dist/native/rollupAcc.js.map +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 +86 -11
- 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 +42 -0
- package/dist/next/captureRewrites.js +57 -0
- package/dist/next/captureRewrites.js.map +1 -0
- package/dist/next/posthogProxyRewrites.d.ts +5 -0
- package/dist/next/posthogProxyRewrites.js +16 -21
- package/dist/next/posthogProxyRewrites.js.map +1 -1
- package/dist/plugin/documentEndpoint.js +71 -24
- package/dist/plugin/documentEndpoint.js.map +1 -1
- package/dist/plugin/errors.d.ts +31 -0
- package/dist/plugin/errors.js +79 -0
- package/dist/plugin/errors.js.map +1 -0
- 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 +17 -1
- package/dist/plugin/paths.js.map +1 -1
- package/dist/plugin/queryEndpoint.js +124 -0
- package/dist/plugin/queryEndpoint.js.map +1 -0
- package/dist/plugin/readContextForRequest.js +73 -0
- package/dist/plugin/readContextForRequest.js.map +1 -0
- package/dist/plugin/realtimeEndpoint.js +37 -16
- package/dist/plugin/realtimeEndpoint.js.map +1 -1
- package/dist/plugin/refreshEndpoint.js +113 -0
- package/dist/plugin/refreshEndpoint.js.map +1 -0
- package/dist/plugin/runtime.d.ts +1 -0
- package/dist/plugin/runtime.js +33 -1
- package/dist/plugin/runtime.js.map +1 -1
- package/dist/plugin/scopeChange.js +22 -0
- package/dist/plugin/scopeChange.js.map +1 -0
- package/dist/plugin/scopeFieldBoot.js +22 -0
- package/dist/plugin/scopeFieldBoot.js.map +1 -0
- package/dist/plugin/sourcesEndpoint.js +16 -41
- 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 +89 -29
- package/dist/providers/collection.js.map +1 -1
- package/dist/providers/factory.js +11 -3
- 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 +14 -0
- package/dist/query/fetchQuery.d.ts +79 -0
- package/dist/query/fetchQuery.js +117 -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/react/AnalyticsProvider.d.ts +50 -0
- package/dist/react/AnalyticsProvider.js +67 -0
- package/dist/react/AnalyticsProvider.js.map +1 -0
- package/dist/react/TrackerBoot.d.ts +22 -0
- package/dist/react/TrackerBoot.js +30 -0
- package/dist/react/TrackerBoot.js.map +1 -0
- package/dist/react/useAnalytics.d.ts +20 -0
- package/dist/react/useAnalytics.js +52 -0
- package/dist/react/useAnalytics.js.map +1 -0
- package/dist/rsc/AnalyticsScripts.d.ts +30 -0
- package/dist/rsc/AnalyticsScripts.js +41 -0
- package/dist/rsc/AnalyticsScripts.js.map +1 -0
- package/dist/surfacing/cacheStore.d.ts +1 -0
- package/dist/surfacing/cacheStore.js +18 -2
- package/dist/surfacing/cacheStore.js.map +1 -1
- package/dist/surfacing/engine.d.ts +1 -0
- package/dist/surfacing/engine.js +47 -6
- package/dist/surfacing/engine.js.map +1 -1
- package/dist/surfacing/epoch.d.ts +1 -0
- package/dist/surfacing/epoch.js +72 -0
- package/dist/surfacing/epoch.js.map +1 -0
- package/dist/surfacing/queue.js +22 -6
- package/dist/surfacing/queue.js.map +1 -1
- package/dist/surfacing/rateLimiter.js +130 -0
- package/dist/surfacing/rateLimiter.js.map +1 -0
- package/dist/surfacing/retryPolicy.js +15 -0
- package/dist/surfacing/retryPolicy.js.map +1 -0
- package/dist/sync/collection.js +23 -7
- package/dist/sync/collection.js.map +1 -1
- package/dist/sync/syncTask.js +68 -33
- package/dist/sync/syncTask.js.map +1 -1
- package/dist/testing/memoryAdapter.d.ts +2 -0
- package/dist/testing/memoryAdapter.js +17 -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/autoCapture.d.ts +48 -0
- package/dist/tracker/autoCapture.js +129 -0
- package/dist/tracker/autoCapture.js.map +1 -0
- package/dist/tracker/consent.d.ts +24 -0
- package/dist/tracker/consent.js +48 -0
- package/dist/tracker/consent.js.map +1 -0
- package/dist/tracker/createTracker.d.ts +18 -0
- package/dist/tracker/createTracker.js +215 -0
- package/dist/tracker/createTracker.js.map +1 -0
- package/dist/tracker/exclusion.d.ts +28 -0
- package/dist/tracker/exclusion.js +50 -0
- package/dist/tracker/exclusion.js.map +1 -0
- package/dist/tracker/initTracker.d.ts +22 -0
- package/dist/tracker/initTracker.js +33 -0
- package/dist/tracker/initTracker.js.map +1 -0
- package/dist/tracker/loadScript.d.ts +14 -0
- package/dist/tracker/loadScript.js +41 -0
- package/dist/tracker/loadScript.js.map +1 -0
- package/dist/tracker/pageTracking.d.ts +17 -0
- package/dist/tracker/pageTracking.js +38 -0
- package/dist/tracker/pageTracking.js.map +1 -0
- package/dist/tracker/registry.d.ts +27 -0
- package/dist/tracker/registry.js +73 -0
- package/dist/tracker/registry.js.map +1 -0
- package/dist/tracker/sinks/ga4.d.ts +29 -0
- package/dist/tracker/sinks/ga4.js +30 -0
- package/dist/tracker/sinks/ga4.js.map +1 -0
- package/dist/tracker/sinks/native.d.ts +22 -0
- package/dist/tracker/sinks/native.js +56 -0
- package/dist/tracker/sinks/native.js.map +1 -0
- package/dist/tracker/sinks/plausible.d.ts +20 -0
- package/dist/tracker/sinks/plausible.js +32 -0
- package/dist/tracker/sinks/plausible.js.map +1 -0
- package/dist/tracker/sinks/posthog.d.ts +18 -0
- package/dist/tracker/sinks/posthog.js +30 -0
- package/dist/tracker/sinks/posthog.js.map +1 -0
- package/dist/tracker/sinks/umami.d.ts +18 -0
- package/dist/tracker/sinks/umami.js +23 -0
- package/dist/tracker/sinks/umami.js.map +1 -0
- package/dist/tracker/sinks/vendor.d.ts +14 -0
- package/dist/tracker/sinks/vendor.js +81 -0
- package/dist/tracker/sinks/vendor.js.map +1 -0
- package/dist/tracker/transport.js +28 -0
- package/dist/tracker/transport.js.map +1 -0
- package/dist/tracker/types.d.ts +91 -0
- package/dist/translations/ar.js +221 -0
- package/dist/translations/ar.js.map +1 -0
- package/dist/translations/de.js +145 -1
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +145 -1
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +221 -0
- package/dist/translations/es.js.map +1 -0
- package/dist/translations/fr.js +221 -0
- package/dist/translations/fr.js.map +1 -0
- package/dist/translations/id.js +221 -0
- package/dist/translations/id.js.map +1 -0
- package/dist/translations/index.d.ts +10 -1
- package/dist/translations/index.js +19 -1
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/keys.d.ts +144 -0
- package/dist/translations/keys.js +145 -1
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +221 -0
- package/dist/translations/ko.js.map +1 -0
- package/dist/translations/metricKeys.js +8 -2
- package/dist/translations/metricKeys.js.map +1 -1
- package/dist/translations/pt.js +221 -0
- package/dist/translations/pt.js.map +1 -0
- package/dist/translations/ru.js +221 -0
- package/dist/translations/ru.js.map +1 -0
- package/dist/translations/server.js.map +1 -1
- package/dist/translations/uk.js +221 -0
- package/dist/translations/uk.js.map +1 -0
- package/dist/translations/zh.js +221 -0
- package/dist/translations/zh.js.map +1 -0
- 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 +244 -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 +76 -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 +198 -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 +207 -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 +76 -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 +18 -4
- 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 +38 -0
- 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 +78 -23
- 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 +26 -3
- package/dist/widgets/readForWidget.js +48 -44
- package/dist/widgets/readForWidget.js.map +1 -1
- package/dist/widgets/readForWidgetBreakdown.d.ts +34 -2
- package/dist/widgets/readForWidgetBreakdown.js +53 -49
- 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 +23 -21
- package/dist/widgets/readForWidgetRealtime.js.map +1 -1
- package/dist/widgets/readForWidgetSeries.d.ts +26 -2
- package/dist/widgets/readForWidgetSeries.js +78 -53
- 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/realtimePoll.js +13 -1
- package/dist/widgets/realtimePoll.js.map +1 -1
- package/dist/widgets/registerWidgets.js +62 -10
- package/dist/widgets/registerWidgets.js.map +1 -1
- package/dist/widgets/types.d.ts +15 -0
- package/dist/widgets/types.js +16 -2
- 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 +28 -8
- package/dist/native/rollups/applyDistinctDeltas.js +0 -9
- package/dist/native/rollups/applyDistinctDeltas.js.map +0 -1
- package/dist/native/rollups/bumpRollup.js +0 -68
- 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/contract.js
CHANGED
|
@@ -4,7 +4,36 @@
|
|
|
4
4
|
* scope. Gated by `access.platformRead`; the query reaches the adapter unscoped.
|
|
5
5
|
*/
|
|
6
6
|
const PLATFORM_SCOPE = "*";
|
|
7
|
+
/** Every breakdown key the contract defines; the registry request parsers validate against. */
|
|
8
|
+
const DIMENSION_KEYS = [
|
|
9
|
+
"page",
|
|
10
|
+
"referrer",
|
|
11
|
+
"source",
|
|
12
|
+
"channel",
|
|
13
|
+
"medium",
|
|
14
|
+
"campaign",
|
|
15
|
+
"utmSource",
|
|
16
|
+
"utmMedium",
|
|
17
|
+
"utmCampaign",
|
|
18
|
+
"utmContent",
|
|
19
|
+
"utmTerm",
|
|
20
|
+
"device",
|
|
21
|
+
"browser",
|
|
22
|
+
"os",
|
|
23
|
+
"country",
|
|
24
|
+
"region",
|
|
25
|
+
"city",
|
|
26
|
+
"language",
|
|
27
|
+
"event",
|
|
28
|
+
"goal"
|
|
29
|
+
];
|
|
30
|
+
/** Every filter operator the contract defines; the registry request parsers validate against. */
|
|
31
|
+
const FILTER_OPERATORS = [
|
|
32
|
+
"eq",
|
|
33
|
+
"contains",
|
|
34
|
+
"matches"
|
|
35
|
+
];
|
|
7
36
|
//#endregion
|
|
8
|
-
export { PLATFORM_SCOPE };
|
|
37
|
+
export { DIMENSION_KEYS, FILTER_OPERATORS, PLATFORM_SCOPE };
|
|
9
38
|
|
|
10
39
|
//# sourceMappingURL=contract.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","names":[],"sources":["../../src/core/contract.ts"],"sourcesContent":["import type { Config, PayloadRequest } from 'payload'\n\n/**\n * Explicit cross-scope read marker: pass as a read's `scope` to aggregate over every\n * scope. Gated by `access.platformRead`; the query reaches the adapter unscoped.\n */\nexport const PLATFORM_SCOPE = '*'\n\nexport type MetricKey =\n\t| 'pageviews'\n\t| 'visitors'\n\t| 'visits'\n\t| 'sessions'\n\t| 'bounceRate'\n\t| 'avgDuration'\n\t| 'scrollDepth'\n\t| 'events'\n\t| 'conversions'\n\t| 'revenue'\n\nexport
|
|
1
|
+
{"version":3,"file":"contract.js","names":[],"sources":["../../src/core/contract.ts"],"sourcesContent":["import type { Config, PayloadRequest } from 'payload'\nimport type { Goal } from '../goals/types'\nimport type { CaptureSupport } from './capture'\nimport type { IngestHostnameResolver, ServerTrack } from './serverEvent'\n\n/**\n * Explicit cross-scope read marker: pass as a read's `scope` to aggregate over every\n * scope. Gated by `access.platformRead`; the query reaches the adapter unscoped.\n */\nexport const PLATFORM_SCOPE = '*'\n\nexport type MetricKey =\n\t| 'pageviews'\n\t| 'visitors'\n\t| 'visits'\n\t| 'sessions'\n\t| 'bounceRate'\n\t| 'avgDuration'\n\t| 'scrollDepth'\n\t| 'events'\n\t| 'conversions'\n\t| 'revenue'\n\n/** Every breakdown key the contract defines; the registry request parsers validate against. */\nexport const DIMENSION_KEYS = [\n\t'page',\n\t'referrer',\n\t'source',\n\t'channel',\n\t'medium',\n\t'campaign',\n\t'utmSource',\n\t'utmMedium',\n\t'utmCampaign',\n\t'utmContent',\n\t'utmTerm',\n\t'device',\n\t'browser',\n\t'os',\n\t'country',\n\t'region',\n\t'city',\n\t'language',\n\t'event',\n\t'goal',\n] as const\n\nexport type DimensionKey = (typeof DIMENSION_KEYS)[number]\n\nexport type Granularity = 'minute' | 'hour' | 'day' | 'week' | 'month'\n\nexport interface DateRange {\n\tstart: Date\n\tend: Date\n}\n\n/** Every filter operator the contract defines; the registry request parsers validate against. */\nexport const FILTER_OPERATORS = ['eq', 'contains', 'matches'] as const\n\nexport type FilterOperator = (typeof FILTER_OPERATORS)[number]\n\nexport interface AnalyticsFilter {\n\tdimension: DimensionKey\n\toperator: FilterOperator\n\tvalue: string\n}\n\nexport interface AnalyticsQuery {\n\tpath?: string\n\thostname?: string\n\tmetrics: MetricKey[]\n\tdimensions?: DimensionKey[]\n\tdateRange: DateRange\n\tgranularity?: Granularity\n\tfilters?: AnalyticsFilter[]\n\tlimit?: number\n\torder?: { metric: MetricKey; direction: 'asc' | 'desc' }\n\t/**\n\t * Analytics boundary this read belongs to (tenant id, site key). Undefined means\n\t * install-wide (the default). Adapters that can filter by scope apply it; others\n\t * ignore it. Always part of the surfacing cache key, so per-scope adapter\n\t * instances sharing an id never share cached results.\n\t */\n\tscope?: string\n\t/**\n\t * IANA reporting timezone the read's day boundaries are aligned to. Undefined\n\t * means UTC. Adapters that can bucket in a timezone apply it (PostHog, Umami);\n\t * others report in their own account timezone. Part of the cache key when set.\n\t */\n\ttimezone?: string\n\t/**\n\t * The scope's goal slugs, set by callers that ask for the `goal` dimension or the\n\t * `conversions` metric, and possibly empty when the scope configures no goals. Provider\n\t * adapters restrict goal rows to it, since nothing in a provider marks which of its\n\t * events are this install's goals; the native engine ignores it and matches completions\n\t * itself. `'unresolved'` is the sentinel for a goal resolver that failed: the read keeps\n\t * its site numbers, reports `goalsUnresolved`, and never shares a healthy cache key.\n\t * Part of the surfacing cache key when set.\n\t */\n\tgoalSlugs?: string[] | 'unresolved'\n}\n\nexport interface AnalyticsRow {\n\tdimensions?: Partial<Record<DimensionKey, string>>\n\tmetrics: Partial<Record<MetricKey, number>>\n\ttimestamp?: string\n}\n\nexport interface AnalyticsResult {\n\trows: AnalyticsRow[]\n\ttotals?: Partial<Record<MetricKey, number>>\n\tmeta: {\n\t\tprovider: string\n\t\tsampled?: boolean\n\t\tclamped?: boolean\n\t\tfetchedAt: string\n\t\t/** Served from an expired cache entry because the live refresh failed. */\n\t\tstale?: boolean\n\t\t/**\n\t\t * Filters the source could not carry, so the rows are wider than the query asked for.\n\t\t * A provider whose API takes one value per dimension reports the ones it dropped here.\n\t\t */\n\t\tunappliedFilters?: AnalyticsFilter[]\n\t\t/**\n\t\t * The read's goal numbers are absent because resolving them failed: it ran without\n\t\t * `AnalyticsQuery.goalSlugs`, or with `'unresolved'`, or the provider rejected the goal\n\t\t * request and the rest of the read was served without it. A scope that configured no\n\t\t * goals is an empty result instead, not this flag.\n\t\t */\n\t\tgoalsUnresolved?: true\n\t}\n}\n\n/**\n * A read carrying conversions costs a provider up to twice the requests: the goal numbers\n * come from a second, goal-filtered request the adapter issues after the plain one.\n */\nexport interface RateLimitDescriptor {\n\trequestsPerMinute?: number\n\trequestsPerHour?: number\n\tmaxConcurrent?: number\n\t/**\n\t * Describes the provider's quota model for documentation; the limiter always\n\t * throttles by request count regardless of this value.\n\t */\n\tquotaModel?: 'requests' | 'tokens'\n\t/** Documents whether reads consume the provider's write/ingest quota too. */\n\treadsCountAsUsage?: boolean\n}\n\nexport interface AnalyticsCapabilities {\n\tperPageQuery: boolean\n\trealtime: boolean\n\trealtimeWindowMinutes?: number\n\t/**\n\t * Period-over-period comparison, which the engine serves for every source by reading the\n\t * previous window itself. Adapters omit this; set it false only to opt a source out.\n\t */\n\tcomparison?: boolean\n\tminGranularity: Granularity\n\tmaxLookbackDays: number | null\n\tmetrics: ReadonlySet<MetricKey>\n\tdimensions: ReadonlySet<DimensionKey>\n\t/** Dimensions the adapter can apply AnalyticsQuery.filters on; empty = filters unsupported. */\n\tfilters: ReadonlySet<DimensionKey>\n\t/** Operators the adapter honors in filters; adapters ignore filters whose operator they lack. */\n\tfilterOperators: ReadonlySet<FilterOperator>\n\tbatchPageReport: boolean\n\trateLimit: RateLimitDescriptor | null\n\trecommendedTtl: { realtime: number; aggregate: number }\n\t/**\n\t * The adapter applies `AnalyticsQuery.scope` as a provider-native filter (native\n\t * scope column, PostHog `scopeProperty`, ...). Without it, a scoped read through\n\t * a shared platform adapter would expose cross-scope data, so such reads are\n\t * gated by `access.platformRead`.\n\t */\n\tscopedQueries?: boolean\n}\n\nexport interface AdapterContext {\n\tsignal?: AbortSignal\n}\n\n/** Extra context the plugin hands adapters when they register config surface. */\nexport interface AdapterRegisterContext {\n\t/** True when the plugin has a scopeResolver configured. */\n\tscoped: boolean\n\t/** The plugin's scopeResolver bound for adapter use (e.g. ingest stamping). */\n\tresolveScope: (req: PayloadRequest) => Promise<string | null>\n\t/**\n\t * The plugin's reportingTimezone bound for adapter use (e.g. bucketing native\n\t * rollups at ingest). Resolves to `'UTC'` when no reportingTimezone is set.\n\t */\n\tresolveTimezone: (req: PayloadRequest, scope?: string | null) => Promise<string>\n\t/**\n\t * The install's goals for a request's scope, for adapters that match completions\n\t * themselves (the native engine, at ingest). Config goals, with the goals collection\n\t * merged over them per scope once the install enables it.\n\t */\n\tresolveGoals: (req: PayloadRequest, scope?: string | null) => Promise<Goal[]>\n\t/** The plugin's `trustedProxyHops`, for adapters that read a request's client address. */\n\ttrustedProxyHops?: number\n}\n\nexport interface AnalyticsAdapter {\n\treadonly id: string\n\treadonly label: string\n\treadonly capabilities: AnalyticsCapabilities\n\t/** Browser-tracker proxying/boot descriptor. Absent when no public capture field is set. */\n\treadonly capture?: CaptureSupport\n\t/**\n\t * Where this adapter's own ingest endpoint listens, relative to `routes.api`, for the\n\t * adapters that register one (the native engine), and how server code reaches the same\n\t * pipeline without an HTTP round trip. Server-side only: the tracker learns the path\n\t * from `TrackerConfig.ingestPath`, and this object is never serialized.\n\t */\n\treadonly ingest?: { path: string; track?: ServerTrack; hostname?: IngestHostnameResolver }\n\tisConfigured(): boolean\n\tquery(query: AnalyticsQuery, ctx: AdapterContext): Promise<AnalyticsResult>\n\trealtime?(query: AnalyticsQuery, ctx: AdapterContext): Promise<AnalyticsResult>\n\tregister?(config: Config, context?: AdapterRegisterContext): void\n}\n\nexport type AnalyticsAdapterFactory<Config> = (config: Config) => AnalyticsAdapter\n"],"mappings":";;;;;AASA,MAAa,iBAAiB;;AAe9B,MAAa,iBAAiB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;AAYA,MAAa,mBAAmB;CAAC;CAAM;CAAY;AAAS"}
|
package/dist/core/granularity.js
CHANGED
|
@@ -12,6 +12,6 @@ const GRANULARITY_ORDER = [
|
|
|
12
12
|
*/
|
|
13
13
|
const supportsGranularity = (caps, g) => GRANULARITY_ORDER.indexOf(g) >= GRANULARITY_ORDER.indexOf(caps.minGranularity);
|
|
14
14
|
//#endregion
|
|
15
|
-
export { supportsGranularity };
|
|
15
|
+
export { GRANULARITY_ORDER, supportsGranularity };
|
|
16
16
|
|
|
17
17
|
//# sourceMappingURL=granularity.js.map
|
package/dist/core/options.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Goal } from "../goals/types.js";
|
|
2
|
+
import { AnalyticsAdapter, MetricKey } from "./contract.js";
|
|
3
3
|
import { AnalyticsBinding } from "../binding/types.js";
|
|
4
|
+
import { CaptureSlot } from "../capture/slots.js";
|
|
5
|
+
import { TimeframePreset } from "../timeframe/presets.js";
|
|
6
|
+
import { TranslationsOption } from "../translations/index.js";
|
|
4
7
|
import { CustomWidgetDef } from "../widgets/customWidget.js";
|
|
5
8
|
import { CollectionConfig, CollectionSlug, Payload, PayloadRequest } from "payload";
|
|
6
9
|
import { KeysConfig } from "@10x-media/fields/encrypted";
|
|
@@ -24,6 +27,13 @@ type TimezoneResolver = (args: {
|
|
|
24
27
|
req: PayloadRequest;
|
|
25
28
|
scope: string | null;
|
|
26
29
|
}) => string | null | Promise<string | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Enumerates the tenant scopes the cron tiers (cache warming, sync) fan out over.
|
|
32
|
+
* Absent, each tier runs once for the install-wide scope.
|
|
33
|
+
*/
|
|
34
|
+
type ScopesResolver = (args: {
|
|
35
|
+
payload: Payload;
|
|
36
|
+
}) => string[] | Promise<string[]>;
|
|
27
37
|
/**
|
|
28
38
|
* Escape hatch replacing the provider-collection lookup: return the runtime
|
|
29
39
|
* adapters for a scope yourself (any store, any shape). Results are layered onto
|
|
@@ -63,7 +73,22 @@ type ProvidersOptions = {
|
|
|
63
73
|
type PlatformReadAccess = (args: {
|
|
64
74
|
req: PayloadRequest;
|
|
65
75
|
}) => boolean | Promise<boolean>;
|
|
76
|
+
/** Access checker for authenticated analytics reads. */
|
|
77
|
+
type AnalyticsReadAccess = (args: {
|
|
78
|
+
req: PayloadRequest;
|
|
79
|
+
}) => boolean | Promise<boolean>;
|
|
80
|
+
/** Access checker for the analytics admin view. */
|
|
81
|
+
type AnalyticsViewAccess = (args: {
|
|
82
|
+
req: PayloadRequest;
|
|
83
|
+
}) => boolean | Promise<boolean>;
|
|
66
84
|
type AnalyticsAccessOptions = {
|
|
85
|
+
/**
|
|
86
|
+
* Gates every authenticated read endpoint: query, document panel, realtime, sources
|
|
87
|
+
* and goals. Defaults to any authenticated user; narrow it to a role check to keep
|
|
88
|
+
* analytics away from admins who should not see them. Scope gating is separate and
|
|
89
|
+
* always applies: granting `read` never widens which scope a user reads.
|
|
90
|
+
*/
|
|
91
|
+
read?: AnalyticsReadAccess;
|
|
67
92
|
/**
|
|
68
93
|
* Gates cross-scope reads: explicit `scope: '*'` reads, and scoped reads through
|
|
69
94
|
* a shared config adapter that cannot filter by scope. Scoped installs
|
|
@@ -72,6 +97,112 @@ type AnalyticsAccessOptions = {
|
|
|
72
97
|
* providers. Unscoped installs default to any authenticated admin-panel user.
|
|
73
98
|
*/
|
|
74
99
|
platformRead?: PlatformReadAccess;
|
|
100
|
+
/**
|
|
101
|
+
* Gates the analytics admin view. Defaults to `read`, so one gate covers the view and
|
|
102
|
+
* the endpoints behind it. A reader this denies still sees the nav link (it is a client
|
|
103
|
+
* component with no access context) and lands on the view's no-access message.
|
|
104
|
+
*/
|
|
105
|
+
view?: AnalyticsViewAccess;
|
|
106
|
+
};
|
|
107
|
+
type ConsentMode = 'none' | 'required';
|
|
108
|
+
/** Per-slot consent decision, evaluated against the slot's resolved adapter. */
|
|
109
|
+
type ConsentResolver = (args: {
|
|
110
|
+
slot: CaptureSlot;
|
|
111
|
+
adapterId: string;
|
|
112
|
+
}) => ConsentMode;
|
|
113
|
+
/** An adapter id to fill a capture slot with, or `false` to leave it deliberately empty. */
|
|
114
|
+
type CaptureSlotOption = string | false;
|
|
115
|
+
/**
|
|
116
|
+
* A bare mode applies to every slot; a resolver decides per request-resolved adapter; the
|
|
117
|
+
* object form maps ids and slots, with an adapter entry winning over a slot entry. Every
|
|
118
|
+
* form overrides the default, which is `none` for the cookieless native tracker and
|
|
119
|
+
* `required` for a vendor's.
|
|
120
|
+
*/
|
|
121
|
+
type CaptureConsentOption = ConsentMode | ConsentResolver | {
|
|
122
|
+
slots?: Partial<Record<CaptureSlot, ConsentMode>>;
|
|
123
|
+
/**
|
|
124
|
+
* Keyed by adapter id. A bare id must name a config adapter; a runtime provider
|
|
125
|
+
* instance id (`<provider>:<instance>`) is taken on trust, since the providers it
|
|
126
|
+
* comes from are only resolved per request.
|
|
127
|
+
*/
|
|
128
|
+
adapters?: Record<string, ConsentMode>;
|
|
129
|
+
};
|
|
130
|
+
type AutoCaptureOptions = {
|
|
131
|
+
scrollDepth?: boolean;
|
|
132
|
+
outboundLinks?: boolean;
|
|
133
|
+
fileDownloads?: boolean;
|
|
134
|
+
goalAttribute?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Send each pageview's query string so ingest can extract its utm keys. The raw query is
|
|
137
|
+
* never stored, only the five campaign values; set false to stop sending it at all.
|
|
138
|
+
*/
|
|
139
|
+
query?: boolean;
|
|
140
|
+
};
|
|
141
|
+
type ResolvedAutoCapture = Required<AutoCaptureOptions>;
|
|
142
|
+
type AnalyticsGoalsCollectionOptions = {
|
|
143
|
+
/** Set false to keep the object form's other settings while leaving the collection off. */enabled?: boolean;
|
|
144
|
+
slug?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Field matched against the resolved scope when looking up a scope's goals. Point it at
|
|
147
|
+
* a tenant plugin's field (e.g. 'tenant') when that plugin manages scoping.
|
|
148
|
+
*/
|
|
149
|
+
scopeField?: string;
|
|
150
|
+
overrides?: (collection: CollectionConfig) => CollectionConfig;
|
|
151
|
+
access?: Partial<CollectionConfig['access']>;
|
|
152
|
+
};
|
|
153
|
+
/** Goals as config, plus the opt-in collection editors manage their own goals through. */
|
|
154
|
+
type AnalyticsGoalsOptions = {
|
|
155
|
+
defaults?: Goal[]; /** Opt-in admin collection whose goals merge over `defaults`, by slug, per scope. */
|
|
156
|
+
collection?: boolean | AnalyticsGoalsCollectionOptions;
|
|
157
|
+
};
|
|
158
|
+
type AnalyticsCaptureOptions = {
|
|
159
|
+
/**
|
|
160
|
+
* Which adapter fills each capture slot, overriding the defaults: `global` is the
|
|
161
|
+
* designated `platformAdapter`, or the single config adapter when only one is
|
|
162
|
+
* configured; `tenant` is the resolved scope's default adapter. A `global` id must
|
|
163
|
+
* name a config adapter; a `tenant` id may also name a runtime provider instance,
|
|
164
|
+
* so it is resolved per request rather than validated at config time.
|
|
165
|
+
*
|
|
166
|
+
* `false` disables a slot outright: it fills with nothing, its proxy mount 404s, and
|
|
167
|
+
* the tracker config omits it. Use it to keep a default from filling a slot at all.
|
|
168
|
+
*/
|
|
169
|
+
slots?: {
|
|
170
|
+
global?: CaptureSlotOption;
|
|
171
|
+
tenant?: CaptureSlotOption;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Mount each slot's snippet points at. Defaults to the runtime proxy endpoint
|
|
175
|
+
* (`<routes.api>/analytics/p/<slot>`); set it when the slot is served through Next
|
|
176
|
+
* rewrites instead, passing the same path `captureRewrites` was mounted at.
|
|
177
|
+
*/
|
|
178
|
+
paths?: {
|
|
179
|
+
global?: string;
|
|
180
|
+
tenant?: string;
|
|
181
|
+
}; /** Whether a slot's tracker waits for consent. Native defaults to no gate, vendors to one. */
|
|
182
|
+
consent?: CaptureConsentOption; /** Browser auto-capture listeners, all on by default except `scrollDepth`. */
|
|
183
|
+
autoCapture?: AutoCaptureOptions; /** Limits for the public runtime capture proxy, separate from the read-path `cache`. */
|
|
184
|
+
proxy?: {
|
|
185
|
+
/**
|
|
186
|
+
* Deadline for the upstream response headers, in ms. Default 10000. The body
|
|
187
|
+
* download is not on the clock, so a large tracker bundle streams to completion.
|
|
188
|
+
*/
|
|
189
|
+
timeoutMs?: number;
|
|
190
|
+
/**
|
|
191
|
+
* Largest proxied request body, in bytes. Default 1 MiB, which clears a PostHog
|
|
192
|
+
* batch carrying session-replay data. Anything larger is refused with 413.
|
|
193
|
+
*/
|
|
194
|
+
maxBodyBytes?: number;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
type AnalyticsViewOptions = {
|
|
198
|
+
/** Admin path the view mounts at, under `routes.admin`. Default `/analytics`. */path?: `/${string}`; /** Timeframe the view opens on before the URL says otherwise. Default `last30days`. */
|
|
199
|
+
defaultRange?: TimeframePreset; /** Metric the cards and the trend open on. Default `pageviews`. */
|
|
200
|
+
defaultMetric?: MetricKey;
|
|
201
|
+
/**
|
|
202
|
+
* Nav link label. A string is used as-is; a map is keyed by admin language code and
|
|
203
|
+
* falls back to `en`. Unset, the plugin's own translated label applies.
|
|
204
|
+
*/
|
|
205
|
+
navLabel?: string | Record<string, string>;
|
|
75
206
|
};
|
|
76
207
|
type AnalyticsPluginOptions = {
|
|
77
208
|
disabled?: boolean;
|
|
@@ -85,6 +216,12 @@ type AnalyticsPluginOptions = {
|
|
|
85
216
|
adapters?: AnalyticsAdapter[];
|
|
86
217
|
defaultAdapter?: string;
|
|
87
218
|
scopeResolver?: ScopeResolver;
|
|
219
|
+
/**
|
|
220
|
+
* Enumerates the tenant scopes the cache-warming and sync cron tiers fan out
|
|
221
|
+
* over, in addition to the install-wide (null) scope every tier already runs.
|
|
222
|
+
* Unset, those tiers run once for the whole install, same as before.
|
|
223
|
+
*/
|
|
224
|
+
scopes?: ScopesResolver;
|
|
88
225
|
/**
|
|
89
226
|
* IANA reporting timezone that day boundaries (timeframe windows, series axes,
|
|
90
227
|
* native rollup buckets) align to. Defaults to UTC. A string forces one timezone
|
|
@@ -102,7 +239,26 @@ type AnalyticsPluginOptions = {
|
|
|
102
239
|
* require `access.platformRead`.
|
|
103
240
|
*/
|
|
104
241
|
platformAdapter?: string;
|
|
242
|
+
/**
|
|
243
|
+
* How many proxies in front of the app are trusted, counted from the right of
|
|
244
|
+
* `x-forwarded-for`, when the plugin reads a request's client address (the native visitor
|
|
245
|
+
* hash, geo, and the address the capture proxy forwards upstream). It also lets the native
|
|
246
|
+
* ingest read `x-forwarded-host` for the event's hostname. Unset keeps the leftmost
|
|
247
|
+
* forwarded entry, which the client controls.
|
|
248
|
+
*/
|
|
249
|
+
trustedProxyHops?: number;
|
|
105
250
|
access?: AnalyticsAccessOptions;
|
|
251
|
+
/**
|
|
252
|
+
* The analytics admin view and its nav link, on by default. `false` registers neither;
|
|
253
|
+
* the read endpoints stay mounted either way, so a custom surface keeps working.
|
|
254
|
+
*/
|
|
255
|
+
view?: false | AnalyticsViewOptions;
|
|
256
|
+
capture?: AnalyticsCaptureOptions;
|
|
257
|
+
/**
|
|
258
|
+
* Conversion goals the tracker and the native ingest match events against. Slugs must
|
|
259
|
+
* be unique and kebab-case; only the slug and its match reach the browser.
|
|
260
|
+
*/
|
|
261
|
+
goals?: Goal[] | AnalyticsGoalsOptions;
|
|
106
262
|
/**
|
|
107
263
|
* Per-collection bindings, keyed by collection slug. With generated types
|
|
108
264
|
* augmented, each slug's resolvers receive that collection's typed document.
|
|
@@ -115,7 +271,8 @@ type AnalyticsPluginOptions = {
|
|
|
115
271
|
};
|
|
116
272
|
warm?: boolean | {
|
|
117
273
|
cron?: string;
|
|
118
|
-
};
|
|
274
|
+
}; /** Per-read provider timeout in ms, spanning retries and limiter waits. Default 15000. */
|
|
275
|
+
timeoutMs?: number;
|
|
119
276
|
};
|
|
120
277
|
widgets?: boolean | {
|
|
121
278
|
disabled?: string[];
|
|
@@ -128,8 +285,9 @@ type AnalyticsPluginOptions = {
|
|
|
128
285
|
localizeText?: boolean;
|
|
129
286
|
/**
|
|
130
287
|
* Period-over-period comparison on the metric and trend widgets. On by
|
|
131
|
-
* default for
|
|
132
|
-
* to skip the second
|
|
288
|
+
* default for every source except one whose adapter sets
|
|
289
|
+
* `capabilities.comparison` false; set false to skip the second
|
|
290
|
+
* (previous-window) read entirely.
|
|
133
291
|
*/
|
|
134
292
|
comparison?: boolean;
|
|
135
293
|
};
|
|
@@ -148,5 +306,5 @@ type AnalyticsPluginOptions = {
|
|
|
148
306
|
};
|
|
149
307
|
};
|
|
150
308
|
//#endregion
|
|
151
|
-
export { AnalyticsAccessOptions, AnalyticsPluginOptions, PlatformReadAccess, ProvidersCollectionOptions, ProvidersOptions, ProvidersResolve, ScopeResolver, TimezoneResolver };
|
|
309
|
+
export { AnalyticsAccessOptions, AnalyticsCaptureOptions, AnalyticsGoalsCollectionOptions, AnalyticsGoalsOptions, AnalyticsPluginOptions, AnalyticsReadAccess, AnalyticsViewAccess, AnalyticsViewOptions, AutoCaptureOptions, CaptureConsentOption, ConsentMode, ConsentResolver, PlatformReadAccess, ProvidersCollectionOptions, ProvidersOptions, ProvidersResolve, ResolvedAutoCapture, ScopeResolver, ScopesResolver, TimezoneResolver };
|
|
152
310
|
//# sourceMappingURL=options.d.ts.map
|
package/dist/core/options.js
CHANGED
|
@@ -1,10 +1,101 @@
|
|
|
1
|
+
import "../capture/proxyEndpoint.js";
|
|
2
|
+
import { GOAL_SLUG_PATTERN } from "../goals/types.js";
|
|
3
|
+
import { GOALS_SLUG } from "../goals/collection.js";
|
|
1
4
|
import { PROVIDERS_SLUG } from "../providers/collection.js";
|
|
5
|
+
import { TIMEFRAME_PRESETS } from "../timeframe/presets.js";
|
|
6
|
+
import { METRIC_KEYS } from "../translations/metricKeys.js";
|
|
2
7
|
//#region src/core/options.ts
|
|
3
8
|
const DEFAULT_WARM_CRON = "*/30 * * * *";
|
|
4
9
|
const DEFAULT_SYNC_CRON = "0 */6 * * *";
|
|
5
10
|
const DEFAULT_SYNC_COLLECTION = "analytics-daily";
|
|
6
11
|
const DEFAULT_SYNC_LOOKBACK = 3;
|
|
7
12
|
const DEFAULT_SCOPE_FIELD = "scope";
|
|
13
|
+
const DEFAULT_TIMEOUT_MS = 15e3;
|
|
14
|
+
/** Scroll depth is the one listener off by default: it fires on every page, for every visitor. */
|
|
15
|
+
const DEFAULT_AUTO_CAPTURE = {
|
|
16
|
+
scrollDepth: false,
|
|
17
|
+
outboundLinks: true,
|
|
18
|
+
fileDownloads: true,
|
|
19
|
+
goalAttribute: true,
|
|
20
|
+
query: true
|
|
21
|
+
};
|
|
22
|
+
const resolveAutoCapture = (option) => ({
|
|
23
|
+
scrollDepth: option?.scrollDepth ?? DEFAULT_AUTO_CAPTURE.scrollDepth,
|
|
24
|
+
outboundLinks: option?.outboundLinks ?? DEFAULT_AUTO_CAPTURE.outboundLinks,
|
|
25
|
+
fileDownloads: option?.fileDownloads ?? DEFAULT_AUTO_CAPTURE.fileDownloads,
|
|
26
|
+
goalAttribute: option?.goalAttribute ?? DEFAULT_AUTO_CAPTURE.goalAttribute,
|
|
27
|
+
query: option?.query ?? DEFAULT_AUTO_CAPTURE.query
|
|
28
|
+
});
|
|
29
|
+
/** Cookieless native capture needs no consent gate; a vendor's tracker does. */
|
|
30
|
+
const defaultConsentFor = (kind) => kind === "native" ? "none" : "required";
|
|
31
|
+
const resolveConsent = (option, adapters) => {
|
|
32
|
+
if (option === "none" || option === "required") return () => option;
|
|
33
|
+
if (typeof option === "function") return (slot, adapterId) => option({
|
|
34
|
+
slot,
|
|
35
|
+
adapterId
|
|
36
|
+
});
|
|
37
|
+
for (const id of Object.keys(option?.adapters ?? {})) if (!id.includes(":") && !adapters.some((a) => a.id === id)) throw new Error(`analytics: unknown consent adapter "${id}"`);
|
|
38
|
+
return (slot, adapterId, kind) => option?.adapters?.[adapterId] ?? option?.slots?.[slot] ?? defaultConsentFor(kind);
|
|
39
|
+
};
|
|
40
|
+
const resolveGoals = (option) => {
|
|
41
|
+
const goals = Array.isArray(option) ? option : option?.defaults ?? [];
|
|
42
|
+
const seen = /* @__PURE__ */ new Set();
|
|
43
|
+
for (const goal of goals) {
|
|
44
|
+
if (!GOAL_SLUG_PATTERN.test(goal.slug)) throw new Error(`analytics: goal slug "${goal.slug}" must be kebab-case`);
|
|
45
|
+
if (seen.has(goal.slug)) throw new Error(`analytics: duplicate goal slug "${goal.slug}"`);
|
|
46
|
+
const fixed = goal.value?.fixed;
|
|
47
|
+
if (fixed !== void 0 && (!Number.isFinite(fixed) || fixed < 0)) throw new Error(`analytics: goal "${goal.slug}" value.fixed must be a finite number >= 0, got ${String(fixed)}`);
|
|
48
|
+
seen.add(goal.slug);
|
|
49
|
+
}
|
|
50
|
+
return goals;
|
|
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
|
+
};
|
|
8
99
|
const resolveBindings = (collections) => {
|
|
9
100
|
const out = {};
|
|
10
101
|
for (const [slug, binding] of Object.entries(collections ?? {})) {
|
|
@@ -17,6 +108,11 @@ const resolveBindings = (collections) => {
|
|
|
17
108
|
function resolveOptions(options) {
|
|
18
109
|
if (!options.adapters || options.adapters.length === 0) throw new Error("analytics: at least one adapter is required");
|
|
19
110
|
if (options.platformAdapter !== void 0 && !options.adapters.some((a) => a.id === options.platformAdapter)) throw new Error(`analytics: unknown platform adapter "${options.platformAdapter}"`);
|
|
111
|
+
for (const [slot, value] of Object.entries(options.capture?.slots ?? {})) if (value !== false && typeof value !== "string" && value !== void 0) throw new Error(`analytics: capture slot "${slot}" must be an adapter id or false, got ${typeof value}`);
|
|
112
|
+
const hops = options.trustedProxyHops;
|
|
113
|
+
if (hops !== void 0 && (!Number.isInteger(hops) || hops < 0)) throw new Error(`analytics: trustedProxyHops must be a non-negative integer, got ${String(hops)}`);
|
|
114
|
+
const globalSlot = options.capture?.slots?.global;
|
|
115
|
+
if (typeof globalSlot === "string" && !options.adapters.some((a) => a.id === globalSlot)) throw new Error(`analytics: unknown global capture slot adapter "${globalSlot}"`);
|
|
20
116
|
const widgets = options.widgets === false ? {
|
|
21
117
|
enabled: false,
|
|
22
118
|
disabled: [],
|
|
@@ -93,14 +189,40 @@ function resolveOptions(options) {
|
|
|
93
189
|
hidden: true
|
|
94
190
|
};
|
|
95
191
|
const scoped = options.scopeResolver !== void 0;
|
|
192
|
+
const read = options.access?.read ?? (({ req }) => Boolean(req.user));
|
|
96
193
|
return {
|
|
97
194
|
adapters: options.adapters,
|
|
98
195
|
defaultAdapter: options.defaultAdapter,
|
|
99
196
|
scopeResolver: options.scopeResolver ?? (() => null),
|
|
100
197
|
scoped,
|
|
198
|
+
scopes: options.scopes,
|
|
101
199
|
reportingTimezone: options.reportingTimezone,
|
|
102
200
|
platformAdapter: options.platformAdapter,
|
|
103
|
-
|
|
201
|
+
trustedProxyHops: hops,
|
|
202
|
+
access: {
|
|
203
|
+
platformRead: options.access?.platformRead ?? (scoped ? () => false : ({ req }) => Boolean(req.user)),
|
|
204
|
+
read,
|
|
205
|
+
view: options.access?.view ?? read
|
|
206
|
+
},
|
|
207
|
+
view: resolveView(options.view),
|
|
208
|
+
capture: {
|
|
209
|
+
slots: {
|
|
210
|
+
global: options.capture?.slots?.global,
|
|
211
|
+
tenant: options.capture?.slots?.tenant
|
|
212
|
+
},
|
|
213
|
+
paths: {
|
|
214
|
+
global: options.capture?.paths?.global,
|
|
215
|
+
tenant: options.capture?.paths?.tenant
|
|
216
|
+
},
|
|
217
|
+
consent: resolveConsent(options.capture?.consent, options.adapters),
|
|
218
|
+
autoCapture: resolveAutoCapture(options.capture?.autoCapture),
|
|
219
|
+
proxy: {
|
|
220
|
+
timeoutMs: options.capture?.proxy?.timeoutMs ?? 1e4,
|
|
221
|
+
maxBodyBytes: options.capture?.proxy?.maxBodyBytes ?? 1048576
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
goals: resolveGoals(options.goals),
|
|
225
|
+
goalsCollection: resolveGoalsCollection(options.goals),
|
|
104
226
|
providers,
|
|
105
227
|
bindings: resolveBindings(options.collections),
|
|
106
228
|
cache: {
|
|
@@ -108,13 +230,14 @@ function resolveOptions(options) {
|
|
|
108
230
|
aggregate: options.cache?.ttl?.aggregate,
|
|
109
231
|
realtime: options.cache?.ttl?.realtime
|
|
110
232
|
},
|
|
111
|
-
warm
|
|
233
|
+
warm,
|
|
234
|
+
timeoutMs: options.cache?.timeoutMs ?? DEFAULT_TIMEOUT_MS
|
|
112
235
|
},
|
|
113
236
|
widgets,
|
|
114
237
|
sync
|
|
115
238
|
};
|
|
116
239
|
}
|
|
117
240
|
//#endregion
|
|
118
|
-
export { resolveOptions };
|
|
241
|
+
export { DEFAULT_AUTO_CAPTURE, DEFAULT_VIEW, defaultConsentFor, resolveOptions };
|
|
119
242
|
|
|
120
243
|
//# 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 { PROVIDERS_SLUG } from '../providers/collection'\nimport type { TranslationsOption } from '../translations'\nimport type { CustomWidgetDef } from '../widgets/customWidget'\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'\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 * 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 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 * 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 * 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?: { ttl?: { aggregate?: number; realtime?: number }; warm?: boolean | { cron?: string } }\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 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 reportingTimezone option; normalized into a resolver at init. */\n\treportingTimezone?: string | TimezoneResolver\n\tplatformAdapter?: string\n\taccess: { platformRead: PlatformReadAccess }\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}\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\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\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\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\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},\n\t\twidgets,\n\t\tsync,\n\t}\n}\n"],"mappings":";;AAQA,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAC1B,MAAM,0BAA0B;AAChC,MAAM,wBAAwB;AAC9B,MAAM,sBAAsB;AA8L5B,MAAM,mBACL,gBACqC;CACrC,MAAM,MAAuC,CAAC;CAC9C,KAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,eAAe,CAAC,CAAC,GAAG;EAChE,IAAI,CAAC,SAAS;EACd,IAAI,CAAC,QAAQ,QAAQ,CAAC,QAAQ,WAC7B,MAAM,IAAI,MAAM,2BAA2B,KAAK,uCAAuC;EAIxF,IAAI,QAAQ;CACb;CACA,OAAO;AACR;AAEA,SAAgB,eAAe,SAAkD;CAChF,IAAI,CAAC,QAAQ,YAAY,QAAQ,SAAS,WAAW,GACpD,MAAM,IAAI,MAAM,6CAA6C;CAE9D,IACC,QAAQ,oBAAoB,KAAA,KAC5B,CAAC,QAAQ,SAAS,MAAM,MAAM,EAAE,OAAO,QAAQ,eAAe,GAE9D,MAAM,IAAI,MAAM,wCAAwC,QAAQ,gBAAgB,EAAE;CAEnF,MAAM,UACL,QAAQ,YAAY,QACjB;EACA,SAAS;EACT,UAAU,CAAC;EACX,UAAU,CAAC;EACX,cAAc;EACd,YAAY;CACb,IACC,QAAQ,YAAY,KAAA,KAAa,QAAQ,YAAY,OACpD;EACA,SAAS;EACT,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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,mBAAmB,QAAQ;EAC3B,iBAAiB,QAAQ;EACzB,QAAQ,EACP,cACC,QAAQ,QAAQ,iBAAiB,eAAe,SAAS,EAAE,UAAU,QAAQ,IAAI,IAAI,GACvF;EACA;EACA,UAAU,gBAAgB,QAAQ,WAAW;EAC7C,OAAO;GAGN,KAAK;IACJ,WAAW,QAAQ,OAAO,KAAK;IAC/B,UAAU,QAAQ,OAAO,KAAK;GAC/B;GACA;EACD;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\t/**\n\t * How many proxies in front of the app are trusted, counted from the right of\n\t * `x-forwarded-for`, when the plugin reads a request's client address (the native visitor\n\t * hash, geo, and the address the capture proxy forwards upstream). It also lets the native\n\t * ingest read `x-forwarded-host` for the event's hostname. Unset keeps the leftmost\n\t * forwarded entry, which the client controls.\n\t */\n\ttrustedProxyHops?: number\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\t/** Raw trustedProxyHops option; undefined keeps the leftmost forwarded-for entry. */\n\ttrustedProxyHops?: number\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 hops = options.trustedProxyHops\n\tif (hops !== undefined && (!Number.isInteger(hops) || hops < 0)) {\n\t\tthrow new Error(\n\t\t\t`analytics: trustedProxyHops must be a non-negative integer, got ${String(hops)}`\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\ttrustedProxyHops: hops,\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;;AAkZ3B,MAAa,uBAA4C;CACxD,aAAa;CACb,eAAe;CACf,eAAe;CACf,eAAe;CACf,OAAO;AACR;AAEA,MAAM,sBAAsB,YAAiE;CAC5F,aAAa,QAAQ,eAAe,qBAAqB;CACzD,eAAe,QAAQ,iBAAiB,qBAAqB;CAC7D,eAAe,QAAQ,iBAAiB,qBAAqB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
|
|
1
|
+
//#region src/core/scopeList.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolves the scopes a cron tier (warm, sync) fans out over: the install-wide
|
|
4
|
+
* null scope first, then each tenant scope from `scopes()`, deduplicated (an
|
|
5
|
+
* empty string folds into null). A throwing or rejecting resolver degrades to
|
|
6
|
+
* the null-only pass so one tenant-enumeration bug does not block the whole run.
|
|
7
|
+
*/
|
|
8
|
+
const resolveScopeList = async (scopes, payload) => {
|
|
9
|
+
if (!scopes) return [null];
|
|
10
|
+
let raw;
|
|
11
|
+
try {
|
|
12
|
+
const result = await scopes({ payload });
|
|
13
|
+
if (!Array.isArray(result)) throw new Error("scopes() must resolve to an array of scope ids");
|
|
14
|
+
raw = result;
|
|
15
|
+
} catch (err) {
|
|
16
|
+
payload.logger.warn(`analytics: scopes() failed, falling back to the install-wide scope: ${String(err)}`);
|
|
17
|
+
return [null];
|
|
18
|
+
}
|
|
19
|
+
const out = [null];
|
|
20
|
+
const seen = new Set([null]);
|
|
21
|
+
for (const value of raw) {
|
|
22
|
+
const scope = value === "" ? null : value;
|
|
23
|
+
if (seen.has(scope)) continue;
|
|
24
|
+
seen.add(scope);
|
|
25
|
+
out.push(scope);
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { resolveScopeList };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=scopeList.js.map
|