@10x-media/analytics 1.0.0-beta.15 → 1.0.0-beta.17
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 +56 -0
- package/README.md +1 -1
- package/dist/adapters/ga4/ga4.js +33 -2
- package/dist/adapters/ga4/ga4.js.map +1 -1
- package/dist/adapters/ga4/measurementId.js +4 -1
- package/dist/adapters/ga4/measurementId.js.map +1 -1
- package/dist/adapters/ga4/propertyId.js +17 -0
- package/dist/adapters/ga4/propertyId.js.map +1 -0
- package/dist/adapters/http/fetchJson.js +24 -1
- package/dist/adapters/http/fetchJson.js.map +1 -1
- package/dist/adapters/plausible/plausible.js +16 -1
- package/dist/adapters/plausible/plausible.js.map +1 -1
- package/dist/adapters/plausible/siteId.js +31 -0
- package/dist/adapters/plausible/siteId.js.map +1 -0
- package/dist/adapters/posthog/cloud.js +20 -0
- package/dist/adapters/posthog/cloud.js.map +1 -0
- package/dist/adapters/posthog/credentials.js +20 -0
- package/dist/adapters/posthog/credentials.js.map +1 -0
- package/dist/adapters/posthog/posthog.d.ts +3 -3
- package/dist/adapters/posthog/posthog.js +24 -10
- package/dist/adapters/posthog/posthog.js.map +1 -1
- package/dist/adapters/umami/umami.js +34 -7
- package/dist/adapters/umami/umami.js.map +1 -1
- package/dist/charts/series.js +1 -1
- package/dist/core/contract.d.ts +16 -1
- package/dist/core/contract.js.map +1 -1
- package/dist/core/options.d.ts +1 -1
- package/dist/core/options.js +1 -1
- package/dist/core/options.js.map +1 -1
- package/dist/core/scopedRead.js +62 -14
- package/dist/core/scopedRead.js.map +1 -1
- package/dist/core/sourceErrors.js +12 -1
- package/dist/core/sourceErrors.js.map +1 -1
- package/dist/core/sourceOptions.js +1 -1
- package/dist/core/sourceOptions.js.map +1 -1
- package/dist/core/sourcePolicy.d.ts +8 -1
- package/dist/core/sourcePolicy.js.map +1 -1
- package/dist/core/throttle.js +3 -1
- package/dist/core/throttle.js.map +1 -1
- package/dist/exports/adapters/contract.d.ts +1 -1
- package/dist/exports/adapters/ga4.d.ts +2 -2
- package/dist/exports/adapters/native.d.ts +2 -2
- package/dist/exports/adapters/plausible.d.ts +2 -2
- package/dist/exports/adapters/posthog.d.ts +2 -2
- package/dist/exports/adapters/umami.d.ts +2 -2
- package/dist/exports/client.d.ts +3 -1
- package/dist/exports/client.js +3 -1
- package/dist/exports/next.d.ts +2 -2
- package/dist/exports/testing.d.ts +2 -2
- package/dist/exports/types.d.ts +3 -3
- package/dist/fields/config/fetchSources.js +1 -1
- package/dist/fields/config/fetchSources.js.map +1 -1
- package/dist/goals/collection.js +3 -2
- package/dist/goals/collection.js.map +1 -1
- package/dist/goals/resolver.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +50 -4
- package/dist/index.js.map +1 -1
- package/dist/native/geo/maxmindResolver.js +1 -1
- package/dist/native/nativeAdapter.js +1 -1
- package/dist/plugin/createRuntime.js +57 -13
- package/dist/plugin/createRuntime.js.map +1 -1
- package/dist/plugin/pluginCollections.js +4 -1
- package/dist/plugin/pluginCollections.js.map +1 -1
- package/dist/plugin/providerStatusEndpoint.js +80 -0
- package/dist/plugin/providerStatusEndpoint.js.map +1 -0
- package/dist/plugin/queryEndpoint.js +1 -1
- package/dist/plugin/queryEndpoint.js.map +1 -1
- package/dist/plugin/readContextForRequest.d.ts +4 -3
- package/dist/plugin/readContextForRequest.js +2 -2
- package/dist/plugin/readContextForRequest.js.map +1 -1
- package/dist/plugin/refreshEndpoint.js +1 -1
- package/dist/plugin/routes.d.ts +5 -0
- package/dist/plugin/routes.js +1 -0
- package/dist/plugin/routes.js.map +1 -1
- package/dist/plugin/runtime.js.map +1 -1
- package/dist/providers/ProviderConnection.d.ts +12 -0
- package/dist/providers/ProviderConnection.js +105 -0
- package/dist/providers/ProviderConnection.js.map +1 -0
- package/dist/providers/ProviderConnectionTest.d.ts +12 -0
- package/dist/providers/ProviderConnectionTest.js +55 -0
- package/dist/providers/ProviderConnectionTest.js.map +1 -0
- package/dist/providers/ProvidersListNotice.d.ts +1 -1
- package/dist/providers/ProvidersListNotice.js +3 -2
- package/dist/providers/ProvidersListNotice.js.map +1 -1
- package/dist/providers/collection.d.ts +1 -1
- package/dist/providers/collection.js +106 -41
- package/dist/providers/collection.js.map +1 -1
- package/dist/providers/connectionCheck.d.ts +1 -0
- package/dist/providers/connectionCheck.js +80 -0
- package/dist/providers/connectionCheck.js.map +1 -0
- package/dist/providers/connectionState.js +53 -0
- package/dist/providers/connectionState.js.map +1 -0
- package/dist/providers/factory.d.ts +1 -3
- package/dist/providers/factory.js +18 -21
- package/dist/providers/factory.js.map +1 -1
- package/dist/providers/hosts.js +31 -9
- package/dist/providers/hosts.js.map +1 -1
- package/dist/providers/ids.d.ts +6 -0
- package/dist/providers/ids.js +32 -0
- package/dist/providers/ids.js.map +1 -0
- package/dist/providers/providerStatusClient.js +60 -0
- package/dist/providers/providerStatusClient.js.map +1 -0
- package/dist/providers/registry.js +56 -20
- package/dist/providers/registry.js.map +1 -1
- package/dist/providers/retarget.js +39 -8
- package/dist/providers/retarget.js.map +1 -1
- package/dist/providers/secrets.d.ts +1 -1
- package/dist/providers/secrets.js.map +1 -1
- package/dist/providers/status.d.ts +1 -0
- package/dist/providers/status.js +181 -0
- package/dist/providers/status.js.map +1 -0
- package/dist/surfacing/classifyError.js +37 -5
- package/dist/surfacing/classifyError.js.map +1 -1
- package/dist/surfacing/engine.js +2 -2
- package/dist/surfacing/engine.js.map +1 -1
- package/dist/surfacing/lanes.js +29 -22
- package/dist/surfacing/lanes.js.map +1 -1
- package/dist/surfacing/rebucket.js +1 -1
- package/dist/testing/settle.d.ts +2 -1
- package/dist/testing/settle.js +6 -2
- package/dist/testing/settle.js.map +1 -1
- package/dist/tracker/sinks/ga4.js +2 -2
- package/dist/translations/ar.js +43 -8
- package/dist/translations/ar.js.map +1 -1
- package/dist/translations/de.js +43 -8
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +43 -8
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +43 -8
- package/dist/translations/es.js.map +1 -1
- package/dist/translations/fr.js +43 -8
- package/dist/translations/fr.js.map +1 -1
- package/dist/translations/id.js +43 -8
- package/dist/translations/id.js.map +1 -1
- package/dist/translations/keys.d.ts +35 -0
- package/dist/translations/keys.js +35 -0
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +43 -8
- package/dist/translations/ko.js.map +1 -1
- package/dist/translations/pt.js +43 -8
- package/dist/translations/pt.js.map +1 -1
- package/dist/translations/ru.js +43 -8
- package/dist/translations/ru.js.map +1 -1
- package/dist/translations/uk.js +43 -8
- package/dist/translations/uk.js.map +1 -1
- package/dist/translations/zh.js +43 -8
- package/dist/translations/zh.js.map +1 -1
- package/dist/ui/analytics.css +63 -0
- package/dist/ui/components/SourcesNoticeBanner.js +4 -3
- package/dist/ui/components/SourcesNoticeBanner.js.map +1 -1
- package/dist/view/ViewSections.js +9 -2
- package/dist/view/ViewSections.js.map +1 -1
- package/dist/view/sections/EmptyStates.js +5 -4
- package/dist/view/sections/EmptyStates.js.map +1 -1
- package/dist/view/sections/OverviewCards.js +6 -2
- package/dist/view/sections/OverviewCards.js.map +1 -1
- package/dist/view/sections/SourceConnectionNote.js +56 -0
- package/dist/view/sections/SourceConnectionNote.js.map +1 -0
- package/dist/view/viewProps.d.ts +2 -0
- package/dist/view/viewProps.js +2 -1
- package/dist/view/viewProps.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { keys } from "../../translations/keys.js";
|
|
3
|
+
import { PROVIDER_NAMES, documentIdOf } from "../../providers/ids.js";
|
|
4
|
+
import { isProviderStatusResponse, vendorWordsOf } from "../../providers/connectionState.js";
|
|
5
|
+
import { dateTimeFormat } from "../../translations/intl.js";
|
|
6
|
+
import { useTranslation } from "../../translations/useTranslation.js";
|
|
7
|
+
import { viewerNow } from "../../ui/viewerClock.js";
|
|
8
|
+
import { requestShaped } from "../../ui/data/request.js";
|
|
9
|
+
import { useEffect, useState } from "react";
|
|
10
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
//#region src/view/sections/SourceConnectionNote.tsx
|
|
12
|
+
/**
|
|
13
|
+
* What the vendor said when it refused a provider document's source, until when reads rest and
|
|
14
|
+
* when it last worked, inside the view's error banner. Shown only to a reader who may read the
|
|
15
|
+
* document; nothing for anyone else, nor for a source no document gives.
|
|
16
|
+
*/
|
|
17
|
+
function SourceConnectionNote({ endpoint, sourceId, locale }) {
|
|
18
|
+
const { t } = useTranslation();
|
|
19
|
+
const [status, setStatus] = useState();
|
|
20
|
+
const docId = documentIdOf(sourceId);
|
|
21
|
+
const url = endpoint === void 0 || docId === void 0 ? void 0 : `${endpoint}?id=${encodeURIComponent(docId)}`;
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (url === void 0) return;
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
requestShaped(url, isProviderStatusResponse, { signal: controller.signal }).then((answer) => setStatus(answer.status), () => {});
|
|
26
|
+
return () => controller.abort();
|
|
27
|
+
}, [url]);
|
|
28
|
+
const words = status?.errorDetail ? vendorWordsOf(status.errorDetail) : void 0;
|
|
29
|
+
const format = dateTimeFormat(locale, {
|
|
30
|
+
dateStyle: "medium",
|
|
31
|
+
timeStyle: "short"
|
|
32
|
+
});
|
|
33
|
+
const pausedAt = status?.pausedUntil ? Date.parse(status.pausedUntil) : NaN;
|
|
34
|
+
const pausedUntil = pausedAt > viewerNow().getTime() ? format.format(pausedAt) : void 0;
|
|
35
|
+
const workedAt = status?.lastSuccessAt ? Date.parse(status.lastSuccessAt) : NaN;
|
|
36
|
+
const lastWorked = Number.isNaN(workedAt) ? void 0 : format.format(workedAt);
|
|
37
|
+
if (!words && !pausedUntil && !lastWorked) return null;
|
|
38
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
39
|
+
words ? /* @__PURE__ */ jsxs("span", {
|
|
40
|
+
className: "analytics-view__source-note",
|
|
41
|
+
children: [words.provider ? `${t(PROVIDER_NAMES[words.provider])}: ` : null, words.message]
|
|
42
|
+
}) : null,
|
|
43
|
+
pausedUntil ? /* @__PURE__ */ jsx("span", {
|
|
44
|
+
className: "analytics-view__source-note",
|
|
45
|
+
children: t(keys.providerConnectionPaused, { date: pausedUntil })
|
|
46
|
+
}) : null,
|
|
47
|
+
lastWorked ? /* @__PURE__ */ jsx("span", {
|
|
48
|
+
className: "analytics-view__source-note",
|
|
49
|
+
children: `${t(keys.providerConnectionLastSuccess)}: ${lastWorked}`
|
|
50
|
+
}) : null
|
|
51
|
+
] });
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { SourceConnectionNote };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=SourceConnectionNote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SourceConnectionNote.js","names":[],"sources":["../../../src/view/sections/SourceConnectionNote.tsx"],"sourcesContent":["'use client'\n\nimport { useEffect, useState } from 'react'\nimport {\n\tisProviderStatusResponse,\n\ttype ProviderStatus,\n\tvendorWordsOf,\n} from '../../providers/connectionState'\nimport { documentIdOf, PROVIDER_NAMES } from '../../providers/ids'\nimport { dateTimeFormat } from '../../translations/intl'\nimport { keys } from '../../translations/keys'\nimport { useTranslation } from '../../translations/useTranslation'\nimport { requestShaped } from '../../ui/data/request'\nimport { viewerNow } from '../../ui/viewerClock'\n\ninterface SourceConnectionNoteProps {\n\t/** The provider status endpoint; absent on an install without provider documents. */\n\tendpoint: string | undefined\n\tsourceId: string\n\tlocale: string\n}\n\n/**\n * What the vendor said when it refused a provider document's source, until when reads rest and\n * when it last worked, inside the view's error banner. Shown only to a reader who may read the\n * document; nothing for anyone else, nor for a source no document gives.\n */\nexport function SourceConnectionNote({ endpoint, sourceId, locale }: SourceConnectionNoteProps) {\n\tconst { t } = useTranslation()\n\tconst [status, setStatus] = useState<ProviderStatus>()\n\tconst docId = documentIdOf(sourceId)\n\tconst url =\n\t\tendpoint === undefined || docId === undefined\n\t\t\t? undefined\n\t\t\t: `${endpoint}?id=${encodeURIComponent(docId)}`\n\n\tuseEffect(() => {\n\t\tif (url === undefined) {\n\t\t\treturn\n\t\t}\n\t\tconst controller = new AbortController()\n\t\t// A reader the document is closed to is answered 404: the error above says enough.\n\t\trequestShaped(url, isProviderStatusResponse, { signal: controller.signal }).then(\n\t\t\t(answer) => setStatus(answer.status),\n\t\t\t() => {}\n\t\t)\n\t\treturn () => controller.abort()\n\t}, [url])\n\n\tconst words = status?.errorDetail ? vendorWordsOf(status.errorDetail) : undefined\n\tconst format = dateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'short' })\n\tconst pausedAt = status?.pausedUntil ? Date.parse(status.pausedUntil) : Number.NaN\n\tconst pausedUntil = pausedAt > viewerNow().getTime() ? format.format(pausedAt) : undefined\n\tconst workedAt = status?.lastSuccessAt ? Date.parse(status.lastSuccessAt) : Number.NaN\n\tconst lastWorked = Number.isNaN(workedAt) ? undefined : format.format(workedAt)\n\tif (!words && !pausedUntil && !lastWorked) {\n\t\treturn null\n\t}\n\treturn (\n\t\t<>\n\t\t\t{words ? (\n\t\t\t\t<span className=\"analytics-view__source-note\">\n\t\t\t\t\t{words.provider ? `${t(PROVIDER_NAMES[words.provider])}: ` : null}\n\t\t\t\t\t{words.message}\n\t\t\t\t</span>\n\t\t\t) : null}\n\t\t\t{pausedUntil ? (\n\t\t\t\t<span className=\"analytics-view__source-note\">\n\t\t\t\t\t{t(keys.providerConnectionPaused, { date: pausedUntil })}\n\t\t\t\t</span>\n\t\t\t) : null}\n\t\t\t{lastWorked ? (\n\t\t\t\t<span className=\"analytics-view__source-note\">\n\t\t\t\t\t{`${t(keys.providerConnectionLastSuccess)}: ${lastWorked}`}\n\t\t\t\t</span>\n\t\t\t) : null}\n\t\t</>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA2BA,SAAgB,qBAAqB,EAAE,UAAU,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AAE,KAAK,6BAA6B,EAAE,IAAI;EACzC,CAAA,IACH;CACH,EAAA,CAAA;AAEJ"}
|
package/dist/view/viewProps.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ interface ViewEndpoints {
|
|
|
39
39
|
query: string;
|
|
40
40
|
refresh: string;
|
|
41
41
|
live: string;
|
|
42
|
+
/** The provider status endpoint, mounted while `providers.collection` is on. */
|
|
43
|
+
providerStatus?: string;
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Everything the client shell needs to render without a second round trip. Serializable
|
package/dist/view/viewProps.js
CHANGED
|
@@ -96,7 +96,8 @@ const resolveViewProps = async (req, resolved, searchParams) => {
|
|
|
96
96
|
endpoints: {
|
|
97
97
|
query: apiPath(config, routes.query),
|
|
98
98
|
refresh: apiPath(config, routes.refresh),
|
|
99
|
-
live: apiPath(config, routes.live)
|
|
99
|
+
live: apiPath(config, routes.live),
|
|
100
|
+
...resolved.providers.collection.enabled ? { providerStatus: apiPath(config, routes.providerStatus) } : {}
|
|
100
101
|
},
|
|
101
102
|
adminRoute: config.routes?.admin ?? "/admin",
|
|
102
103
|
locale: intlLocale(req.i18n.language),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewProps.js","names":[],"sources":["../../src/view/viewProps.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { readGate } from '../access/readGate'\nimport { type MetricKey, PLATFORM_SCOPE } from '../core/contract'\nimport { DEFAULT_VIEW, type ResolvedOptions } from '../core/options'\nimport { type RequestedScope, resolveRequestedScope } from '../core/scopedRead'\nimport type { SourcesResponse } from '../fields/config/fetchSources'\nimport { apiPath } from '../plugin/apiPath'\nimport { resolveSourcesForRequest } from '../plugin/readContextForRequest'\nimport { analyticsRoutes } from '../plugin/routes'\nimport {\n\ttype AnalyticsRuntime,\n\tgetRuntime,\n\tgoalNamesFor,\n\tresolveCurrencyFor,\n\tresolveScopeFor,\n\tresolveTimezoneFor,\n\ttype ScopeGates,\n\tscopeGates,\n} from '../plugin/runtime'\nimport type { TimeframePreset } from '../timeframe/presets'\nimport { DEFAULT_TIMEZONE } from '../timeframe/tz'\nimport { intlLocale } from '../translations/intl'\nimport type { CountryFlags } from './CountryFlag'\nimport { aggregateFrom, isAggregateToken } from './state'\n\n/**\n * A goal as the view lists it: the picker needs no match or value details.\n *\n * @beta\n */\nexport interface ViewGoal {\n\tslug: string\n\tname: string\n}\n\n/**\n * Which scope the view reads; scoped installs only. The host owns the scope and the view only\n * toggles aggregation, so `own` sits beside `current` for the Site select to switch back to.\n *\n * @beta\n */\nexport interface ViewScopes {\n\t/** The scope the reads carry: `'*'` for every scope at once, `''` for none. */\n\tcurrent: string\n\t/** The scope this request resolves to on its own, whatever the URL asked for. */\n\town: string\n\t/** What `scope.label` calls `own`, when it names it. */\n\townLabel?: string\n\t/** `access.crossScope.aggregate` for this request; gates the Site select. */\n\tcanAggregate: boolean\n}\n\n/**\n * The endpoints the view reads through, each under the app's `routes.api` and the plugin's base.\n *\n * @beta\n */\nexport interface ViewEndpoints {\n\tquery: string\n\trefresh: string\n\tlive: string\n}\n\n/**\n * Everything the client shell needs to render without a second round trip. Serializable\n * by construction: the RSC boundary drops functions, so only wire shapes appear here.\n *\n * @beta\n */\nexport interface AnalyticsViewClientProps {\n\t/** Same payload the sources endpoint answers, resolved for this request's scope. */\n\tsources: SourcesResponse\n\tgoals: ViewGoal[]\n\tdefaults: { range: TimeframePreset; metric: MetricKey }\n\tendpoints: ViewEndpoints\n\tadminRoute: string\n\t/** IANA reporting timezone the day boundaries align to. */\n\ttimezone: string\n\t/** ISO 4217 code revenue is formatted in, from `revenue.currency`; absent, a plain number. */\n\tcurrency?: string\n\t/** Admin UI language (`req.i18n.language`), for number and date formatting. */\n\tlocale: string\n\t/**\n\t * The flag beside a country name: `true` the plugin's own, or the host's `countryFlags.Component`\n\t * as the server shell looked it up, which every row renders with its `code`.\n\t */\n\tcountryFlags: CountryFlags\n\t/**\n\t * Scope this render resolved to, `''` for none. Keys the client body: a host tenant switch's\n\t * `router.refresh()` keeps client state, and two tenants' reads can be identical strings.\n\t */\n\tscopeKey: string\n\t/** Scope caption and Site select; absent on an unscoped install. */\n\tscopes?: ViewScopes\n\t/**\n\t * The `scope` the URL may keep: the aggregate token this request honoured, else absent. The\n\t * client rewrites the address to match what was read.\n\t */\n\tscopeParam?: string\n\t/**\n\t * Where the view asks for the exclusion link of the reader's own scope, while\n\t * `capture.exclusion` is on; absent, the view offers no exclusion at all.\n\t */\n\texclusion?: { endpoint: string }\n\t/**\n\t * The reader works per site and has none selected (a scoped install that resolved no scope\n\t * for them), so the view asks for one instead of reporting that no source is connected.\n\t */\n\tneedsScope?: boolean\n}\n\n/**\n * `denied` is a value, not a thrown error, so the view renders its no-access message inside the\n * admin template instead of redirecting a signed-in reader.\n */\nexport type ViewPropsResult = { denied: true } | { denied: false; props: AnalyticsViewClientProps }\n\n/**\n * Goals the request's scope may see, mirroring the goals endpoint; a failed resolution falls back\n * to config goals only when unscoped.\n */\nconst resolveGoalsList = async (\n\truntime: AnalyticsRuntime,\n\treq: PayloadRequest,\n\tscope: string | null\n): Promise<ViewGoal[]> => {\n\ttry {\n\t\treturn await goalNamesFor({ runtime, req, scope })\n\t} catch (err) {\n\t\treq.payload.logger?.warn(`analytics: view goals listing failed: ${String(err)}`)\n\t\treturn runtime.scoped\n\t\t\t? []\n\t\t\t: (runtime.goals ?? []).map((goal) => ({ slug: goal.slug, name: goal.name }))\n\t}\n}\n\nconst emptySources = (): SourcesResponse => ({ defaultId: null, sources: [] })\n\n/**\n * Caption scope and Site select state. `own` resolves apart from `current` so the select keeps\n * naming the reader's own tenant while reads aggregate.\n */\nconst resolveScopes = async (args: {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\tgates: ScopeGates\n\tcurrent: string\n\town: string\n}): Promise<ViewScopes> => {\n\tconst { runtime, req, gates, current, own } = args\n\tconst ownLabel = await resolveOwnLabel(runtime, req, own)\n\treturn {\n\t\tcurrent,\n\t\town,\n\t\tcanAggregate: await gates.aggregate({ scope: PLATFORM_SCOPE }),\n\t\t...(ownLabel === undefined ? {} : { ownLabel }),\n\t}\n}\n\n/** What to call the request's own scope; the id stands wherever the host names nothing. */\nconst resolveOwnLabel = async (\n\truntime: AnalyticsRuntime,\n\treq: PayloadRequest,\n\tscope: string\n): Promise<string | undefined> => {\n\tif (!runtime.scopeLabel || scope === '' || scope === PLATFORM_SCOPE) {\n\t\treturn undefined\n\t}\n\ttry {\n\t\treturn (await runtime.scopeLabel({ req, scope })) ?? undefined\n\t} catch (err) {\n\t\treq.payload.logger?.warn(`analytics: scope.label failed: ${String(err)}`)\n\t\treturn undefined\n\t}\n}\n\n/** The `scope` a URL is allowed to carry into the view: an aggregate token, and nothing else. */\nconst requestedAggregate = (searchParams: ViewSearchParams | undefined): string | undefined => {\n\tconst raw = searchParams?.scope\n\tconst value = Array.isArray(raw) ? raw[0] : raw\n\treturn typeof value === 'string' && isAggregateToken(value) ? value : undefined\n}\n\n/**\n * The scope this request resolves to on its own; `''` for none, for a resolver that threw, and\n * for a tenant the user selected without belonging to it, whose name the view never shows.\n */\nconst ownScopeFor = async (\n\truntime: AnalyticsRuntime,\n\treq: PayloadRequest,\n\town: RequestedScope\n): Promise<string> => {\n\tif (own.ok) {\n\t\treturn own.scope ?? ''\n\t}\n\tif (own.reason !== 'unresolved') {\n\t\treturn ''\n\t}\n\ttry {\n\t\treturn (await resolveScopeFor(runtime, req)) ?? ''\n\t} catch {\n\t\treturn ''\n\t}\n}\n\n/** The admin view's `searchParams`, as Payload hands them to a server component. */\nexport type ViewSearchParams = { [key: string]: string | string[] | undefined }\n\n/**\n * Client shell props for one request. Host's `scope.resolve` is the one scope authority: the URL\n * may only ask to aggregate (granted by `access.crossScope.aggregate`); other `scope` values drop.\n */\nexport const resolveViewProps = async (\n\treq: PayloadRequest,\n\tresolved: ResolvedOptions,\n\tsearchParams?: ViewSearchParams\n): Promise<ViewPropsResult> => {\n\tif (!(await resolved.access.view({ req }))) {\n\t\treturn { denied: true }\n\t}\n\t// `false` cannot reach a render (the view is then never registered); it defaults anyway.\n\tconst view = resolved.view === false ? DEFAULT_VIEW : resolved.view\n\tconst runtime = getRuntime(req.payload)\n\tconst config = req.payload.config\n\tconst routes = analyticsRoutes(config)\n\tconst base = {\n\t\tdefaults: { range: view.defaultRange, metric: view.defaultMetric },\n\t\tendpoints: {\n\t\t\tquery: apiPath(config, routes.query),\n\t\t\trefresh: apiPath(config, routes.refresh),\n\t\t\tlive: apiPath(config, routes.live),\n\t\t},\n\t\tadminRoute: config.routes?.admin ?? '/admin',\n\t\tlocale: intlLocale(req.i18n.language),\n\t\t// The host's component is looked up by the view's body (`renderViewBody`), which hands it on.\n\t\tcountryFlags: resolved.countryFlags === true,\n\t\t...(resolved.capture.exclusion\n\t\t\t? { exclusion: { endpoint: apiPath(config, routes.exclusion) } }\n\t\t\t: {}),\n\t}\n\t// No runtime means the plugin is not installed on this instance: nothing is readable.\n\tif (!runtime) {\n\t\treturn {\n\t\t\tdenied: false,\n\t\t\tprops: {\n\t\t\t\t...base,\n\t\t\t\tsources: emptySources(),\n\t\t\t\tgoals: [],\n\t\t\t\ttimezone: DEFAULT_TIMEZONE,\n\t\t\t\tscopeKey: '',\n\t\t\t},\n\t\t}\n\t}\n\tconst gates = scopeGates(runtime, req)\n\tconst token = requestedAggregate(searchParams)\n\tconst ownRequested = await resolveRequestedScope({ runtime, req, gates })\n\tconst own = await ownScopeFor(runtime, req, ownRequested)\n\t// The aggregate belongs to the tenant it was chosen from; the host's selector can move while\n\t// the address stays open, so a token tagged with another falls back to the request's scope.\n\tconst aggregate = token !== undefined && aggregateFrom(token) === own\n\t// A wildcard this reader may not have degrades to their own scope rather than to nothing:\n\t// they are entitled to that read, and the client rewrites the address to match.\n\tlet requested = ownRequested\n\tif (aggregate) {\n\t\tconst all = await resolveRequestedScope({ runtime, req, gates, raw: PLATFORM_SCOPE })\n\t\tif (all.ok) {\n\t\t\trequested = all\n\t\t}\n\t}\n\tconst scope = requested.ok ? requested.scope : null\n\tconst scopeKey = scope ?? ''\n\tconst registryScope = scope === PLATFORM_SCOPE ? null : scope\n\t// `access.view` may be wider than `access.read`: goal names and scope names are read data too.\n\tconst readable = await readGate(runtime, req).catch(() => false)\n\tconst [sources, goals, timezone, currency, scopes] = await Promise.all([\n\t\trequested.ok\n\t\t\t? resolveSourcesForRequest(req, { gates, scope: requested.gated })\n\t\t\t: emptySources(),\n\t\trequested.ok && readable ? resolveGoalsList(runtime, req, scope) : [],\n\t\tresolveTimezoneFor(runtime, req, registryScope).catch(() => DEFAULT_TIMEZONE),\n\t\tresolveCurrencyFor(runtime, req, registryScope),\n\t\truntime.scoped === true && readable\n\t\t\t? resolveScopes({ runtime, req, gates, current: scopeKey, own })\n\t\t\t: undefined,\n\t])\n\treturn {\n\t\tdenied: false,\n\t\tprops: {\n\t\t\t...base,\n\t\t\tsources: {\n\t\t\t\tdefaultId: sources.defaultId,\n\t\t\t\tsources: sources.sources,\n\t\t\t\t...(sources.notice ? { notice: sources.notice } : {}),\n\t\t\t},\n\t\t\tgoals,\n\t\t\ttimezone,\n\t\t\tscopeKey,\n\t\t\t...(scope === PLATFORM_SCOPE && token !== undefined ? { scopeParam: token } : {}),\n\t\t\t...(!requested.ok && requested.reason === 'unresolved' ? { needsScope: true } : {}),\n\t\t\t...(currency ? { currency } : {}),\n\t\t\t...(scopes ? { scopes } : {}),\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyHA,MAAM,mBAAmB,OACxB,SACA,KACA,UACyB;CACzB,IAAI;EACH,OAAO,MAAM,aAAa;GAAE;GAAS;GAAK;EAAM,CAAC;CAClD,SAAS,KAAK;EACb,IAAI,QAAQ,QAAQ,KAAK,yCAAyC,OAAO,GAAG,GAAG;EAC/E,OAAO,QAAQ,SACZ,CAAC,KACA,QAAQ,SAAS,CAAC,GAAG,KAAK,UAAU;GAAE,MAAM,KAAK;GAAM,MAAM,KAAK;EAAK,EAAE;CAC9E;A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AAI;EACtE,UAAU,KACP,yBAAyB,KAAK;GAAE;GAAO,OAAO,UAAU;EAAM,CAAC,IAC/D,aAAa;EAChB,UAAU,MAAM,WAAW,iBAAiB,SAAS,KAAK,KAAK,IAAI,CAAC;EACpE,mBAAmB,SAAS,KAAK,aAAa,EAAE,YAAA,KAA4B;EAC5E,mBAAmB,SAAS,KAAK,aAAa;EAC9C,QAAQ,WAAW,QAAQ,WACxB,cAAc;GAAE;GAAS;GAAK;GAAO,SAAS;GAAU;EAAI,CAAC,IAC7D,KAAA;CACJ,CAAC;CACD,OAAO;EACN,QAAQ;EACR,OAAO;GACN,GAAG;GACH,SAAS;IACR,WAAW,QAAQ;IACnB,SAAS,QAAQ;IACjB,GAAI,QAAQ,SAAS,EAAE,QAAQ,QAAQ,OAAO,IAAI,CAAC;GACpD;GACA;GACA;GACA;GACA,GAAI,UAAA,OAA4B,UAAU,KAAA,IAAY,EAAE,YAAY,MAAM,IAAI,CAAC;GAC/E,GAAI,CAAC,UAAU,MAAM,UAAU,WAAW,eAAe,EAAE,YAAY,KAAK,IAAI,CAAC;GACjF,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;GAC/B,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;EAC5B;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"viewProps.js","names":[],"sources":["../../src/view/viewProps.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { readGate } from '../access/readGate'\nimport { type MetricKey, PLATFORM_SCOPE } from '../core/contract'\nimport { DEFAULT_VIEW, type ResolvedOptions } from '../core/options'\nimport { type RequestedScope, resolveRequestedScope } from '../core/scopedRead'\nimport type { SourcesResponse } from '../fields/config/fetchSources'\nimport { apiPath } from '../plugin/apiPath'\nimport { resolveSourcesForRequest } from '../plugin/readContextForRequest'\nimport { analyticsRoutes } from '../plugin/routes'\nimport {\n\ttype AnalyticsRuntime,\n\tgetRuntime,\n\tgoalNamesFor,\n\tresolveCurrencyFor,\n\tresolveScopeFor,\n\tresolveTimezoneFor,\n\ttype ScopeGates,\n\tscopeGates,\n} from '../plugin/runtime'\nimport type { TimeframePreset } from '../timeframe/presets'\nimport { DEFAULT_TIMEZONE } from '../timeframe/tz'\nimport { intlLocale } from '../translations/intl'\nimport type { CountryFlags } from './CountryFlag'\nimport { aggregateFrom, isAggregateToken } from './state'\n\n/**\n * A goal as the view lists it: the picker needs no match or value details.\n *\n * @beta\n */\nexport interface ViewGoal {\n\tslug: string\n\tname: string\n}\n\n/**\n * Which scope the view reads; scoped installs only. The host owns the scope and the view only\n * toggles aggregation, so `own` sits beside `current` for the Site select to switch back to.\n *\n * @beta\n */\nexport interface ViewScopes {\n\t/** The scope the reads carry: `'*'` for every scope at once, `''` for none. */\n\tcurrent: string\n\t/** The scope this request resolves to on its own, whatever the URL asked for. */\n\town: string\n\t/** What `scope.label` calls `own`, when it names it. */\n\townLabel?: string\n\t/** `access.crossScope.aggregate` for this request; gates the Site select. */\n\tcanAggregate: boolean\n}\n\n/**\n * The endpoints the view reads through, each under the app's `routes.api` and the plugin's base.\n *\n * @beta\n */\nexport interface ViewEndpoints {\n\tquery: string\n\trefresh: string\n\tlive: string\n\t/** The provider status endpoint, mounted while `providers.collection` is on. */\n\tproviderStatus?: string\n}\n\n/**\n * Everything the client shell needs to render without a second round trip. Serializable\n * by construction: the RSC boundary drops functions, so only wire shapes appear here.\n *\n * @beta\n */\nexport interface AnalyticsViewClientProps {\n\t/** Same payload the sources endpoint answers, resolved for this request's scope. */\n\tsources: SourcesResponse\n\tgoals: ViewGoal[]\n\tdefaults: { range: TimeframePreset; metric: MetricKey }\n\tendpoints: ViewEndpoints\n\tadminRoute: string\n\t/** IANA reporting timezone the day boundaries align to. */\n\ttimezone: string\n\t/** ISO 4217 code revenue is formatted in, from `revenue.currency`; absent, a plain number. */\n\tcurrency?: string\n\t/** Admin UI language (`req.i18n.language`), for number and date formatting. */\n\tlocale: string\n\t/**\n\t * The flag beside a country name: `true` the plugin's own, or the host's `countryFlags.Component`\n\t * as the server shell looked it up, which every row renders with its `code`.\n\t */\n\tcountryFlags: CountryFlags\n\t/**\n\t * Scope this render resolved to, `''` for none. Keys the client body: a host tenant switch's\n\t * `router.refresh()` keeps client state, and two tenants' reads can be identical strings.\n\t */\n\tscopeKey: string\n\t/** Scope caption and Site select; absent on an unscoped install. */\n\tscopes?: ViewScopes\n\t/**\n\t * The `scope` the URL may keep: the aggregate token this request honoured, else absent. The\n\t * client rewrites the address to match what was read.\n\t */\n\tscopeParam?: string\n\t/**\n\t * Where the view asks for the exclusion link of the reader's own scope, while\n\t * `capture.exclusion` is on; absent, the view offers no exclusion at all.\n\t */\n\texclusion?: { endpoint: string }\n\t/**\n\t * The reader works per site and has none selected (a scoped install that resolved no scope\n\t * for them), so the view asks for one instead of reporting that no source is connected.\n\t */\n\tneedsScope?: boolean\n}\n\n/**\n * `denied` is a value, not a thrown error, so the view renders its no-access message inside the\n * admin template instead of redirecting a signed-in reader.\n */\nexport type ViewPropsResult = { denied: true } | { denied: false; props: AnalyticsViewClientProps }\n\n/**\n * Goals the request's scope may see, mirroring the goals endpoint; a failed resolution falls back\n * to config goals only when unscoped.\n */\nconst resolveGoalsList = async (\n\truntime: AnalyticsRuntime,\n\treq: PayloadRequest,\n\tscope: string | null\n): Promise<ViewGoal[]> => {\n\ttry {\n\t\treturn await goalNamesFor({ runtime, req, scope })\n\t} catch (err) {\n\t\treq.payload.logger?.warn(`analytics: view goals listing failed: ${String(err)}`)\n\t\treturn runtime.scoped\n\t\t\t? []\n\t\t\t: (runtime.goals ?? []).map((goal) => ({ slug: goal.slug, name: goal.name }))\n\t}\n}\n\nconst emptySources = (): SourcesResponse => ({ defaultId: null, sources: [] })\n\n/**\n * Caption scope and Site select state. `own` resolves apart from `current` so the select keeps\n * naming the reader's own tenant while reads aggregate.\n */\nconst resolveScopes = async (args: {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\tgates: ScopeGates\n\tcurrent: string\n\town: string\n}): Promise<ViewScopes> => {\n\tconst { runtime, req, gates, current, own } = args\n\tconst ownLabel = await resolveOwnLabel(runtime, req, own)\n\treturn {\n\t\tcurrent,\n\t\town,\n\t\tcanAggregate: await gates.aggregate({ scope: PLATFORM_SCOPE }),\n\t\t...(ownLabel === undefined ? {} : { ownLabel }),\n\t}\n}\n\n/** What to call the request's own scope; the id stands wherever the host names nothing. */\nconst resolveOwnLabel = async (\n\truntime: AnalyticsRuntime,\n\treq: PayloadRequest,\n\tscope: string\n): Promise<string | undefined> => {\n\tif (!runtime.scopeLabel || scope === '' || scope === PLATFORM_SCOPE) {\n\t\treturn undefined\n\t}\n\ttry {\n\t\treturn (await runtime.scopeLabel({ req, scope })) ?? undefined\n\t} catch (err) {\n\t\treq.payload.logger?.warn(`analytics: scope.label failed: ${String(err)}`)\n\t\treturn undefined\n\t}\n}\n\n/** The `scope` a URL is allowed to carry into the view: an aggregate token, and nothing else. */\nconst requestedAggregate = (searchParams: ViewSearchParams | undefined): string | undefined => {\n\tconst raw = searchParams?.scope\n\tconst value = Array.isArray(raw) ? raw[0] : raw\n\treturn typeof value === 'string' && isAggregateToken(value) ? value : undefined\n}\n\n/**\n * The scope this request resolves to on its own; `''` for none, for a resolver that threw, and\n * for a tenant the user selected without belonging to it, whose name the view never shows.\n */\nconst ownScopeFor = async (\n\truntime: AnalyticsRuntime,\n\treq: PayloadRequest,\n\town: RequestedScope\n): Promise<string> => {\n\tif (own.ok) {\n\t\treturn own.scope ?? ''\n\t}\n\tif (own.reason !== 'unresolved') {\n\t\treturn ''\n\t}\n\ttry {\n\t\treturn (await resolveScopeFor(runtime, req)) ?? ''\n\t} catch {\n\t\treturn ''\n\t}\n}\n\n/** The admin view's `searchParams`, as Payload hands them to a server component. */\nexport type ViewSearchParams = { [key: string]: string | string[] | undefined }\n\n/**\n * Client shell props for one request. Host's `scope.resolve` is the one scope authority: the URL\n * may only ask to aggregate (granted by `access.crossScope.aggregate`); other `scope` values drop.\n */\nexport const resolveViewProps = async (\n\treq: PayloadRequest,\n\tresolved: ResolvedOptions,\n\tsearchParams?: ViewSearchParams\n): Promise<ViewPropsResult> => {\n\tif (!(await resolved.access.view({ req }))) {\n\t\treturn { denied: true }\n\t}\n\t// `false` cannot reach a render (the view is then never registered); it defaults anyway.\n\tconst view = resolved.view === false ? DEFAULT_VIEW : resolved.view\n\tconst runtime = getRuntime(req.payload)\n\tconst config = req.payload.config\n\tconst routes = analyticsRoutes(config)\n\tconst base = {\n\t\tdefaults: { range: view.defaultRange, metric: view.defaultMetric },\n\t\tendpoints: {\n\t\t\tquery: apiPath(config, routes.query),\n\t\t\trefresh: apiPath(config, routes.refresh),\n\t\t\tlive: apiPath(config, routes.live),\n\t\t\t...(resolved.providers.collection.enabled\n\t\t\t\t? { providerStatus: apiPath(config, routes.providerStatus) }\n\t\t\t\t: {}),\n\t\t},\n\t\tadminRoute: config.routes?.admin ?? '/admin',\n\t\tlocale: intlLocale(req.i18n.language),\n\t\t// The host's component is looked up by the view's body (`renderViewBody`), which hands it on.\n\t\tcountryFlags: resolved.countryFlags === true,\n\t\t...(resolved.capture.exclusion\n\t\t\t? { exclusion: { endpoint: apiPath(config, routes.exclusion) } }\n\t\t\t: {}),\n\t}\n\t// No runtime means the plugin is not installed on this instance: nothing is readable.\n\tif (!runtime) {\n\t\treturn {\n\t\t\tdenied: false,\n\t\t\tprops: {\n\t\t\t\t...base,\n\t\t\t\tsources: emptySources(),\n\t\t\t\tgoals: [],\n\t\t\t\ttimezone: DEFAULT_TIMEZONE,\n\t\t\t\tscopeKey: '',\n\t\t\t},\n\t\t}\n\t}\n\tconst gates = scopeGates(runtime, req)\n\tconst token = requestedAggregate(searchParams)\n\tconst ownRequested = await resolveRequestedScope({ runtime, req, gates })\n\tconst own = await ownScopeFor(runtime, req, ownRequested)\n\t// The aggregate belongs to the tenant it was chosen from; the host's selector can move while\n\t// the address stays open, so a token tagged with another falls back to the request's scope.\n\tconst aggregate = token !== undefined && aggregateFrom(token) === own\n\t// A wildcard this reader may not have degrades to their own scope rather than to nothing:\n\t// they are entitled to that read, and the client rewrites the address to match.\n\tlet requested = ownRequested\n\tif (aggregate) {\n\t\tconst all = await resolveRequestedScope({ runtime, req, gates, raw: PLATFORM_SCOPE })\n\t\tif (all.ok) {\n\t\t\trequested = all\n\t\t}\n\t}\n\tconst scope = requested.ok ? requested.scope : null\n\tconst scopeKey = scope ?? ''\n\tconst registryScope = scope === PLATFORM_SCOPE ? null : scope\n\t// `access.view` may be wider than `access.read`: goal names and scope names are read data too.\n\tconst readable = await readGate(runtime, req).catch(() => false)\n\tconst [sources, goals, timezone, currency, scopes] = await Promise.all([\n\t\trequested.ok\n\t\t\t? resolveSourcesForRequest(req, { gates, scope: requested.gated })\n\t\t\t: emptySources(),\n\t\trequested.ok && readable ? resolveGoalsList(runtime, req, scope) : [],\n\t\tresolveTimezoneFor(runtime, req, registryScope).catch(() => DEFAULT_TIMEZONE),\n\t\tresolveCurrencyFor(runtime, req, registryScope),\n\t\truntime.scoped === true && readable\n\t\t\t? resolveScopes({ runtime, req, gates, current: scopeKey, own })\n\t\t\t: undefined,\n\t])\n\treturn {\n\t\tdenied: false,\n\t\tprops: {\n\t\t\t...base,\n\t\t\tsources: {\n\t\t\t\tdefaultId: sources.defaultId,\n\t\t\t\tsources: sources.sources,\n\t\t\t\t...(sources.notice ? { notice: sources.notice } : {}),\n\t\t\t},\n\t\t\tgoals,\n\t\t\ttimezone,\n\t\t\tscopeKey,\n\t\t\t...(scope === PLATFORM_SCOPE && token !== undefined ? { scopeParam: token } : {}),\n\t\t\t...(!requested.ok && requested.reason === 'unresolved' ? { needsScope: true } : {}),\n\t\t\t...(currency ? { currency } : {}),\n\t\t\t...(scopes ? { scopes } : {}),\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2HA,MAAM,mBAAmB,OACxB,SACA,KACA,UACyB;CACzB,IAAI;EACH,OAAO,MAAM,aAAa;GAAE;GAAS;GAAK;EAAM,CAAC;CAClD,SAAS,KAAK;EACb,IAAI,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AAC;EACpF,IAAI,IAAI,IACP,YAAY;CAEd;CACA,MAAM,QAAQ,UAAU,KAAK,UAAU,QAAQ;CAC/C,MAAM,WAAW,SAAS;CAC1B,MAAM,gBAAgB,UAAA,MAA2B,OAAO;CAExD,MAAM,WAAW,MAAM,SAAS,SAAS,GAAG,EAAE,YAAY,KAAK;CAC/D,MAAM,CAAC,SAAS,OAAO,UAAU,UAAU,UAAU,MAAM,QAAQ,IAAI;EACtE,UAAU,KACP,yBAAyB,KAAK;GAAE;GAAO,OAAO,UAAU;EAAM,CAAC,IAC/D,aAAa;EAChB,UAAU,MAAM,WAAW,iBAAiB,SAAS,KAAK,KAAK,IAAI,CAAC;EACpE,mBAAmB,SAAS,KAAK,aAAa,EAAE,YAAA,KAA4B;EAC5E,mBAAmB,SAAS,KAAK,aAAa;EAC9C,QAAQ,WAAW,QAAQ,WACxB,cAAc;GAAE;GAAS;GAAK;GAAO,SAAS;GAAU;EAAI,CAAC,IAC7D,KAAA;CACJ,CAAC;CACD,OAAO;EACN,QAAQ;EACR,OAAO;GACN,GAAG;GACH,SAAS;IACR,WAAW,QAAQ;IACnB,SAAS,QAAQ;IACjB,GAAI,QAAQ,SAAS,EAAE,QAAQ,QAAQ,OAAO,IAAI,CAAC;GACpD;GACA;GACA;GACA;GACA,GAAI,UAAA,OAA4B,UAAU,KAAA,IAAY,EAAE,YAAY,MAAM,IAAI,CAAC;GAC/E,GAAI,CAAC,UAAU,MAAM,UAAU,WAAW,eAAe,EAAE,YAAY,KAAK,IAAI,CAAC;GACjF,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;GAC/B,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;EAC5B;CACD;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@10x-media/analytics",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.17",
|
|
4
4
|
"description": "Adapter-based analytics for Payload: providers, a native engine, dashboard widgets, and portable fields.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -176,12 +176,12 @@
|
|
|
176
176
|
"tsdown": "0.22.1",
|
|
177
177
|
"typescript": "5.9.3",
|
|
178
178
|
"vitest": "4.1.7",
|
|
179
|
-
"@10x-media/fields": "0.1.0-beta.
|
|
179
|
+
"@10x-media/fields": "0.1.0-beta.10",
|
|
180
180
|
"@10x-media/form-builder": "0.1.0-beta.27",
|
|
181
|
-
"@10x-media/tsconfig": "0.0.0",
|
|
182
|
-
"@10x-media/vitest-config": "0.0.0",
|
|
183
181
|
"@10x-media/payload-test-harness": "0.0.0",
|
|
184
|
-
"@10x-media/
|
|
182
|
+
"@10x-media/tsconfig": "0.0.0",
|
|
183
|
+
"@10x-media/tsdown-config": "0.0.0",
|
|
184
|
+
"@10x-media/vitest-config": "0.0.0"
|
|
185
185
|
},
|
|
186
186
|
"publishConfig": {
|
|
187
187
|
"access": "public"
|