@10x-media/analytics 1.0.0-beta.7 → 1.0.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +118 -0
- package/LICENSE +21 -21
- package/README.md +10 -4
- package/dist/adapters/ga4/eventName.d.ts +15 -0
- package/dist/adapters/ga4/eventName.js +19 -0
- package/dist/adapters/ga4/eventName.js.map +1 -0
- package/dist/adapters/ga4/ga4.d.ts +5 -0
- package/dist/adapters/ga4/ga4.js +179 -70
- package/dist/adapters/ga4/ga4.js.map +1 -1
- package/dist/adapters/ga4/measurementId.js +15 -0
- package/dist/adapters/ga4/measurementId.js.map +1 -0
- package/dist/adapters/goalRead.js +126 -0
- package/dist/adapters/goalRead.js.map +1 -0
- package/dist/adapters/plausible/plausible.d.ts +15 -0
- package/dist/adapters/plausible/plausible.js +112 -43
- package/dist/adapters/plausible/plausible.js.map +1 -1
- package/dist/adapters/posthog/posthog.js +47 -25
- package/dist/adapters/posthog/posthog.js.map +1 -1
- package/dist/adapters/umami/umami.d.ts +8 -0
- package/dist/adapters/umami/umami.js +237 -28
- package/dist/adapters/umami/umami.js.map +1 -1
- package/dist/capture/slots.js +16 -5
- package/dist/capture/slots.js.map +1 -1
- package/dist/capture/trackerConfig.d.ts +1 -0
- package/dist/capture/trackerConfig.js +28 -3
- package/dist/capture/trackerConfig.js.map +1 -1
- package/dist/charts/BarList.d.ts +15 -1
- package/dist/charts/BarList.js +41 -19
- package/dist/charts/BarList.js.map +1 -1
- package/dist/charts/TrendChart.d.ts +16 -3
- package/dist/charts/TrendChart.js +172 -106
- package/dist/charts/TrendChart.js.map +1 -1
- package/dist/charts/bars.d.ts +2 -0
- package/dist/charts/bars.js +2 -1
- package/dist/charts/bars.js.map +1 -1
- package/dist/charts/bucket.js +10 -1
- package/dist/charts/bucket.js.map +1 -1
- package/dist/charts/spline.js +2 -2
- package/dist/charts/spline.js.map +1 -1
- package/dist/charts/styles.js +18 -1
- package/dist/charts/styles.js.map +1 -1
- package/dist/core/cacheKey.js +24 -2
- package/dist/core/cacheKey.js.map +1 -1
- package/dist/core/capabilities.js +7 -2
- package/dist/core/capabilities.js.map +1 -1
- package/dist/core/capture.d.ts +1 -1
- package/dist/core/contract.d.ts +46 -9
- package/dist/core/contract.js +29 -1
- package/dist/core/contract.js.map +1 -1
- package/dist/core/granularity.js +1 -1
- package/dist/core/options.d.ts +62 -7
- package/dist/core/options.js +63 -4
- package/dist/core/options.js.map +1 -1
- package/dist/core/scopedRead.js +33 -23
- package/dist/core/scopedRead.js.map +1 -1
- package/dist/core/serverEvent.d.ts +44 -0
- package/dist/core/serverEvent.js +12 -0
- package/dist/core/serverEvent.js.map +1 -0
- package/dist/exports/adapters/ga4.d.ts +2 -1
- package/dist/exports/adapters/ga4.js +2 -1
- package/dist/exports/client.d.ts +12 -3
- package/dist/exports/client.js +9 -1
- package/dist/exports/rsc.d.ts +7 -2
- package/dist/exports/rsc.js +6 -3
- package/dist/exports/tracker.d.ts +3 -2
- package/dist/exports/tracker.js +2 -1
- package/dist/exports/types.d.ts +13 -4
- package/dist/exports/types.js +3 -2
- package/dist/fields/AnalyticsPanelClient.js +1 -1
- package/dist/fields/AnalyticsPanelField.js +1 -1
- package/dist/fields/AnalyticsStatField.js +2 -2
- package/dist/fields/config/FilterDimensionSelectField.d.ts +14 -0
- package/dist/fields/config/FilterDimensionSelectField.js +77 -0
- package/dist/fields/config/FilterDimensionSelectField.js.map +1 -0
- package/dist/fields/config/FilterOperatorSelectField.d.ts +14 -0
- package/dist/fields/config/FilterOperatorSelectField.js +75 -0
- package/dist/fields/config/FilterOperatorSelectField.js.map +1 -0
- package/dist/fields/config/MetricSelectField.js +3 -3
- package/dist/fields/config/MetricSelectField.js.map +1 -1
- package/dist/fields/config/SourceSelectField.js +3 -3
- package/dist/fields/config/SourceSelectField.js.map +1 -1
- package/dist/fields/config/fetchSources.d.ts +5 -1
- package/dist/fields/config/sourcesState.js +19 -3
- package/dist/fields/config/sourcesState.js.map +1 -1
- package/dist/fields/config/useAnalyticsSources.d.ts +8 -3
- package/dist/fields/config/useAnalyticsSources.js +9 -6
- package/dist/fields/config/useAnalyticsSources.js.map +1 -1
- package/dist/fields/config/useFilterCapabilities.d.ts +28 -0
- package/dist/fields/config/useFilterCapabilities.js +52 -0
- package/dist/fields/config/useFilterCapabilities.js.map +1 -0
- package/dist/fields/readForDocument.d.ts +5 -0
- package/dist/fields/readForDocument.js +21 -9
- package/dist/fields/readForDocument.js.map +1 -1
- package/dist/goals/GoalSelectField.d.ts +7 -0
- package/dist/goals/GoalSelectField.js +77 -0
- package/dist/goals/GoalSelectField.js.map +1 -0
- package/dist/goals/collection.js +250 -0
- package/dist/goals/collection.js.map +1 -0
- package/dist/goals/currency.js +14 -0
- package/dist/goals/currency.js.map +1 -0
- package/dist/goals/fetchGoals.d.ts +18 -0
- package/dist/goals/fetchGoals.js +29 -0
- package/dist/goals/fetchGoals.js.map +1 -0
- package/dist/goals/goalField.d.ts +31 -0
- package/dist/goals/goalField.js +56 -0
- package/dist/goals/goalField.js.map +1 -0
- package/dist/goals/goalsEndpoint.d.ts +1 -0
- package/dist/goals/goalsEndpoint.js +55 -0
- package/dist/goals/goalsEndpoint.js.map +1 -0
- package/dist/goals/resolver.d.ts +8 -0
- package/dist/goals/resolver.js +147 -0
- package/dist/goals/resolver.js.map +1 -0
- package/dist/goals/trackGoalAction.d.ts +74 -0
- package/dist/goals/trackGoalAction.js +139 -0
- package/dist/goals/trackGoalAction.js.map +1 -0
- package/dist/goals/useAnalyticsGoals.d.ts +20 -0
- package/dist/goals/useAnalyticsGoals.js +67 -0
- package/dist/goals/useAnalyticsGoals.js.map +1 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.js +75 -11
- package/dist/index.js.map +1 -1
- package/dist/native/collections/events.js +36 -0
- package/dist/native/collections/events.js.map +1 -1
- package/dist/native/eventScan.js +25 -0
- package/dist/native/eventScan.js.map +1 -0
- package/dist/native/ingest/browser.js +47 -0
- package/dist/native/ingest/browser.js.map +1 -0
- package/dist/native/ingest/device.js +11 -3
- package/dist/native/ingest/device.js.map +1 -1
- package/dist/native/ingest/endpoint.d.ts +1 -0
- package/dist/native/ingest/endpoint.js +2 -17
- package/dist/native/ingest/endpoint.js.map +1 -1
- package/dist/native/ingest/flushBatch.js +26 -26
- package/dist/native/ingest/flushBatch.js.map +1 -1
- package/dist/native/ingest/language.js +14 -0
- package/dist/native/ingest/language.js.map +1 -0
- package/dist/native/ingest/normalizeEvent.d.ts +26 -0
- package/dist/native/ingest/normalizeEvent.js +35 -7
- package/dist/native/ingest/normalizeEvent.js.map +1 -1
- package/dist/native/ingest/referrer.js +48 -0
- package/dist/native/ingest/referrer.js.map +1 -0
- package/dist/native/ingest/serverTrack.d.ts +20 -0
- package/dist/native/ingest/serverTrack.js +100 -0
- package/dist/native/ingest/serverTrack.js.map +1 -0
- package/dist/native/ingest/source.d.ts +7 -0
- package/dist/native/ingest/source.js +139 -14
- package/dist/native/ingest/source.js.map +1 -1
- package/dist/native/ingest/utm.js +33 -0
- package/dist/native/ingest/utm.js.map +1 -0
- package/dist/native/ingest/validate.js +27 -0
- package/dist/native/ingest/validate.js.map +1 -0
- package/dist/native/nativeAdapter.d.ts +1 -1
- package/dist/native/nativeAdapter.js +53 -36
- package/dist/native/nativeAdapter.js.map +1 -1
- package/dist/native/query/eventAgg.js +14 -1
- package/dist/native/query/eventAgg.js.map +1 -1
- package/dist/native/retention/pruneTask.js +1 -1
- package/dist/native/rollups/bucketKey.js +15 -0
- package/dist/native/rollups/bucketKey.js.map +1 -0
- package/dist/native/rollups/bumpRollups.js +116 -0
- package/dist/native/rollups/bumpRollups.js.map +1 -0
- package/dist/native/rollups/deltas.js +30 -15
- package/dist/native/rollups/deltas.js.map +1 -1
- package/dist/native/rollups/insertManyIfNew.js +93 -0
- package/dist/native/rollups/insertManyIfNew.js.map +1 -0
- package/dist/next/captureRewrites.d.ts +3 -2
- package/dist/next/captureRewrites.js +3 -2
- package/dist/next/captureRewrites.js.map +1 -1
- package/dist/plugin/documentEndpoint.js +52 -15
- package/dist/plugin/documentEndpoint.js.map +1 -1
- package/dist/plugin/goalHint.d.ts +1 -0
- package/dist/plugin/goalHint.js +24 -0
- package/dist/plugin/goalHint.js.map +1 -0
- package/dist/plugin/paths.js +5 -1
- package/dist/plugin/paths.js.map +1 -1
- package/dist/plugin/queryEndpoint.js +120 -0
- package/dist/plugin/queryEndpoint.js.map +1 -0
- package/dist/plugin/readContextForRequest.js +71 -0
- package/dist/plugin/readContextForRequest.js.map +1 -0
- package/dist/plugin/realtimeEndpoint.js +43 -15
- package/dist/plugin/realtimeEndpoint.js.map +1 -1
- package/dist/plugin/responses.js +17 -0
- package/dist/plugin/responses.js.map +1 -0
- package/dist/plugin/runtime.js +31 -1
- package/dist/plugin/runtime.js.map +1 -1
- package/dist/plugin/scopeFieldBoot.js +22 -0
- package/dist/plugin/scopeFieldBoot.js.map +1 -0
- package/dist/plugin/sourcesEndpoint.js +21 -52
- package/dist/plugin/sourcesEndpoint.js.map +1 -1
- package/dist/plugin/warmTask.js +0 -0
- package/dist/plugin/warmTask.js.map +1 -1
- package/dist/providers/collection.js +29 -13
- package/dist/providers/collection.js.map +1 -1
- package/dist/providers/factory.js +4 -2
- package/dist/providers/factory.js.map +1 -1
- package/dist/providers/resolver.js.map +1 -1
- package/dist/query/dates.js +64 -0
- package/dist/query/dates.js.map +1 -0
- package/dist/query/errors.d.ts +17 -0
- package/dist/query/errors.js +10 -0
- package/dist/query/errors.js.map +1 -0
- package/dist/query/fetchQuery.d.ts +59 -0
- package/dist/query/fetchQuery.js +110 -0
- package/dist/query/fetchQuery.js.map +1 -0
- package/dist/query/parse.d.ts +22 -0
- package/dist/query/parse.js +168 -0
- package/dist/query/parse.js.map +1 -0
- package/dist/query/response.d.ts +39 -0
- package/dist/query/response.js +11 -0
- package/dist/query/response.js.map +1 -0
- package/dist/surfacing/engine.js +1 -1
- package/dist/surfacing/engine.js.map +1 -1
- package/dist/testing/memoryAdapter.js +0 -1
- package/dist/testing/memoryAdapter.js.map +1 -1
- package/dist/timeframe/tz.js +17 -6
- package/dist/timeframe/tz.js.map +1 -1
- package/dist/tracker/createTracker.js +13 -1
- package/dist/tracker/createTracker.js.map +1 -1
- package/dist/tracker/sinks/ga4.d.ts +21 -0
- package/dist/tracker/sinks/ga4.js +26 -0
- package/dist/tracker/sinks/ga4.js.map +1 -0
- package/dist/tracker/types.d.ts +5 -0
- package/dist/translations/ar.js +127 -1
- package/dist/translations/ar.js.map +1 -1
- package/dist/translations/de.js +127 -1
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +127 -1
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +127 -1
- package/dist/translations/es.js.map +1 -1
- package/dist/translations/fr.js +127 -1
- package/dist/translations/fr.js.map +1 -1
- package/dist/translations/id.js +127 -1
- package/dist/translations/id.js.map +1 -1
- package/dist/translations/keys.d.ts +126 -0
- package/dist/translations/keys.js +127 -1
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +127 -1
- package/dist/translations/ko.js.map +1 -1
- package/dist/translations/metricKeys.js +8 -2
- package/dist/translations/metricKeys.js.map +1 -1
- package/dist/translations/pt.js +127 -1
- package/dist/translations/pt.js.map +1 -1
- package/dist/translations/ru.js +127 -1
- package/dist/translations/ru.js.map +1 -1
- package/dist/translations/server.js.map +1 -1
- package/dist/translations/uk.js +127 -1
- package/dist/translations/uk.js.map +1 -1
- package/dist/translations/zh.js +127 -1
- package/dist/translations/zh.js.map +1 -1
- package/dist/view/AnalyticsNavLink.d.ts +19 -0
- package/dist/view/AnalyticsNavLink.js +40 -0
- package/dist/view/AnalyticsNavLink.js.map +1 -0
- package/dist/view/AnalyticsView.d.ts +23 -0
- package/dist/view/AnalyticsView.js +45 -0
- package/dist/view/AnalyticsView.js.map +1 -0
- package/dist/view/AnalyticsViewClient.d.ts +15 -0
- package/dist/view/AnalyticsViewClient.js +200 -0
- package/dist/view/AnalyticsViewClient.js.map +1 -0
- package/dist/view/authRedirect.js +32 -0
- package/dist/view/authRedirect.js.map +1 -0
- package/dist/view/conversionRate.js +18 -0
- package/dist/view/conversionRate.js.map +1 -0
- package/dist/view/dayRange.js +68 -0
- package/dist/view/dayRange.js.map +1 -0
- package/dist/view/gating.d.ts +1 -0
- package/dist/view/gating.js +142 -0
- package/dist/view/gating.js.map +1 -0
- package/dist/view/labels.js +64 -0
- package/dist/view/labels.js.map +1 -0
- package/dist/view/registerView.js +48 -0
- package/dist/view/registerView.js.map +1 -0
- package/dist/view/sections/Breakdowns.js +197 -0
- package/dist/view/sections/Breakdowns.js.map +1 -0
- package/dist/view/sections/EmptyStates.js +92 -0
- package/dist/view/sections/EmptyStates.js.map +1 -0
- package/dist/view/sections/FilterChips.js +46 -0
- package/dist/view/sections/FilterChips.js.map +1 -0
- package/dist/view/sections/GoalsPanel.js +82 -0
- package/dist/view/sections/GoalsPanel.js.map +1 -0
- package/dist/view/sections/OverviewCards.js +65 -0
- package/dist/view/sections/OverviewCards.js.map +1 -0
- package/dist/view/sections/RealtimeStrip.js +80 -0
- package/dist/view/sections/RealtimeStrip.js.map +1 -0
- package/dist/view/sections/Toolbar.js +186 -0
- package/dist/view/sections/Toolbar.js.map +1 -0
- package/dist/view/sections/Trend.js +125 -0
- package/dist/view/sections/Trend.js.map +1 -0
- package/dist/view/sections/styles.js +74 -0
- package/dist/view/sections/styles.js.map +1 -0
- package/dist/view/state.js +211 -0
- package/dist/view/state.js.map +1 -0
- package/dist/view/useViewQueries.js +153 -0
- package/dist/view/useViewQueries.js.map +1 -0
- package/dist/view/viewProps.d.ts +40 -0
- package/dist/view/viewProps.js +90 -0
- package/dist/view/viewProps.js.map +1 -0
- package/dist/widgets/AnalyticsBreakdownWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsBreakdownWidget.js +78 -11
- package/dist/widgets/AnalyticsBreakdownWidget.js.map +1 -1
- package/dist/widgets/AnalyticsGoalsWidget.d.ts +14 -0
- package/dist/widgets/AnalyticsGoalsWidget.js +196 -0
- package/dist/widgets/AnalyticsGoalsWidget.js.map +1 -0
- package/dist/widgets/AnalyticsMetricWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsMetricWidget.js +63 -13
- package/dist/widgets/AnalyticsMetricWidget.js.map +1 -1
- package/dist/widgets/AnalyticsRealtimeWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsRealtimeWidget.js +44 -22
- package/dist/widgets/AnalyticsRealtimeWidget.js.map +1 -1
- package/dist/widgets/AnalyticsTrendWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsTrendWidget.js +79 -16
- package/dist/widgets/AnalyticsTrendWidget.js.map +1 -1
- package/dist/widgets/RealtimeCounter.d.ts +4 -0
- package/dist/widgets/RealtimeCounter.js +10 -1
- package/dist/widgets/RealtimeCounter.js.map +1 -1
- package/dist/widgets/WidgetViewLink.js +17 -0
- package/dist/widgets/WidgetViewLink.js.map +1 -0
- package/dist/widgets/breakdownTypes.js +28 -1
- package/dist/widgets/breakdownTypes.js.map +1 -1
- package/dist/widgets/cardChrome.js +31 -7
- package/dist/widgets/cardChrome.js.map +1 -1
- package/dist/widgets/comparison.js +15 -1
- package/dist/widgets/comparison.js.map +1 -1
- package/dist/widgets/defaults.d.ts +6 -2
- package/dist/widgets/defaults.js +72 -25
- package/dist/widgets/defaults.js.map +1 -1
- package/dist/widgets/filterCaption.js +27 -0
- package/dist/widgets/filterCaption.js.map +1 -0
- package/dist/widgets/filterField.d.ts +19 -0
- package/dist/widgets/filterField.js +75 -0
- package/dist/widgets/filterField.js.map +1 -0
- package/dist/widgets/prepareWidgetRead.d.ts +7 -0
- package/dist/widgets/prepareWidgetRead.js +74 -0
- package/dist/widgets/prepareWidgetRead.js.map +1 -0
- package/dist/widgets/range.js +43 -12
- package/dist/widgets/range.js.map +1 -1
- package/dist/widgets/readForWidget.d.ts +24 -2
- package/dist/widgets/readForWidget.js +34 -48
- package/dist/widgets/readForWidget.js.map +1 -1
- package/dist/widgets/readForWidgetBreakdown.d.ts +32 -1
- package/dist/widgets/readForWidgetBreakdown.js +32 -42
- package/dist/widgets/readForWidgetBreakdown.js.map +1 -1
- package/dist/widgets/readForWidgetGoals.d.ts +67 -0
- package/dist/widgets/readForWidgetGoals.js +140 -0
- package/dist/widgets/readForWidgetGoals.js.map +1 -0
- package/dist/widgets/readForWidgetRealtime.d.ts +8 -0
- package/dist/widgets/readForWidgetRealtime.js +21 -20
- package/dist/widgets/readForWidgetRealtime.js.map +1 -1
- package/dist/widgets/readForWidgetSeries.d.ts +24 -1
- package/dist/widgets/readForWidgetSeries.js +63 -56
- package/dist/widgets/readForWidgetSeries.js.map +1 -1
- package/dist/widgets/readMeta.js +18 -0
- package/dist/widgets/readMeta.js.map +1 -0
- package/dist/widgets/registerWidgets.js +53 -7
- package/dist/widgets/registerWidgets.js.map +1 -1
- package/dist/widgets/types.d.ts +15 -0
- package/dist/widgets/types.js +12 -1
- package/dist/widgets/types.js.map +1 -1
- package/dist/widgets/viewLink.d.ts +22 -0
- package/dist/widgets/viewLink.js +86 -0
- package/dist/widgets/viewLink.js.map +1 -0
- package/package.json +9 -4
- package/dist/native/rollups/applyDistinctDeltas.js +0 -9
- package/dist/native/rollups/applyDistinctDeltas.js.map +0 -1
- package/dist/native/rollups/bumpRollup.js +0 -73
- package/dist/native/rollups/bumpRollup.js.map +0 -1
- package/dist/native/rollups/insertIfNew.js +0 -19
- package/dist/native/rollups/insertIfNew.js.map +0 -1
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
//#region src/widgets/cardChrome.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The card chrome, as token values rather than only as style objects: the widgets apply them
|
|
4
|
+
* inline (they are server-rendered and the package ships no stylesheet), while the analytics
|
|
5
|
+
* view interpolates the same values into its own injected CSS, where hover and pressed states
|
|
6
|
+
* need real selectors. One definition, so the two surfaces cannot drift apart.
|
|
7
|
+
*/
|
|
8
|
+
const CARD_CHROME = {
|
|
5
9
|
gap: "0.375rem",
|
|
6
10
|
padding: "var(--base, 1rem)",
|
|
7
11
|
background: "var(--theme-elevation-50)",
|
|
8
12
|
border: "1px solid var(--theme-elevation-150)",
|
|
9
|
-
|
|
10
|
-
boxSizing: "border-box"
|
|
13
|
+
radius: "var(--style-radius-m, 6px)"
|
|
11
14
|
};
|
|
12
|
-
const
|
|
15
|
+
const CARD_LABEL = {
|
|
13
16
|
fontSize: "0.6875rem",
|
|
14
17
|
fontWeight: 600,
|
|
15
18
|
letterSpacing: "0.04em",
|
|
16
19
|
textTransform: "uppercase",
|
|
17
20
|
color: "var(--theme-elevation-500)"
|
|
18
21
|
};
|
|
22
|
+
const cardStyle = {
|
|
23
|
+
display: "flex",
|
|
24
|
+
flexDirection: "column",
|
|
25
|
+
gap: CARD_CHROME.gap,
|
|
26
|
+
padding: CARD_CHROME.padding,
|
|
27
|
+
background: CARD_CHROME.background,
|
|
28
|
+
border: CARD_CHROME.border,
|
|
29
|
+
borderRadius: CARD_CHROME.radius,
|
|
30
|
+
boxSizing: "border-box"
|
|
31
|
+
};
|
|
32
|
+
const labelStyle = { ...CARD_LABEL };
|
|
33
|
+
/** The card's footer link. `marginTop: auto` floors it, so cards of a row line their links up. */
|
|
34
|
+
const linkStyle = {
|
|
35
|
+
marginTop: "auto",
|
|
36
|
+
alignSelf: "flex-start",
|
|
37
|
+
fontSize: "0.75rem",
|
|
38
|
+
fontWeight: 500,
|
|
39
|
+
color: "var(--theme-elevation-500)",
|
|
40
|
+
textDecoration: "underline",
|
|
41
|
+
textUnderlineOffset: "2px"
|
|
42
|
+
};
|
|
19
43
|
//#endregion
|
|
20
|
-
export { cardStyle, labelStyle };
|
|
44
|
+
export { CARD_CHROME, CARD_LABEL, cardStyle, labelStyle, linkStyle };
|
|
21
45
|
|
|
22
46
|
//# sourceMappingURL=cardChrome.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cardChrome.js","names":[],"sources":["../../src/widgets/cardChrome.ts"],"sourcesContent":["import type { CSSProperties } from 'react'\n\
|
|
1
|
+
{"version":3,"file":"cardChrome.js","names":[],"sources":["../../src/widgets/cardChrome.ts"],"sourcesContent":["import type { CSSProperties } from 'react'\n\n/**\n * The card chrome, as token values rather than only as style objects: the widgets apply them\n * inline (they are server-rendered and the package ships no stylesheet), while the analytics\n * view interpolates the same values into its own injected CSS, where hover and pressed states\n * need real selectors. One definition, so the two surfaces cannot drift apart.\n */\nexport const CARD_CHROME = {\n\tgap: '0.375rem',\n\tpadding: 'var(--base, 1rem)',\n\tbackground: 'var(--theme-elevation-50)',\n\tborder: '1px solid var(--theme-elevation-150)',\n\tradius: 'var(--style-radius-m, 6px)',\n} as const\n\nexport const CARD_LABEL = {\n\tfontSize: '0.6875rem',\n\tfontWeight: 600,\n\tletterSpacing: '0.04em',\n\ttextTransform: 'uppercase',\n\tcolor: 'var(--theme-elevation-500)',\n} as const\n\nexport const cardStyle: CSSProperties = {\n\tdisplay: 'flex',\n\tflexDirection: 'column',\n\tgap: CARD_CHROME.gap,\n\tpadding: CARD_CHROME.padding,\n\tbackground: CARD_CHROME.background,\n\tborder: CARD_CHROME.border,\n\tborderRadius: CARD_CHROME.radius,\n\tboxSizing: 'border-box',\n}\n\nexport const labelStyle: CSSProperties = { ...CARD_LABEL }\n\n/** The card's footer link. `marginTop: auto` floors it, so cards of a row line their links up. */\nexport const linkStyle: CSSProperties = {\n\tmarginTop: 'auto',\n\talignSelf: 'flex-start',\n\tfontSize: '0.75rem',\n\tfontWeight: 500,\n\tcolor: 'var(--theme-elevation-500)',\n\ttextDecoration: 'underline',\n\ttextUnderlineOffset: '2px',\n}\n"],"mappings":";;;;;;;AAQA,MAAa,cAAc;CAC1B,KAAK;CACL,SAAS;CACT,YAAY;CACZ,QAAQ;CACR,QAAQ;AACT;AAEA,MAAa,aAAa;CACzB,UAAU;CACV,YAAY;CACZ,eAAe;CACf,eAAe;CACf,OAAO;AACR;AAEA,MAAa,YAA2B;CACvC,SAAS;CACT,eAAe;CACf,KAAK,YAAY;CACjB,SAAS,YAAY;CACrB,YAAY,YAAY;CACxB,QAAQ,YAAY;CACpB,cAAc,YAAY;CAC1B,WAAW;AACZ;AAEA,MAAa,aAA4B,EAAE,GAAG,WAAW;;AAGzD,MAAa,YAA2B;CACvC,WAAW;CACX,WAAW;CACX,UAAU;CACV,YAAY;CACZ,OAAO;CACP,gBAAgB;CAChB,qBAAqB;AACtB"}
|
|
@@ -26,6 +26,20 @@ const previousWindow = (range, tz = "UTC") => {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
|
+
* Whether a source can still answer for `window`. The engine's clamp floors a read at that
|
|
30
|
+
* read's own end minus the lookback, so a previous window is clamped only when it is itself
|
|
31
|
+
* longer than the lookback: a 60-day range on a 90-day source reads 120 days back unmarked.
|
|
32
|
+
* Callers check this first and omit the comparison instead. The floor uses the clamp's formula
|
|
33
|
+
* but anchors on `now` rather than the read's end, because a provider measures its lookback from
|
|
34
|
+
* today. Fixed-day arithmetic can put it an hour off across a DST change, which is harmless while
|
|
35
|
+
* every caller goes through this one helper.
|
|
36
|
+
*/
|
|
37
|
+
const withinLookback = (window, maxLookbackDays, args = {}) => {
|
|
38
|
+
if (maxLookbackDays == null) return true;
|
|
39
|
+
const floor = startOfDayInTz(args.now ?? /* @__PURE__ */ new Date(), args.tz ?? "UTC").getTime() - maxLookbackDays * DAY_MS;
|
|
40
|
+
return window.start.getTime() >= floor;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
29
43
|
* Period-over-period delta for one metric value against its previous-window value.
|
|
30
44
|
* Returns null when either side is missing so the caller can omit the comparison.
|
|
31
45
|
*/
|
|
@@ -38,6 +52,6 @@ const computeDelta = (current, previous) => {
|
|
|
38
52
|
};
|
|
39
53
|
};
|
|
40
54
|
//#endregion
|
|
41
|
-
export { computeDelta, previousWindow };
|
|
55
|
+
export { computeDelta, previousWindow, withinLookback };
|
|
42
56
|
|
|
43
57
|
//# sourceMappingURL=comparison.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comparison.js","names":[],"sources":["../../src/widgets/comparison.ts"],"sourcesContent":["import type { DateRange } from '../core/contract'\nimport { addDaysInTz, DEFAULT_TIMEZONE, startOfDayInTz } from '../timeframe/tz'\n\nexport type DeltaDirection = 'up' | 'down' | 'none'\n\nexport interface MetricDelta {\n\tdirection: DeltaDirection\n\t/**\n\t * Signed percentage change vs the previous value, or null when the previous value is\n\t * 0 (the baseline is undefined, so a percentage would be infinite/meaningless).\n\t */\n\tpercent: number | null\n}\n\nconst DAY_MS = 86_400_000\n\n/**\n * Comparison windows beyond a year are not meaningful period-over-period reads; the cap\n * also rejects the unbounded `allTime` range, which would otherwise compare against a\n * pre-1970 window.\n */\nconst MAX_COMPARISON_DAYS = 366\n\n/**\n * The comparable window immediately preceding `range`, aligned to whole reporting-timezone\n * days so daily rollup stores (which stamp each day at its local midnight) never lose their\n * first day to a mid-day window start. It spans the same count of calendar days the current\n * range touches (the current partial day counts as one) and ends 1ms before the current\n * range's first day. Returns null when the range spans more than\n * {@link MAX_COMPARISON_DAYS} days, where a previous period is not meaningful.\n */\nexport const previousWindow = (\n\trange: DateRange,\n\ttz: string = DEFAULT_TIMEZONE\n): DateRange | null => {\n\tconst firstDay = startOfDayInTz(range.start, tz)\n\tconst lastDay = startOfDayInTz(range.end, tz)\n\tconst days = Math.round((lastDay.getTime() - firstDay.getTime()) / DAY_MS) + 1\n\tif (!Number.isFinite(days) || days < 1 || days > MAX_COMPARISON_DAYS) {\n\t\treturn null\n\t}\n\treturn { start: addDaysInTz(firstDay, -days, tz), end: new Date(firstDay.getTime() - 1) }\n}\n\n/**\n * Period-over-period delta for one metric value against its previous-window value.\n * Returns null when either side is missing so the caller can omit the comparison.\n */\nexport const computeDelta = (current?: number, previous?: number): MetricDelta | null => {\n\tif (current === undefined || previous === undefined) {\n\t\treturn null\n\t}\n\tconst diff = current - previous\n\tconst direction: DeltaDirection = diff > 0 ? 'up' : diff < 0 ? 'down' : 'none'\n\tconst percent = previous === 0 ? null : (diff / previous) * 100\n\treturn { direction, percent }\n}\n"],"mappings":";;AAcA,MAAM,SAAS;;;;;;AAOf,MAAM,sBAAsB;;;;;;;;;AAU5B,MAAa,kBACZ,OACA,KAAA,UACsB;CACtB,MAAM,WAAW,eAAe,MAAM,OAAO,EAAE;CAC/C,MAAM,UAAU,eAAe,MAAM,KAAK,EAAE;CAC5C,MAAM,OAAO,KAAK,OAAO,QAAQ,QAAQ,IAAI,SAAS,QAAQ,KAAK,MAAM,IAAI;CAC7E,IAAI,CAAC,OAAO,SAAS,IAAI,KAAK,OAAO,KAAK,OAAO,qBAChD,OAAO;CAER,OAAO;EAAE,OAAO,YAAY,UAAU,CAAC,MAAM,EAAE;EAAG,qBAAK,IAAI,KAAK,SAAS,QAAQ,IAAI,CAAC;CAAE;AACzF;;;;;AAMA,MAAa,gBAAgB,SAAkB,aAA0C;CACxF,IAAI,YAAY,KAAA,KAAa,aAAa,KAAA,GACzC,OAAO;CAER,MAAM,OAAO,UAAU;CAGvB,OAAO;EAAE,WAFyB,OAAO,IAAI,OAAO,OAAO,IAAI,SAAS;EAEpD,SADJ,aAAa,IAAI,OAAQ,OAAO,WAAY;CAChC;AAC7B"}
|
|
1
|
+
{"version":3,"file":"comparison.js","names":[],"sources":["../../src/widgets/comparison.ts"],"sourcesContent":["import type { DateRange } from '../core/contract'\nimport { addDaysInTz, DEFAULT_TIMEZONE, startOfDayInTz } from '../timeframe/tz'\n\nexport type DeltaDirection = 'up' | 'down' | 'none'\n\nexport interface MetricDelta {\n\tdirection: DeltaDirection\n\t/**\n\t * Signed percentage change vs the previous value, or null when the previous value is\n\t * 0 (the baseline is undefined, so a percentage would be infinite/meaningless).\n\t */\n\tpercent: number | null\n}\n\nconst DAY_MS = 86_400_000\n\n/**\n * Comparison windows beyond a year are not meaningful period-over-period reads; the cap\n * also rejects the unbounded `allTime` range, which would otherwise compare against a\n * pre-1970 window.\n */\nconst MAX_COMPARISON_DAYS = 366\n\n/**\n * The comparable window immediately preceding `range`, aligned to whole reporting-timezone\n * days so daily rollup stores (which stamp each day at its local midnight) never lose their\n * first day to a mid-day window start. It spans the same count of calendar days the current\n * range touches (the current partial day counts as one) and ends 1ms before the current\n * range's first day. Returns null when the range spans more than\n * {@link MAX_COMPARISON_DAYS} days, where a previous period is not meaningful.\n */\nexport const previousWindow = (\n\trange: DateRange,\n\ttz: string = DEFAULT_TIMEZONE\n): DateRange | null => {\n\tconst firstDay = startOfDayInTz(range.start, tz)\n\tconst lastDay = startOfDayInTz(range.end, tz)\n\tconst days = Math.round((lastDay.getTime() - firstDay.getTime()) / DAY_MS) + 1\n\tif (!Number.isFinite(days) || days < 1 || days > MAX_COMPARISON_DAYS) {\n\t\treturn null\n\t}\n\treturn { start: addDaysInTz(firstDay, -days, tz), end: new Date(firstDay.getTime() - 1) }\n}\n\n/**\n * Whether a source can still answer for `window`. The engine's clamp floors a read at that\n * read's own end minus the lookback, so a previous window is clamped only when it is itself\n * longer than the lookback: a 60-day range on a 90-day source reads 120 days back unmarked.\n * Callers check this first and omit the comparison instead. The floor uses the clamp's formula\n * but anchors on `now` rather than the read's end, because a provider measures its lookback from\n * today. Fixed-day arithmetic can put it an hour off across a DST change, which is harmless while\n * every caller goes through this one helper.\n */\nexport const withinLookback = (\n\twindow: DateRange,\n\tmaxLookbackDays: number | null,\n\targs: { tz?: string; now?: Date } = {}\n): boolean => {\n\tif (maxLookbackDays == null) {\n\t\treturn true\n\t}\n\tconst floor =\n\t\tstartOfDayInTz(args.now ?? new Date(), args.tz ?? DEFAULT_TIMEZONE).getTime() -\n\t\tmaxLookbackDays * DAY_MS\n\treturn window.start.getTime() >= floor\n}\n\n/**\n * Period-over-period delta for one metric value against its previous-window value.\n * Returns null when either side is missing so the caller can omit the comparison.\n */\nexport const computeDelta = (current?: number, previous?: number): MetricDelta | null => {\n\tif (current === undefined || previous === undefined) {\n\t\treturn null\n\t}\n\tconst diff = current - previous\n\tconst direction: DeltaDirection = diff > 0 ? 'up' : diff < 0 ? 'down' : 'none'\n\tconst percent = previous === 0 ? null : (diff / previous) * 100\n\treturn { direction, percent }\n}\n"],"mappings":";;AAcA,MAAM,SAAS;;;;;;AAOf,MAAM,sBAAsB;;;;;;;;;AAU5B,MAAa,kBACZ,OACA,KAAA,UACsB;CACtB,MAAM,WAAW,eAAe,MAAM,OAAO,EAAE;CAC/C,MAAM,UAAU,eAAe,MAAM,KAAK,EAAE;CAC5C,MAAM,OAAO,KAAK,OAAO,QAAQ,QAAQ,IAAI,SAAS,QAAQ,KAAK,MAAM,IAAI;CAC7E,IAAI,CAAC,OAAO,SAAS,IAAI,KAAK,OAAO,KAAK,OAAO,qBAChD,OAAO;CAER,OAAO;EAAE,OAAO,YAAY,UAAU,CAAC,MAAM,EAAE;EAAG,qBAAK,IAAI,KAAK,SAAS,QAAQ,IAAI,CAAC;CAAE;AACzF;;;;;;;;;;AAWA,MAAa,kBACZ,QACA,iBACA,OAAoC,CAAC,MACxB;CACb,IAAI,mBAAmB,MACtB,OAAO;CAER,MAAM,QACL,eAAe,KAAK,uBAAO,IAAI,KAAK,GAAG,KAAK,MAAA,KAAsB,EAAE,QAAQ,IAC5E,kBAAkB;CACnB,OAAO,OAAO,MAAM,QAAQ,KAAK;AAClC;;;;;AAMA,MAAa,gBAAgB,SAAkB,aAA0C;CACxF,IAAI,YAAY,KAAA,KAAa,aAAa,KAAA,GACzC,OAAO;CAER,MAAM,OAAO,UAAU;CAGvB,OAAO;EAAE,WAFyB,OAAO,IAAI,OAAO,OAAO,IAAI,SAAS;EAEpD,SADJ,aAAa,IAAI,OAAQ,OAAO,WAAY;CAChC;AAC7B"}
|
|
@@ -3,8 +3,12 @@ import { WidgetInstance } from "payload";
|
|
|
3
3
|
//#region src/widgets/defaults.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Default analytics widget instances to spread into an app's own
|
|
6
|
-
* `admin.dashboard.defaultLayout
|
|
7
|
-
*
|
|
6
|
+
* `admin.dashboard.defaultLayout`: every built-in widget, headline numbers first, then the
|
|
7
|
+
* trend, the goals table, the realtime counter and one card per breakdown. A plugin must
|
|
8
|
+
* never set `defaultLayout` itself (Payload applies it with `??=`, so any setter would
|
|
9
|
+
* clobber the app's layout). Each slug is spelled out rather than mapped from
|
|
10
|
+
* `BREAKDOWN_SPECS`, because an app's generated types narrow `widgetSlug` to its own
|
|
11
|
+
* registered widgets; `defaults.test.ts` is what keeps the list complete.
|
|
8
12
|
*/
|
|
9
13
|
declare const analyticsDefaultWidgets: () => WidgetInstance[];
|
|
10
14
|
//#endregion
|
package/dist/widgets/defaults.js
CHANGED
|
@@ -1,68 +1,115 @@
|
|
|
1
1
|
//#region src/widgets/defaults.ts
|
|
2
|
+
const TIMEFRAME = "last30days";
|
|
3
|
+
/** The data every breakdown card opens with: its dimension's top five by pageviews. */
|
|
4
|
+
const BREAKDOWN_DATA = {
|
|
5
|
+
metric: "pageviews",
|
|
6
|
+
timeframe: TIMEFRAME,
|
|
7
|
+
limit: 5
|
|
8
|
+
};
|
|
2
9
|
/**
|
|
3
10
|
* Default analytics widget instances to spread into an app's own
|
|
4
|
-
* `admin.dashboard.defaultLayout
|
|
5
|
-
*
|
|
11
|
+
* `admin.dashboard.defaultLayout`: every built-in widget, headline numbers first, then the
|
|
12
|
+
* trend, the goals table, the realtime counter and one card per breakdown. A plugin must
|
|
13
|
+
* never set `defaultLayout` itself (Payload applies it with `??=`, so any setter would
|
|
14
|
+
* clobber the app's layout). Each slug is spelled out rather than mapped from
|
|
15
|
+
* `BREAKDOWN_SPECS`, because an app's generated types narrow `widgetSlug` to its own
|
|
16
|
+
* registered widgets; `defaults.test.ts` is what keeps the list complete.
|
|
6
17
|
*/
|
|
7
18
|
const analyticsDefaultWidgets = () => [
|
|
8
19
|
{
|
|
9
|
-
widgetSlug: "analytics-
|
|
10
|
-
width: "
|
|
20
|
+
widgetSlug: "analytics-metric",
|
|
21
|
+
width: "small",
|
|
11
22
|
data: {
|
|
12
23
|
metric: "pageviews",
|
|
13
|
-
timeframe:
|
|
24
|
+
timeframe: TIMEFRAME
|
|
14
25
|
}
|
|
15
26
|
},
|
|
16
27
|
{
|
|
17
28
|
widgetSlug: "analytics-metric",
|
|
18
29
|
width: "small",
|
|
30
|
+
data: {
|
|
31
|
+
metric: "visitors",
|
|
32
|
+
timeframe: TIMEFRAME
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
widgetSlug: "analytics-trend",
|
|
37
|
+
width: "large",
|
|
19
38
|
data: {
|
|
20
39
|
metric: "pageviews",
|
|
21
|
-
timeframe:
|
|
40
|
+
timeframe: TIMEFRAME
|
|
22
41
|
}
|
|
23
42
|
},
|
|
24
43
|
{
|
|
25
|
-
widgetSlug: "analytics-
|
|
44
|
+
widgetSlug: "analytics-goals",
|
|
45
|
+
width: "medium",
|
|
46
|
+
data: {
|
|
47
|
+
timeframe: TIMEFRAME,
|
|
48
|
+
limit: "10"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
widgetSlug: "analytics-realtime",
|
|
26
53
|
width: "small",
|
|
27
54
|
data: {
|
|
28
55
|
metric: "visitors",
|
|
29
|
-
|
|
56
|
+
windowMinutes: "30"
|
|
30
57
|
}
|
|
31
58
|
},
|
|
32
59
|
{
|
|
33
60
|
widgetSlug: "analytics-breakdown-pages",
|
|
34
61
|
width: "medium",
|
|
35
|
-
data:
|
|
36
|
-
metric: "pageviews",
|
|
37
|
-
timeframe: "last30days",
|
|
38
|
-
limit: 5
|
|
39
|
-
}
|
|
62
|
+
data: BREAKDOWN_DATA
|
|
40
63
|
},
|
|
41
64
|
{
|
|
42
65
|
widgetSlug: "analytics-breakdown-sources",
|
|
43
66
|
width: "medium",
|
|
44
|
-
data:
|
|
45
|
-
metric: "pageviews",
|
|
46
|
-
timeframe: "last30days",
|
|
47
|
-
limit: 5
|
|
48
|
-
}
|
|
67
|
+
data: BREAKDOWN_DATA
|
|
49
68
|
},
|
|
50
69
|
{
|
|
51
70
|
widgetSlug: "analytics-breakdown-devices",
|
|
52
71
|
width: "medium",
|
|
72
|
+
data: BREAKDOWN_DATA
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
widgetSlug: "analytics-breakdown-countries",
|
|
76
|
+
width: "medium",
|
|
77
|
+
data: BREAKDOWN_DATA
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
widgetSlug: "analytics-breakdown-goals",
|
|
81
|
+
width: "medium",
|
|
53
82
|
data: {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
limit: 5
|
|
83
|
+
...BREAKDOWN_DATA,
|
|
84
|
+
metric: "conversions"
|
|
57
85
|
}
|
|
58
86
|
},
|
|
59
87
|
{
|
|
60
|
-
widgetSlug: "analytics-breakdown-
|
|
88
|
+
widgetSlug: "analytics-breakdown-referrers",
|
|
89
|
+
width: "medium",
|
|
90
|
+
data: BREAKDOWN_DATA
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
widgetSlug: "analytics-breakdown-browsers",
|
|
94
|
+
width: "medium",
|
|
95
|
+
data: BREAKDOWN_DATA
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
widgetSlug: "analytics-breakdown-os",
|
|
99
|
+
width: "medium",
|
|
100
|
+
data: BREAKDOWN_DATA
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
widgetSlug: "analytics-breakdown-campaigns",
|
|
104
|
+
width: "medium",
|
|
105
|
+
data: BREAKDOWN_DATA
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
widgetSlug: "analytics-breakdown-events",
|
|
61
109
|
width: "medium",
|
|
62
110
|
data: {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
limit: 5
|
|
111
|
+
...BREAKDOWN_DATA,
|
|
112
|
+
metric: "events"
|
|
66
113
|
}
|
|
67
114
|
}
|
|
68
115
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","names":[],"sources":["../../src/widgets/defaults.ts"],"sourcesContent":["import type { WidgetInstance } from 'payload'\n\n/**\n * Default analytics widget instances to spread into an app's own\n * `admin.dashboard.defaultLayout
|
|
1
|
+
{"version":3,"file":"defaults.js","names":[],"sources":["../../src/widgets/defaults.ts"],"sourcesContent":["import type { WidgetInstance } from 'payload'\n\nconst TIMEFRAME = 'last30days'\n\n/** The data every breakdown card opens with: its dimension's top five by pageviews. */\nconst BREAKDOWN_DATA = { metric: 'pageviews', timeframe: TIMEFRAME, limit: 5 } as const\n\n/**\n * Default analytics widget instances to spread into an app's own\n * `admin.dashboard.defaultLayout`: every built-in widget, headline numbers first, then the\n * trend, the goals table, the realtime counter and one card per breakdown. A plugin must\n * never set `defaultLayout` itself (Payload applies it with `??=`, so any setter would\n * clobber the app's layout). Each slug is spelled out rather than mapped from\n * `BREAKDOWN_SPECS`, because an app's generated types narrow `widgetSlug` to its own\n * registered widgets; `defaults.test.ts` is what keeps the list complete.\n */\nexport const analyticsDefaultWidgets = (): WidgetInstance[] => [\n\t{\n\t\twidgetSlug: 'analytics-metric',\n\t\twidth: 'small',\n\t\tdata: { metric: 'pageviews', timeframe: TIMEFRAME },\n\t},\n\t{\n\t\twidgetSlug: 'analytics-metric',\n\t\twidth: 'small',\n\t\tdata: { metric: 'visitors', timeframe: TIMEFRAME },\n\t},\n\t{\n\t\twidgetSlug: 'analytics-trend',\n\t\twidth: 'large',\n\t\tdata: { metric: 'pageviews', timeframe: TIMEFRAME },\n\t},\n\t{\n\t\twidgetSlug: 'analytics-goals',\n\t\twidth: 'medium',\n\t\t// The goals table stores its row count as its select's own string value.\n\t\tdata: { timeframe: TIMEFRAME, limit: '10' },\n\t},\n\t{\n\t\twidgetSlug: 'analytics-realtime',\n\t\twidth: 'small',\n\t\tdata: { metric: 'visitors', windowMinutes: '30' },\n\t},\n\t{ widgetSlug: 'analytics-breakdown-pages', width: 'medium', data: BREAKDOWN_DATA },\n\t{ widgetSlug: 'analytics-breakdown-sources', width: 'medium', data: BREAKDOWN_DATA },\n\t{ widgetSlug: 'analytics-breakdown-devices', width: 'medium', data: BREAKDOWN_DATA },\n\t{ widgetSlug: 'analytics-breakdown-countries', width: 'medium', data: BREAKDOWN_DATA },\n\t{\n\t\twidgetSlug: 'analytics-breakdown-goals',\n\t\twidth: 'medium',\n\t\tdata: { ...BREAKDOWN_DATA, metric: 'conversions' },\n\t},\n\t{ widgetSlug: 'analytics-breakdown-referrers', width: 'medium', data: BREAKDOWN_DATA },\n\t{ widgetSlug: 'analytics-breakdown-browsers', width: 'medium', data: BREAKDOWN_DATA },\n\t{ widgetSlug: 'analytics-breakdown-os', width: 'medium', data: BREAKDOWN_DATA },\n\t{ widgetSlug: 'analytics-breakdown-campaigns', width: 'medium', data: BREAKDOWN_DATA },\n\t{\n\t\twidgetSlug: 'analytics-breakdown-events',\n\t\twidth: 'medium',\n\t\tdata: { ...BREAKDOWN_DATA, metric: 'events' },\n\t},\n]\n"],"mappings":";AAEA,MAAM,YAAY;;AAGlB,MAAM,iBAAiB;CAAE,QAAQ;CAAa,WAAW;CAAW,OAAO;AAAE;;;;;;;;;;AAW7E,MAAa,gCAAkD;CAC9D;EACC,YAAY;EACZ,OAAO;EACP,MAAM;GAAE,QAAQ;GAAa,WAAW;EAAU;CACnD;CACA;EACC,YAAY;EACZ,OAAO;EACP,MAAM;GAAE,QAAQ;GAAY,WAAW;EAAU;CAClD;CACA;EACC,YAAY;EACZ,OAAO;EACP,MAAM;GAAE,QAAQ;GAAa,WAAW;EAAU;CACnD;CACA;EACC,YAAY;EACZ,OAAO;EAEP,MAAM;GAAE,WAAW;GAAW,OAAO;EAAK;CAC3C;CACA;EACC,YAAY;EACZ,OAAO;EACP,MAAM;GAAE,QAAQ;GAAY,eAAe;EAAK;CACjD;CACA;EAAE,YAAY;EAA6B,OAAO;EAAU,MAAM;CAAe;CACjF;EAAE,YAAY;EAA+B,OAAO;EAAU,MAAM;CAAe;CACnF;EAAE,YAAY;EAA+B,OAAO;EAAU,MAAM;CAAe;CACnF;EAAE,YAAY;EAAiC,OAAO;EAAU,MAAM;CAAe;CACrF;EACC,YAAY;EACZ,OAAO;EACP,MAAM;GAAE,GAAG;GAAgB,QAAQ;EAAc;CAClD;CACA;EAAE,YAAY;EAAiC,OAAO;EAAU,MAAM;CAAe;CACrF;EAAE,YAAY;EAAgC,OAAO;EAAU,MAAM;CAAe;CACpF;EAAE,YAAY;EAA0B,OAAO;EAAU,MAAM;CAAe;CAC9E;EAAE,YAAY;EAAiC,OAAO;EAAU,MAAM;CAAe;CACrF;EACC,YAAY;EACZ,OAAO;EACP,MAAM;GAAE,GAAG;GAAgB,QAAQ;EAAS;CAC7C;AACD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { keys } from "../translations/keys.js";
|
|
2
|
+
import { FILTER_OPERATOR_KEYS } from "../translations/metricKeys.js";
|
|
3
|
+
import { DIMENSION_LABELS } from "../view/labels.js";
|
|
4
|
+
//#region src/widgets/filterCaption.ts
|
|
5
|
+
/**
|
|
6
|
+
* One filter as a sentence a caption can end on ("where Country is DE"). Both parts are
|
|
7
|
+
* translated before they reach the sentence, which is itself a translated template, so a
|
|
8
|
+
* locale can reorder them. The value is the editor's own text and is never translated.
|
|
9
|
+
*/
|
|
10
|
+
const filterCaption = (filter, t) => t(keys.widgetFilterCaption, {
|
|
11
|
+
dimension: t(DIMENSION_LABELS[filter.dimension]),
|
|
12
|
+
operator: t(FILTER_OPERATOR_KEYS[filter.operator]),
|
|
13
|
+
value: filter.value
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* A widget's caption: its window, and the filter sentence after it when there is one. The
|
|
17
|
+
* join is a translated template too, so a locale that does not separate the two with a
|
|
18
|
+
* space (zh) does not get one.
|
|
19
|
+
*/
|
|
20
|
+
const captionWithFilter = (windowCaption, filter, t) => filter ? t(keys.widgetCaptionWithFilter, {
|
|
21
|
+
window: windowCaption,
|
|
22
|
+
filter: filterCaption(filter, t)
|
|
23
|
+
}) : windowCaption;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { captionWithFilter };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=filterCaption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterCaption.js","names":[],"sources":["../../src/widgets/filterCaption.ts"],"sourcesContent":["import type { AnalyticsFilter } from '../core/contract'\nimport { keys } from '../translations/keys'\nimport { FILTER_OPERATOR_KEYS } from '../translations/metricKeys'\nimport type { Translate } from '../translations/server'\nimport { DIMENSION_LABELS } from '../view/labels'\n\n/**\n * One filter as a sentence a caption can end on (\"where Country is DE\"). Both parts are\n * translated before they reach the sentence, which is itself a translated template, so a\n * locale can reorder them. The value is the editor's own text and is never translated.\n */\nexport const filterCaption = (filter: AnalyticsFilter, t: Translate): string =>\n\tt(keys.widgetFilterCaption, {\n\t\tdimension: t(DIMENSION_LABELS[filter.dimension]),\n\t\toperator: t(FILTER_OPERATOR_KEYS[filter.operator]),\n\t\tvalue: filter.value,\n\t})\n\n/**\n * A widget's caption: its window, and the filter sentence after it when there is one. The\n * join is a translated template too, so a locale that does not separate the two with a\n * space (zh) does not get one.\n */\nexport const captionWithFilter = (\n\twindowCaption: string,\n\tfilter: AnalyticsFilter | undefined,\n\tt: Translate\n): string =>\n\tfilter\n\t\t? t(keys.widgetCaptionWithFilter, {\n\t\t\t\twindow: windowCaption,\n\t\t\t\tfilter: filterCaption(filter, t),\n\t\t\t})\n\t\t: windowCaption\n"],"mappings":";;;;;;;;;AAWA,MAAa,iBAAiB,QAAyB,MACtD,EAAE,KAAK,qBAAqB;CAC3B,WAAW,EAAE,iBAAiB,OAAO,UAAU;CAC/C,UAAU,EAAE,qBAAqB,OAAO,SAAS;CACjD,OAAO,OAAO;AACf,CAAC;;;;;;AAOF,MAAa,qBACZ,eACA,QACA,MAEA,SACG,EAAE,KAAK,yBAAyB;CAChC,QAAQ;CACR,QAAQ,cAAc,QAAQ,CAAC;AAChC,CAAC,IACA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AnalyticsFilter } from "../core/contract.js";
|
|
2
|
+
import { WidgetFilter } from "./types.js";
|
|
3
|
+
//#region src/widgets/filterField.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The stored group as query filters: one entry, or none at all. A group without both a
|
|
6
|
+
* dimension and a value is still being configured, and the value is stored exactly as it
|
|
7
|
+
* was typed, so the query's own trimming and cap are applied here rather than assumed.
|
|
8
|
+
*
|
|
9
|
+
* Both keys are text fields the pickers fill, so a hand-edited layout or a widget saved
|
|
10
|
+
* against an older contract can hold anything. A dimension the contract does not define
|
|
11
|
+
* has no label to caption it with, so it is no filter at all; an undefined operator falls
|
|
12
|
+
* back to `eq`, the field's own default.
|
|
13
|
+
*/
|
|
14
|
+
declare const widgetFilters: (data: {
|
|
15
|
+
filter?: WidgetFilter;
|
|
16
|
+
}) => AnalyticsFilter[];
|
|
17
|
+
//#endregion
|
|
18
|
+
export { widgetFilters };
|
|
19
|
+
//# sourceMappingURL=filterField.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { DIMENSION_KEYS, FILTER_OPERATORS } from "../core/contract.js";
|
|
2
|
+
import { keys } from "../translations/keys.js";
|
|
3
|
+
import { asTranslate, labelForKey } from "../translations/server.js";
|
|
4
|
+
//#region src/widgets/filterField.ts
|
|
5
|
+
/** importMap paths of the scoped pickers; the factory never imports the components. */
|
|
6
|
+
const FILTER_DIMENSION_COMPONENT = "@10x-media/analytics/client#FilterDimensionSelectField";
|
|
7
|
+
const FILTER_OPERATOR_COMPONENT = "@10x-media/analytics/client#FilterOperatorSelectField";
|
|
8
|
+
/**
|
|
9
|
+
* The dimension is the gate: without one there is no filter, so an empty value is fine.
|
|
10
|
+
* With one, a blank value would filter on nothing and read as an accident.
|
|
11
|
+
*/
|
|
12
|
+
const validateValue = (value, { req, siblingData }) => {
|
|
13
|
+
const dimension = siblingData?.dimension;
|
|
14
|
+
if (typeof dimension !== "string" || dimension.trim() === "") return true;
|
|
15
|
+
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
16
|
+
if (trimmed === "") return asTranslate(req.t)(keys.widgetFilterValueRequired);
|
|
17
|
+
return trimmed.length <= 256 ? true : asTranslate(req.t)(keys.widgetFilterValueTooLong);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The stored group as query filters: one entry, or none at all. A group without both a
|
|
21
|
+
* dimension and a value is still being configured, and the value is stored exactly as it
|
|
22
|
+
* was typed, so the query's own trimming and cap are applied here rather than assumed.
|
|
23
|
+
*
|
|
24
|
+
* Both keys are text fields the pickers fill, so a hand-edited layout or a widget saved
|
|
25
|
+
* against an older contract can hold anything. A dimension the contract does not define
|
|
26
|
+
* has no label to caption it with, so it is no filter at all; an undefined operator falls
|
|
27
|
+
* back to `eq`, the field's own default.
|
|
28
|
+
*/
|
|
29
|
+
const widgetFilters = (data) => {
|
|
30
|
+
const { dimension, operator, value } = data.filter ?? {};
|
|
31
|
+
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
32
|
+
if (!dimension || !DIMENSION_KEYS.includes(dimension) || trimmed === "") return [];
|
|
33
|
+
return [{
|
|
34
|
+
dimension,
|
|
35
|
+
operator: operator && FILTER_OPERATORS.includes(operator) ? operator : "eq",
|
|
36
|
+
value: trimmed.slice(0, 256)
|
|
37
|
+
}];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The optional one-filter group every filterable widget carries. Text-backed rather than
|
|
41
|
+
* select-backed on purpose: the servable dimensions and operators are per source and per
|
|
42
|
+
* request, so the option lists are the client pickers' to build, not the config's.
|
|
43
|
+
*/
|
|
44
|
+
const filterField = () => ({
|
|
45
|
+
name: "filter",
|
|
46
|
+
type: "group",
|
|
47
|
+
label: labelForKey(keys.widgetFieldFilter),
|
|
48
|
+
admin: { description: labelForKey(keys.widgetFieldFilterDescription) },
|
|
49
|
+
fields: [
|
|
50
|
+
{
|
|
51
|
+
name: "dimension",
|
|
52
|
+
type: "text",
|
|
53
|
+
label: labelForKey(keys.widgetFieldFilterDimension),
|
|
54
|
+
admin: { components: { Field: { path: FILTER_DIMENSION_COMPONENT } } }
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "operator",
|
|
58
|
+
type: "text",
|
|
59
|
+
defaultValue: "eq",
|
|
60
|
+
label: labelForKey(keys.widgetFieldFilterOperator),
|
|
61
|
+
admin: { components: { Field: { path: FILTER_OPERATOR_COMPONENT } } }
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "value",
|
|
65
|
+
type: "text",
|
|
66
|
+
maxLength: 256,
|
|
67
|
+
label: labelForKey(keys.widgetFieldFilterValue),
|
|
68
|
+
validate: validateValue
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
//#endregion
|
|
73
|
+
export { filterField, widgetFilters };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=filterField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterField.js","names":[],"sources":["../../src/widgets/filterField.ts"],"sourcesContent":["import type { NamedGroupField, TextFieldSingleValidation } from 'payload'\nimport { type AnalyticsFilter, DIMENSION_KEYS, FILTER_OPERATORS } from '../core/contract'\nimport { MAX_QUERY_FILTER_VALUE_LENGTH } from '../query/limits'\nimport { keys } from '../translations/keys'\nimport { asTranslate, labelForKey } from '../translations/server'\nimport type { WidgetFilter } from './types'\n\n/** importMap paths of the scoped pickers; the factory never imports the components. */\nexport const FILTER_DIMENSION_COMPONENT = '@10x-media/analytics/client#FilterDimensionSelectField'\nexport const FILTER_OPERATOR_COMPONENT = '@10x-media/analytics/client#FilterOperatorSelectField'\n\n/**\n * The dimension is the gate: without one there is no filter, so an empty value is fine.\n * With one, a blank value would filter on nothing and read as an accident.\n */\nconst validateValue: TextFieldSingleValidation = (value, { req, siblingData }) => {\n\tconst dimension = (siblingData as { dimension?: unknown } | undefined)?.dimension\n\tif (typeof dimension !== 'string' || dimension.trim() === '') return true\n\tconst trimmed = typeof value === 'string' ? value.trim() : ''\n\tif (trimmed === '') return asTranslate(req.t)(keys.widgetFilterValueRequired)\n\treturn trimmed.length <= MAX_QUERY_FILTER_VALUE_LENGTH\n\t\t? true\n\t\t: asTranslate(req.t)(keys.widgetFilterValueTooLong)\n}\n\n/**\n * The stored group as query filters: one entry, or none at all. A group without both a\n * dimension and a value is still being configured, and the value is stored exactly as it\n * was typed, so the query's own trimming and cap are applied here rather than assumed.\n *\n * Both keys are text fields the pickers fill, so a hand-edited layout or a widget saved\n * against an older contract can hold anything. A dimension the contract does not define\n * has no label to caption it with, so it is no filter at all; an undefined operator falls\n * back to `eq`, the field's own default.\n */\nexport const widgetFilters = (data: { filter?: WidgetFilter }): AnalyticsFilter[] => {\n\tconst { dimension, operator, value } = data.filter ?? {}\n\tconst trimmed = typeof value === 'string' ? value.trim() : ''\n\tif (!dimension || !DIMENSION_KEYS.includes(dimension) || trimmed === '') {\n\t\treturn []\n\t}\n\treturn [\n\t\t{\n\t\t\tdimension,\n\t\t\toperator: operator && FILTER_OPERATORS.includes(operator) ? operator : 'eq',\n\t\t\tvalue: trimmed.slice(0, MAX_QUERY_FILTER_VALUE_LENGTH),\n\t\t},\n\t]\n}\n\n/**\n * The optional one-filter group every filterable widget carries. Text-backed rather than\n * select-backed on purpose: the servable dimensions and operators are per source and per\n * request, so the option lists are the client pickers' to build, not the config's.\n */\nexport const filterField = (): NamedGroupField => ({\n\tname: 'filter',\n\ttype: 'group',\n\tlabel: labelForKey(keys.widgetFieldFilter),\n\tadmin: { description: labelForKey(keys.widgetFieldFilterDescription) },\n\tfields: [\n\t\t{\n\t\t\tname: 'dimension',\n\t\t\ttype: 'text',\n\t\t\tlabel: labelForKey(keys.widgetFieldFilterDimension),\n\t\t\tadmin: { components: { Field: { path: FILTER_DIMENSION_COMPONENT } } },\n\t\t},\n\t\t{\n\t\t\tname: 'operator',\n\t\t\ttype: 'text',\n\t\t\tdefaultValue: 'eq',\n\t\t\tlabel: labelForKey(keys.widgetFieldFilterOperator),\n\t\t\tadmin: { components: { Field: { path: FILTER_OPERATOR_COMPONENT } } },\n\t\t},\n\t\t{\n\t\t\tname: 'value',\n\t\t\ttype: 'text',\n\t\t\tmaxLength: MAX_QUERY_FILTER_VALUE_LENGTH,\n\t\t\tlabel: labelForKey(keys.widgetFieldFilterValue),\n\t\t\tvalidate: validateValue,\n\t\t},\n\t],\n})\n"],"mappings":";;;;;AAQA,MAAa,6BAA6B;AAC1C,MAAa,4BAA4B;;;;;AAMzC,MAAM,iBAA4C,OAAO,EAAE,KAAK,kBAAkB;CACjF,MAAM,YAAa,aAAqD;CACxE,IAAI,OAAO,cAAc,YAAY,UAAU,KAAK,MAAM,IAAI,OAAO;CACrE,MAAM,UAAU,OAAO,UAAU,WAAW,MAAM,KAAK,IAAI;CAC3D,IAAI,YAAY,IAAI,OAAO,YAAY,IAAI,CAAC,EAAE,KAAK,yBAAyB;CAC5E,OAAO,QAAQ,UAAA,MACZ,OACA,YAAY,IAAI,CAAC,EAAE,KAAK,wBAAwB;AACpD;;;;;;;;;;;AAYA,MAAa,iBAAiB,SAAuD;CACpF,MAAM,EAAE,WAAW,UAAU,UAAU,KAAK,UAAU,CAAC;CACvD,MAAM,UAAU,OAAO,UAAU,WAAW,MAAM,KAAK,IAAI;CAC3D,IAAI,CAAC,aAAa,CAAC,eAAe,SAAS,SAAS,KAAK,YAAY,IACpE,OAAO,CAAC;CAET,OAAO,CACN;EACC;EACA,UAAU,YAAY,iBAAiB,SAAS,QAAQ,IAAI,WAAW;EACvE,OAAO,QAAQ,MAAM,GAAA,GAAgC;CACtD,CACD;AACD;;;;;;AAOA,MAAa,qBAAsC;CAClD,MAAM;CACN,MAAM;CACN,OAAO,YAAY,KAAK,iBAAiB;CACzC,OAAO,EAAE,aAAa,YAAY,KAAK,4BAA4B,EAAE;CACrE,QAAQ;EACP;GACC,MAAM;GACN,MAAM;GACN,OAAO,YAAY,KAAK,0BAA0B;GAClD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,2BAA2B,EAAE,EAAE;EACtE;EACA;GACC,MAAM;GACN,MAAM;GACN,cAAc;GACd,OAAO,YAAY,KAAK,yBAAyB;GACjD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,0BAA0B,EAAE,EAAE;EACrE;EACA;GACC,MAAM;GACN,MAAM;GACN,WAAA;GACA,OAAO,YAAY,KAAK,sBAAsB;GAC9C,UAAU;EACX;CACD;AACD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PayloadRequest } from "payload";
|
|
2
|
+
|
|
3
|
+
//#region src/widgets/prepareWidgetRead.d.ts
|
|
4
|
+
type WidgetReadStatus = 'ok' | 'not-configured' | 'unavailable' | 'filter-unsupported';
|
|
5
|
+
//#endregion
|
|
6
|
+
export { WidgetReadStatus };
|
|
7
|
+
//# sourceMappingURL=prepareWidgetRead.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { getRuntime, resolveTimezoneFor } from "../plugin/runtime.js";
|
|
2
|
+
import { resolveTimeframe } from "../timeframe/presets.js";
|
|
3
|
+
import { satisfiesCapabilities } from "../core/capabilities.js";
|
|
4
|
+
import { supportsGranularity } from "../core/granularity.js";
|
|
5
|
+
import { resolveReadContext } from "../core/scopedRead.js";
|
|
6
|
+
import { goalSlugsFor } from "../plugin/goalHint.js";
|
|
7
|
+
//#region src/widgets/prepareWidgetRead.ts
|
|
8
|
+
/**
|
|
9
|
+
* Whether the serving source can apply every filter the read carries. Answered before the
|
|
10
|
+
* query so a source that cannot filter says so rather than returning site-wide numbers a
|
|
11
|
+
* reader would take for filtered ones.
|
|
12
|
+
*/
|
|
13
|
+
const supportsFilters = (caps, filters) => !filters || filters.length === 0 || satisfiesCapabilities(caps, {
|
|
14
|
+
filters: filters.map((f) => f.dimension),
|
|
15
|
+
filterOperators: filters.map((f) => f.operator)
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* The prologue every widget read shares: the runtime, the read's scope and adapter, the
|
|
19
|
+
* reporting timezone, the window, and the gates a source has to pass before it is worth
|
|
20
|
+
* querying. A refusal carries the status the widget renders and the window it would have
|
|
21
|
+
* read, so a helper's own failure shape is one spread rather than five early returns.
|
|
22
|
+
*/
|
|
23
|
+
const prepareWidgetRead = async (args) => {
|
|
24
|
+
const { req, now } = args;
|
|
25
|
+
const windowIn = (zone) => args.timeframe === void 0 ? args.range : args.range ?? resolveTimeframe(args.timeframe, now, zone);
|
|
26
|
+
const runtime = getRuntime(req.payload);
|
|
27
|
+
const ctx = runtime ? await resolveReadContext({
|
|
28
|
+
runtime,
|
|
29
|
+
req,
|
|
30
|
+
adapterId: args.adapterId,
|
|
31
|
+
scope: args.scope
|
|
32
|
+
}) : { ok: false };
|
|
33
|
+
if (!runtime || !ctx.ok) return {
|
|
34
|
+
ok: false,
|
|
35
|
+
status: "unavailable",
|
|
36
|
+
adapterId: args.adapterId ?? "",
|
|
37
|
+
dateRange: windowIn(args.timezone),
|
|
38
|
+
tz: args.timezone ?? "UTC"
|
|
39
|
+
};
|
|
40
|
+
const tz = args.timezone ?? await resolveTimezoneFor(runtime, req, ctx.scope);
|
|
41
|
+
const dateRange = windowIn(tz);
|
|
42
|
+
const adapter = ctx.adapter;
|
|
43
|
+
const refuse = (status) => ({
|
|
44
|
+
ok: false,
|
|
45
|
+
status,
|
|
46
|
+
adapterId: adapter.id,
|
|
47
|
+
dateRange,
|
|
48
|
+
tz
|
|
49
|
+
});
|
|
50
|
+
if (!adapter.isConfigured()) return refuse("not-configured");
|
|
51
|
+
if (args.requires && !satisfiesCapabilities(adapter.capabilities, args.requires)) return refuse("unavailable");
|
|
52
|
+
if (args.granularity && !supportsGranularity(adapter.capabilities, args.granularity)) return refuse("unavailable");
|
|
53
|
+
if (!supportsFilters(adapter.capabilities, args.filters)) return refuse("filter-unsupported");
|
|
54
|
+
const goalSlugs = args.goalSlugs ?? (args.goalRead ? await goalSlugsFor({
|
|
55
|
+
runtime,
|
|
56
|
+
req,
|
|
57
|
+
scope: ctx.scope,
|
|
58
|
+
...args.goalRead(adapter)
|
|
59
|
+
}) : void 0);
|
|
60
|
+
return {
|
|
61
|
+
ok: true,
|
|
62
|
+
runtime,
|
|
63
|
+
adapter,
|
|
64
|
+
tz,
|
|
65
|
+
dateRange,
|
|
66
|
+
scope: ctx.scope,
|
|
67
|
+
...ctx.queryScope === void 0 ? {} : { queryScope: ctx.queryScope },
|
|
68
|
+
...goalSlugs === void 0 ? {} : { goalSlugs }
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
export { prepareWidgetRead };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=prepareWidgetRead.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareWidgetRead.js","names":[],"sources":["../../src/widgets/prepareWidgetRead.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { type CapabilityRequirement, satisfiesCapabilities } from '../core/capabilities'\nimport type {\n\tAnalyticsAdapter,\n\tAnalyticsCapabilities,\n\tAnalyticsFilter,\n\tDateRange,\n\tGranularity,\n} from '../core/contract'\nimport { supportsGranularity } from '../core/granularity'\nimport { resolveReadContext } from '../core/scopedRead'\nimport { type GoalRead, goalSlugsFor } from '../plugin/goalHint'\nimport { type AnalyticsRuntime, getRuntime, resolveTimezoneFor } from '../plugin/runtime'\nimport { resolveTimeframe, type TimeframePreset } from '../timeframe/presets'\nimport { DEFAULT_TIMEZONE } from '../timeframe/tz'\n\nexport type WidgetReadStatus = 'ok' | 'not-configured' | 'unavailable' | 'filter-unsupported'\n\n/**\n * Whether the serving source can apply every filter the read carries. Answered before the\n * query so a source that cannot filter says so rather than returning site-wide numbers a\n * reader would take for filtered ones.\n */\nexport const supportsFilters = (\n\tcaps: AnalyticsCapabilities,\n\tfilters?: AnalyticsFilter[]\n): boolean =>\n\t!filters ||\n\tfilters.length === 0 ||\n\tsatisfiesCapabilities(caps, {\n\t\tfilters: filters.map((f) => f.dimension),\n\t\tfilterOperators: filters.map((f) => f.operator),\n\t})\n\ninterface PrepareWidgetReadBase {\n\treq: PayloadRequest\n\tnow: Date\n\tadapterId?: string\n\t/** Explicit scope override; omitted resolves via the plugin's scopeResolver. */\n\tscope?: string | null\n\t/**\n\t * Reporting timezone the caller already resolved, reused rather than resolved again so\n\t * a caller-supplied `range` is read in the very timezone it was interpreted in.\n\t */\n\ttimezone?: string\n\tfilters?: AnalyticsFilter[]\n\t/** What the source must serve for the read to be worth making. */\n\trequires?: CapabilityRequirement\n\t/** The finest bucket the read needs, gated against the source's `minGranularity`. */\n\tgranularity?: Granularity\n\t/**\n\t * The read the goal hint is resolved for, answered once the adapter is known so a caller\n\t * that narrows its metrics against the source hints on the list it will actually ask for.\n\t * Omitted asks about no goals.\n\t */\n\tgoalRead?: (adapter: AnalyticsAdapter) => GoalRead\n\t/** A hint the caller already resolved, which wins over `goalRead`. */\n\tgoalSlugs?: string[] | 'unresolved'\n}\n\n/** Either a preset to resolve the window from or the window itself. */\nexport type PrepareWidgetReadArgs = PrepareWidgetReadBase &\n\t({ timeframe: TimeframePreset; range?: DateRange } | { timeframe?: undefined; range: DateRange })\n\nexport type PreparedWidgetRead =\n\t| {\n\t\t\tok: true\n\t\t\truntime: AnalyticsRuntime\n\t\t\tadapter: AnalyticsAdapter\n\t\t\t/** Reporting timezone the window was resolved in. */\n\t\t\ttz: string\n\t\t\tdateRange: DateRange\n\t\t\t/** The read's own scope, which sub-reads pin so all of them answer about one thing. */\n\t\t\tscope: string | null\n\t\t\t/** The scope to stamp on the adapter query; undefined for install-wide reads. */\n\t\t\tqueryScope?: string\n\t\t\t/** The scope's goal slugs, `'unresolved'`, or absent for a read about no goals. */\n\t\t\tgoalSlugs?: string[] | 'unresolved'\n\t }\n\t| {\n\t\t\tok: false\n\t\t\tstatus: WidgetReadStatus\n\t\t\tadapterId: string\n\t\t\tdateRange: DateRange\n\t\t\t/** The timezone the window was read in: the resolved one, or the caller's own, or UTC. */\n\t\t\ttz: string\n\t }\n\n/**\n * The prologue every widget read shares: the runtime, the read's scope and adapter, the\n * reporting timezone, the window, and the gates a source has to pass before it is worth\n * querying. A refusal carries the status the widget renders and the window it would have\n * read, so a helper's own failure shape is one spread rather than five early returns.\n */\nexport const prepareWidgetRead = async (\n\targs: PrepareWidgetReadArgs\n): Promise<PreparedWidgetRead> => {\n\tconst { req, now } = args\n\tconst windowIn = (zone?: string): DateRange =>\n\t\targs.timeframe === undefined\n\t\t\t? args.range\n\t\t\t: (args.range ?? resolveTimeframe(args.timeframe, now, zone))\n\n\tconst runtime = getRuntime(req.payload)\n\tconst ctx = runtime\n\t\t? await resolveReadContext({ runtime, req, adapterId: args.adapterId, scope: args.scope })\n\t\t: { ok: false as const }\n\tif (!runtime || !ctx.ok) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tstatus: 'unavailable',\n\t\t\tadapterId: args.adapterId ?? '',\n\t\t\tdateRange: windowIn(args.timezone),\n\t\t\ttz: args.timezone ?? DEFAULT_TIMEZONE,\n\t\t}\n\t}\n\n\tconst tz = args.timezone ?? (await resolveTimezoneFor(runtime, req, ctx.scope))\n\tconst dateRange = windowIn(tz)\n\tconst adapter = ctx.adapter\n\tconst refuse = (status: WidgetReadStatus): PreparedWidgetRead => ({\n\t\tok: false,\n\t\tstatus,\n\t\tadapterId: adapter.id,\n\t\tdateRange,\n\t\ttz,\n\t})\n\tif (!adapter.isConfigured()) {\n\t\treturn refuse('not-configured')\n\t}\n\tif (args.requires && !satisfiesCapabilities(adapter.capabilities, args.requires)) {\n\t\treturn refuse('unavailable')\n\t}\n\tif (args.granularity && !supportsGranularity(adapter.capabilities, args.granularity)) {\n\t\treturn refuse('unavailable')\n\t}\n\tif (!supportsFilters(adapter.capabilities, args.filters)) {\n\t\treturn refuse('filter-unsupported')\n\t}\n\n\tconst goalSlugs =\n\t\targs.goalSlugs ??\n\t\t(args.goalRead\n\t\t\t? await goalSlugsFor({ runtime, req, scope: ctx.scope, ...args.goalRead(adapter) })\n\t\t\t: undefined)\n\treturn {\n\t\tok: true,\n\t\truntime,\n\t\tadapter,\n\t\ttz,\n\t\tdateRange,\n\t\tscope: ctx.scope,\n\t\t...(ctx.queryScope === undefined ? {} : { queryScope: ctx.queryScope }),\n\t\t...(goalSlugs === undefined ? {} : { goalSlugs }),\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAa,mBACZ,MACA,YAEA,CAAC,WACD,QAAQ,WAAW,KACnB,sBAAsB,MAAM;CAC3B,SAAS,QAAQ,KAAK,MAAM,EAAE,SAAS;CACvC,iBAAiB,QAAQ,KAAK,MAAM,EAAE,QAAQ;AAC/C,CAAC;;;;;;;AA8DF,MAAa,oBAAoB,OAChC,SACiC;CACjC,MAAM,EAAE,KAAK,QAAQ;CACrB,MAAM,YAAY,SACjB,KAAK,cAAc,KAAA,IAChB,KAAK,QACJ,KAAK,SAAS,iBAAiB,KAAK,WAAW,KAAK,IAAI;CAE7D,MAAM,UAAU,WAAW,IAAI,OAAO;CACtC,MAAM,MAAM,UACT,MAAM,mBAAmB;EAAE;EAAS;EAAK,WAAW,KAAK;EAAW,OAAO,KAAK;CAAM,CAAC,IACvF,EAAE,IAAI,MAAe;CACxB,IAAI,CAAC,WAAW,CAAC,IAAI,IACpB,OAAO;EACN,IAAI;EACJ,QAAQ;EACR,WAAW,KAAK,aAAa;EAC7B,WAAW,SAAS,KAAK,QAAQ;EACjC,IAAI,KAAK,YAAA;CACV;CAGD,MAAM,KAAK,KAAK,YAAa,MAAM,mBAAmB,SAAS,KAAK,IAAI,KAAK;CAC7E,MAAM,YAAY,SAAS,EAAE;CAC7B,MAAM,UAAU,IAAI;CACpB,MAAM,UAAU,YAAkD;EACjE,IAAI;EACJ;EACA,WAAW,QAAQ;EACnB;EACA;CACD;CACA,IAAI,CAAC,QAAQ,aAAa,GACzB,OAAO,OAAO,gBAAgB;CAE/B,IAAI,KAAK,YAAY,CAAC,sBAAsB,QAAQ,cAAc,KAAK,QAAQ,GAC9E,OAAO,OAAO,aAAa;CAE5B,IAAI,KAAK,eAAe,CAAC,oBAAoB,QAAQ,cAAc,KAAK,WAAW,GAClF,OAAO,OAAO,aAAa;CAE5B,IAAI,CAAC,gBAAgB,QAAQ,cAAc,KAAK,OAAO,GACtD,OAAO,OAAO,oBAAoB;CAGnC,MAAM,YACL,KAAK,cACJ,KAAK,WACH,MAAM,aAAa;EAAE;EAAS;EAAK,OAAO,IAAI;EAAO,GAAG,KAAK,SAAS,OAAO;CAAE,CAAC,IAChF,KAAA;CACJ,OAAO;EACN,IAAI;EACJ;EACA;EACA;EACA;EACA,OAAO,IAAI;EACX,GAAI,IAAI,eAAe,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY,IAAI,WAAW;EACrE,GAAI,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU;CAChD;AACD"}
|
package/dist/widgets/range.js
CHANGED
|
@@ -1,27 +1,58 @@
|
|
|
1
|
+
import { zonedCalendarDay } from "../timeframe/tz.js";
|
|
2
|
+
import { DATE_ONLY, parseDayOrInstant } from "../query/dates.js";
|
|
1
3
|
//#region src/widgets/range.ts
|
|
4
|
+
const NOON_MS = 12 * 36e5;
|
|
2
5
|
/**
|
|
3
|
-
*
|
|
4
|
-
* the
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* The calendar day a stored bound names. The `dayOnly` picker stores the picked day at the
|
|
7
|
+
* admin browser's local midnight, so the instant lands on that day or the one before it in
|
|
8
|
+
* UTC depending on the browser's offset; a 12-hour shift recovers the picked day for every
|
|
9
|
+
* offset in (-12, +12]. Zones at +12:45 and beyond (Chatham in DST, Kiritimati) recover the
|
|
10
|
+
* day before, and the uninhabited UTC-12 the day after.
|
|
7
11
|
*/
|
|
8
|
-
const
|
|
12
|
+
const pickedDay = (raw) => {
|
|
13
|
+
if (DATE_ONLY.test(raw)) return raw;
|
|
14
|
+
const instant = new Date(raw);
|
|
15
|
+
if (Number.isNaN(instant.getTime())) return null;
|
|
16
|
+
return zonedCalendarDay(new Date(instant.getTime() + NOON_MS), "UTC");
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Resolve a widget's explicit custom range to a concrete DateRange, or undefined when the
|
|
20
|
+
* widget is on a relative preset, the custom range is incomplete, or either bound names no
|
|
21
|
+
* real day (a corrupt or hand-set widgetData would otherwise reach the cache key and throw
|
|
22
|
+
* on `toISOString`). The two picked days are read inclusively in `timezone`, the reporting
|
|
23
|
+
* timezone the read resolves in: `from` at the first instant of its day, `to` at the last.
|
|
24
|
+
*/
|
|
25
|
+
const resolveCustomRange = (timeframe, range, timezone) => {
|
|
9
26
|
if (timeframe !== "custom" || !range?.from || !range?.to) return;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
27
|
+
const fromDay = pickedDay(range.from);
|
|
28
|
+
const toDay = pickedDay(range.to);
|
|
29
|
+
if (!fromDay || !toDay) return;
|
|
30
|
+
const start = parseDayOrInstant(fromDay, {
|
|
31
|
+
timezone,
|
|
32
|
+
edge: "start"
|
|
33
|
+
});
|
|
34
|
+
const end = parseDayOrInstant(toDay, {
|
|
35
|
+
timezone,
|
|
36
|
+
edge: "end"
|
|
37
|
+
});
|
|
38
|
+
if (!start || !end) return;
|
|
13
39
|
return {
|
|
14
40
|
start,
|
|
15
41
|
end
|
|
16
42
|
};
|
|
17
43
|
};
|
|
18
|
-
const formatDay = (d, locale) => d.toLocaleDateString(locale, {
|
|
44
|
+
const formatDay = (d, locale, timeZone) => d.toLocaleDateString(locale, {
|
|
19
45
|
month: "short",
|
|
20
46
|
day: "numeric",
|
|
21
|
-
year: "numeric"
|
|
47
|
+
year: "numeric",
|
|
48
|
+
timeZone
|
|
22
49
|
});
|
|
23
|
-
/**
|
|
24
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Server-side caption for a custom range, e.g. "Jun 1, 2026 - Jun 23, 2026". Both bounds
|
|
52
|
+
* render in the reporting timezone, so the caption names the days that were read rather
|
|
53
|
+
* than the days the server's own zone would spell them as.
|
|
54
|
+
*/
|
|
55
|
+
const formatRangeCaption = (range, locale, timezone) => `${formatDay(range.start, locale, timezone)} - ${formatDay(range.end, locale, timezone)}`;
|
|
25
56
|
//#endregion
|
|
26
57
|
export { formatRangeCaption, resolveCustomRange };
|
|
27
58
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.js","names":[],"sources":["../../src/widgets/range.ts"],"sourcesContent":["import type { DateRange } from '../core/contract'\nimport type { WidgetRange } from './types'\n\n/**\n * Resolve a widget's explicit custom range to a concrete DateRange, or undefined when\n *
|
|
1
|
+
{"version":3,"file":"range.js","names":[],"sources":["../../src/widgets/range.ts"],"sourcesContent":["import type { DateRange } from '../core/contract'\nimport { DATE_ONLY, parseDayOrInstant } from '../query/dates'\nimport { zonedCalendarDay } from '../timeframe/tz'\nimport type { WidgetRange } from './types'\n\nconst NOON_MS = 12 * 3_600_000\n\n/**\n * The calendar day a stored bound names. The `dayOnly` picker stores the picked day at the\n * admin browser's local midnight, so the instant lands on that day or the one before it in\n * UTC depending on the browser's offset; a 12-hour shift recovers the picked day for every\n * offset in (-12, +12]. Zones at +12:45 and beyond (Chatham in DST, Kiritimati) recover the\n * day before, and the uninhabited UTC-12 the day after.\n */\nconst pickedDay = (raw: string): string | null => {\n\tif (DATE_ONLY.test(raw)) {\n\t\treturn raw\n\t}\n\tconst instant = new Date(raw)\n\tif (Number.isNaN(instant.getTime())) {\n\t\treturn null\n\t}\n\treturn zonedCalendarDay(new Date(instant.getTime() + NOON_MS), 'UTC')\n}\n\n/**\n * Resolve a widget's explicit custom range to a concrete DateRange, or undefined when the\n * widget is on a relative preset, the custom range is incomplete, or either bound names no\n * real day (a corrupt or hand-set widgetData would otherwise reach the cache key and throw\n * on `toISOString`). The two picked days are read inclusively in `timezone`, the reporting\n * timezone the read resolves in: `from` at the first instant of its day, `to` at the last.\n */\nexport const resolveCustomRange = (\n\ttimeframe: string | undefined,\n\trange: WidgetRange | undefined,\n\ttimezone: string\n): DateRange | undefined => {\n\tif (timeframe !== 'custom' || !range?.from || !range?.to) {\n\t\treturn undefined\n\t}\n\tconst fromDay = pickedDay(range.from)\n\tconst toDay = pickedDay(range.to)\n\tif (!fromDay || !toDay) {\n\t\treturn undefined\n\t}\n\tconst start = parseDayOrInstant(fromDay, { timezone, edge: 'start' })\n\tconst end = parseDayOrInstant(toDay, { timezone, edge: 'end' })\n\tif (!start || !end) {\n\t\treturn undefined\n\t}\n\treturn { start, end }\n}\n\nconst formatDay = (d: Date, locale: string, timeZone: string): string =>\n\td.toLocaleDateString(locale, { month: 'short', day: 'numeric', year: 'numeric', timeZone })\n\n/**\n * Server-side caption for a custom range, e.g. \"Jun 1, 2026 - Jun 23, 2026\". Both bounds\n * render in the reporting timezone, so the caption names the days that were read rather\n * than the days the server's own zone would spell them as.\n */\nexport const formatRangeCaption = (range: DateRange, locale: string, timezone: string): string =>\n\t`${formatDay(range.start, locale, timezone)} - ${formatDay(range.end, locale, timezone)}`\n"],"mappings":";;;AAKA,MAAM,UAAU,KAAK;;;;;;;;AASrB,MAAM,aAAa,QAA+B;CACjD,IAAI,UAAU,KAAK,GAAG,GACrB,OAAO;CAER,MAAM,UAAU,IAAI,KAAK,GAAG;CAC5B,IAAI,OAAO,MAAM,QAAQ,QAAQ,CAAC,GACjC,OAAO;CAER,OAAO,iBAAiB,IAAI,KAAK,QAAQ,QAAQ,IAAI,OAAO,GAAG,KAAK;AACrE;;;;;;;;AASA,MAAa,sBACZ,WACA,OACA,aAC2B;CAC3B,IAAI,cAAc,YAAY,CAAC,OAAO,QAAQ,CAAC,OAAO,IACrD;CAED,MAAM,UAAU,UAAU,MAAM,IAAI;CACpC,MAAM,QAAQ,UAAU,MAAM,EAAE;CAChC,IAAI,CAAC,WAAW,CAAC,OAChB;CAED,MAAM,QAAQ,kBAAkB,SAAS;EAAE;EAAU,MAAM;CAAQ,CAAC;CACpE,MAAM,MAAM,kBAAkB,OAAO;EAAE;EAAU,MAAM;CAAM,CAAC;CAC9D,IAAI,CAAC,SAAS,CAAC,KACd;CAED,OAAO;EAAE;EAAO;CAAI;AACrB;AAEA,MAAM,aAAa,GAAS,QAAgB,aAC3C,EAAE,mBAAmB,QAAQ;CAAE,OAAO;CAAS,KAAK;CAAW,MAAM;CAAW;AAAS,CAAC;;;;;;AAO3F,MAAa,sBAAsB,OAAkB,QAAgB,aACpE,GAAG,UAAU,MAAM,OAAO,QAAQ,QAAQ,EAAE,KAAK,UAAU,MAAM,KAAK,QAAQ,QAAQ"}
|