@10x-media/analytics 0.1.0-beta.5 → 1.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (515) hide show
  1. package/CHANGELOG.md +270 -0
  2. package/LICENSE +21 -21
  3. package/README.md +15 -4
  4. package/dist/adapters/ga4/disableKey.d.ts +9 -0
  5. package/dist/adapters/ga4/disableKey.js +21 -0
  6. package/dist/adapters/ga4/disableKey.js.map +1 -0
  7. package/dist/adapters/ga4/eventName.d.ts +15 -0
  8. package/dist/adapters/ga4/eventName.js +19 -0
  9. package/dist/adapters/ga4/eventName.js.map +1 -0
  10. package/dist/adapters/ga4/ga4.d.ts +5 -0
  11. package/dist/adapters/ga4/ga4.js +186 -58
  12. package/dist/adapters/ga4/ga4.js.map +1 -1
  13. package/dist/adapters/ga4/measurementId.js +15 -0
  14. package/dist/adapters/ga4/measurementId.js.map +1 -0
  15. package/dist/adapters/goalRead.js +126 -0
  16. package/dist/adapters/goalRead.js.map +1 -0
  17. package/dist/adapters/http/fetchJson.js +1 -1
  18. package/dist/adapters/plausible/plausible.d.ts +25 -0
  19. package/dist/adapters/plausible/plausible.js +159 -38
  20. package/dist/adapters/plausible/plausible.js.map +1 -1
  21. package/dist/adapters/posthog/posthog.d.ts +10 -1
  22. package/dist/adapters/posthog/posthog.js +130 -21
  23. package/dist/adapters/posthog/posthog.js.map +1 -1
  24. package/dist/adapters/series.js +11 -1
  25. package/dist/adapters/series.js.map +1 -1
  26. package/dist/adapters/umami/umami.d.ts +13 -1
  27. package/dist/adapters/umami/umami.js +278 -26
  28. package/dist/adapters/umami/umami.js.map +1 -1
  29. package/dist/binding/resolvePath.js +18 -2
  30. package/dist/binding/resolvePath.js.map +1 -1
  31. package/dist/capture/getTrackerConfig.d.ts +20 -0
  32. package/dist/capture/getTrackerConfig.js +31 -0
  33. package/dist/capture/getTrackerConfig.js.map +1 -0
  34. package/dist/capture/mountPath.js +14 -0
  35. package/dist/capture/mountPath.js.map +1 -0
  36. package/dist/capture/proxyEndpoint.js +127 -0
  37. package/dist/capture/proxyEndpoint.js.map +1 -0
  38. package/dist/capture/proxyRoutes.js +108 -0
  39. package/dist/capture/proxyRoutes.js.map +1 -0
  40. package/dist/capture/requestBody.js +68 -0
  41. package/dist/capture/requestBody.js.map +1 -0
  42. package/dist/capture/slots.d.ts +8 -0
  43. package/dist/capture/slots.js +54 -0
  44. package/dist/capture/slots.js.map +1 -0
  45. package/dist/capture/trackerConfig.d.ts +33 -0
  46. package/dist/capture/trackerConfig.js +95 -0
  47. package/dist/capture/trackerConfig.js.map +1 -0
  48. package/dist/capture/trackerEndpoint.js +35 -0
  49. package/dist/capture/trackerEndpoint.js.map +1 -0
  50. package/dist/charts/BarList.d.ts +16 -1
  51. package/dist/charts/BarList.js +41 -19
  52. package/dist/charts/BarList.js.map +1 -1
  53. package/dist/charts/TrendChart.d.ts +16 -3
  54. package/dist/charts/TrendChart.js +172 -106
  55. package/dist/charts/TrendChart.js.map +1 -1
  56. package/dist/charts/bars.d.ts +4 -0
  57. package/dist/charts/bars.js +3 -1
  58. package/dist/charts/bars.js.map +1 -1
  59. package/dist/charts/bucket.js +10 -1
  60. package/dist/charts/bucket.js.map +1 -1
  61. package/dist/charts/spline.js +2 -2
  62. package/dist/charts/spline.js.map +1 -1
  63. package/dist/charts/styles.js +18 -1
  64. package/dist/charts/styles.js.map +1 -1
  65. package/dist/core/cacheKey.js +26 -3
  66. package/dist/core/cacheKey.js.map +1 -1
  67. package/dist/core/capabilities.d.ts +5 -1
  68. package/dist/core/capabilities.js +11 -2
  69. package/dist/core/capabilities.js.map +1 -1
  70. package/dist/core/capture.d.ts +49 -0
  71. package/dist/core/contract.d.ts +74 -5
  72. package/dist/core/contract.js +30 -1
  73. package/dist/core/contract.js.map +1 -1
  74. package/dist/core/granularity.js +1 -1
  75. package/dist/core/options.d.ts +164 -6
  76. package/dist/core/options.js +126 -3
  77. package/dist/core/options.js.map +1 -1
  78. package/dist/core/registry.d.ts +1 -0
  79. package/dist/core/scopeList.js +32 -0
  80. package/dist/core/scopeList.js.map +1 -0
  81. package/dist/core/scopedRead.js +101 -30
  82. package/dist/core/scopedRead.js.map +1 -1
  83. package/dist/core/serverEvent.d.ts +60 -0
  84. package/dist/core/serverEvent.js +12 -0
  85. package/dist/core/serverEvent.js.map +1 -0
  86. package/dist/exports/adapters/ga4.d.ts +2 -1
  87. package/dist/exports/adapters/ga4.js +2 -1
  88. package/dist/exports/adapters/native.d.ts +3 -1
  89. package/dist/exports/adapters/native.js +2 -1
  90. package/dist/exports/client.d.ts +13 -3
  91. package/dist/exports/client.js +10 -1
  92. package/dist/exports/geo.d.ts +2 -2
  93. package/dist/exports/next.d.ts +2 -1
  94. package/dist/exports/next.js +2 -1
  95. package/dist/exports/react.d.ts +4 -0
  96. package/dist/exports/react.js +5 -0
  97. package/dist/exports/rsc.d.ts +11 -3
  98. package/dist/exports/rsc.js +7 -2
  99. package/dist/exports/tracker.d.ts +21 -0
  100. package/dist/exports/tracker.js +15 -0
  101. package/dist/exports/types.d.ts +16 -3
  102. package/dist/exports/types.js +4 -2
  103. package/dist/fields/AnalyticsPanelClient.js +2 -2
  104. package/dist/fields/AnalyticsPanelField.js +1 -1
  105. package/dist/fields/AnalyticsStatField.js +2 -2
  106. package/dist/fields/config/FilterDimensionSelectField.d.ts +14 -0
  107. package/dist/fields/config/FilterDimensionSelectField.js +77 -0
  108. package/dist/fields/config/FilterDimensionSelectField.js.map +1 -0
  109. package/dist/fields/config/FilterOperatorSelectField.d.ts +14 -0
  110. package/dist/fields/config/FilterOperatorSelectField.js +75 -0
  111. package/dist/fields/config/FilterOperatorSelectField.js.map +1 -0
  112. package/dist/fields/config/MetricSelectField.js +3 -3
  113. package/dist/fields/config/MetricSelectField.js.map +1 -1
  114. package/dist/fields/config/SourceSelectField.js +3 -3
  115. package/dist/fields/config/SourceSelectField.js.map +1 -1
  116. package/dist/fields/config/fetchSources.d.ts +5 -1
  117. package/dist/fields/config/fetchSources.js +7 -3
  118. package/dist/fields/config/fetchSources.js.map +1 -1
  119. package/dist/fields/config/narrow.js +2 -0
  120. package/dist/fields/config/narrow.js.map +1 -1
  121. package/dist/fields/config/sourcesState.js +19 -3
  122. package/dist/fields/config/sourcesState.js.map +1 -1
  123. package/dist/fields/config/useAnalyticsSources.d.ts +8 -3
  124. package/dist/fields/config/useAnalyticsSources.js +9 -6
  125. package/dist/fields/config/useAnalyticsSources.js.map +1 -1
  126. package/dist/fields/config/useFilterCapabilities.d.ts +28 -0
  127. package/dist/fields/config/useFilterCapabilities.js +52 -0
  128. package/dist/fields/config/useFilterCapabilities.js.map +1 -0
  129. package/dist/fields/readForDocument.d.ts +5 -0
  130. package/dist/fields/readForDocument.js +22 -10
  131. package/dist/fields/readForDocument.js.map +1 -1
  132. package/dist/goals/GoalSelectField.d.ts +7 -0
  133. package/dist/goals/GoalSelectField.js +77 -0
  134. package/dist/goals/GoalSelectField.js.map +1 -0
  135. package/dist/goals/collection.js +254 -0
  136. package/dist/goals/collection.js.map +1 -0
  137. package/dist/goals/currency.js +14 -0
  138. package/dist/goals/currency.js.map +1 -0
  139. package/dist/goals/fetchGoals.d.ts +18 -0
  140. package/dist/goals/fetchGoals.js +33 -0
  141. package/dist/goals/fetchGoals.js.map +1 -0
  142. package/dist/goals/goalField.d.ts +31 -0
  143. package/dist/goals/goalField.js +56 -0
  144. package/dist/goals/goalField.js.map +1 -0
  145. package/dist/goals/goalsEndpoint.d.ts +1 -0
  146. package/dist/goals/goalsEndpoint.js +58 -0
  147. package/dist/goals/goalsEndpoint.js.map +1 -0
  148. package/dist/goals/match.js +64 -0
  149. package/dist/goals/match.js.map +1 -0
  150. package/dist/goals/resolver.d.ts +8 -0
  151. package/dist/goals/resolver.js +147 -0
  152. package/dist/goals/resolver.js.map +1 -0
  153. package/dist/goals/trackGoalAction.d.ts +76 -0
  154. package/dist/goals/trackGoalAction.js +158 -0
  155. package/dist/goals/trackGoalAction.js.map +1 -0
  156. package/dist/goals/types.d.ts +33 -0
  157. package/dist/goals/types.js +7 -0
  158. package/dist/goals/types.js.map +1 -0
  159. package/dist/goals/useAnalyticsGoals.d.ts +20 -0
  160. package/dist/goals/useAnalyticsGoals.js +67 -0
  161. package/dist/goals/useAnalyticsGoals.js.map +1 -0
  162. package/dist/index.d.ts +14 -3
  163. package/dist/index.js +174 -19
  164. package/dist/index.js.map +1 -1
  165. package/dist/native/collections/events.js +65 -1
  166. package/dist/native/collections/events.js.map +1 -1
  167. package/dist/native/collections/rollups.js +39 -3
  168. package/dist/native/collections/rollups.js.map +1 -1
  169. package/dist/native/eventScan.js +25 -0
  170. package/dist/native/eventScan.js.map +1 -0
  171. package/dist/native/geo/composeGeoResolvers.js +2 -2
  172. package/dist/native/geo/composeGeoResolvers.js.map +1 -1
  173. package/dist/native/geo/geoResolver.d.ts +9 -2
  174. package/dist/native/geo/geoResolver.js.map +1 -1
  175. package/dist/native/geo/maxmindResolver.js +3 -5
  176. package/dist/native/geo/maxmindResolver.js.map +1 -1
  177. package/dist/native/ingest/bots.d.ts +11 -0
  178. package/dist/native/ingest/bots.js +71 -0
  179. package/dist/native/ingest/bots.js.map +1 -0
  180. package/dist/native/ingest/browser.js +47 -0
  181. package/dist/native/ingest/browser.js.map +1 -0
  182. package/dist/native/ingest/clientIp.js +20 -0
  183. package/dist/native/ingest/clientIp.js.map +1 -0
  184. package/dist/native/ingest/device.js +11 -3
  185. package/dist/native/ingest/device.js.map +1 -1
  186. package/dist/native/ingest/endpoint.d.ts +1 -0
  187. package/dist/native/ingest/endpoint.js +107 -21
  188. package/dist/native/ingest/endpoint.js.map +1 -1
  189. package/dist/native/ingest/flushBatch.js +29 -38
  190. package/dist/native/ingest/flushBatch.js.map +1 -1
  191. package/dist/native/ingest/language.js +14 -0
  192. package/dist/native/ingest/language.js.map +1 -0
  193. package/dist/native/ingest/normalizeEvent.d.ts +30 -0
  194. package/dist/native/ingest/normalizeEvent.js +115 -16
  195. package/dist/native/ingest/normalizeEvent.js.map +1 -1
  196. package/dist/native/ingest/referrer.js +48 -0
  197. package/dist/native/ingest/referrer.js.map +1 -0
  198. package/dist/native/ingest/requestHost.js +57 -0
  199. package/dist/native/ingest/requestHost.js.map +1 -0
  200. package/dist/native/ingest/resolveHostname.d.ts +29 -0
  201. package/dist/native/ingest/resolveHostname.js +52 -0
  202. package/dist/native/ingest/resolveHostname.js.map +1 -0
  203. package/dist/native/ingest/salt.js +27 -2
  204. package/dist/native/ingest/salt.js.map +1 -1
  205. package/dist/native/ingest/serverTrack.d.ts +20 -0
  206. package/dist/native/ingest/serverTrack.js +109 -0
  207. package/dist/native/ingest/serverTrack.js.map +1 -0
  208. package/dist/native/ingest/source.d.ts +11 -0
  209. package/dist/native/ingest/source.js +264 -16
  210. package/dist/native/ingest/source.js.map +1 -1
  211. package/dist/native/ingest/utm.js +33 -0
  212. package/dist/native/ingest/utm.js.map +1 -0
  213. package/dist/native/ingest/validate.js +26 -0
  214. package/dist/native/ingest/validate.js.map +1 -0
  215. package/dist/native/nativeAdapter.d.ts +37 -1
  216. package/dist/native/nativeAdapter.js +175 -22
  217. package/dist/native/nativeAdapter.js.map +1 -1
  218. package/dist/native/query/eventAgg.js +175 -0
  219. package/dist/native/query/eventAgg.js.map +1 -0
  220. package/dist/native/retention/pruneTask.js +53 -13
  221. package/dist/native/retention/pruneTask.js.map +1 -1
  222. package/dist/native/rollupAcc.js +12 -1
  223. package/dist/native/rollupAcc.js.map +1 -1
  224. package/dist/native/rollups/bucketKey.js +15 -0
  225. package/dist/native/rollups/bucketKey.js.map +1 -0
  226. package/dist/native/rollups/bumpRollups.js +116 -0
  227. package/dist/native/rollups/bumpRollups.js.map +1 -0
  228. package/dist/native/rollups/deltas.js +86 -11
  229. package/dist/native/rollups/deltas.js.map +1 -1
  230. package/dist/native/rollups/insertManyIfNew.js +93 -0
  231. package/dist/native/rollups/insertManyIfNew.js.map +1 -0
  232. package/dist/next/captureRewrites.d.ts +42 -0
  233. package/dist/next/captureRewrites.js +57 -0
  234. package/dist/next/captureRewrites.js.map +1 -0
  235. package/dist/next/posthogProxyRewrites.d.ts +5 -0
  236. package/dist/next/posthogProxyRewrites.js +16 -21
  237. package/dist/next/posthogProxyRewrites.js.map +1 -1
  238. package/dist/plugin/documentEndpoint.js +71 -24
  239. package/dist/plugin/documentEndpoint.js.map +1 -1
  240. package/dist/plugin/errors.d.ts +31 -0
  241. package/dist/plugin/errors.js +79 -0
  242. package/dist/plugin/errors.js.map +1 -0
  243. package/dist/plugin/goalHint.d.ts +1 -0
  244. package/dist/plugin/goalHint.js +24 -0
  245. package/dist/plugin/goalHint.js.map +1 -0
  246. package/dist/plugin/paths.js +17 -1
  247. package/dist/plugin/paths.js.map +1 -1
  248. package/dist/plugin/queryEndpoint.js +124 -0
  249. package/dist/plugin/queryEndpoint.js.map +1 -0
  250. package/dist/plugin/readContextForRequest.js +73 -0
  251. package/dist/plugin/readContextForRequest.js.map +1 -0
  252. package/dist/plugin/realtimeEndpoint.js +37 -16
  253. package/dist/plugin/realtimeEndpoint.js.map +1 -1
  254. package/dist/plugin/refreshEndpoint.js +113 -0
  255. package/dist/plugin/refreshEndpoint.js.map +1 -0
  256. package/dist/plugin/runtime.d.ts +1 -0
  257. package/dist/plugin/runtime.js +33 -1
  258. package/dist/plugin/runtime.js.map +1 -1
  259. package/dist/plugin/scopeChange.js +22 -0
  260. package/dist/plugin/scopeChange.js.map +1 -0
  261. package/dist/plugin/scopeFieldBoot.js +22 -0
  262. package/dist/plugin/scopeFieldBoot.js.map +1 -0
  263. package/dist/plugin/sourcesEndpoint.js +16 -41
  264. package/dist/plugin/sourcesEndpoint.js.map +1 -1
  265. package/dist/plugin/warmTask.js +0 -0
  266. package/dist/plugin/warmTask.js.map +1 -1
  267. package/dist/providers/collection.js +89 -29
  268. package/dist/providers/collection.js.map +1 -1
  269. package/dist/providers/factory.js +11 -3
  270. package/dist/providers/factory.js.map +1 -1
  271. package/dist/providers/resolver.js.map +1 -1
  272. package/dist/query/dates.js +64 -0
  273. package/dist/query/dates.js.map +1 -0
  274. package/dist/query/errors.d.ts +14 -0
  275. package/dist/query/fetchQuery.d.ts +79 -0
  276. package/dist/query/fetchQuery.js +117 -0
  277. package/dist/query/fetchQuery.js.map +1 -0
  278. package/dist/query/parse.d.ts +22 -0
  279. package/dist/query/parse.js +168 -0
  280. package/dist/query/parse.js.map +1 -0
  281. package/dist/query/response.d.ts +39 -0
  282. package/dist/query/response.js +11 -0
  283. package/dist/query/response.js.map +1 -0
  284. package/dist/react/AnalyticsProvider.d.ts +50 -0
  285. package/dist/react/AnalyticsProvider.js +67 -0
  286. package/dist/react/AnalyticsProvider.js.map +1 -0
  287. package/dist/react/TrackerBoot.d.ts +22 -0
  288. package/dist/react/TrackerBoot.js +30 -0
  289. package/dist/react/TrackerBoot.js.map +1 -0
  290. package/dist/react/useAnalytics.d.ts +20 -0
  291. package/dist/react/useAnalytics.js +52 -0
  292. package/dist/react/useAnalytics.js.map +1 -0
  293. package/dist/rsc/AnalyticsScripts.d.ts +30 -0
  294. package/dist/rsc/AnalyticsScripts.js +41 -0
  295. package/dist/rsc/AnalyticsScripts.js.map +1 -0
  296. package/dist/surfacing/cacheStore.d.ts +1 -0
  297. package/dist/surfacing/cacheStore.js +18 -2
  298. package/dist/surfacing/cacheStore.js.map +1 -1
  299. package/dist/surfacing/engine.d.ts +1 -0
  300. package/dist/surfacing/engine.js +47 -6
  301. package/dist/surfacing/engine.js.map +1 -1
  302. package/dist/surfacing/epoch.d.ts +1 -0
  303. package/dist/surfacing/epoch.js +72 -0
  304. package/dist/surfacing/epoch.js.map +1 -0
  305. package/dist/surfacing/queue.js +22 -6
  306. package/dist/surfacing/queue.js.map +1 -1
  307. package/dist/surfacing/rateLimiter.js +130 -0
  308. package/dist/surfacing/rateLimiter.js.map +1 -0
  309. package/dist/surfacing/retryPolicy.js +15 -0
  310. package/dist/surfacing/retryPolicy.js.map +1 -0
  311. package/dist/sync/collection.js +23 -7
  312. package/dist/sync/collection.js.map +1 -1
  313. package/dist/sync/syncTask.js +68 -33
  314. package/dist/sync/syncTask.js.map +1 -1
  315. package/dist/testing/memoryAdapter.d.ts +2 -0
  316. package/dist/testing/memoryAdapter.js +17 -1
  317. package/dist/testing/memoryAdapter.js.map +1 -1
  318. package/dist/timeframe/tz.js +17 -6
  319. package/dist/timeframe/tz.js.map +1 -1
  320. package/dist/tracker/autoCapture.d.ts +48 -0
  321. package/dist/tracker/autoCapture.js +129 -0
  322. package/dist/tracker/autoCapture.js.map +1 -0
  323. package/dist/tracker/consent.d.ts +24 -0
  324. package/dist/tracker/consent.js +48 -0
  325. package/dist/tracker/consent.js.map +1 -0
  326. package/dist/tracker/createTracker.d.ts +18 -0
  327. package/dist/tracker/createTracker.js +215 -0
  328. package/dist/tracker/createTracker.js.map +1 -0
  329. package/dist/tracker/exclusion.d.ts +28 -0
  330. package/dist/tracker/exclusion.js +50 -0
  331. package/dist/tracker/exclusion.js.map +1 -0
  332. package/dist/tracker/initTracker.d.ts +22 -0
  333. package/dist/tracker/initTracker.js +33 -0
  334. package/dist/tracker/initTracker.js.map +1 -0
  335. package/dist/tracker/loadScript.d.ts +14 -0
  336. package/dist/tracker/loadScript.js +41 -0
  337. package/dist/tracker/loadScript.js.map +1 -0
  338. package/dist/tracker/pageTracking.d.ts +17 -0
  339. package/dist/tracker/pageTracking.js +38 -0
  340. package/dist/tracker/pageTracking.js.map +1 -0
  341. package/dist/tracker/registry.d.ts +27 -0
  342. package/dist/tracker/registry.js +73 -0
  343. package/dist/tracker/registry.js.map +1 -0
  344. package/dist/tracker/sinks/ga4.d.ts +29 -0
  345. package/dist/tracker/sinks/ga4.js +30 -0
  346. package/dist/tracker/sinks/ga4.js.map +1 -0
  347. package/dist/tracker/sinks/native.d.ts +22 -0
  348. package/dist/tracker/sinks/native.js +56 -0
  349. package/dist/tracker/sinks/native.js.map +1 -0
  350. package/dist/tracker/sinks/plausible.d.ts +20 -0
  351. package/dist/tracker/sinks/plausible.js +32 -0
  352. package/dist/tracker/sinks/plausible.js.map +1 -0
  353. package/dist/tracker/sinks/posthog.d.ts +18 -0
  354. package/dist/tracker/sinks/posthog.js +30 -0
  355. package/dist/tracker/sinks/posthog.js.map +1 -0
  356. package/dist/tracker/sinks/umami.d.ts +18 -0
  357. package/dist/tracker/sinks/umami.js +23 -0
  358. package/dist/tracker/sinks/umami.js.map +1 -0
  359. package/dist/tracker/sinks/vendor.d.ts +14 -0
  360. package/dist/tracker/sinks/vendor.js +81 -0
  361. package/dist/tracker/sinks/vendor.js.map +1 -0
  362. package/dist/tracker/transport.js +28 -0
  363. package/dist/tracker/transport.js.map +1 -0
  364. package/dist/tracker/types.d.ts +91 -0
  365. package/dist/translations/ar.js +221 -0
  366. package/dist/translations/ar.js.map +1 -0
  367. package/dist/translations/de.js +145 -1
  368. package/dist/translations/de.js.map +1 -1
  369. package/dist/translations/en.js +145 -1
  370. package/dist/translations/en.js.map +1 -1
  371. package/dist/translations/es.js +221 -0
  372. package/dist/translations/es.js.map +1 -0
  373. package/dist/translations/fr.js +221 -0
  374. package/dist/translations/fr.js.map +1 -0
  375. package/dist/translations/id.js +221 -0
  376. package/dist/translations/id.js.map +1 -0
  377. package/dist/translations/index.d.ts +10 -1
  378. package/dist/translations/index.js +19 -1
  379. package/dist/translations/index.js.map +1 -1
  380. package/dist/translations/keys.d.ts +144 -0
  381. package/dist/translations/keys.js +145 -1
  382. package/dist/translations/keys.js.map +1 -1
  383. package/dist/translations/ko.js +221 -0
  384. package/dist/translations/ko.js.map +1 -0
  385. package/dist/translations/metricKeys.js +8 -2
  386. package/dist/translations/metricKeys.js.map +1 -1
  387. package/dist/translations/pt.js +221 -0
  388. package/dist/translations/pt.js.map +1 -0
  389. package/dist/translations/ru.js +221 -0
  390. package/dist/translations/ru.js.map +1 -0
  391. package/dist/translations/server.js.map +1 -1
  392. package/dist/translations/uk.js +221 -0
  393. package/dist/translations/uk.js.map +1 -0
  394. package/dist/translations/zh.js +221 -0
  395. package/dist/translations/zh.js.map +1 -0
  396. package/dist/view/AnalyticsNavLink.d.ts +19 -0
  397. package/dist/view/AnalyticsNavLink.js +40 -0
  398. package/dist/view/AnalyticsNavLink.js.map +1 -0
  399. package/dist/view/AnalyticsView.d.ts +23 -0
  400. package/dist/view/AnalyticsView.js +45 -0
  401. package/dist/view/AnalyticsView.js.map +1 -0
  402. package/dist/view/AnalyticsViewClient.d.ts +15 -0
  403. package/dist/view/AnalyticsViewClient.js +244 -0
  404. package/dist/view/AnalyticsViewClient.js.map +1 -0
  405. package/dist/view/authRedirect.js +32 -0
  406. package/dist/view/authRedirect.js.map +1 -0
  407. package/dist/view/conversionRate.js +18 -0
  408. package/dist/view/conversionRate.js.map +1 -0
  409. package/dist/view/dayRange.js +68 -0
  410. package/dist/view/dayRange.js.map +1 -0
  411. package/dist/view/gating.d.ts +1 -0
  412. package/dist/view/gating.js +142 -0
  413. package/dist/view/gating.js.map +1 -0
  414. package/dist/view/labels.js +76 -0
  415. package/dist/view/labels.js.map +1 -0
  416. package/dist/view/registerView.js +48 -0
  417. package/dist/view/registerView.js.map +1 -0
  418. package/dist/view/sections/Breakdowns.js +198 -0
  419. package/dist/view/sections/Breakdowns.js.map +1 -0
  420. package/dist/view/sections/EmptyStates.js +92 -0
  421. package/dist/view/sections/EmptyStates.js.map +1 -0
  422. package/dist/view/sections/FilterChips.js +46 -0
  423. package/dist/view/sections/FilterChips.js.map +1 -0
  424. package/dist/view/sections/GoalsPanel.js +82 -0
  425. package/dist/view/sections/GoalsPanel.js.map +1 -0
  426. package/dist/view/sections/OverviewCards.js +65 -0
  427. package/dist/view/sections/OverviewCards.js.map +1 -0
  428. package/dist/view/sections/RealtimeStrip.js +80 -0
  429. package/dist/view/sections/RealtimeStrip.js.map +1 -0
  430. package/dist/view/sections/Toolbar.js +207 -0
  431. package/dist/view/sections/Toolbar.js.map +1 -0
  432. package/dist/view/sections/Trend.js +125 -0
  433. package/dist/view/sections/Trend.js.map +1 -0
  434. package/dist/view/sections/styles.js +76 -0
  435. package/dist/view/sections/styles.js.map +1 -0
  436. package/dist/view/state.js +211 -0
  437. package/dist/view/state.js.map +1 -0
  438. package/dist/view/useViewQueries.js +153 -0
  439. package/dist/view/useViewQueries.js.map +1 -0
  440. package/dist/view/viewProps.d.ts +40 -0
  441. package/dist/view/viewProps.js +90 -0
  442. package/dist/view/viewProps.js.map +1 -0
  443. package/dist/widgets/AnalyticsBreakdownWidget.d.ts +2 -1
  444. package/dist/widgets/AnalyticsBreakdownWidget.js +78 -11
  445. package/dist/widgets/AnalyticsBreakdownWidget.js.map +1 -1
  446. package/dist/widgets/AnalyticsGoalsWidget.d.ts +14 -0
  447. package/dist/widgets/AnalyticsGoalsWidget.js +196 -0
  448. package/dist/widgets/AnalyticsGoalsWidget.js.map +1 -0
  449. package/dist/widgets/AnalyticsMetricWidget.d.ts +2 -1
  450. package/dist/widgets/AnalyticsMetricWidget.js +63 -13
  451. package/dist/widgets/AnalyticsMetricWidget.js.map +1 -1
  452. package/dist/widgets/AnalyticsRealtimeWidget.d.ts +2 -1
  453. package/dist/widgets/AnalyticsRealtimeWidget.js +44 -22
  454. package/dist/widgets/AnalyticsRealtimeWidget.js.map +1 -1
  455. package/dist/widgets/AnalyticsTrendWidget.d.ts +2 -1
  456. package/dist/widgets/AnalyticsTrendWidget.js +79 -16
  457. package/dist/widgets/AnalyticsTrendWidget.js.map +1 -1
  458. package/dist/widgets/RealtimeCounter.d.ts +4 -0
  459. package/dist/widgets/RealtimeCounter.js +18 -4
  460. package/dist/widgets/RealtimeCounter.js.map +1 -1
  461. package/dist/widgets/WidgetViewLink.js +17 -0
  462. package/dist/widgets/WidgetViewLink.js.map +1 -0
  463. package/dist/widgets/breakdownTypes.js +38 -0
  464. package/dist/widgets/breakdownTypes.js.map +1 -1
  465. package/dist/widgets/cardChrome.js +31 -7
  466. package/dist/widgets/cardChrome.js.map +1 -1
  467. package/dist/widgets/comparison.js +15 -1
  468. package/dist/widgets/comparison.js.map +1 -1
  469. package/dist/widgets/defaults.d.ts +6 -2
  470. package/dist/widgets/defaults.js +78 -23
  471. package/dist/widgets/defaults.js.map +1 -1
  472. package/dist/widgets/filterCaption.js +27 -0
  473. package/dist/widgets/filterCaption.js.map +1 -0
  474. package/dist/widgets/filterField.d.ts +19 -0
  475. package/dist/widgets/filterField.js +75 -0
  476. package/dist/widgets/filterField.js.map +1 -0
  477. package/dist/widgets/prepareWidgetRead.d.ts +7 -0
  478. package/dist/widgets/prepareWidgetRead.js +74 -0
  479. package/dist/widgets/prepareWidgetRead.js.map +1 -0
  480. package/dist/widgets/range.js +43 -12
  481. package/dist/widgets/range.js.map +1 -1
  482. package/dist/widgets/readForWidget.d.ts +26 -3
  483. package/dist/widgets/readForWidget.js +48 -44
  484. package/dist/widgets/readForWidget.js.map +1 -1
  485. package/dist/widgets/readForWidgetBreakdown.d.ts +34 -2
  486. package/dist/widgets/readForWidgetBreakdown.js +53 -49
  487. package/dist/widgets/readForWidgetBreakdown.js.map +1 -1
  488. package/dist/widgets/readForWidgetGoals.d.ts +67 -0
  489. package/dist/widgets/readForWidgetGoals.js +140 -0
  490. package/dist/widgets/readForWidgetGoals.js.map +1 -0
  491. package/dist/widgets/readForWidgetRealtime.d.ts +8 -0
  492. package/dist/widgets/readForWidgetRealtime.js +23 -21
  493. package/dist/widgets/readForWidgetRealtime.js.map +1 -1
  494. package/dist/widgets/readForWidgetSeries.d.ts +26 -2
  495. package/dist/widgets/readForWidgetSeries.js +78 -53
  496. package/dist/widgets/readForWidgetSeries.js.map +1 -1
  497. package/dist/widgets/readMeta.js +18 -0
  498. package/dist/widgets/readMeta.js.map +1 -0
  499. package/dist/widgets/realtimePoll.js +13 -1
  500. package/dist/widgets/realtimePoll.js.map +1 -1
  501. package/dist/widgets/registerWidgets.js +62 -10
  502. package/dist/widgets/registerWidgets.js.map +1 -1
  503. package/dist/widgets/types.d.ts +15 -0
  504. package/dist/widgets/types.js +16 -2
  505. package/dist/widgets/types.js.map +1 -1
  506. package/dist/widgets/viewLink.d.ts +22 -0
  507. package/dist/widgets/viewLink.js +86 -0
  508. package/dist/widgets/viewLink.js.map +1 -0
  509. package/package.json +28 -8
  510. package/dist/native/rollups/applyDistinctDeltas.js +0 -9
  511. package/dist/native/rollups/applyDistinctDeltas.js.map +0 -1
  512. package/dist/native/rollups/bumpRollup.js +0 -68
  513. package/dist/native/rollups/bumpRollup.js.map +0 -1
  514. package/dist/native/rollups/insertIfNew.js +0 -19
  515. package/dist/native/rollups/insertIfNew.js.map +0 -1
@@ -0,0 +1,77 @@
1
+ "use client";
2
+ import { DIMENSION_KEYS } from "../../core/contract.js";
3
+ import { keys } from "../../translations/keys.js";
4
+ import { useTranslation as useTranslation$1 } from "../../translations/useTranslation.js";
5
+ import { DIMENSION_LABELS } from "../../view/labels.js";
6
+ import { useFilterCapabilities } from "./useFilterCapabilities.js";
7
+ import { useMemo } from "react";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ import { FieldDescription, SelectInput, useField, withCondition } from "@payloadcms/ui";
10
+ import { mergeFieldStyles } from "@payloadcms/ui/shared";
11
+ //#region src/fields/config/FilterDimensionSelectField.tsx
12
+ const asDimension = (value) => DIMENSION_KEYS.find((key) => key === value);
13
+ /**
14
+ * Dimension picker for a widget's filter group: offers only the dimensions the widget's
15
+ * chosen source can filter by, unioned over the request's sources while none is chosen.
16
+ * A stored dimension the source dropped stays in the list so it reads as the filter it is
17
+ * and can be cleared; the read path renders the unsupported state for it either way.
18
+ * While the source list is in flight the picker offers nothing rather than a wrong list,
19
+ * and says so once it settles empty or failed.
20
+ */
21
+ const FilterDimensionSelectFieldComponent = (props) => {
22
+ const { field, path: pathFromProps, readOnly, sourceFieldPath } = props;
23
+ const { t } = useTranslation$1();
24
+ const { dimensions, error, resolved } = useFilterCapabilities(sourceFieldPath);
25
+ const { customComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {}, disabled, path, setValue, showError, value } = useField({ potentiallyStalePath: pathFromProps });
26
+ const options = useMemo(() => {
27
+ const offered = dimensions.map((key) => ({
28
+ label: t(DIMENSION_LABELS[key]),
29
+ value: key
30
+ }));
31
+ if (!value || dimensions.some((key) => key === value)) return offered;
32
+ const known = asDimension(value);
33
+ return [{
34
+ label: known ? t(DIMENSION_LABELS[known]) : value,
35
+ value
36
+ }, ...offered];
37
+ }, [
38
+ dimensions,
39
+ t,
40
+ value
41
+ ]);
42
+ const style = useMemo(() => mergeFieldStyles(field), [field]);
43
+ const notice = error ? t(keys.fieldFilterError) : resolved && dimensions.length === 0 ? t(keys.fieldFilterEmpty) : 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
+ }), /* @__PURE__ */ jsx("div", {
52
+ className: "field-description",
53
+ children: notice
54
+ })] }) : Description,
55
+ description: field.admin?.description,
56
+ Error: ErrorComponent,
57
+ isClearable: true,
58
+ Label,
59
+ label: field.label,
60
+ name: field.name,
61
+ onChange: (selected) => {
62
+ const option = Array.isArray(selected) ? selected[0] : selected;
63
+ setValue(option?.value ? String(option.value) : null);
64
+ },
65
+ options,
66
+ path,
67
+ readOnly: readOnly || disabled || field.admin?.readOnly,
68
+ showError,
69
+ style,
70
+ value
71
+ });
72
+ };
73
+ const FilterDimensionSelectField = withCondition(FilterDimensionSelectFieldComponent);
74
+ //#endregion
75
+ export { FilterDimensionSelectField };
76
+
77
+ //# sourceMappingURL=FilterDimensionSelectField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilterDimensionSelectField.js","names":["useTranslation"],"sources":["../../../src/fields/config/FilterDimensionSelectField.tsx"],"sourcesContent":["'use client'\n\nimport {\n\tFieldDescription,\n\ttype ReactSelectOption,\n\tSelectInput,\n\tuseField,\n\twithCondition,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps } from 'payload'\nimport { useMemo } from 'react'\nimport { DIMENSION_KEYS, type DimensionKey } from '../../core/contract'\nimport { keys } from '../../translations/keys'\nimport { useTranslation } from '../../translations/useTranslation'\nimport { DIMENSION_LABELS } from '../../view/labels'\nimport { useFilterCapabilities } from './useFilterCapabilities'\n\nexport type FilterDimensionSelectFieldProps = TextFieldClientProps & {\n\t/**\n\t * Path of the sibling source select this picker narrows against, for custom widgets\n\t * whose source field is named differently. Defaults to `'dataSource'`.\n\t */\n\tsourceFieldPath?: string\n}\n\nconst asDimension = (value: string): DimensionKey | undefined =>\n\tDIMENSION_KEYS.find((key) => key === value)\n\n/**\n * Dimension picker for a widget's filter group: offers only the dimensions the widget's\n * chosen source can filter by, unioned over the request's sources while none is chosen.\n * A stored dimension the source dropped stays in the list so it reads as the filter it is\n * and can be cleared; the read path renders the unsupported state for it either way.\n * While the source list is in flight the picker offers nothing rather than a wrong list,\n * and says so once it settles empty or failed.\n */\nconst FilterDimensionSelectFieldComponent = (props: FilterDimensionSelectFieldProps) => {\n\tconst { field, path: pathFromProps, readOnly, sourceFieldPath } = props\n\tconst { t } = useTranslation()\n\tconst { dimensions, error, resolved } = useFilterCapabilities(sourceFieldPath)\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\n\tconst options = useMemo(() => {\n\t\tconst offered = dimensions.map((key) => ({ label: t(DIMENSION_LABELS[key]), value: key }))\n\t\tif (!value || dimensions.some((key) => key === value)) return offered\n\t\tconst known = asDimension(value)\n\t\treturn [{ label: known ? t(DIMENSION_LABELS[known]) : value, value }, ...offered]\n\t}, [dimensions, t, value])\n\tconst style = useMemo(() => mergeFieldStyles(field), [field])\n\n\tconst notice = error\n\t\t? t(keys.fieldFilterError)\n\t\t: resolved && dimensions.length === 0\n\t\t\t? t(keys.fieldFilterEmpty)\n\t\t\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<div className=\"field-description\">{notice}</div>\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\n\t\t\tLabel={Label}\n\t\t\tlabel={field.label}\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\treadOnly={readOnly || disabled || field.admin?.readOnly}\n\t\t\tshowError={showError}\n\t\t\tstyle={style}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n\nexport const FilterDimensionSelectField = withCondition(FilterDimensionSelectFieldComponent)\n"],"mappings":";;;;;;;;;;;AA0BA,MAAM,eAAe,UACpB,eAAe,MAAM,QAAQ,QAAQ,KAAK;;;;;;;;;AAU3C,MAAM,uCAAuC,UAA2C;CACvF,MAAM,EAAE,OAAO,MAAM,eAAe,UAAU,oBAAoB;CAClE,MAAM,EAAE,MAAMA,iBAAe;CAC7B,MAAM,EAAE,YAAY,OAAO,aAAa,sBAAsB,eAAe;CAC7E,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,MACA,UACA,WACA,UACG,SAAiB,EAAE,sBAAsB,cAAc,CAAC;CAE5D,MAAM,UAAU,cAAc;EAC7B,MAAM,UAAU,WAAW,KAAK,SAAS;GAAE,OAAO,EAAE,iBAAiB,IAAI;GAAG,OAAO;EAAI,EAAE;EACzF,IAAI,CAAC,SAAS,WAAW,MAAM,QAAQ,QAAQ,KAAK,GAAG,OAAO;EAC9D,MAAM,QAAQ,YAAY,KAAK;EAC/B,OAAO,CAAC;GAAE,OAAO,QAAQ,EAAE,iBAAiB,MAAM,IAAI;GAAO;EAAM,GAAG,GAAG,OAAO;CACjF,GAAG;EAAC;EAAY;EAAG;CAAK,CAAC;CACzB,MAAM,QAAQ,cAAc,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;CAE5D,MAAM,SAAS,QACZ,EAAE,KAAK,gBAAgB,IACvB,YAAY,WAAW,WAAW,IACjC,EAAE,KAAK,gBAAgB,IACvB;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,GACtF,oBAAC,OAAD;GAAK,WAAU;aAAqB;EAAY,CAAA,CAC/C,EAAA,CAAA,IAEF;EAGF,aAAa,MAAM,OAAO;EAC1B,OAAO;EACP,aAAA;EACO;EACP,OAAO,MAAM;EACb,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,UAAU,YAAY,YAAY,MAAM,OAAO;EACpC;EACJ;EACA;CACP,CAAA;AAEH;AAEA,MAAa,6BAA6B,cAAc,mCAAmC"}
@@ -0,0 +1,14 @@
1
+ import { TextFieldClientProps } from "payload";
2
+
3
+ //#region src/fields/config/FilterOperatorSelectField.d.ts
4
+ type FilterOperatorSelectFieldProps = TextFieldClientProps & {
5
+ /**
6
+ * Path of the sibling source select this picker narrows against, for custom widgets
7
+ * whose source field is named differently. Defaults to `'dataSource'`.
8
+ */
9
+ sourceFieldPath?: string;
10
+ };
11
+ declare const FilterOperatorSelectField: import("react").FC<FilterOperatorSelectFieldProps>;
12
+ //#endregion
13
+ export { FilterOperatorSelectField, FilterOperatorSelectFieldProps };
14
+ //# sourceMappingURL=FilterOperatorSelectField.d.ts.map
@@ -0,0 +1,75 @@
1
+ "use client";
2
+ import { FILTER_OPERATORS } from "../../core/contract.js";
3
+ import { keys } from "../../translations/keys.js";
4
+ import { FILTER_OPERATOR_KEYS } from "../../translations/metricKeys.js";
5
+ import { useTranslation as useTranslation$1 } from "../../translations/useTranslation.js";
6
+ import { useFilterCapabilities } from "./useFilterCapabilities.js";
7
+ import { useMemo } from "react";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ import { FieldDescription, SelectInput, useField, withCondition } from "@payloadcms/ui";
10
+ import { mergeFieldStyles } from "@payloadcms/ui/shared";
11
+ //#region src/fields/config/FilterOperatorSelectField.tsx
12
+ const asOperator = (value) => FILTER_OPERATORS.find((op) => op === value);
13
+ /**
14
+ * Operator picker for a widget's filter group: offers only the operators the widget's
15
+ * chosen source supports, unioned over the request's sources while none is chosen. It is
16
+ * not clearable, because a filter always compares somehow; the dimension is the gate that
17
+ * turns the filter off.
18
+ */
19
+ const FilterOperatorSelectFieldComponent = (props) => {
20
+ const { field, path: pathFromProps, readOnly, sourceFieldPath } = props;
21
+ const { t } = useTranslation$1();
22
+ const { error, operators, resolved } = useFilterCapabilities(sourceFieldPath);
23
+ const { customComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {}, disabled, path, setValue, showError, value } = useField({ potentiallyStalePath: pathFromProps });
24
+ const options = useMemo(() => {
25
+ const offered = operators.map((op) => ({
26
+ label: t(FILTER_OPERATOR_KEYS[op]),
27
+ value: op
28
+ }));
29
+ if (!value || operators.some((op) => op === value)) return offered;
30
+ const known = asOperator(value);
31
+ return [{
32
+ label: known ? t(FILTER_OPERATOR_KEYS[known]) : value,
33
+ value
34
+ }, ...offered];
35
+ }, [
36
+ operators,
37
+ t,
38
+ value
39
+ ]);
40
+ const style = useMemo(() => mergeFieldStyles(field), [field]);
41
+ const notice = error ? t(keys.fieldFilterError) : resolved && operators.length === 0 ? t(keys.fieldFilterEmpty) : null;
42
+ return /* @__PURE__ */ jsx(SelectInput, {
43
+ AfterInput,
44
+ BeforeInput,
45
+ className: field.admin?.className,
46
+ Description: notice ? /* @__PURE__ */ jsxs(Fragment, { children: [Description ?? /* @__PURE__ */ jsx(FieldDescription, {
47
+ description: field.admin?.description,
48
+ path
49
+ }), /* @__PURE__ */ jsx("div", {
50
+ className: "field-description",
51
+ children: notice
52
+ })] }) : Description,
53
+ description: field.admin?.description,
54
+ Error: ErrorComponent,
55
+ isClearable: false,
56
+ Label,
57
+ label: field.label,
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
+ readOnly: readOnly || disabled || field.admin?.readOnly,
66
+ showError,
67
+ style,
68
+ value
69
+ });
70
+ };
71
+ const FilterOperatorSelectField = withCondition(FilterOperatorSelectFieldComponent);
72
+ //#endregion
73
+ export { FilterOperatorSelectField };
74
+
75
+ //# sourceMappingURL=FilterOperatorSelectField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilterOperatorSelectField.js","names":["useTranslation"],"sources":["../../../src/fields/config/FilterOperatorSelectField.tsx"],"sourcesContent":["'use client'\n\nimport {\n\tFieldDescription,\n\ttype ReactSelectOption,\n\tSelectInput,\n\tuseField,\n\twithCondition,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps } from 'payload'\nimport { useMemo } from 'react'\nimport { FILTER_OPERATORS, type FilterOperator } from '../../core/contract'\nimport { keys } from '../../translations/keys'\nimport { FILTER_OPERATOR_KEYS } from '../../translations/metricKeys'\nimport { useTranslation } from '../../translations/useTranslation'\nimport { useFilterCapabilities } from './useFilterCapabilities'\n\nexport type FilterOperatorSelectFieldProps = TextFieldClientProps & {\n\t/**\n\t * Path of the sibling source select this picker narrows against, for custom widgets\n\t * whose source field is named differently. Defaults to `'dataSource'`.\n\t */\n\tsourceFieldPath?: string\n}\n\nconst asOperator = (value: string): FilterOperator | undefined =>\n\tFILTER_OPERATORS.find((op) => op === value)\n\n/**\n * Operator picker for a widget's filter group: offers only the operators the widget's\n * chosen source supports, unioned over the request's sources while none is chosen. It is\n * not clearable, because a filter always compares somehow; the dimension is the gate that\n * turns the filter off.\n */\nconst FilterOperatorSelectFieldComponent = (props: FilterOperatorSelectFieldProps) => {\n\tconst { field, path: pathFromProps, readOnly, sourceFieldPath } = props\n\tconst { t } = useTranslation()\n\tconst { error, operators, resolved } = useFilterCapabilities(sourceFieldPath)\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\n\tconst options = useMemo(() => {\n\t\tconst offered = operators.map((op) => ({ label: t(FILTER_OPERATOR_KEYS[op]), value: op }))\n\t\tif (!value || operators.some((op) => op === value)) return offered\n\t\tconst known = asOperator(value)\n\t\treturn [{ label: known ? t(FILTER_OPERATOR_KEYS[known]) : value, value }, ...offered]\n\t}, [operators, t, value])\n\tconst style = useMemo(() => mergeFieldStyles(field), [field])\n\n\tconst notice = error\n\t\t? t(keys.fieldFilterError)\n\t\t: resolved && operators.length === 0\n\t\t\t? t(keys.fieldFilterEmpty)\n\t\t\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<div className=\"field-description\">{notice}</div>\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={false}\n\t\t\tLabel={Label}\n\t\t\tlabel={field.label}\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\treadOnly={readOnly || disabled || field.admin?.readOnly}\n\t\t\tshowError={showError}\n\t\t\tstyle={style}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n\nexport const FilterOperatorSelectField = withCondition(FilterOperatorSelectFieldComponent)\n"],"mappings":";;;;;;;;;;;AA0BA,MAAM,cAAc,UACnB,iBAAiB,MAAM,OAAO,OAAO,KAAK;;;;;;;AAQ3C,MAAM,sCAAsC,UAA0C;CACrF,MAAM,EAAE,OAAO,MAAM,eAAe,UAAU,oBAAoB;CAClE,MAAM,EAAE,MAAMA,iBAAe;CAC7B,MAAM,EAAE,OAAO,WAAW,aAAa,sBAAsB,eAAe;CAC5E,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,MACA,UACA,WACA,UACG,SAAiB,EAAE,sBAAsB,cAAc,CAAC;CAE5D,MAAM,UAAU,cAAc;EAC7B,MAAM,UAAU,UAAU,KAAK,QAAQ;GAAE,OAAO,EAAE,qBAAqB,GAAG;GAAG,OAAO;EAAG,EAAE;EACzF,IAAI,CAAC,SAAS,UAAU,MAAM,OAAO,OAAO,KAAK,GAAG,OAAO;EAC3D,MAAM,QAAQ,WAAW,KAAK;EAC9B,OAAO,CAAC;GAAE,OAAO,QAAQ,EAAE,qBAAqB,MAAM,IAAI;GAAO;EAAM,GAAG,GAAG,OAAO;CACrF,GAAG;EAAC;EAAW;EAAG;CAAK,CAAC;CACxB,MAAM,QAAQ,cAAc,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;CAE5D,MAAM,SAAS,QACZ,EAAE,KAAK,gBAAgB,IACvB,YAAY,UAAU,WAAW,IAChC,EAAE,KAAK,gBAAgB,IACvB;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,GACtF,oBAAC,OAAD;GAAK,WAAU;aAAqB;EAAY,CAAA,CAC/C,EAAA,CAAA,IAEF;EAGF,aAAa,MAAM,OAAO;EAC1B,OAAO;EACP,aAAa;EACN;EACP,OAAO,MAAM;EACb,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,UAAU,YAAY,YAAY,MAAM,OAAO;EACpC;EACJ;EACA;CACP,CAAA;AAEH;AAEA,MAAa,4BAA4B,cAAc,kCAAkC"}
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import { useTranslation as useTranslation$1 } from "../../translations/useTranslation.js";
3
+ import { useAnalyticsSources } from "./useAnalyticsSources.js";
3
4
  import { narrowMetricOptions } from "./narrow.js";
4
5
  import { toSelectOption } from "./toSelectOption.js";
5
- import { useAnalyticsSources } from "./useAnalyticsSources.js";
6
6
  import { useMemo } from "react";
7
7
  import { jsx } from "react/jsx-runtime";
8
8
  import { SelectInput, useField, useFormFields } from "@payloadcms/ui";
@@ -14,10 +14,10 @@ import { SelectInput, useField, useFormFields } from "@payloadcms/ui";
14
14
  * narrowing filters out; the read path degrades that case on its own.
15
15
  */
16
16
  const MetricSelectField = (props) => {
17
- const { field, path, readOnly, requires, sourceFieldPath = "dataSource" } = props;
17
+ const { field, path: pathFromProps, readOnly, requires, sourceFieldPath = "dataSource" } = props;
18
18
  const { i18n } = useTranslation$1();
19
19
  const locale = i18n.language;
20
- const { setValue, showError, value } = useField({ path });
20
+ const { path, setValue, showError, value } = useField({ potentiallyStalePath: pathFromProps });
21
21
  const { sources } = useAnalyticsSources();
22
22
  const sourceId = useFormFields(([fields]) => fields?.[sourceFieldPath]?.value);
23
23
  const options = narrowMetricOptions({
@@ -1 +1 @@
1
- {"version":3,"file":"MetricSelectField.js","names":["useTranslation"],"sources":["../../../src/fields/config/MetricSelectField.tsx"],"sourcesContent":["'use client'\n\nimport { type ReactSelectOption, SelectInput, useField, useFormFields } from '@payloadcms/ui'\nimport type { SelectFieldClientProps } from 'payload'\nimport { useMemo } from 'react'\nimport type { CapabilityRequirement } from '../../core/capabilities'\nimport { useTranslation } from '../../translations/useTranslation'\nimport { narrowMetricOptions } from './narrow'\nimport { toSelectOption } from './toSelectOption'\nimport { useAnalyticsSources } from './useAnalyticsSources'\n\nexport type MetricSelectFieldProps = SelectFieldClientProps & {\n\t/** Extra capability requirement (beyond the picked metric) a widget's other config imposes, e.g. a breakdown dimension. */\n\trequires?: Omit<CapabilityRequirement, 'metrics'>\n\t/**\n\t * Path of the sibling source select this picker narrows against, for\n\t * custom widgets whose source field is named differently. Defaults to\n\t * `'dataSource'`.\n\t */\n\tsourceFieldPath?: string\n}\n\n/**\n * Metric picker for scoped widget config: narrows the static option list to\n * what the sibling source field's selected source can actually serve, once\n * the sources endpoint answers. Never clears an already-picked value that\n * narrowing filters out; the read path degrades that case on its own.\n */\nexport const MetricSelectField = (props: MetricSelectFieldProps) => {\n\tconst { field, path, readOnly, requires, sourceFieldPath = 'dataSource' } = props\n\tconst { i18n } = useTranslation()\n\tconst locale = i18n.language\n\tconst { setValue, showError, value } = useField<string>({ path })\n\tconst { sources } = useAnalyticsSources()\n\tconst sourceId = useFormFields(\n\t\t([fields]) => fields?.[sourceFieldPath]?.value as string | undefined\n\t)\n\n\tconst staticOptions = useMemo(\n\t\t() => field.options.map((option) => toSelectOption(option, locale)),\n\t\t[field.options, locale]\n\t)\n\n\tconst options = narrowMetricOptions({\n\t\toptions: staticOptions,\n\t\trequires,\n\t\tsourceId,\n\t\tsources: sources ?? [],\n\t}).map((option) => ({ label: option.label as string, value: option.value }))\n\n\treturn (\n\t\t<SelectInput\n\t\t\tisClearable={false}\n\t\t\tlabel={field.label}\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 ? String(option.value) : null)\n\t\t\t}}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\treadOnly={readOnly}\n\t\t\trequired={field.required}\n\t\t\tshowError={showError}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,MAAa,qBAAqB,UAAkC;CACnE,MAAM,EAAE,OAAO,MAAM,UAAU,UAAU,kBAAkB,iBAAiB;CAC5E,MAAM,EAAE,SAASA,iBAAe;CAChC,MAAM,SAAS,KAAK;CACpB,MAAM,EAAE,UAAU,WAAW,UAAU,SAAiB,EAAE,KAAK,CAAC;CAChE,MAAM,EAAE,YAAY,oBAAoB;CACxC,MAAM,WAAW,eACf,CAAC,YAAY,SAAS,kBAAkB,KAC1C;CAOA,MAAM,UAAU,oBAAoB;EACnC,SANqB,cACf,MAAM,QAAQ,KAAK,WAAW,eAAe,QAAQ,MAAM,CAAC,GAClE,CAAC,MAAM,SAAS,MAAM,CAID;EACrB;EACA;EACA,SAAS,WAAW,CAAC;CACtB,CAAC,EAAE,KAAK,YAAY;EAAE,OAAO,OAAO;EAAiB,OAAO,OAAO;CAAM,EAAE;CAE3E,OACC,oBAAC,aAAD;EACC,aAAa;EACb,OAAO,MAAM;EACb,MAAM,MAAM;EACZ,WAAW,aAAsD;GAChE,MAAM,SAAS,MAAM,QAAQ,QAAQ,IAAI,SAAS,KAAK;GACvD,SAAS,SAAS,OAAO,OAAO,KAAK,IAAI,IAAI;EAC9C;EACS;EACH;EACI;EACV,UAAU,MAAM;EACL;EACJ;CACP,CAAA;AAEH"}
1
+ {"version":3,"file":"MetricSelectField.js","names":["useTranslation"],"sources":["../../../src/fields/config/MetricSelectField.tsx"],"sourcesContent":["'use client'\n\nimport { type ReactSelectOption, SelectInput, useField, useFormFields } from '@payloadcms/ui'\nimport type { SelectFieldClientProps } from 'payload'\nimport { useMemo } from 'react'\nimport type { CapabilityRequirement } from '../../core/capabilities'\nimport { useTranslation } from '../../translations/useTranslation'\nimport { narrowMetricOptions } from './narrow'\nimport { toSelectOption } from './toSelectOption'\nimport { useAnalyticsSources } from './useAnalyticsSources'\n\nexport type MetricSelectFieldProps = SelectFieldClientProps & {\n\t/** Extra capability requirement (beyond the picked metric) a widget's other config imposes, e.g. a breakdown dimension. */\n\trequires?: Omit<CapabilityRequirement, 'metrics'>\n\t/**\n\t * Path of the sibling source select this picker narrows against, for\n\t * custom widgets whose source field is named differently. Defaults to\n\t * `'dataSource'`.\n\t */\n\tsourceFieldPath?: string\n}\n\n/**\n * Metric picker for scoped widget config: narrows the static option list to\n * what the sibling source field's selected source can actually serve, once\n * the sources endpoint answers. Never clears an already-picked value that\n * narrowing filters out; the read path degrades that case on its own.\n */\nexport const MetricSelectField = (props: MetricSelectFieldProps) => {\n\tconst { field, path: pathFromProps, readOnly, requires, sourceFieldPath = 'dataSource' } = props\n\tconst { i18n } = useTranslation()\n\tconst locale = i18n.language\n\tconst { path, setValue, showError, value } = useField<string>({\n\t\tpotentiallyStalePath: pathFromProps,\n\t})\n\tconst { sources } = useAnalyticsSources()\n\tconst sourceId = useFormFields(\n\t\t([fields]) => fields?.[sourceFieldPath]?.value as string | undefined\n\t)\n\n\tconst staticOptions = useMemo(\n\t\t() => field.options.map((option) => toSelectOption(option, locale)),\n\t\t[field.options, locale]\n\t)\n\n\tconst options = narrowMetricOptions({\n\t\toptions: staticOptions,\n\t\trequires,\n\t\tsourceId,\n\t\tsources: sources ?? [],\n\t}).map((option) => ({ label: option.label as string, value: option.value }))\n\n\treturn (\n\t\t<SelectInput\n\t\t\tisClearable={false}\n\t\t\tlabel={field.label}\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 ? String(option.value) : null)\n\t\t\t}}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\treadOnly={readOnly}\n\t\t\trequired={field.required}\n\t\t\tshowError={showError}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,MAAa,qBAAqB,UAAkC;CACnE,MAAM,EAAE,OAAO,MAAM,eAAe,UAAU,UAAU,kBAAkB,iBAAiB;CAC3F,MAAM,EAAE,SAASA,iBAAe;CAChC,MAAM,SAAS,KAAK;CACpB,MAAM,EAAE,MAAM,UAAU,WAAW,UAAU,SAAiB,EAC7D,sBAAsB,cACvB,CAAC;CACD,MAAM,EAAE,YAAY,oBAAoB;CACxC,MAAM,WAAW,eACf,CAAC,YAAY,SAAS,kBAAkB,KAC1C;CAOA,MAAM,UAAU,oBAAoB;EACnC,SANqB,cACf,MAAM,QAAQ,KAAK,WAAW,eAAe,QAAQ,MAAM,CAAC,GAClE,CAAC,MAAM,SAAS,MAAM,CAID;EACrB;EACA;EACA,SAAS,WAAW,CAAC;CACtB,CAAC,EAAE,KAAK,YAAY;EAAE,OAAO,OAAO;EAAiB,OAAO,OAAO;CAAM,EAAE;CAE3E,OACC,oBAAC,aAAD;EACC,aAAa;EACb,OAAO,MAAM;EACb,MAAM,MAAM;EACZ,WAAW,aAAsD;GAChE,MAAM,SAAS,MAAM,QAAQ,QAAQ,IAAI,SAAS,KAAK;GACvD,SAAS,SAAS,OAAO,OAAO,KAAK,IAAI,IAAI;EAC9C;EACS;EACH;EACI;EACV,UAAU,MAAM;EACL;EACJ;CACP,CAAA;AAEH"}
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { useTranslation as useTranslation$1 } from "../../translations/useTranslation.js";
3
- import { toSelectOption } from "./toSelectOption.js";
4
3
  import { useAnalyticsSources } from "./useAnalyticsSources.js";
4
+ import { toSelectOption } from "./toSelectOption.js";
5
5
  import { useMemo } from "react";
6
6
  import { jsx } from "react/jsx-runtime";
7
7
  import { SelectInput, useField } from "@payloadcms/ui";
@@ -14,10 +14,10 @@ import { SelectInput, useField } from "@payloadcms/ui";
14
14
  * emptying the picker.
15
15
  */
16
16
  const SourceSelectField = (props) => {
17
- const { field, path, readOnly } = props;
17
+ const { field, path: pathFromProps, readOnly } = props;
18
18
  const { i18n } = useTranslation$1();
19
19
  const locale = i18n.language;
20
- const { setValue, showError, value } = useField({ path });
20
+ const { path, setValue, showError, value } = useField({ potentiallyStalePath: pathFromProps });
21
21
  const { sources } = useAnalyticsSources();
22
22
  const staticOptions = useMemo(() => field.options.map((option) => toSelectOption(option, locale)), [field.options, locale]);
23
23
  const options = sources && sources.length > 0 ? sources.map((source) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"SourceSelectField.js","names":["useTranslation"],"sources":["../../../src/fields/config/SourceSelectField.tsx"],"sourcesContent":["'use client'\n\nimport { type ReactSelectOption, SelectInput, useField } from '@payloadcms/ui'\nimport type { SelectFieldClientProps } from 'payload'\nimport { useMemo } from 'react'\nimport { useTranslation } from '../../translations/useTranslation'\nimport { toSelectOption } from './toSelectOption'\nimport { useAnalyticsSources } from './useAnalyticsSources'\n\n/**\n * Source picker for scoped widget config: starts from the field's static\n * option list and, once the caller-scope sources endpoint answers, replaces\n * it with the live adapter list so a tenant only ever sees sources it can\n * actually read from. A failed fetch keeps the static list rather than\n * emptying the picker.\n */\nexport const SourceSelectField = (props: SelectFieldClientProps) => {\n\tconst { field, path, readOnly } = props\n\tconst { i18n } = useTranslation()\n\tconst locale = i18n.language\n\tconst { setValue, showError, value } = useField<string>({ path })\n\tconst { sources } = useAnalyticsSources()\n\n\tconst staticOptions = useMemo(\n\t\t() => field.options.map((option) => toSelectOption(option, locale)),\n\t\t[field.options, locale]\n\t)\n\n\tconst options =\n\t\tsources && sources.length > 0\n\t\t\t? sources.map((source) => ({ value: source.id, label: source.label }))\n\t\t\t: staticOptions\n\n\treturn (\n\t\t<SelectInput\n\t\t\tisClearable={false}\n\t\t\tlabel={field.label}\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 ? String(option.value) : null)\n\t\t\t}}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\treadOnly={readOnly}\n\t\t\trequired={field.required}\n\t\t\tshowError={showError}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAa,qBAAqB,UAAkC;CACnE,MAAM,EAAE,OAAO,MAAM,aAAa;CAClC,MAAM,EAAE,SAASA,iBAAe;CAChC,MAAM,SAAS,KAAK;CACpB,MAAM,EAAE,UAAU,WAAW,UAAU,SAAiB,EAAE,KAAK,CAAC;CAChE,MAAM,EAAE,YAAY,oBAAoB;CAExC,MAAM,gBAAgB,cACf,MAAM,QAAQ,KAAK,WAAW,eAAe,QAAQ,MAAM,CAAC,GAClE,CAAC,MAAM,SAAS,MAAM,CACvB;CAEA,MAAM,UACL,WAAW,QAAQ,SAAS,IACzB,QAAQ,KAAK,YAAY;EAAE,OAAO,OAAO;EAAI,OAAO,OAAO;CAAM,EAAE,IACnE;CAEJ,OACC,oBAAC,aAAD;EACC,aAAa;EACb,OAAO,MAAM;EACb,MAAM,MAAM;EACZ,WAAW,aAAsD;GAChE,MAAM,SAAS,MAAM,QAAQ,QAAQ,IAAI,SAAS,KAAK;GACvD,SAAS,SAAS,OAAO,OAAO,KAAK,IAAI,IAAI;EAC9C;EACS;EACH;EACI;EACV,UAAU,MAAM;EACL;EACJ;CACP,CAAA;AAEH"}
1
+ {"version":3,"file":"SourceSelectField.js","names":["useTranslation"],"sources":["../../../src/fields/config/SourceSelectField.tsx"],"sourcesContent":["'use client'\n\nimport { type ReactSelectOption, SelectInput, useField } from '@payloadcms/ui'\nimport type { SelectFieldClientProps } from 'payload'\nimport { useMemo } from 'react'\nimport { useTranslation } from '../../translations/useTranslation'\nimport { toSelectOption } from './toSelectOption'\nimport { useAnalyticsSources } from './useAnalyticsSources'\n\n/**\n * Source picker for scoped widget config: starts from the field's static\n * option list and, once the caller-scope sources endpoint answers, replaces\n * it with the live adapter list so a tenant only ever sees sources it can\n * actually read from. A failed fetch keeps the static list rather than\n * emptying the picker.\n */\nexport const SourceSelectField = (props: SelectFieldClientProps) => {\n\tconst { field, path: pathFromProps, readOnly } = props\n\tconst { i18n } = useTranslation()\n\tconst locale = i18n.language\n\tconst { path, setValue, showError, value } = useField<string>({\n\t\tpotentiallyStalePath: pathFromProps,\n\t})\n\tconst { sources } = useAnalyticsSources()\n\n\tconst staticOptions = useMemo(\n\t\t() => field.options.map((option) => toSelectOption(option, locale)),\n\t\t[field.options, locale]\n\t)\n\n\tconst options =\n\t\tsources && sources.length > 0\n\t\t\t? sources.map((source) => ({ value: source.id, label: source.label }))\n\t\t\t: staticOptions\n\n\treturn (\n\t\t<SelectInput\n\t\t\tisClearable={false}\n\t\t\tlabel={field.label}\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 ? String(option.value) : null)\n\t\t\t}}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\treadOnly={readOnly}\n\t\t\trequired={field.required}\n\t\t\tshowError={showError}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAa,qBAAqB,UAAkC;CACnE,MAAM,EAAE,OAAO,MAAM,eAAe,aAAa;CACjD,MAAM,EAAE,SAASA,iBAAe;CAChC,MAAM,SAAS,KAAK;CACpB,MAAM,EAAE,MAAM,UAAU,WAAW,UAAU,SAAiB,EAC7D,sBAAsB,cACvB,CAAC;CACD,MAAM,EAAE,YAAY,oBAAoB;CAExC,MAAM,gBAAgB,cACf,MAAM,QAAQ,KAAK,WAAW,eAAe,QAAQ,MAAM,CAAC,GAClE,CAAC,MAAM,SAAS,MAAM,CACvB;CAEA,MAAM,UACL,WAAW,QAAQ,SAAS,IACzB,QAAQ,KAAK,YAAY;EAAE,OAAO,OAAO;EAAI,OAAO,OAAO;CAAM,EAAE,IACnE;CAEJ,OACC,oBAAC,aAAD;EACC,aAAa;EACb,OAAO,MAAM;EACb,MAAM,MAAM;EACZ,WAAW,aAAsD;GAChE,MAAM,SAAS,MAAM,QAAQ,QAAQ,IAAI,SAAS,KAAK;GACvD,SAAS,SAAS,OAAO,OAAO,KAAK,IAAI,IAAI;EAC9C;EACS;EACH;EACI;EACV,UAAU,MAAM;EACL;EACJ;CACP,CAAA;AAEH"}
@@ -7,6 +7,10 @@ interface WireSource {
7
7
  kind: 'config' | 'runtime';
8
8
  capabilities: SerializedCapabilities;
9
9
  }
10
+ interface SourcesResponse {
11
+ defaultId: string | null;
12
+ sources: WireSource[];
13
+ }
10
14
  //#endregion
11
- export { WireSource };
15
+ export { SourcesResponse, WireSource };
12
16
  //# sourceMappingURL=fetchSources.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { SOURCES_PATH } from "../../plugin/paths.js";
2
+ import { readResponseError } from "../../plugin/errors.js";
2
3
  //#region src/fields/config/fetchSources.ts
3
4
  const cache = /* @__PURE__ */ new Map();
4
5
  /**
@@ -13,9 +14,12 @@ const fetchSources = (serverURL, apiRoute, userKey) => {
13
14
  const key = `${userKey}:${url}`;
14
15
  const hit = cache.get(key);
15
16
  if (hit) return hit;
16
- const p = fetch(url, { credentials: "include" }).then((res) => {
17
- if (!res.ok) throw new Error(`sources ${res.status}`);
18
- return res.json();
17
+ const p = fetch(url, { credentials: "include" }).then(async (res) => {
18
+ if (!res.ok) {
19
+ const code = (await readResponseError(res))?.code;
20
+ throw new Error(`analytics: sources ${res.status}${code ? ` ${code}` : ""}`);
21
+ }
22
+ return await res.json();
19
23
  }).catch((err) => {
20
24
  cache.delete(key);
21
25
  throw err;
@@ -1 +1 @@
1
- {"version":3,"file":"fetchSources.js","names":[],"sources":["../../../src/fields/config/fetchSources.ts"],"sourcesContent":["import type { SerializedCapabilities } from '../../core/capabilities'\nimport { SOURCES_PATH } from '../../plugin/paths'\n\nexport interface WireSource {\n\tid: string\n\tlabel: string\n\tkind: 'config' | 'runtime'\n\tcapabilities: SerializedCapabilities\n}\n\nexport interface SourcesResponse {\n\tdefaultId: string | null\n\tsources: WireSource[]\n}\n\nconst cache = new Map<string, Promise<SourcesResponse>>()\n\n/**\n * Fetch the caller-scope source list once per user per admin session and share\n * it between every picker instance on the page; a failed fetch clears its cache\n * entry so a later mount retries instead of pinning the error. Keying by user\n * id keeps a soft-navigation logout/login from serving the previous user's\n * cached sources.\n */\nexport const fetchSources = (\n\tserverURL: string,\n\tapiRoute: string,\n\tuserKey: string\n): Promise<SourcesResponse> => {\n\tconst url = `${serverURL}${apiRoute}${SOURCES_PATH}`\n\tconst key = `${userKey}:${url}`\n\tconst hit = cache.get(key)\n\tif (hit) return hit\n\tconst p = fetch(url, { credentials: 'include' })\n\t\t.then((res) => {\n\t\t\tif (!res.ok) throw new Error(`sources ${res.status}`)\n\t\t\treturn res.json() as Promise<SourcesResponse>\n\t\t})\n\t\t.catch((err) => {\n\t\t\tcache.delete(key)\n\t\t\tthrow err\n\t\t})\n\tcache.set(key, p)\n\treturn p\n}\n"],"mappings":";;AAeA,MAAM,wBAAQ,IAAI,IAAsC;;;;;;;;AASxD,MAAa,gBACZ,WACA,UACA,YAC8B;CAC9B,MAAM,MAAM,GAAG,YAAY,WAAW;CACtC,MAAM,MAAM,GAAG,QAAQ,GAAG;CAC1B,MAAM,MAAM,MAAM,IAAI,GAAG;CACzB,IAAI,KAAK,OAAO;CAChB,MAAM,IAAI,MAAM,KAAK,EAAE,aAAa,UAAU,CAAC,EAC7C,MAAM,QAAQ;EACd,IAAI,CAAC,IAAI,IAAI,MAAM,IAAI,MAAM,WAAW,IAAI,QAAQ;EACpD,OAAO,IAAI,KAAK;CACjB,CAAC,EACA,OAAO,QAAQ;EACf,MAAM,OAAO,GAAG;EAChB,MAAM;CACP,CAAC;CACF,MAAM,IAAI,KAAK,CAAC;CAChB,OAAO;AACR"}
1
+ {"version":3,"file":"fetchSources.js","names":[],"sources":["../../../src/fields/config/fetchSources.ts"],"sourcesContent":["import type { SerializedCapabilities } from '../../core/capabilities'\nimport { readResponseError } from '../../plugin/errors'\nimport { SOURCES_PATH } from '../../plugin/paths'\n\nexport interface WireSource {\n\tid: string\n\tlabel: string\n\tkind: 'config' | 'runtime'\n\tcapabilities: SerializedCapabilities\n}\n\nexport interface SourcesResponse {\n\tdefaultId: string | null\n\tsources: WireSource[]\n}\n\nconst cache = new Map<string, Promise<SourcesResponse>>()\n\n/**\n * Fetch the caller-scope source list once per user per admin session and share\n * it between every picker instance on the page; a failed fetch clears its cache\n * entry so a later mount retries instead of pinning the error. Keying by user\n * id keeps a soft-navigation logout/login from serving the previous user's\n * cached sources.\n */\nexport const fetchSources = (\n\tserverURL: string,\n\tapiRoute: string,\n\tuserKey: string\n): Promise<SourcesResponse> => {\n\tconst url = `${serverURL}${apiRoute}${SOURCES_PATH}`\n\tconst key = `${userKey}:${url}`\n\tconst hit = cache.get(key)\n\tif (hit) return hit\n\tconst p = fetch(url, { credentials: 'include' })\n\t\t.then(async (res) => {\n\t\t\tif (!res.ok) {\n\t\t\t\t// The picker shows one failed state either way, so the code rides in the message\n\t\t\t\t// rather than inventing a second: a denied listing and a down one read alike in\n\t\t\t\t// the console otherwise.\n\t\t\t\tconst code = (await readResponseError(res))?.code\n\t\t\t\tthrow new Error(`analytics: sources ${res.status}${code ? ` ${code}` : ''}`)\n\t\t\t}\n\t\t\treturn (await res.json()) as SourcesResponse\n\t\t})\n\t\t.catch((err) => {\n\t\t\tcache.delete(key)\n\t\t\tthrow err\n\t\t})\n\tcache.set(key, p)\n\treturn p\n}\n"],"mappings":";;;AAgBA,MAAM,wBAAQ,IAAI,IAAsC;;;;;;;;AASxD,MAAa,gBACZ,WACA,UACA,YAC8B;CAC9B,MAAM,MAAM,GAAG,YAAY,WAAW;CACtC,MAAM,MAAM,GAAG,QAAQ,GAAG;CAC1B,MAAM,MAAM,MAAM,IAAI,GAAG;CACzB,IAAI,KAAK,OAAO;CAChB,MAAM,IAAI,MAAM,KAAK,EAAE,aAAa,UAAU,CAAC,EAC7C,KAAK,OAAO,QAAQ;EACpB,IAAI,CAAC,IAAI,IAAI;GAIZ,MAAM,QAAQ,MAAM,kBAAkB,GAAG,IAAI;GAC7C,MAAM,IAAI,MAAM,sBAAsB,IAAI,SAAS,OAAO,IAAI,SAAS,IAAI;EAC5E;EACA,OAAQ,MAAM,IAAI,KAAK;CACxB,CAAC,EACA,OAAO,QAAQ;EACf,MAAM,OAAO,GAAG;EAChB,MAAM;CACP,CAAC;CACF,MAAM,IAAI,KAAK,CAAC;CAChB,OAAO;AACR"}
@@ -5,6 +5,8 @@ const satisfiesSerialized = (caps, req) => {
5
5
  if (req.perPageQuery && !caps.perPageQuery) return false;
6
6
  if (req.metrics?.some((m) => !caps.metrics.includes(m))) return false;
7
7
  if (req.dimensions?.some((d) => !caps.dimensions.includes(d))) return false;
8
+ if (req.filters?.some((d) => !caps.filters.includes(d))) return false;
9
+ if (req.filterOperators?.some((op) => !caps.filterOperators.includes(op))) return false;
8
10
  return true;
9
11
  };
10
12
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"narrow.js","names":[],"sources":["../../../src/fields/config/narrow.ts"],"sourcesContent":["import type { CapabilityRequirement, SerializedCapabilities } from '../../core/capabilities'\nimport type { WireSource } from './fetchSources'\n\nexport interface SelectOption {\n\tvalue: string\n\tlabel: unknown\n}\n\n/** satisfiesCapabilities over the wire form (arrays instead of Sets). */\nexport const satisfiesSerialized = (\n\tcaps: SerializedCapabilities,\n\treq: CapabilityRequirement\n): boolean => {\n\tif (req.realtime && !caps.realtime) return false\n\tif (req.perPageQuery && !caps.perPageQuery) return false\n\tif (req.metrics?.some((m) => !caps.metrics.includes(m))) return false\n\tif (req.dimensions?.some((d) => !caps.dimensions.includes(d))) return false\n\treturn true\n}\n\n/**\n * Options for the metric picker, narrowed to what the selected source can\n * serve. An unknown source id (a stale value, a source the endpoint could not\n * list) keeps the full static list, mirroring the server-side filterOptions\n * fallback, and a source that cannot meet the widget's extra requirements at\n * all falls back to the full list rather than an empty picker.\n */\nexport const narrowMetricOptions = (args: {\n\toptions: SelectOption[]\n\tsources: WireSource[]\n\tsourceId: string | undefined\n\trequires?: Omit<CapabilityRequirement, 'metrics'>\n}): SelectOption[] => {\n\tconst src = args.sourceId ? args.sources.find((s) => s.id === args.sourceId) : undefined\n\tif (!src) return args.options\n\tif (args.requires && !satisfiesSerialized(src.capabilities, args.requires)) {\n\t\treturn args.options\n\t}\n\tconst narrowed = args.options.filter((o) =>\n\t\tsatisfiesSerialized(src.capabilities, { ...args.requires, metrics: [o.value as never] })\n\t)\n\treturn narrowed.length > 0 ? narrowed : args.options\n}\n"],"mappings":";;AASA,MAAa,uBACZ,MACA,QACa;CACb,IAAI,IAAI,YAAY,CAAC,KAAK,UAAU,OAAO;CAC3C,IAAI,IAAI,gBAAgB,CAAC,KAAK,cAAc,OAAO;CACnD,IAAI,IAAI,SAAS,MAAM,MAAM,CAAC,KAAK,QAAQ,SAAS,CAAC,CAAC,GAAG,OAAO;CAChE,IAAI,IAAI,YAAY,MAAM,MAAM,CAAC,KAAK,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;CACtE,OAAO;AACR;;;;;;;;AASA,MAAa,uBAAuB,SAKd;CACrB,MAAM,MAAM,KAAK,WAAW,KAAK,QAAQ,MAAM,MAAM,EAAE,OAAO,KAAK,QAAQ,IAAI,KAAA;CAC/E,IAAI,CAAC,KAAK,OAAO,KAAK;CACtB,IAAI,KAAK,YAAY,CAAC,oBAAoB,IAAI,cAAc,KAAK,QAAQ,GACxE,OAAO,KAAK;CAEb,MAAM,WAAW,KAAK,QAAQ,QAAQ,MACrC,oBAAoB,IAAI,cAAc;EAAE,GAAG,KAAK;EAAU,SAAS,CAAC,EAAE,KAAc;CAAE,CAAC,CACxF;CACA,OAAO,SAAS,SAAS,IAAI,WAAW,KAAK;AAC9C"}
1
+ {"version":3,"file":"narrow.js","names":[],"sources":["../../../src/fields/config/narrow.ts"],"sourcesContent":["import type { CapabilityRequirement, SerializedCapabilities } from '../../core/capabilities'\nimport type { WireSource } from './fetchSources'\n\nexport interface SelectOption {\n\tvalue: string\n\tlabel: unknown\n}\n\n/** satisfiesCapabilities over the wire form (arrays instead of Sets). */\nexport const satisfiesSerialized = (\n\tcaps: SerializedCapabilities,\n\treq: CapabilityRequirement\n): boolean => {\n\tif (req.realtime && !caps.realtime) return false\n\tif (req.perPageQuery && !caps.perPageQuery) return false\n\tif (req.metrics?.some((m) => !caps.metrics.includes(m))) return false\n\tif (req.dimensions?.some((d) => !caps.dimensions.includes(d))) return false\n\tif (req.filters?.some((d) => !caps.filters.includes(d))) return false\n\tif (req.filterOperators?.some((op) => !caps.filterOperators.includes(op))) return false\n\treturn true\n}\n\n/**\n * Options for the metric picker, narrowed to what the selected source can\n * serve. An unknown source id (a stale value, a source the endpoint could not\n * list) keeps the full static list, mirroring the server-side filterOptions\n * fallback, and a source that cannot meet the widget's extra requirements at\n * all falls back to the full list rather than an empty picker.\n */\nexport const narrowMetricOptions = (args: {\n\toptions: SelectOption[]\n\tsources: WireSource[]\n\tsourceId: string | undefined\n\trequires?: Omit<CapabilityRequirement, 'metrics'>\n}): SelectOption[] => {\n\tconst src = args.sourceId ? args.sources.find((s) => s.id === args.sourceId) : undefined\n\tif (!src) return args.options\n\tif (args.requires && !satisfiesSerialized(src.capabilities, args.requires)) {\n\t\treturn args.options\n\t}\n\tconst narrowed = args.options.filter((o) =>\n\t\tsatisfiesSerialized(src.capabilities, { ...args.requires, metrics: [o.value as never] })\n\t)\n\treturn narrowed.length > 0 ? narrowed : args.options\n}\n"],"mappings":";;AASA,MAAa,uBACZ,MACA,QACa;CACb,IAAI,IAAI,YAAY,CAAC,KAAK,UAAU,OAAO;CAC3C,IAAI,IAAI,gBAAgB,CAAC,KAAK,cAAc,OAAO;CACnD,IAAI,IAAI,SAAS,MAAM,MAAM,CAAC,KAAK,QAAQ,SAAS,CAAC,CAAC,GAAG,OAAO;CAChE,IAAI,IAAI,YAAY,MAAM,MAAM,CAAC,KAAK,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;CACtE,IAAI,IAAI,SAAS,MAAM,MAAM,CAAC,KAAK,QAAQ,SAAS,CAAC,CAAC,GAAG,OAAO;CAChE,IAAI,IAAI,iBAAiB,MAAM,OAAO,CAAC,KAAK,gBAAgB,SAAS,EAAE,CAAC,GAAG,OAAO;CAClF,OAAO;AACR;;;;;;;;AASA,MAAa,uBAAuB,SAKd;CACrB,MAAM,MAAM,KAAK,WAAW,KAAK,QAAQ,MAAM,MAAM,EAAE,OAAO,KAAK,QAAQ,IAAI,KAAA;CAC/E,IAAI,CAAC,KAAK,OAAO,KAAK;CACtB,IAAI,KAAK,YAAY,CAAC,oBAAoB,IAAI,cAAc,KAAK,QAAQ,GACxE,OAAO,KAAK;CAEb,MAAM,WAAW,KAAK,QAAQ,QAAQ,MACrC,oBAAoB,IAAI,cAAc;EAAE,GAAG,KAAK;EAAU,SAAS,CAAC,EAAE,KAAc;CAAE,CAAC,CACxF;CACA,OAAO,SAAS,SAAS,IAAI,WAAW,KAAK;AAC9C"}
@@ -1,11 +1,27 @@
1
1
  //#region src/fields/config/sourcesState.ts
2
2
  const EMPTY_SOURCES = {
3
3
  defaultId: null,
4
+ error: false,
5
+ loading: false,
4
6
  sources: null
5
7
  };
6
- /** Sources fetched for another user never render: a key mismatch reads as not-yet-loaded. */
7
- const resolveSourcesState = (state, userKey) => state.key === userKey ? state.data : EMPTY_SOURCES;
8
+ const LOADING_SOURCES = {
9
+ ...EMPTY_SOURCES,
10
+ loading: true
11
+ };
12
+ const FAILED_SOURCES = {
13
+ ...EMPTY_SOURCES,
14
+ error: true
15
+ };
16
+ /**
17
+ * Sources fetched for another user never render: a key mismatch reads as not-yet-loaded,
18
+ * and as still loading whenever there is a user whose fetch has yet to answer.
19
+ */
20
+ const resolveSourcesState = (state, userKey) => {
21
+ if (state.key === userKey) return state.data;
22
+ return userKey ? LOADING_SOURCES : EMPTY_SOURCES;
23
+ };
8
24
  //#endregion
9
- export { EMPTY_SOURCES, resolveSourcesState };
25
+ export { EMPTY_SOURCES, FAILED_SOURCES, resolveSourcesState };
10
26
 
11
27
  //# sourceMappingURL=sourcesState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sourcesState.js","names":[],"sources":["../../../src/fields/config/sourcesState.ts"],"sourcesContent":["import type { AnalyticsSources } from './useAnalyticsSources'\n\nexport interface KeyedSources {\n\tkey: string\n\tdata: AnalyticsSources\n}\n\nexport const EMPTY_SOURCES: AnalyticsSources = { defaultId: null, sources: null }\n\n/** Sources fetched for another user never render: a key mismatch reads as not-yet-loaded. */\nexport const resolveSourcesState = (state: KeyedSources, userKey: string): AnalyticsSources =>\n\tstate.key === userKey ? state.data : EMPTY_SOURCES\n"],"mappings":";AAOA,MAAa,gBAAkC;CAAE,WAAW;CAAM,SAAS;AAAK;;AAGhF,MAAa,uBAAuB,OAAqB,YACxD,MAAM,QAAQ,UAAU,MAAM,OAAO"}
1
+ {"version":3,"file":"sourcesState.js","names":[],"sources":["../../../src/fields/config/sourcesState.ts"],"sourcesContent":["import type { AnalyticsSources } from './useAnalyticsSources'\n\nexport interface KeyedSources {\n\tkey: string\n\tdata: AnalyticsSources\n}\n\nexport const EMPTY_SOURCES: AnalyticsSources = {\n\tdefaultId: null,\n\terror: false,\n\tloading: false,\n\tsources: null,\n}\n\nexport const LOADING_SOURCES: AnalyticsSources = { ...EMPTY_SOURCES, loading: true }\n\nexport const FAILED_SOURCES: AnalyticsSources = { ...EMPTY_SOURCES, error: true }\n\n/**\n * Sources fetched for another user never render: a key mismatch reads as not-yet-loaded,\n * and as still loading whenever there is a user whose fetch has yet to answer.\n */\nexport const resolveSourcesState = (state: KeyedSources, userKey: string): AnalyticsSources => {\n\tif (state.key === userKey) return state.data\n\treturn userKey ? LOADING_SOURCES : EMPTY_SOURCES\n}\n"],"mappings":";AAOA,MAAa,gBAAkC;CAC9C,WAAW;CACX,OAAO;CACP,SAAS;CACT,SAAS;AACV;AAEA,MAAa,kBAAoC;CAAE,GAAG;CAAe,SAAS;AAAK;AAEnF,MAAa,iBAAmC;CAAE,GAAG;CAAe,OAAO;AAAK;;;;;AAMhF,MAAa,uBAAuB,OAAqB,YAAsC;CAC9F,IAAI,MAAM,QAAQ,SAAS,OAAO,MAAM;CACxC,OAAO,UAAU,kBAAkB;AACpC"}
@@ -4,16 +4,21 @@ import { WireSource } from "./fetchSources.js";
4
4
  interface AnalyticsSources {
5
5
  sources: WireSource[] | null;
6
6
  defaultId: string | null;
7
+ /** The fetch has yet to answer: not the same thing as a scope with no sources. */
8
+ loading: boolean;
9
+ /** The fetch settled in failure, so a picker can say so instead of claiming none exist. */
10
+ error: boolean;
7
11
  }
8
12
  /**
9
13
  * Fetches the caller-scope source list for widget config pickers, sharing the
10
14
  * per-user cache `fetchSources` already keeps. `sources` and `defaultId` stay
11
15
  * null until the fetch resolves, on a failed fetch, or when there is no
12
16
  * authenticated user yet; consumers fall back to their static option list in
13
- * that window. Sources fetched for a previous user are never returned while
14
- * a new user's fetch is pending.
17
+ * that window, and `loading`/`error` tell those two windows apart. Sources
18
+ * fetched for a previous user are never returned while a new user's fetch is
19
+ * pending.
15
20
  */
16
21
  declare const useAnalyticsSources: () => AnalyticsSources;
17
22
  //#endregion
18
- export { useAnalyticsSources };
23
+ export { AnalyticsSources, useAnalyticsSources };
19
24
  //# sourceMappingURL=useAnalyticsSources.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { fetchSources } from "./fetchSources.js";
3
- import { EMPTY_SOURCES, resolveSourcesState } from "./sourcesState.js";
3
+ import { EMPTY_SOURCES, FAILED_SOURCES, resolveSourcesState } from "./sourcesState.js";
4
4
  import { useEffect, useState } from "react";
5
5
  import { useAuth, useConfig } from "@payloadcms/ui";
6
6
  //#region src/fields/config/useAnalyticsSources.ts
@@ -9,8 +9,9 @@ import { useAuth, useConfig } from "@payloadcms/ui";
9
9
  * per-user cache `fetchSources` already keeps. `sources` and `defaultId` stay
10
10
  * null until the fetch resolves, on a failed fetch, or when there is no
11
11
  * authenticated user yet; consumers fall back to their static option list in
12
- * that window. Sources fetched for a previous user are never returned while
13
- * a new user's fetch is pending.
12
+ * that window, and `loading`/`error` tell those two windows apart. Sources
13
+ * fetched for a previous user are never returned while a new user's fetch is
14
+ * pending.
14
15
  */
15
16
  const useAnalyticsSources = () => {
16
17
  const { user } = useAuth();
@@ -33,14 +34,16 @@ const useAnalyticsSources = () => {
33
34
  if (!cancelled) setState({
34
35
  key: userKey,
35
36
  data: {
36
- sources,
37
- defaultId
37
+ defaultId,
38
+ error: false,
39
+ loading: false,
40
+ sources
38
41
  }
39
42
  });
40
43
  }).catch(() => {
41
44
  if (!cancelled) setState({
42
45
  key: userKey,
43
- data: EMPTY_SOURCES
46
+ data: FAILED_SOURCES
44
47
  });
45
48
  });
46
49
  return () => {
@@ -1 +1 @@
1
- {"version":3,"file":"useAnalyticsSources.js","names":[],"sources":["../../../src/fields/config/useAnalyticsSources.ts"],"sourcesContent":["'use client'\n\nimport { useAuth, useConfig } from '@payloadcms/ui'\nimport { useEffect, useState } from 'react'\nimport { fetchSources, type WireSource } from './fetchSources'\nimport { EMPTY_SOURCES, type KeyedSources, resolveSourcesState } from './sourcesState'\n\nexport interface AnalyticsSources {\n\tsources: WireSource[] | null\n\tdefaultId: string | null\n}\n\n/**\n * Fetches the caller-scope source list for widget config pickers, sharing the\n * per-user cache `fetchSources` already keeps. `sources` and `defaultId` stay\n * null until the fetch resolves, on a failed fetch, or when there is no\n * authenticated user yet; consumers fall back to their static option list in\n * that window. Sources fetched for a previous user are never returned while\n * a new user's fetch is pending.\n */\nexport const useAnalyticsSources = (): AnalyticsSources => {\n\tconst { user } = useAuth()\n\tconst {\n\t\tconfig: {\n\t\t\troutes: { api },\n\t\t\tserverURL,\n\t\t},\n\t} = useConfig()\n\tconst userKey = String(user?.id ?? '')\n\tconst [state, setState] = useState<KeyedSources>({ key: '', data: EMPTY_SOURCES })\n\n\tuseEffect(() => {\n\t\tif (!userKey) {\n\t\t\tsetState({ key: '', data: EMPTY_SOURCES })\n\t\t\treturn\n\t\t}\n\t\tlet cancelled = false\n\t\tfetchSources(serverURL ?? '', api, userKey)\n\t\t\t.then(({ defaultId, sources }) => {\n\t\t\t\tif (!cancelled) setState({ key: userKey, data: { sources, defaultId } })\n\t\t\t})\n\t\t\t.catch(() => {\n\t\t\t\tif (!cancelled) setState({ key: userKey, data: EMPTY_SOURCES })\n\t\t\t})\n\t\treturn () => {\n\t\t\tcancelled = true\n\t\t}\n\t}, [api, serverURL, userKey])\n\n\treturn resolveSourcesState(state, userKey)\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAa,4BAA8C;CAC1D,MAAM,EAAE,SAAS,QAAQ;CACzB,MAAM,EACL,QAAQ,EACP,QAAQ,EAAE,OACV,gBAEE,UAAU;CACd,MAAM,UAAU,OAAO,MAAM,MAAM,EAAE;CACrC,MAAM,CAAC,OAAO,YAAY,SAAuB;EAAE,KAAK;EAAI,MAAM;CAAc,CAAC;CAEjF,gBAAgB;EACf,IAAI,CAAC,SAAS;GACb,SAAS;IAAE,KAAK;IAAI,MAAM;GAAc,CAAC;GACzC;EACD;EACA,IAAI,YAAY;EAChB,aAAa,aAAa,IAAI,KAAK,OAAO,EACxC,MAAM,EAAE,WAAW,cAAc;GACjC,IAAI,CAAC,WAAW,SAAS;IAAE,KAAK;IAAS,MAAM;KAAE;KAAS;IAAU;GAAE,CAAC;EACxE,CAAC,EACA,YAAY;GACZ,IAAI,CAAC,WAAW,SAAS;IAAE,KAAK;IAAS,MAAM;GAAc,CAAC;EAC/D,CAAC;EACF,aAAa;GACZ,YAAY;EACb;CACD,GAAG;EAAC;EAAK;EAAW;CAAO,CAAC;CAE5B,OAAO,oBAAoB,OAAO,OAAO;AAC1C"}
1
+ {"version":3,"file":"useAnalyticsSources.js","names":[],"sources":["../../../src/fields/config/useAnalyticsSources.ts"],"sourcesContent":["'use client'\n\nimport { useAuth, useConfig } from '@payloadcms/ui'\nimport { useEffect, useState } from 'react'\nimport { fetchSources, type WireSource } from './fetchSources'\nimport {\n\tEMPTY_SOURCES,\n\tFAILED_SOURCES,\n\ttype KeyedSources,\n\tresolveSourcesState,\n} from './sourcesState'\n\nexport interface AnalyticsSources {\n\tsources: WireSource[] | null\n\tdefaultId: string | null\n\t/** The fetch has yet to answer: not the same thing as a scope with no sources. */\n\tloading: boolean\n\t/** The fetch settled in failure, so a picker can say so instead of claiming none exist. */\n\terror: boolean\n}\n\n/**\n * Fetches the caller-scope source list for widget config pickers, sharing the\n * per-user cache `fetchSources` already keeps. `sources` and `defaultId` stay\n * null until the fetch resolves, on a failed fetch, or when there is no\n * authenticated user yet; consumers fall back to their static option list in\n * that window, and `loading`/`error` tell those two windows apart. Sources\n * fetched for a previous user are never returned while a new user's fetch is\n * pending.\n */\nexport const useAnalyticsSources = (): AnalyticsSources => {\n\tconst { user } = useAuth()\n\tconst {\n\t\tconfig: {\n\t\t\troutes: { api },\n\t\t\tserverURL,\n\t\t},\n\t} = useConfig()\n\tconst userKey = String(user?.id ?? '')\n\tconst [state, setState] = useState<KeyedSources>({ key: '', data: EMPTY_SOURCES })\n\n\tuseEffect(() => {\n\t\tif (!userKey) {\n\t\t\tsetState({ key: '', data: EMPTY_SOURCES })\n\t\t\treturn\n\t\t}\n\t\tlet cancelled = false\n\t\tfetchSources(serverURL ?? '', api, userKey)\n\t\t\t.then(({ defaultId, sources }) => {\n\t\t\t\tif (!cancelled) {\n\t\t\t\t\tsetState({ key: userKey, data: { defaultId, error: false, loading: false, sources } })\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch(() => {\n\t\t\t\tif (!cancelled) setState({ key: userKey, data: FAILED_SOURCES })\n\t\t\t})\n\t\treturn () => {\n\t\t\tcancelled = true\n\t\t}\n\t}, [api, serverURL, userKey])\n\n\treturn resolveSourcesState(state, userKey)\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8BA,MAAa,4BAA8C;CAC1D,MAAM,EAAE,SAAS,QAAQ;CACzB,MAAM,EACL,QAAQ,EACP,QAAQ,EAAE,OACV,gBAEE,UAAU;CACd,MAAM,UAAU,OAAO,MAAM,MAAM,EAAE;CACrC,MAAM,CAAC,OAAO,YAAY,SAAuB;EAAE,KAAK;EAAI,MAAM;CAAc,CAAC;CAEjF,gBAAgB;EACf,IAAI,CAAC,SAAS;GACb,SAAS;IAAE,KAAK;IAAI,MAAM;GAAc,CAAC;GACzC;EACD;EACA,IAAI,YAAY;EAChB,aAAa,aAAa,IAAI,KAAK,OAAO,EACxC,MAAM,EAAE,WAAW,cAAc;GACjC,IAAI,CAAC,WACJ,SAAS;IAAE,KAAK;IAAS,MAAM;KAAE;KAAW,OAAO;KAAO,SAAS;KAAO;IAAQ;GAAE,CAAC;EAEvF,CAAC,EACA,YAAY;GACZ,IAAI,CAAC,WAAW,SAAS;IAAE,KAAK;IAAS,MAAM;GAAe,CAAC;EAChE,CAAC;EACF,aAAa;GACZ,YAAY;EACb;CACD,GAAG;EAAC;EAAK;EAAW;CAAO,CAAC;CAE5B,OAAO,oBAAoB,OAAO,OAAO;AAC1C"}
@@ -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. */