@10x-media/analytics 0.1.0-beta.4 → 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 +280 -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 +17 -2
- package/dist/core/capabilities.js +20 -1
- 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 +168 -8
- package/dist/core/options.js +132 -4
- 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 -29
- 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 +16 -2
- package/dist/exports/client.js +13 -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 +12 -4
- 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 +17 -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.d.ts +23 -0
- package/dist/fields/config/MetricSelectField.js +51 -0
- package/dist/fields/config/MetricSelectField.js.map +1 -0
- package/dist/fields/config/SourceSelectField.d.ts +14 -0
- package/dist/fields/config/SourceSelectField.js +46 -0
- package/dist/fields/config/SourceSelectField.js.map +1 -0
- package/dist/fields/config/fetchSources.d.ts +16 -0
- package/dist/fields/config/fetchSources.js +33 -0
- package/dist/fields/config/fetchSources.js.map +1 -0
- package/dist/fields/config/narrow.js +32 -0
- package/dist/fields/config/narrow.js.map +1 -0
- package/dist/fields/config/sourcesState.js +27 -0
- package/dist/fields/config/sourcesState.js.map +1 -0
- package/dist/fields/config/toSelectOption.js +27 -0
- package/dist/fields/config/toSelectOption.js.map +1 -0
- package/dist/fields/config/useAnalyticsSources.d.ts +24 -0
- package/dist/fields/config/useAnalyticsSources.js +62 -0
- package/dist/fields/config/useAnalyticsSources.js.map +1 -0
- 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 +185 -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 +19 -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 +39 -18
- 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 +28 -0
- package/dist/plugin/sourcesEndpoint.js.map +1 -0
- package/dist/plugin/warmTask.js +0 -0
- package/dist/plugin/warmTask.js.map +1 -1
- package/dist/providers/access.js +2 -1
- package/dist/providers/access.js.map +1 -1
- package/dist/providers/collection.js +90 -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 +45 -23
- 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 +16 -1
- package/dist/widgets/realtimePoll.js.map +1 -1
- package/dist/widgets/registerWidgets.js +76 -14
- 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 +27 -7
- 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
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DimensionKey, FilterOperator } from "../../core/contract.js";
|
|
2
|
+
//#region src/fields/config/useFilterCapabilities.d.ts
|
|
3
|
+
interface FilterCapabilities {
|
|
4
|
+
/** Dimensions the widget may filter on, in contract order. */
|
|
5
|
+
dimensions: DimensionKey[];
|
|
6
|
+
/** Operators the widget may filter with, in contract order. */
|
|
7
|
+
operators: FilterOperator[];
|
|
8
|
+
/** The source list has yet to answer; offer nothing rather than a wrong list. */
|
|
9
|
+
loading: boolean;
|
|
10
|
+
/** The source list could not be fetched, so an empty offer is not a verdict. */
|
|
11
|
+
error: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* A source list actually answered. False covers both the pending fetch and the window
|
|
14
|
+
* before there is a user to fetch for, where nothing offered is not yet a verdict.
|
|
15
|
+
*/
|
|
16
|
+
resolved: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Filter capabilities for the source a widget's config form currently points at, read
|
|
20
|
+
* from that field's value in form state. `dataSourcePath` is a form path, not a relative
|
|
21
|
+
* sibling lookup: it defaults to the top-level `dataSource` the widget config forms use,
|
|
22
|
+
* and a custom widget whose source field sits elsewhere passes its own path, exactly as
|
|
23
|
+
* `MetricSelectField` does.
|
|
24
|
+
*/
|
|
25
|
+
declare const useFilterCapabilities: (dataSourcePath?: string) => FilterCapabilities;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { FilterCapabilities, useFilterCapabilities };
|
|
28
|
+
//# sourceMappingURL=useFilterCapabilities.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { DIMENSION_KEYS, FILTER_OPERATORS } from "../../core/contract.js";
|
|
3
|
+
import { useAnalyticsSources } from "./useAnalyticsSources.js";
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import { useFormFields } from "@payloadcms/ui";
|
|
6
|
+
//#region src/fields/config/useFilterCapabilities.ts
|
|
7
|
+
const EMPTY = {
|
|
8
|
+
dimensions: [],
|
|
9
|
+
operators: []
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* What the widget's chosen source can filter by. An unknown source id (a stale value, a
|
|
13
|
+
* runtime source the endpoint could not list) falls back to the union, mirroring the
|
|
14
|
+
* metric picker's narrowing; the union is also what a single-provider install sees, where
|
|
15
|
+
* there is no source field to read.
|
|
16
|
+
*/
|
|
17
|
+
const deriveFilterCapabilities = (args) => {
|
|
18
|
+
const { sourceId, sources } = args;
|
|
19
|
+
if (!sources || sources.length === 0) return EMPTY;
|
|
20
|
+
const picked = sourceId ? sources.find((s) => s.id === sourceId) : void 0;
|
|
21
|
+
const scope = picked ? [picked] : sources;
|
|
22
|
+
return {
|
|
23
|
+
dimensions: DIMENSION_KEYS.filter((d) => scope.some((s) => s.capabilities.filters.includes(d))),
|
|
24
|
+
operators: FILTER_OPERATORS.filter((op) => scope.some((s) => s.capabilities.filterOperators.includes(op)))
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Filter capabilities for the source a widget's config form currently points at, read
|
|
29
|
+
* from that field's value in form state. `dataSourcePath` is a form path, not a relative
|
|
30
|
+
* sibling lookup: it defaults to the top-level `dataSource` the widget config forms use,
|
|
31
|
+
* and a custom widget whose source field sits elsewhere passes its own path, exactly as
|
|
32
|
+
* `MetricSelectField` does.
|
|
33
|
+
*/
|
|
34
|
+
const useFilterCapabilities = (dataSourcePath = "dataSource") => {
|
|
35
|
+
const { error, loading, sources } = useAnalyticsSources();
|
|
36
|
+
const sourceId = useFormFields(([fields]) => fields?.[dataSourcePath]?.value);
|
|
37
|
+
const { dimensions, operators } = useMemo(() => deriveFilterCapabilities({
|
|
38
|
+
sourceId,
|
|
39
|
+
sources
|
|
40
|
+
}), [sourceId, sources]);
|
|
41
|
+
return {
|
|
42
|
+
dimensions,
|
|
43
|
+
error,
|
|
44
|
+
loading,
|
|
45
|
+
operators,
|
|
46
|
+
resolved: sources !== null
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
export { useFilterCapabilities };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=useFilterCapabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFilterCapabilities.js","names":[],"sources":["../../../src/fields/config/useFilterCapabilities.ts"],"sourcesContent":["'use client'\n\nimport { useFormFields } from '@payloadcms/ui'\nimport { useMemo } from 'react'\nimport {\n\tDIMENSION_KEYS,\n\ttype DimensionKey,\n\tFILTER_OPERATORS,\n\ttype FilterOperator,\n} from '../../core/contract'\nimport type { WireSource } from './fetchSources'\nimport { useAnalyticsSources } from './useAnalyticsSources'\n\nexport interface FilterCapabilities {\n\t/** Dimensions the widget may filter on, in contract order. */\n\tdimensions: DimensionKey[]\n\t/** Operators the widget may filter with, in contract order. */\n\toperators: FilterOperator[]\n\t/** The source list has yet to answer; offer nothing rather than a wrong list. */\n\tloading: boolean\n\t/** The source list could not be fetched, so an empty offer is not a verdict. */\n\terror: boolean\n\t/**\n\t * A source list actually answered. False covers both the pending fetch and the window\n\t * before there is a user to fetch for, where nothing offered is not yet a verdict.\n\t */\n\tresolved: boolean\n}\n\nconst EMPTY: Pick<FilterCapabilities, 'dimensions' | 'operators'> = {\n\tdimensions: [],\n\toperators: [],\n}\n\n/**\n * What the widget's chosen source can filter by. An unknown source id (a stale value, a\n * runtime source the endpoint could not list) falls back to the union, mirroring the\n * metric picker's narrowing; the union is also what a single-provider install sees, where\n * there is no source field to read.\n */\nexport const deriveFilterCapabilities = (args: {\n\tsources: WireSource[] | null\n\tsourceId: string | undefined\n}): Pick<FilterCapabilities, 'dimensions' | 'operators'> => {\n\tconst { sourceId, sources } = args\n\tif (!sources || sources.length === 0) return EMPTY\n\tconst picked = sourceId ? sources.find((s) => s.id === sourceId) : undefined\n\tconst scope = picked ? [picked] : sources\n\treturn {\n\t\tdimensions: DIMENSION_KEYS.filter((d) => scope.some((s) => s.capabilities.filters.includes(d))),\n\t\toperators: FILTER_OPERATORS.filter((op) =>\n\t\t\tscope.some((s) => s.capabilities.filterOperators.includes(op))\n\t\t),\n\t}\n}\n\n/**\n * Filter capabilities for the source a widget's config form currently points at, read\n * from that field's value in form state. `dataSourcePath` is a form path, not a relative\n * sibling lookup: it defaults to the top-level `dataSource` the widget config forms use,\n * and a custom widget whose source field sits elsewhere passes its own path, exactly as\n * `MetricSelectField` does.\n */\nexport const useFilterCapabilities = (dataSourcePath = 'dataSource'): FilterCapabilities => {\n\tconst { error, loading, sources } = useAnalyticsSources()\n\tconst sourceId = useFormFields(\n\t\t([fields]) => fields?.[dataSourcePath]?.value as string | undefined\n\t)\n\tconst { dimensions, operators } = useMemo(\n\t\t() => deriveFilterCapabilities({ sourceId, sources }),\n\t\t[sourceId, sources]\n\t)\n\treturn { dimensions, error, loading, operators, resolved: sources !== null }\n}\n"],"mappings":";;;;;;AA6BA,MAAM,QAA8D;CACnE,YAAY,CAAC;CACb,WAAW,CAAC;AACb;;;;;;;AAQA,MAAa,4BAA4B,SAGmB;CAC3D,MAAM,EAAE,UAAU,YAAY;CAC9B,IAAI,CAAC,WAAW,QAAQ,WAAW,GAAG,OAAO;CAC7C,MAAM,SAAS,WAAW,QAAQ,MAAM,MAAM,EAAE,OAAO,QAAQ,IAAI,KAAA;CACnE,MAAM,QAAQ,SAAS,CAAC,MAAM,IAAI;CAClC,OAAO;EACN,YAAY,eAAe,QAAQ,MAAM,MAAM,MAAM,MAAM,EAAE,aAAa,QAAQ,SAAS,CAAC,CAAC,CAAC;EAC9F,WAAW,iBAAiB,QAAQ,OACnC,MAAM,MAAM,MAAM,EAAE,aAAa,gBAAgB,SAAS,EAAE,CAAC,CAC9D;CACD;AACD;;;;;;;;AASA,MAAa,yBAAyB,iBAAiB,iBAAqC;CAC3F,MAAM,EAAE,OAAO,SAAS,YAAY,oBAAoB;CACxD,MAAM,WAAW,eACf,CAAC,YAAY,SAAS,iBAAiB,KACzC;CACA,MAAM,EAAE,YAAY,cAAc,cAC3B,yBAAyB;EAAE;EAAU;CAAQ,CAAC,GACpD,CAAC,UAAU,OAAO,CACnB;CACA,OAAO;EAAE;EAAY;EAAO;EAAS;EAAW,UAAU,YAAY;CAAK;AAC5E"}
|
|
@@ -36,6 +36,11 @@ interface ReadForFieldArgs {
|
|
|
36
36
|
now: Date;
|
|
37
37
|
/** Explicit scope override; omitted resolves via the plugin's scopeResolver. */
|
|
38
38
|
scope?: string | null;
|
|
39
|
+
/**
|
|
40
|
+
* Reporting timezone the caller already resolved, reused rather than resolved again so
|
|
41
|
+
* a caller-supplied `range` is read in the very timezone it was interpreted in.
|
|
42
|
+
*/
|
|
43
|
+
timezone?: string;
|
|
39
44
|
/** Also read the previous comparable window when the adapter supports comparison. */
|
|
40
45
|
compare?: boolean;
|
|
41
46
|
/** Also read a daily series for the first supported metric when the adapter can. */
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { getRuntime, resolveTimezoneFor } from "../plugin/runtime.js";
|
|
2
|
+
import { resolveTimeframe } from "../timeframe/presets.js";
|
|
1
3
|
import { resolveHostname, resolvePathCached } from "../binding/resolvePath.js";
|
|
2
|
-
import { satisfiesCapabilities } from "../core/capabilities.js";
|
|
4
|
+
import { comparisonOf, satisfiesCapabilities } from "../core/capabilities.js";
|
|
3
5
|
import { supportsGranularity } from "../core/granularity.js";
|
|
4
|
-
import { getRuntime, resolveTimezoneFor } from "../plugin/runtime.js";
|
|
5
6
|
import { resolveReadContext } from "../core/scopedRead.js";
|
|
6
|
-
import {
|
|
7
|
-
import { previousWindow } from "../widgets/comparison.js";
|
|
7
|
+
import { goalSlugsFor } from "../plugin/goalHint.js";
|
|
8
|
+
import { previousWindow, withinLookback } from "../widgets/comparison.js";
|
|
8
9
|
import { fillDailySeries } from "../widgets/readForWidgetSeries.js";
|
|
9
10
|
//#region src/fields/readForDocument.ts
|
|
10
11
|
/**
|
|
@@ -30,7 +31,7 @@ const readForField = async (args) => {
|
|
|
30
31
|
status: "not-bound",
|
|
31
32
|
adapterId: adapterId ?? "",
|
|
32
33
|
dateRange,
|
|
33
|
-
timezone: "UTC",
|
|
34
|
+
timezone: args.timezone ?? "UTC",
|
|
34
35
|
...empty
|
|
35
36
|
};
|
|
36
37
|
const binding = runtime.bindings[collectionSlug];
|
|
@@ -38,7 +39,7 @@ const readForField = async (args) => {
|
|
|
38
39
|
status: "not-bound",
|
|
39
40
|
adapterId: adapterId ?? "",
|
|
40
41
|
dateRange,
|
|
41
|
-
timezone: "UTC",
|
|
42
|
+
timezone: args.timezone ?? "UTC",
|
|
42
43
|
...empty
|
|
43
44
|
};
|
|
44
45
|
const ctx = await resolveReadContext({
|
|
@@ -51,10 +52,10 @@ const readForField = async (args) => {
|
|
|
51
52
|
status: "unavailable",
|
|
52
53
|
adapterId: adapterId ?? "",
|
|
53
54
|
dateRange,
|
|
54
|
-
timezone: "UTC",
|
|
55
|
+
timezone: args.timezone ?? "UTC",
|
|
55
56
|
...empty
|
|
56
57
|
};
|
|
57
|
-
const tz = await resolveTimezoneFor(runtime, req, ctx.scope);
|
|
58
|
+
const tz = args.timezone ?? await resolveTimezoneFor(runtime, req, ctx.scope);
|
|
58
59
|
dateRange = range ?? resolveTimeframe(timeframe, now, tz);
|
|
59
60
|
const adapter = ctx.adapter;
|
|
60
61
|
const bindingCtx = {
|
|
@@ -97,13 +98,24 @@ const readForField = async (args) => {
|
|
|
97
98
|
droppedMetrics: metrics
|
|
98
99
|
};
|
|
99
100
|
const hostname = await resolveHostname(binding, data, bindingCtx);
|
|
101
|
+
const goalSlugs = await goalSlugsFor({
|
|
102
|
+
runtime,
|
|
103
|
+
req,
|
|
104
|
+
scope: ctx.scope,
|
|
105
|
+
metrics: supportedMetrics
|
|
106
|
+
});
|
|
100
107
|
const base = {
|
|
101
108
|
path,
|
|
102
109
|
hostname,
|
|
103
110
|
timezone: tz,
|
|
104
|
-
scope: ctx.queryScope
|
|
111
|
+
scope: ctx.queryScope,
|
|
112
|
+
...goalSlugs === void 0 ? {} : { goalSlugs }
|
|
105
113
|
};
|
|
106
|
-
const
|
|
114
|
+
const previousRange = args.compare && runtime.comparison && comparisonOf(adapter.capabilities) ? previousWindow(dateRange, tz) : null;
|
|
115
|
+
const comparisonRange = previousRange && withinLookback(previousRange, adapter.capabilities.maxLookbackDays, {
|
|
116
|
+
tz,
|
|
117
|
+
now
|
|
118
|
+
}) ? previousRange : void 0;
|
|
107
119
|
const wantsSeries = args.series && supportsGranularity(adapter.capabilities, "day");
|
|
108
120
|
const [result, previous, seriesResult] = await Promise.all([
|
|
109
121
|
runtime.engine.read(adapter, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readForDocument.js","names":[],"sources":["../../src/fields/readForDocument.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { resolveHostname, resolvePathCached } from '../binding/resolvePath'\nimport type { BindingDoc } from '../binding/types'\nimport { satisfiesCapabilities } from '../core/capabilities'\nimport type { AnalyticsAdapter, DateRange, MetricKey } from '../core/contract'\nimport { supportsGranularity } from '../core/granularity'\nimport { resolveReadContext } from '../core/scopedRead'\nimport { getRuntime, resolveTimezoneFor } from '../plugin/runtime'\nimport { resolveTimeframe, type TimeframePreset } from '../timeframe/presets'\nimport { DEFAULT_TIMEZONE } from '../timeframe/tz'\nimport { previousWindow } from '../widgets/comparison'\nimport { fillDailySeries, type SeriesPoint } from '../widgets/readForWidgetSeries'\n\nexport type FieldReadStatus = 'ok' | 'no-path' | 'not-bound' | 'not-configured' | 'unavailable'\n\nexport interface FieldReadResult {\n\tstatus: FieldReadStatus\n\tadapterId: string\n\tdateRange: DateRange\n\t/** The reporting timezone the read resolved in; the trend axis buckets in it. */\n\ttimezone: string\n\tmetrics: Partial<Record<MetricKey, number>>\n\t/** Requested metrics the adapter supports, in request order; the set actually read. */\n\tsupportedMetrics: MetricKey[]\n\t/** Requested metrics the adapter cannot serve, dropped from the read. */\n\tdroppedMetrics: MetricKey[]\n\t/** Previous-window totals, present only when comparison was requested and supported. */\n\tpreviousMetrics?: Partial<Record<MetricKey, number>>\n\t/** The previous comparable window, present only when comparison ran. */\n\tcomparisonRange?: DateRange\n\t/** Per-day series for the first supported metric, present only when requested. */\n\tpoints?: SeriesPoint[]\n}\n\nexport interface ReadForFieldArgs {\n\treq: PayloadRequest\n\tcollectionSlug: string\n\tdata: BindingDoc\n\tmetrics: MetricKey[]\n\ttimeframe: TimeframePreset\n\t/** Overrides the preset window (custom range). */\n\trange?: DateRange\n\tadapterId?: string\n\tnow: Date\n\t/** Explicit scope override; omitted resolves via the plugin's scopeResolver. */\n\tscope?: string | null\n\t/** Also read the previous comparable window when the adapter supports comparison. */\n\tcompare?: boolean\n\t/** Also read a daily series for the first supported metric when the adapter can. */\n\tseries?: boolean\n}\n\n/**\n * Resolve a document's analytics for one display field: look up the runtime, resolve\n * the bound path, capability-gate the requested metrics against the active adapter,\n * then read through the surfacing engine. Returns a discriminated status so the\n * rendering component can show the right empty state without throwing.\n *\n * A metric the adapter does not support is dropped (with one warning per field\n * render), not fatal; `unavailable` is returned only when no requested metric\n * survives or the adapter cannot query per page at all.\n */\nexport const readForField = async (args: ReadForFieldArgs): Promise<FieldReadResult> => {\n\tconst { req, collectionSlug, data, metrics, timeframe, range, adapterId, now } = args\n\tlet dateRange = range ?? resolveTimeframe(timeframe, now)\n\tconst empty = { metrics: {}, supportedMetrics: [], droppedMetrics: [] }\n\tconst runtime = getRuntime(req.payload)\n\tif (!runtime) {\n\t\treturn {\n\t\t\tstatus: 'not-bound',\n\t\t\tadapterId: adapterId ?? '',\n\t\t\tdateRange,\n\t\t\ttimezone: DEFAULT_TIMEZONE,\n\t\t\t...empty,\n\t\t}\n\t}\n\tconst binding = runtime.bindings[collectionSlug]\n\tif (!binding) {\n\t\treturn {\n\t\t\tstatus: 'not-bound',\n\t\t\tadapterId: adapterId ?? '',\n\t\t\tdateRange,\n\t\t\ttimezone: DEFAULT_TIMEZONE,\n\t\t\t...empty,\n\t\t}\n\t}\n\tconst ctx = await resolveReadContext({ runtime, req, adapterId, scope: args.scope })\n\tif (!ctx.ok) {\n\t\treturn {\n\t\t\tstatus: 'unavailable',\n\t\t\tadapterId: adapterId ?? '',\n\t\t\tdateRange,\n\t\t\ttimezone: DEFAULT_TIMEZONE,\n\t\t\t...empty,\n\t\t}\n\t}\n\tconst tz = await resolveTimezoneFor(runtime, req, ctx.scope)\n\tdateRange = range ?? resolveTimeframe(timeframe, now, tz)\n\tconst adapter: AnalyticsAdapter = ctx.adapter\n\tconst bindingCtx = { req, locale: req.locale ?? undefined }\n\tlet path: string | null\n\ttry {\n\t\tpath = await resolvePathCached(binding, data, bindingCtx)\n\t} catch {\n\t\tpath = null\n\t}\n\tif (!path) {\n\t\treturn { status: 'no-path', adapterId: adapter.id, dateRange, timezone: tz, ...empty }\n\t}\n\tif (!adapter.isConfigured()) {\n\t\treturn { status: 'not-configured', adapterId: adapter.id, dateRange, timezone: tz, ...empty }\n\t}\n\tconst supportedMetrics = metrics.filter((m) => adapter.capabilities.metrics.has(m))\n\tconst droppedMetrics = metrics.filter((m) => !adapter.capabilities.metrics.has(m))\n\tif (droppedMetrics.length > 0) {\n\t\treq.payload.logger.warn(\n\t\t\t`analytics: adapter \"${adapter.id}\" does not support metric(s) ${droppedMetrics.join(', ')}; dropped from the \"${collectionSlug}\" display field`\n\t\t)\n\t}\n\tif (\n\t\tsupportedMetrics.length === 0 ||\n\t\t!satisfiesCapabilities(adapter.capabilities, { metrics: supportedMetrics, perPageQuery: true })\n\t) {\n\t\treturn {\n\t\t\tstatus: 'unavailable',\n\t\t\tadapterId: adapter.id,\n\t\t\tdateRange,\n\t\t\ttimezone: tz,\n\t\t\tmetrics: {},\n\t\t\tsupportedMetrics: [],\n\t\t\tdroppedMetrics: metrics,\n\t\t}\n\t}\n\tconst hostname = await resolveHostname(binding, data, bindingCtx)\n\tconst base = { path, hostname, timezone: tz, scope: ctx.queryScope }\n\tconst comparisonRange =\n\t\targs.compare && runtime.comparison && adapter.capabilities.comparison\n\t\t\t? (previousWindow(dateRange, tz) ?? undefined)\n\t\t\t: undefined\n\tconst wantsSeries = args.series && supportsGranularity(adapter.capabilities, 'day')\n\tconst [result, previous, seriesResult] = await Promise.all([\n\t\truntime.engine.read(adapter, { ...base, metrics: supportedMetrics, dateRange }),\n\t\tcomparisonRange\n\t\t\t? runtime.engine.read(adapter, {\n\t\t\t\t\t...base,\n\t\t\t\t\tmetrics: supportedMetrics,\n\t\t\t\t\tdateRange: comparisonRange,\n\t\t\t\t})\n\t\t\t: undefined,\n\t\twantsSeries\n\t\t\t? runtime.engine.read(adapter, {\n\t\t\t\t\t...base,\n\t\t\t\t\tmetrics: [supportedMetrics[0] as MetricKey],\n\t\t\t\t\tdateRange,\n\t\t\t\t\tgranularity: 'day',\n\t\t\t\t})\n\t\t\t: undefined,\n\t])\n\treturn {\n\t\tstatus: 'ok',\n\t\tadapterId: adapter.id,\n\t\tdateRange,\n\t\ttimezone: tz,\n\t\tmetrics: result.totals ?? {},\n\t\tsupportedMetrics,\n\t\tdroppedMetrics,\n\t\tpreviousMetrics: previous ? (previous.totals ?? {}) : undefined,\n\t\tcomparisonRange,\n\t\tpoints: seriesResult\n\t\t\t? fillDailySeries({\n\t\t\t\t\trows: seriesResult.rows,\n\t\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ACN,QAAQ;EACR,WAAW,QAAQ;EACnB;EACA,UAAU;EACV,SAAS,OAAO,UAAU,CAAC;EAC3B;EACA;EACA,iBAAiB,WAAY,SAAS,UAAU,CAAC,IAAK,KAAA;EACtD;EACA,QAAQ,eACL,gBAAgB;GAChB,MAAM,aAAa;GACnB;GACA,QAAQ,iBAAiB;GACzB;EACD,CAAC,IACA,KAAA;CACJ;AACD"}
|
|
1
|
+
{"version":3,"file":"readForDocument.js","names":[],"sources":["../../src/fields/readForDocument.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { resolveHostname, resolvePathCached } from '../binding/resolvePath'\nimport type { BindingDoc } from '../binding/types'\nimport { comparisonOf, satisfiesCapabilities } from '../core/capabilities'\nimport type { AnalyticsAdapter, DateRange, MetricKey } from '../core/contract'\nimport { supportsGranularity } from '../core/granularity'\nimport { resolveReadContext } from '../core/scopedRead'\nimport { goalSlugsFor } from '../plugin/goalHint'\nimport { getRuntime, resolveTimezoneFor } from '../plugin/runtime'\nimport { resolveTimeframe, type TimeframePreset } from '../timeframe/presets'\nimport { DEFAULT_TIMEZONE } from '../timeframe/tz'\nimport { previousWindow, withinLookback } from '../widgets/comparison'\nimport { fillDailySeries, type SeriesPoint } from '../widgets/readForWidgetSeries'\n\nexport type FieldReadStatus = 'ok' | 'no-path' | 'not-bound' | 'not-configured' | 'unavailable'\n\nexport interface FieldReadResult {\n\tstatus: FieldReadStatus\n\tadapterId: string\n\tdateRange: DateRange\n\t/** The reporting timezone the read resolved in; the trend axis buckets in it. */\n\ttimezone: string\n\tmetrics: Partial<Record<MetricKey, number>>\n\t/** Requested metrics the adapter supports, in request order; the set actually read. */\n\tsupportedMetrics: MetricKey[]\n\t/** Requested metrics the adapter cannot serve, dropped from the read. */\n\tdroppedMetrics: MetricKey[]\n\t/** Previous-window totals, present only when comparison was requested and supported. */\n\tpreviousMetrics?: Partial<Record<MetricKey, number>>\n\t/** The previous comparable window, present only when comparison ran. */\n\tcomparisonRange?: DateRange\n\t/** Per-day series for the first supported metric, present only when requested. */\n\tpoints?: SeriesPoint[]\n}\n\nexport interface ReadForFieldArgs {\n\treq: PayloadRequest\n\tcollectionSlug: string\n\tdata: BindingDoc\n\tmetrics: MetricKey[]\n\ttimeframe: TimeframePreset\n\t/** Overrides the preset window (custom range). */\n\trange?: DateRange\n\tadapterId?: string\n\tnow: Date\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\t/** Also read the previous comparable window when the adapter supports comparison. */\n\tcompare?: boolean\n\t/** Also read a daily series for the first supported metric when the adapter can. */\n\tseries?: boolean\n}\n\n/**\n * Resolve a document's analytics for one display field: look up the runtime, resolve\n * the bound path, capability-gate the requested metrics against the active adapter,\n * then read through the surfacing engine. Returns a discriminated status so the\n * rendering component can show the right empty state without throwing.\n *\n * A metric the adapter does not support is dropped (with one warning per field\n * render), not fatal; `unavailable` is returned only when no requested metric\n * survives or the adapter cannot query per page at all.\n */\nexport const readForField = async (args: ReadForFieldArgs): Promise<FieldReadResult> => {\n\tconst { req, collectionSlug, data, metrics, timeframe, range, adapterId, now } = args\n\tlet dateRange = range ?? resolveTimeframe(timeframe, now)\n\tconst empty = { metrics: {}, supportedMetrics: [], droppedMetrics: [] }\n\tconst runtime = getRuntime(req.payload)\n\tif (!runtime) {\n\t\treturn {\n\t\t\tstatus: 'not-bound',\n\t\t\tadapterId: adapterId ?? '',\n\t\t\tdateRange,\n\t\t\ttimezone: args.timezone ?? DEFAULT_TIMEZONE,\n\t\t\t...empty,\n\t\t}\n\t}\n\tconst binding = runtime.bindings[collectionSlug]\n\tif (!binding) {\n\t\treturn {\n\t\t\tstatus: 'not-bound',\n\t\t\tadapterId: adapterId ?? '',\n\t\t\tdateRange,\n\t\t\ttimezone: args.timezone ?? DEFAULT_TIMEZONE,\n\t\t\t...empty,\n\t\t}\n\t}\n\tconst ctx = await resolveReadContext({ runtime, req, adapterId, scope: args.scope })\n\tif (!ctx.ok) {\n\t\treturn {\n\t\t\tstatus: 'unavailable',\n\t\t\tadapterId: adapterId ?? '',\n\t\t\tdateRange,\n\t\t\ttimezone: args.timezone ?? DEFAULT_TIMEZONE,\n\t\t\t...empty,\n\t\t}\n\t}\n\tconst tz = args.timezone ?? (await resolveTimezoneFor(runtime, req, ctx.scope))\n\tdateRange = range ?? resolveTimeframe(timeframe, now, tz)\n\tconst adapter: AnalyticsAdapter = ctx.adapter\n\tconst bindingCtx = { req, locale: req.locale ?? undefined }\n\tlet path: string | null\n\ttry {\n\t\tpath = await resolvePathCached(binding, data, bindingCtx)\n\t} catch {\n\t\tpath = null\n\t}\n\tif (!path) {\n\t\treturn { status: 'no-path', adapterId: adapter.id, dateRange, timezone: tz, ...empty }\n\t}\n\tif (!adapter.isConfigured()) {\n\t\treturn { status: 'not-configured', adapterId: adapter.id, dateRange, timezone: tz, ...empty }\n\t}\n\tconst supportedMetrics = metrics.filter((m) => adapter.capabilities.metrics.has(m))\n\tconst droppedMetrics = metrics.filter((m) => !adapter.capabilities.metrics.has(m))\n\tif (droppedMetrics.length > 0) {\n\t\treq.payload.logger.warn(\n\t\t\t`analytics: adapter \"${adapter.id}\" does not support metric(s) ${droppedMetrics.join(', ')}; dropped from the \"${collectionSlug}\" display field`\n\t\t)\n\t}\n\tif (\n\t\tsupportedMetrics.length === 0 ||\n\t\t!satisfiesCapabilities(adapter.capabilities, { metrics: supportedMetrics, perPageQuery: true })\n\t) {\n\t\treturn {\n\t\t\tstatus: 'unavailable',\n\t\t\tadapterId: adapter.id,\n\t\t\tdateRange,\n\t\t\ttimezone: tz,\n\t\t\tmetrics: {},\n\t\t\tsupportedMetrics: [],\n\t\t\tdroppedMetrics: metrics,\n\t\t}\n\t}\n\tconst hostname = await resolveHostname(binding, data, bindingCtx)\n\tconst goalSlugs = await goalSlugsFor({\n\t\truntime,\n\t\treq,\n\t\tscope: ctx.scope,\n\t\tmetrics: supportedMetrics,\n\t})\n\tconst base = {\n\t\tpath,\n\t\thostname,\n\t\ttimezone: tz,\n\t\tscope: ctx.queryScope,\n\t\t...(goalSlugs === undefined ? {} : { goalSlugs }),\n\t}\n\tconst previousRange =\n\t\targs.compare && runtime.comparison && comparisonOf(adapter.capabilities)\n\t\t\t? previousWindow(dateRange, tz)\n\t\t\t: null\n\tconst comparisonRange =\n\t\tpreviousRange &&\n\t\twithinLookback(previousRange, adapter.capabilities.maxLookbackDays, { tz, now })\n\t\t\t? previousRange\n\t\t\t: undefined\n\tconst wantsSeries = args.series && supportsGranularity(adapter.capabilities, 'day')\n\tconst [result, previous, seriesResult] = await Promise.all([\n\t\truntime.engine.read(adapter, { ...base, metrics: supportedMetrics, dateRange }),\n\t\tcomparisonRange\n\t\t\t? runtime.engine.read(adapter, {\n\t\t\t\t\t...base,\n\t\t\t\t\tmetrics: supportedMetrics,\n\t\t\t\t\tdateRange: comparisonRange,\n\t\t\t\t})\n\t\t\t: undefined,\n\t\twantsSeries\n\t\t\t? runtime.engine.read(adapter, {\n\t\t\t\t\t...base,\n\t\t\t\t\tmetrics: [supportedMetrics[0] as MetricKey],\n\t\t\t\t\tdateRange,\n\t\t\t\t\tgranularity: 'day',\n\t\t\t\t})\n\t\t\t: undefined,\n\t])\n\treturn {\n\t\tstatus: 'ok',\n\t\tadapterId: adapter.id,\n\t\tdateRange,\n\t\ttimezone: tz,\n\t\tmetrics: result.totals ?? {},\n\t\tsupportedMetrics,\n\t\tdroppedMetrics,\n\t\tpreviousMetrics: previous ? (previous.totals ?? {}) : undefined,\n\t\tcomparisonRange,\n\t\tpoints: seriesResult\n\t\t\t? fillDailySeries({\n\t\t\t\t\trows: seriesResult.rows,\n\t\t\t\t\tdateRange,\n\t\t\t\t\tmetric: supportedMetrics[0] as MetricKey,\n\t\t\t\t\ttz,\n\t\t\t\t})\n\t\t\t: undefined,\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;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,OAAO,KAAK,SAAS;GAC7B,GAAG;GACH,SAAS,CAAC,iBAAiB,EAAe;GAC1C;GACA,aAAa;EACd,CAAC,IACA,KAAA;CACJ,CAAC;CACD,OAAO;EACN,QAAQ;EACR,WAAW,QAAQ;EACnB;EACA,UAAU;EACV,SAAS,OAAO,UAAU,CAAC;EAC3B;EACA;EACA,iBAAiB,WAAY,SAAS,UAAU,CAAC,IAAK,KAAA;EACtD;EACA,QAAQ,eACL,gBAAgB;GAChB,MAAM,aAAa;GACnB;GACA,QAAQ,iBAAiB;GACzB;EACD,CAAC,IACA,KAAA;CACJ;AACD"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { keys } from "../translations/keys.js";
|
|
3
|
+
import { useTranslation as useTranslation$1 } from "../translations/useTranslation.js";
|
|
4
|
+
import { useAnalyticsGoals } from "./useAnalyticsGoals.js";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { FieldDescription, SelectInput, useConfig, useField, withCondition } from "@payloadcms/ui";
|
|
8
|
+
import { mergeFieldStyles } from "@payloadcms/ui/shared";
|
|
9
|
+
//#region src/goals/GoalSelectField.tsx
|
|
10
|
+
/** Admin placeholders are a plain string or a locale map; SelectInput wants one string. */
|
|
11
|
+
const resolvePlaceholder = (placeholder, locale) => typeof placeholder === "string" ? placeholder : placeholder?.[locale] ?? placeholder?.en;
|
|
12
|
+
/**
|
|
13
|
+
* Goal picker for a {@link goalField}: lists the config goals merged with the goals
|
|
14
|
+
* collection for the caller's scope and stores the picked goal's slug. While the fetch is
|
|
15
|
+
* in flight the picker renders with no options rather than a notice, so a slow answer
|
|
16
|
+
* never reads as "this install has no goals". Once it settles, an empty scope and a failed
|
|
17
|
+
* fetch each say so below the input, next to the field's own description rather than in
|
|
18
|
+
* place of it, and the picker stays editable either way so a stored slug can still be
|
|
19
|
+
* cleared.
|
|
20
|
+
*/
|
|
21
|
+
const GoalSelectFieldComponent = (props) => {
|
|
22
|
+
const { field, path: pathFromProps, readOnly } = props;
|
|
23
|
+
const { i18n, t } = useTranslation$1();
|
|
24
|
+
const { collection, error, goals } = useAnalyticsGoals();
|
|
25
|
+
const { customComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {}, disabled, path, setValue, showError, value } = useField({ potentiallyStalePath: pathFromProps });
|
|
26
|
+
const { config: { routes: { admin: adminRoute } } } = useConfig();
|
|
27
|
+
const options = useMemo(() => (goals ?? []).map((goal) => ({
|
|
28
|
+
label: goal.name,
|
|
29
|
+
value: goal.slug
|
|
30
|
+
})), [goals]);
|
|
31
|
+
const style = useMemo(() => mergeFieldStyles(field), [field]);
|
|
32
|
+
const empty = goals !== null && goals.length === 0;
|
|
33
|
+
const manageHref = collection ? `${adminRoute}/collections/${collection.slug}` : null;
|
|
34
|
+
const notice = empty ? /* @__PURE__ */ jsxs("div", {
|
|
35
|
+
className: "field-description",
|
|
36
|
+
children: [t(keys.fieldGoalEmpty), manageHref ? /* @__PURE__ */ jsxs(Fragment, { children: [" ", /* @__PURE__ */ jsx("a", {
|
|
37
|
+
href: manageHref,
|
|
38
|
+
children: t(keys.fieldGoalManage)
|
|
39
|
+
})] }) : null]
|
|
40
|
+
}) : error ? /* @__PURE__ */ jsx("div", {
|
|
41
|
+
className: "field-description",
|
|
42
|
+
children: t(keys.fieldGoalError)
|
|
43
|
+
}) : null;
|
|
44
|
+
return /* @__PURE__ */ jsx(SelectInput, {
|
|
45
|
+
AfterInput,
|
|
46
|
+
BeforeInput,
|
|
47
|
+
className: field.admin?.className,
|
|
48
|
+
Description: notice ? /* @__PURE__ */ jsxs(Fragment, { children: [Description ?? /* @__PURE__ */ jsx(FieldDescription, {
|
|
49
|
+
description: field.admin?.description,
|
|
50
|
+
path
|
|
51
|
+
}), notice] }) : Description,
|
|
52
|
+
description: field.admin?.description,
|
|
53
|
+
Error: ErrorComponent,
|
|
54
|
+
isClearable: !field.required,
|
|
55
|
+
Label,
|
|
56
|
+
label: field.label,
|
|
57
|
+
localized: field.localized,
|
|
58
|
+
name: field.name,
|
|
59
|
+
onChange: (selected) => {
|
|
60
|
+
const option = Array.isArray(selected) ? selected[0] : selected;
|
|
61
|
+
setValue(option?.value ? String(option.value) : null);
|
|
62
|
+
},
|
|
63
|
+
options,
|
|
64
|
+
path,
|
|
65
|
+
placeholder: resolvePlaceholder(field.admin?.placeholder, i18n.language),
|
|
66
|
+
readOnly: readOnly || disabled || field.admin?.readOnly,
|
|
67
|
+
required: field.required,
|
|
68
|
+
showError,
|
|
69
|
+
style,
|
|
70
|
+
value
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
const GoalSelectField = withCondition(GoalSelectFieldComponent);
|
|
74
|
+
//#endregion
|
|
75
|
+
export { GoalSelectField };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=GoalSelectField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoalSelectField.js","names":["useTranslation"],"sources":["../../src/goals/GoalSelectField.tsx"],"sourcesContent":["'use client'\n\nimport {\n\tFieldDescription,\n\ttype ReactSelectOption,\n\tSelectInput,\n\tuseConfig,\n\tuseField,\n\twithCondition,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps } from 'payload'\nimport { useMemo } from 'react'\nimport { keys } from '../translations/keys'\nimport { useTranslation } from '../translations/useTranslation'\nimport { useAnalyticsGoals } from './useAnalyticsGoals'\n\n/** Admin placeholders are a plain string or a locale map; SelectInput wants one string. */\nconst resolvePlaceholder = (\n\tplaceholder: Record<string, string> | string | undefined,\n\tlocale: string\n): string | undefined =>\n\ttypeof placeholder === 'string' ? placeholder : (placeholder?.[locale] ?? placeholder?.en)\n\n/**\n * Goal picker for a {@link goalField}: lists the config goals merged with the goals\n * collection for the caller's scope and stores the picked goal's slug. While the fetch is\n * in flight the picker renders with no options rather than a notice, so a slow answer\n * never reads as \"this install has no goals\". Once it settles, an empty scope and a failed\n * fetch each say so below the input, next to the field's own description rather than in\n * place of it, and the picker stays editable either way so a stored slug can still be\n * cleared.\n */\nconst GoalSelectFieldComponent = (props: TextFieldClientProps) => {\n\tconst { field, path: pathFromProps, readOnly } = props\n\tconst { i18n, t } = useTranslation()\n\tconst { collection, error, goals } = useAnalyticsGoals()\n\tconst {\n\t\tcustomComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {},\n\t\tdisabled,\n\t\tpath,\n\t\tsetValue,\n\t\tshowError,\n\t\tvalue,\n\t} = useField<string>({ potentiallyStalePath: pathFromProps })\n\tconst {\n\t\tconfig: {\n\t\t\troutes: { admin: adminRoute },\n\t\t},\n\t} = useConfig()\n\n\tconst options = useMemo(\n\t\t() => (goals ?? []).map((goal) => ({ label: goal.name, value: goal.slug })),\n\t\t[goals]\n\t)\n\tconst style = useMemo(() => mergeFieldStyles(field), [field])\n\n\tconst empty = goals !== null && goals.length === 0\n\tconst manageHref = collection ? `${adminRoute}/collections/${collection.slug}` : null\n\tconst notice = empty ? (\n\t\t<div className=\"field-description\">\n\t\t\t{t(keys.fieldGoalEmpty)}\n\t\t\t{manageHref ? (\n\t\t\t\t<>\n\t\t\t\t\t{' '}\n\t\t\t\t\t<a href={manageHref}>{t(keys.fieldGoalManage)}</a>\n\t\t\t\t</>\n\t\t\t) : null}\n\t\t</div>\n\t) : error ? (\n\t\t<div className=\"field-description\">{t(keys.fieldGoalError)}</div>\n\t) : null\n\n\treturn (\n\t\t<SelectInput\n\t\t\tAfterInput={AfterInput}\n\t\t\tBeforeInput={BeforeInput}\n\t\t\tclassName={field.admin?.className}\n\t\t\tDescription={\n\t\t\t\tnotice ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{Description ?? <FieldDescription description={field.admin?.description} path={path} />}\n\t\t\t\t\t\t{notice}\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\tDescription\n\t\t\t\t)\n\t\t\t}\n\t\t\tdescription={field.admin?.description}\n\t\t\tError={ErrorComponent}\n\t\t\tisClearable={!field.required}\n\t\t\tLabel={Label}\n\t\t\tlabel={field.label}\n\t\t\tlocalized={field.localized}\n\t\t\tname={field.name}\n\t\t\tonChange={(selected: ReactSelectOption | ReactSelectOption[]) => {\n\t\t\t\tconst option = Array.isArray(selected) ? selected[0] : selected\n\t\t\t\tsetValue(option?.value ? String(option.value) : null)\n\t\t\t}}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\tplaceholder={resolvePlaceholder(field.admin?.placeholder, i18n.language)}\n\t\t\treadOnly={readOnly || disabled || field.admin?.readOnly}\n\t\t\trequired={field.required}\n\t\t\tshowError={showError}\n\t\t\tstyle={style}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n\nexport const GoalSelectField = withCondition(GoalSelectFieldComponent)\n"],"mappings":";;;;;;;;;;AAkBA,MAAM,sBACL,aACA,WAEA,OAAO,gBAAgB,WAAW,cAAe,cAAc,WAAW,aAAa;;;;;;;;;;AAWxF,MAAM,4BAA4B,UAAgC;CACjE,MAAM,EAAE,OAAO,MAAM,eAAe,aAAa;CACjD,MAAM,EAAE,MAAM,MAAMA,iBAAe;CACnC,MAAM,EAAE,YAAY,OAAO,UAAU,kBAAkB;CACvD,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,MACA,UACA,WACA,UACG,SAAiB,EAAE,sBAAsB,cAAc,CAAC;CAC5D,MAAM,EACL,QAAQ,EACP,QAAQ,EAAE,OAAO,mBAEf,UAAU;CAEd,MAAM,UAAU,eACR,SAAS,CAAC,GAAG,KAAK,UAAU;EAAE,OAAO,KAAK;EAAM,OAAO,KAAK;CAAK,EAAE,GAC1E,CAAC,KAAK,CACP;CACA,MAAM,QAAQ,cAAc,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;CAE5D,MAAM,QAAQ,UAAU,QAAQ,MAAM,WAAW;CACjD,MAAM,aAAa,aAAa,GAAG,WAAW,eAAe,WAAW,SAAS;CACjF,MAAM,SAAS,QACd,qBAAC,OAAD;EAAK,WAAU;YAAf,CACE,EAAE,KAAK,cAAc,GACrB,aACA,qBAAA,UAAA,EAAA,UAAA,CACE,KACD,oBAAC,KAAD;GAAG,MAAM;aAAa,EAAE,KAAK,eAAe;EAAK,CAAA,CAChD,EAAA,CAAA,IACC,IACA;MACF,QACH,oBAAC,OAAD;EAAK,WAAU;YAAqB,EAAE,KAAK,cAAc;CAAO,CAAA,IAC7D;CAEJ,OACC,oBAAC,aAAD;EACa;EACC;EACb,WAAW,MAAM,OAAO;EACxB,aACC,SACC,qBAAA,UAAA,EAAA,UAAA,CACE,eAAe,oBAAC,kBAAD;GAAkB,aAAa,MAAM,OAAO;GAAmB;EAAO,CAAA,GACrF,MACA,EAAA,CAAA,IAEF;EAGF,aAAa,MAAM,OAAO;EAC1B,OAAO;EACP,aAAa,CAAC,MAAM;EACb;EACP,OAAO,MAAM;EACb,WAAW,MAAM;EACjB,MAAM,MAAM;EACZ,WAAW,aAAsD;GAChE,MAAM,SAAS,MAAM,QAAQ,QAAQ,IAAI,SAAS,KAAK;GACvD,SAAS,QAAQ,QAAQ,OAAO,OAAO,KAAK,IAAI,IAAI;EACrD;EACS;EACH;EACN,aAAa,mBAAmB,MAAM,OAAO,aAAa,KAAK,QAAQ;EACvE,UAAU,YAAY,YAAY,MAAM,OAAO;EAC/C,UAAU,MAAM;EACL;EACJ;EACA;CACP,CAAA;AAEH;AAEA,MAAa,kBAAkB,cAAc,wBAAwB"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { docScope } from "../plugin/scopeChange.js";
|
|
2
|
+
import { providerCreateAccess, providerRowAccess } from "../providers/access.js";
|
|
3
|
+
import { stampScope } from "../providers/stampScope.js";
|
|
4
|
+
import { keys } from "../translations/keys.js";
|
|
5
|
+
import { asTranslate, labelForKey } from "../translations/server.js";
|
|
6
|
+
import { validateCurrency } from "./currency.js";
|
|
7
|
+
import { GOAL_SLUG_PATTERN } from "./types.js";
|
|
8
|
+
import { goalScopeWhere } from "./resolver.js";
|
|
9
|
+
import { ValidationError } from "payload";
|
|
10
|
+
//#region src/goals/collection.ts
|
|
11
|
+
const GOALS_SLUG = "analytics-goals";
|
|
12
|
+
const validateSlug = (value, { req }) => typeof value === "string" && GOAL_SLUG_PATTERN.test(value) ? true : asTranslate(req.t)(keys.goalErrorSlug);
|
|
13
|
+
const asScope = (value) => value === null || value === void 0 || value === "" ? null : String(value);
|
|
14
|
+
/**
|
|
15
|
+
* The scope the stamp will land the write in, resolved with stampScope's precedence. Only a
|
|
16
|
+
* platform admin's declared scope is honoured: taking an ordinary tenant's body scope on
|
|
17
|
+
* trust would turn "slug taken" into an oracle for what another tenant owns, since the stamp
|
|
18
|
+
* refuses the write either way.
|
|
19
|
+
*/
|
|
20
|
+
const writeScope = async (args, write) => {
|
|
21
|
+
const { data, originalDoc, req } = write;
|
|
22
|
+
try {
|
|
23
|
+
if (await args.platformRead({ req })) return asScope(data?.[args.scopeField]) ?? asScope(originalDoc?.[args.scopeField]);
|
|
24
|
+
return asScope(await args.resolveScope(req));
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Slugs stay editable, so uniqueness is checked on every write: the same slug may exist once
|
|
31
|
+
* per scope, and the tracker and the rollups key on it. The compound index backs this up
|
|
32
|
+
* where it can, but it cannot cover install-wide rows on Postgres or a host-owned scope field.
|
|
33
|
+
*/
|
|
34
|
+
const uniqueSlug = (args) => {
|
|
35
|
+
return async ({ data, originalDoc, req }) => {
|
|
36
|
+
const slug = data?.slug;
|
|
37
|
+
if (typeof slug !== "string" || slug === "") return data;
|
|
38
|
+
const where = [{ slug: { equals: slug } }];
|
|
39
|
+
if (args.scoped) where.push(goalScopeWhere(args.scopeField, await writeScope(args, {
|
|
40
|
+
data,
|
|
41
|
+
originalDoc,
|
|
42
|
+
req
|
|
43
|
+
})));
|
|
44
|
+
const id = originalDoc?.id;
|
|
45
|
+
if (id !== void 0 && id !== null) where.push({ id: { not_equals: id } });
|
|
46
|
+
const { docs } = await req.payload.find({
|
|
47
|
+
collection: args.slug,
|
|
48
|
+
where: { and: where },
|
|
49
|
+
limit: 1,
|
|
50
|
+
pagination: false,
|
|
51
|
+
depth: 0,
|
|
52
|
+
overrideAccess: true,
|
|
53
|
+
req
|
|
54
|
+
});
|
|
55
|
+
if (docs.length > 0) throw new ValidationError({
|
|
56
|
+
collection: args.slug,
|
|
57
|
+
errors: [{
|
|
58
|
+
label: labelForKey(keys.goalFieldSlug),
|
|
59
|
+
message: asTranslate(req.t)(keys.goalErrorSlugTaken),
|
|
60
|
+
path: "slug"
|
|
61
|
+
}]
|
|
62
|
+
});
|
|
63
|
+
return data;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Database-level backstop for the hook, and only where the plugin owns the scope field: a
|
|
68
|
+
* host-owned one (a tenant plugin's relationship) is not ours to index. Postgres treats a
|
|
69
|
+
* NULL scope as distinct from every other, so install-wide rows stay hook-guarded.
|
|
70
|
+
*/
|
|
71
|
+
const uniqueSlugIndex = (args) => {
|
|
72
|
+
if (!args.scoped) return {
|
|
73
|
+
fields: ["slug"],
|
|
74
|
+
unique: true
|
|
75
|
+
};
|
|
76
|
+
return args.scopeField === "scope" ? {
|
|
77
|
+
fields: ["slug", "scope"],
|
|
78
|
+
unique: true
|
|
79
|
+
} : void 0;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* The plugin's own scope field, and only when `scopeField` still names it: a host-owned
|
|
83
|
+
* field (a tenant plugin's relationship) is the host's to register, and shadowing it with a
|
|
84
|
+
* hidden text field of another name would store the scope twice.
|
|
85
|
+
*/
|
|
86
|
+
const scopeField = (args) => args.scopeField === "scope" ? [{
|
|
87
|
+
name: "scope",
|
|
88
|
+
type: "text",
|
|
89
|
+
index: true,
|
|
90
|
+
label: labelForKey(keys.providerFieldScope),
|
|
91
|
+
admin: { hidden: true }
|
|
92
|
+
}] : [];
|
|
93
|
+
const matchField = () => ({
|
|
94
|
+
name: "match",
|
|
95
|
+
type: "group",
|
|
96
|
+
label: labelForKey(keys.goalFieldMatch),
|
|
97
|
+
fields: [
|
|
98
|
+
{
|
|
99
|
+
name: "kind",
|
|
100
|
+
type: "select",
|
|
101
|
+
required: true,
|
|
102
|
+
defaultValue: "goal",
|
|
103
|
+
label: labelForKey(keys.goalFieldMatchKind),
|
|
104
|
+
options: [
|
|
105
|
+
{
|
|
106
|
+
label: labelForKey(keys.goalKindGoal),
|
|
107
|
+
value: "goal"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
label: labelForKey(keys.goalKindEvent),
|
|
111
|
+
value: "event"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
label: labelForKey(keys.goalKindPath),
|
|
115
|
+
value: "path"
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "name",
|
|
121
|
+
type: "text",
|
|
122
|
+
label: labelForKey(keys.goalFieldMatchEventName),
|
|
123
|
+
admin: { condition: (_data, siblingData) => siblingData?.kind === "event" }
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: "pattern",
|
|
127
|
+
type: "text",
|
|
128
|
+
label: labelForKey(keys.goalFieldMatchPathPattern),
|
|
129
|
+
admin: {
|
|
130
|
+
condition: (_data, siblingData) => siblingData?.kind === "path",
|
|
131
|
+
description: labelForKey(keys.goalFieldMatchPathPatternHelp)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
});
|
|
136
|
+
const valueField = () => ({
|
|
137
|
+
name: "value",
|
|
138
|
+
type: "group",
|
|
139
|
+
label: labelForKey(keys.goalFieldValue),
|
|
140
|
+
fields: [{
|
|
141
|
+
type: "row",
|
|
142
|
+
fields: [{
|
|
143
|
+
name: "fixed",
|
|
144
|
+
type: "number",
|
|
145
|
+
min: 0,
|
|
146
|
+
label: labelForKey(keys.goalFieldValueFixed),
|
|
147
|
+
admin: { width: "50%" }
|
|
148
|
+
}, {
|
|
149
|
+
name: "prop",
|
|
150
|
+
type: "text",
|
|
151
|
+
label: labelForKey(keys.goalFieldValueProp),
|
|
152
|
+
admin: {
|
|
153
|
+
width: "50%",
|
|
154
|
+
description: labelForKey(keys.goalFieldValuePropHelp)
|
|
155
|
+
}
|
|
156
|
+
}]
|
|
157
|
+
}]
|
|
158
|
+
});
|
|
159
|
+
/**
|
|
160
|
+
* The editor-managed goals collection: one document per goal (and per scope in scoped
|
|
161
|
+
* installs), merged over the config goals by the resolver. Admin-only by default; `access`
|
|
162
|
+
* entries override individual operations and `overrides` reshapes the whole config last,
|
|
163
|
+
* so slugs, labels, fields, and access all stay overridable.
|
|
164
|
+
*/
|
|
165
|
+
const buildGoalsCollection = (args) => {
|
|
166
|
+
const unique = uniqueSlugIndex(args);
|
|
167
|
+
const collection = {
|
|
168
|
+
slug: args.slug,
|
|
169
|
+
...unique ? { indexes: [unique] } : {},
|
|
170
|
+
labels: {
|
|
171
|
+
singular: labelForKey(keys.goalsCollectionSingular),
|
|
172
|
+
plural: labelForKey(keys.goalsCollectionPlural)
|
|
173
|
+
},
|
|
174
|
+
disableDuplicate: true,
|
|
175
|
+
admin: {
|
|
176
|
+
useAsTitle: "name",
|
|
177
|
+
defaultColumns: [
|
|
178
|
+
"name",
|
|
179
|
+
"slug",
|
|
180
|
+
"match.kind",
|
|
181
|
+
"enabled"
|
|
182
|
+
],
|
|
183
|
+
group: "Analytics"
|
|
184
|
+
},
|
|
185
|
+
access: {
|
|
186
|
+
read: providerRowAccess(args),
|
|
187
|
+
create: providerCreateAccess(args),
|
|
188
|
+
update: providerRowAccess(args),
|
|
189
|
+
delete: providerRowAccess(args),
|
|
190
|
+
...args.access
|
|
191
|
+
},
|
|
192
|
+
hooks: {
|
|
193
|
+
beforeValidate: [uniqueSlug(args)],
|
|
194
|
+
beforeChange: [stampScope(args)],
|
|
195
|
+
afterChange: [async ({ doc, operation, previousDoc }) => {
|
|
196
|
+
await args.onChange({
|
|
197
|
+
scope: docScope(doc, args.scopeField),
|
|
198
|
+
...operation === "update" ? { previousScope: docScope(previousDoc, args.scopeField) } : {}
|
|
199
|
+
});
|
|
200
|
+
return doc;
|
|
201
|
+
}],
|
|
202
|
+
afterDelete: [async ({ doc }) => {
|
|
203
|
+
await args.onChange({ scope: docScope(doc, args.scopeField) });
|
|
204
|
+
return doc;
|
|
205
|
+
}]
|
|
206
|
+
},
|
|
207
|
+
fields: [
|
|
208
|
+
{
|
|
209
|
+
name: "name",
|
|
210
|
+
type: "text",
|
|
211
|
+
required: true,
|
|
212
|
+
label: labelForKey(keys.goalFieldName)
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
type: "row",
|
|
216
|
+
fields: [{
|
|
217
|
+
name: "slug",
|
|
218
|
+
type: "text",
|
|
219
|
+
required: true,
|
|
220
|
+
index: unique === void 0,
|
|
221
|
+
label: labelForKey(keys.goalFieldSlug),
|
|
222
|
+
validate: validateSlug,
|
|
223
|
+
admin: {
|
|
224
|
+
width: "50%",
|
|
225
|
+
description: labelForKey(keys.goalFieldSlugHelp)
|
|
226
|
+
}
|
|
227
|
+
}, {
|
|
228
|
+
name: "enabled",
|
|
229
|
+
type: "checkbox",
|
|
230
|
+
defaultValue: true,
|
|
231
|
+
label: labelForKey(keys.goalFieldEnabled),
|
|
232
|
+
admin: {
|
|
233
|
+
width: "50%",
|
|
234
|
+
style: { alignSelf: "flex-end" }
|
|
235
|
+
}
|
|
236
|
+
}]
|
|
237
|
+
},
|
|
238
|
+
matchField(),
|
|
239
|
+
valueField(),
|
|
240
|
+
{
|
|
241
|
+
name: "currency",
|
|
242
|
+
type: "text",
|
|
243
|
+
label: labelForKey(keys.goalFieldCurrency),
|
|
244
|
+
validate: validateCurrency
|
|
245
|
+
},
|
|
246
|
+
...scopeField(args)
|
|
247
|
+
]
|
|
248
|
+
};
|
|
249
|
+
return args.overrides ? args.overrides(collection) : collection;
|
|
250
|
+
};
|
|
251
|
+
//#endregion
|
|
252
|
+
export { GOALS_SLUG, buildGoalsCollection };
|
|
253
|
+
|
|
254
|
+
//# sourceMappingURL=collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection.js","names":[],"sources":["../../src/goals/collection.ts"],"sourcesContent":["import type {\n\tCollectionBeforeValidateHook,\n\tCollectionConfig,\n\tCompoundIndex,\n\tField,\n\tPayloadRequest,\n\tTextFieldSingleValidation,\n\tWhere,\n} from 'payload'\nimport { ValidationError } from 'payload'\nimport { docScope, type ScopeChange } from '../plugin/scopeChange'\nimport type { ProviderAccessArgs } from '../providers/access'\nimport { providerCreateAccess, providerRowAccess } from '../providers/access'\nimport { stampScope } from '../providers/stampScope'\nimport { keys } from '../translations/keys'\nimport { asTranslate, labelForKey } from '../translations/server'\nimport { validateCurrency } from './currency'\nimport { goalScopeWhere } from './resolver'\nimport { GOAL_SLUG_PATTERN } from './types'\n\nexport const GOALS_SLUG = 'analytics-goals'\n\nexport interface BuildGoalsCollectionArgs extends ProviderAccessArgs {\n\tslug: string\n\taccess?: Partial<CollectionConfig['access']>\n\toverrides?: (collection: CollectionConfig) => CollectionConfig\n\t/**\n\t * Called after any change or delete with the scopes the write touched, so the merged\n\t * resolver drops its cached goals and the scope's cached reads are retired.\n\t */\n\tonChange: (change: ScopeChange) => void | Promise<void>\n}\n\nconst validateSlug: TextFieldSingleValidation = (value, { req }) =>\n\ttypeof value === 'string' && GOAL_SLUG_PATTERN.test(value)\n\t\t? true\n\t\t: asTranslate(req.t)(keys.goalErrorSlug)\n\nconst asScope = (value: unknown): string | null =>\n\tvalue === null || value === undefined || value === '' ? null : String(value)\n\n/**\n * The scope the stamp will land the write in, resolved with stampScope's precedence. Only a\n * platform admin's declared scope is honoured: taking an ordinary tenant's body scope on\n * trust would turn \"slug taken\" into an oracle for what another tenant owns, since the stamp\n * refuses the write either way.\n */\nconst writeScope = async (\n\targs: BuildGoalsCollectionArgs,\n\twrite: {\n\t\tdata?: Record<string, unknown>\n\t\toriginalDoc?: Record<string, unknown>\n\t\treq: PayloadRequest\n\t}\n): Promise<string | null> => {\n\tconst { data, originalDoc, req } = write\n\ttry {\n\t\tif (await args.platformRead({ req })) {\n\t\t\t// No declared scope means an install-wide goal, not one in whatever scope the\n\t\t\t// admin's own request happens to resolve to.\n\t\t\treturn asScope(data?.[args.scopeField]) ?? asScope(originalDoc?.[args.scopeField])\n\t\t}\n\t\treturn asScope(await args.resolveScope(req))\n\t} catch {\n\t\treturn null\n\t}\n}\n\n/**\n * Slugs stay editable, so uniqueness is checked on every write: the same slug may exist once\n * per scope, and the tracker and the rollups key on it. The compound index backs this up\n * where it can, but it cannot cover install-wide rows on Postgres or a host-owned scope field.\n */\nconst uniqueSlug = (args: BuildGoalsCollectionArgs): CollectionBeforeValidateHook => {\n\treturn async ({ data, originalDoc, req }) => {\n\t\tconst slug = data?.slug\n\t\tif (typeof slug !== 'string' || slug === '') {\n\t\t\treturn data\n\t\t}\n\t\tconst where: Where[] = [{ slug: { equals: slug } }]\n\t\tif (args.scoped) {\n\t\t\twhere.push(\n\t\t\t\tgoalScopeWhere(args.scopeField, await writeScope(args, { data, originalDoc, req }))\n\t\t\t)\n\t\t}\n\t\tconst id = originalDoc?.id\n\t\tif (id !== undefined && id !== null) {\n\t\t\twhere.push({ id: { not_equals: id } })\n\t\t}\n\t\t// pagination:false is load-bearing: a paginated read fires its count and its find in\n\t\t// parallel on one Mongo session, which the write's open transaction refuses.\n\t\tconst { docs } = await req.payload.find({\n\t\t\tcollection: args.slug as never,\n\t\t\twhere: { and: where },\n\t\t\tlimit: 1,\n\t\t\tpagination: false,\n\t\t\tdepth: 0,\n\t\t\toverrideAccess: true,\n\t\t\treq,\n\t\t})\n\t\tif (docs.length > 0) {\n\t\t\tthrow new ValidationError({\n\t\t\t\tcollection: args.slug,\n\t\t\t\terrors: [\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: labelForKey(keys.goalFieldSlug),\n\t\t\t\t\t\tmessage: asTranslate(req.t)(keys.goalErrorSlugTaken),\n\t\t\t\t\t\tpath: 'slug',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t})\n\t\t}\n\t\treturn data\n\t}\n}\n\n/**\n * Database-level backstop for the hook, and only where the plugin owns the scope field: a\n * host-owned one (a tenant plugin's relationship) is not ours to index. Postgres treats a\n * NULL scope as distinct from every other, so install-wide rows stay hook-guarded.\n */\nconst uniqueSlugIndex = (args: BuildGoalsCollectionArgs): CompoundIndex | undefined => {\n\tif (!args.scoped) {\n\t\treturn { fields: ['slug'], unique: true }\n\t}\n\treturn args.scopeField === 'scope' ? { fields: ['slug', 'scope'], unique: true } : undefined\n}\n\n/**\n * The plugin's own scope field, and only when `scopeField` still names it: a host-owned\n * field (a tenant plugin's relationship) is the host's to register, and shadowing it with a\n * hidden text field of another name would store the scope twice.\n */\nconst scopeField = (args: BuildGoalsCollectionArgs): Field[] =>\n\targs.scopeField === 'scope'\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\t// Written by scoped setups; hidden because single-site installs never touch it.\n\t\t\t\t\tname: 'scope',\n\t\t\t\t\ttype: 'text',\n\t\t\t\t\tindex: true,\n\t\t\t\t\tlabel: labelForKey(keys.providerFieldScope),\n\t\t\t\t\tadmin: { hidden: true },\n\t\t\t\t},\n\t\t\t]\n\t\t: []\n\nconst matchField = (): Field => ({\n\tname: 'match',\n\ttype: 'group',\n\tlabel: labelForKey(keys.goalFieldMatch),\n\tfields: [\n\t\t{\n\t\t\tname: 'kind',\n\t\t\ttype: 'select',\n\t\t\trequired: true,\n\t\t\tdefaultValue: 'goal',\n\t\t\tlabel: labelForKey(keys.goalFieldMatchKind),\n\t\t\toptions: [\n\t\t\t\t{ label: labelForKey(keys.goalKindGoal), value: 'goal' },\n\t\t\t\t{ label: labelForKey(keys.goalKindEvent), value: 'event' },\n\t\t\t\t{ label: labelForKey(keys.goalKindPath), value: 'path' },\n\t\t\t],\n\t\t},\n\t\t{\n\t\t\tname: 'name',\n\t\t\ttype: 'text',\n\t\t\tlabel: labelForKey(keys.goalFieldMatchEventName),\n\t\t\tadmin: { condition: (_data, siblingData) => siblingData?.kind === 'event' },\n\t\t},\n\t\t{\n\t\t\tname: 'pattern',\n\t\t\ttype: 'text',\n\t\t\tlabel: labelForKey(keys.goalFieldMatchPathPattern),\n\t\t\tadmin: {\n\t\t\t\tcondition: (_data, siblingData) => siblingData?.kind === 'path',\n\t\t\t\tdescription: labelForKey(keys.goalFieldMatchPathPatternHelp),\n\t\t\t},\n\t\t},\n\t],\n})\n\nconst valueField = (): Field => ({\n\tname: 'value',\n\ttype: 'group',\n\tlabel: labelForKey(keys.goalFieldValue),\n\tfields: [\n\t\t{\n\t\t\ttype: 'row',\n\t\t\tfields: [\n\t\t\t\t{\n\t\t\t\t\tname: 'fixed',\n\t\t\t\t\ttype: 'number',\n\t\t\t\t\tmin: 0,\n\t\t\t\t\tlabel: labelForKey(keys.goalFieldValueFixed),\n\t\t\t\t\tadmin: { width: '50%' },\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: 'prop',\n\t\t\t\t\ttype: 'text',\n\t\t\t\t\tlabel: labelForKey(keys.goalFieldValueProp),\n\t\t\t\t\tadmin: {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\tdescription: labelForKey(keys.goalFieldValuePropHelp),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t],\n})\n\n/**\n * The editor-managed goals collection: one document per goal (and per scope in scoped\n * installs), merged over the config goals by the resolver. Admin-only by default; `access`\n * entries override individual operations and `overrides` reshapes the whole config last,\n * so slugs, labels, fields, and access all stay overridable.\n */\nexport const buildGoalsCollection = (args: BuildGoalsCollectionArgs): CollectionConfig => {\n\tconst unique = uniqueSlugIndex(args)\n\tconst collection: CollectionConfig = {\n\t\tslug: args.slug,\n\t\t...(unique ? { indexes: [unique] } : {}),\n\t\tlabels: {\n\t\t\tsingular: labelForKey(keys.goalsCollectionSingular),\n\t\t\tplural: labelForKey(keys.goalsCollectionPlural),\n\t\t},\n\t\t// A duplicate would carry the slug over, which the uniqueness hook refuses anyway.\n\t\tdisableDuplicate: true,\n\t\tadmin: {\n\t\t\tuseAsTitle: 'name',\n\t\t\tdefaultColumns: ['name', 'slug', 'match.kind', 'enabled'],\n\t\t\tgroup: 'Analytics',\n\t\t},\n\t\taccess: {\n\t\t\tread: providerRowAccess(args),\n\t\t\tcreate: providerCreateAccess(args),\n\t\t\tupdate: providerRowAccess(args),\n\t\t\tdelete: providerRowAccess(args),\n\t\t\t...args.access,\n\t\t},\n\t\thooks: {\n\t\t\tbeforeValidate: [uniqueSlug(args)],\n\t\t\tbeforeChange: [stampScope(args)],\n\t\t\tafterChange: [\n\t\t\t\tasync ({ doc, operation, previousDoc }) => {\n\t\t\t\t\tawait args.onChange({\n\t\t\t\t\t\tscope: docScope(doc, args.scopeField),\n\t\t\t\t\t\t...(operation === 'update'\n\t\t\t\t\t\t\t? { previousScope: docScope(previousDoc, args.scopeField) }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t})\n\t\t\t\t\treturn doc\n\t\t\t\t},\n\t\t\t],\n\t\t\tafterDelete: [\n\t\t\t\tasync ({ doc }) => {\n\t\t\t\t\tawait args.onChange({ scope: docScope(doc, args.scopeField) })\n\t\t\t\t\treturn doc\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\tfields: [\n\t\t\t{\n\t\t\t\tname: 'name',\n\t\t\t\ttype: 'text',\n\t\t\t\trequired: true,\n\t\t\t\tlabel: labelForKey(keys.goalFieldName),\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'slug',\n\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t// Mongoose refuses a field index and a compound index that share a key\n\t\t\t\t\t\t// spec, and the compound one already covers a lookup by slug.\n\t\t\t\t\t\tindex: unique === undefined,\n\t\t\t\t\t\tlabel: labelForKey(keys.goalFieldSlug),\n\t\t\t\t\t\tvalidate: validateSlug,\n\t\t\t\t\t\tadmin: {\n\t\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\t\tdescription: labelForKey(keys.goalFieldSlugHelp),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'enabled',\n\t\t\t\t\t\ttype: 'checkbox',\n\t\t\t\t\t\tdefaultValue: true,\n\t\t\t\t\t\tlabel: labelForKey(keys.goalFieldEnabled),\n\t\t\t\t\t\tadmin: { width: '50%', style: { alignSelf: 'flex-end' } },\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\tmatchField(),\n\t\t\tvalueField(),\n\t\t\t{\n\t\t\t\tname: 'currency',\n\t\t\t\ttype: 'text',\n\t\t\t\tlabel: labelForKey(keys.goalFieldCurrency),\n\t\t\t\tvalidate: validateCurrency,\n\t\t\t},\n\t\t\t...scopeField(args),\n\t\t],\n\t}\n\treturn args.overrides ? args.overrides(collection) : collection\n}\n"],"mappings":";;;;;;;;;;AAoBA,MAAa,aAAa;AAa1B,MAAM,gBAA2C,OAAO,EAAE,UACzD,OAAO,UAAU,YAAY,kBAAkB,KAAK,KAAK,IACtD,OACA,YAAY,IAAI,CAAC,EAAE,KAAK,aAAa;AAEzC,MAAM,WAAW,UAChB,UAAU,QAAQ,UAAU,KAAA,KAAa,UAAU,KAAK,OAAO,OAAO,KAAK;;;;;;;AAQ5E,MAAM,aAAa,OAClB,MACA,UAK4B;CAC5B,MAAM,EAAE,MAAM,aAAa,QAAQ;CACnC,IAAI;EACH,IAAI,MAAM,KAAK,aAAa,EAAE,IAAI,CAAC,GAGlC,OAAO,QAAQ,OAAO,KAAK,WAAW,KAAK,QAAQ,cAAc,KAAK,WAAW;EAElF,OAAO,QAAQ,MAAM,KAAK,aAAa,GAAG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ACzC,UAAU;GACX;GACA,GAAG,WAAW,IAAI;EACnB;CACD;CACA,OAAO,KAAK,YAAY,KAAK,UAAU,UAAU,IAAI;AACtD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { keys } from "../translations/keys.js";
|
|
2
|
+
import { asTranslate } from "../translations/server.js";
|
|
3
|
+
//#region src/goals/currency.ts
|
|
4
|
+
/** ISO 4217: three uppercase letters. */
|
|
5
|
+
const CURRENCY_PATTERN = /^[A-Z]{3}$/;
|
|
6
|
+
/**
|
|
7
|
+
* Shared by the goals collection and the form-builder goal action so a currency authored in
|
|
8
|
+
* either place is accepted on the same terms. Empty is allowed: the currency is optional.
|
|
9
|
+
*/
|
|
10
|
+
const validateCurrency = (value, { req }) => !value || CURRENCY_PATTERN.test(value) ? true : asTranslate(req.t)(keys.goalErrorCurrency);
|
|
11
|
+
//#endregion
|
|
12
|
+
export { validateCurrency };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=currency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.js","names":[],"sources":["../../src/goals/currency.ts"],"sourcesContent":["import type { TextFieldSingleValidation } from 'payload'\nimport { keys } from '../translations/keys'\nimport { asTranslate } from '../translations/server'\n\n/** ISO 4217: three uppercase letters. */\nexport const CURRENCY_PATTERN = /^[A-Z]{3}$/\n\n/**\n * Shared by the goals collection and the form-builder goal action so a currency authored in\n * either place is accepted on the same terms. Empty is allowed: the currency is optional.\n */\nexport const validateCurrency: TextFieldSingleValidation = (value, { req }) =>\n\t!value || CURRENCY_PATTERN.test(value) ? true : asTranslate(req.t)(keys.goalErrorCurrency)\n"],"mappings":";;;;AAKA,MAAa,mBAAmB;;;;;AAMhC,MAAa,oBAA+C,OAAO,EAAE,UACpE,CAAC,SAAS,iBAAiB,KAAK,KAAK,IAAI,OAAO,YAAY,IAAI,CAAC,EAAE,KAAK,iBAAiB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { GoalSource } from "./resolver.js";
|
|
2
|
+
|
|
3
|
+
//#region src/goals/fetchGoals.d.ts
|
|
4
|
+
interface WireGoal {
|
|
5
|
+
slug: string;
|
|
6
|
+
name: string;
|
|
7
|
+
source: GoalSource;
|
|
8
|
+
}
|
|
9
|
+
interface GoalsResponse {
|
|
10
|
+
goals: WireGoal[];
|
|
11
|
+
/** The goals collection, when the install enabled it, so a picker can link to it. */
|
|
12
|
+
collection: {
|
|
13
|
+
slug: string;
|
|
14
|
+
} | null;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { GoalsResponse, WireGoal };
|
|
18
|
+
//# sourceMappingURL=fetchGoals.d.ts.map
|