@10x-media/analytics 1.0.0-beta.12 → 1.0.0-beta.14
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 +75 -0
- package/dist/adapters/ga4/ga4.d.ts +6 -0
- package/dist/adapters/ga4/ga4.js +3 -2
- package/dist/adapters/ga4/ga4.js.map +1 -1
- package/dist/adapters/plausible/plausible.d.ts +6 -0
- package/dist/adapters/plausible/plausible.js +2 -1
- package/dist/adapters/plausible/plausible.js.map +1 -1
- package/dist/adapters/posthog/posthog.d.ts +6 -0
- package/dist/adapters/posthog/posthog.js +21 -8
- package/dist/adapters/posthog/posthog.js.map +1 -1
- package/dist/adapters/umami/umami.d.ts +6 -0
- package/dist/adapters/umami/umami.js +2 -1
- package/dist/adapters/umami/umami.js.map +1 -1
- package/dist/capture/exclusionEndpoint.js +1 -1
- package/dist/capture/exclusionEndpoint.js.map +1 -1
- package/dist/capture/slots.js +3 -3
- package/dist/capture/slots.js.map +1 -1
- package/dist/capture/trackerConfig.js +11 -3
- package/dist/capture/trackerConfig.js.map +1 -1
- package/dist/charts/series.js +1 -1
- package/dist/core/adminOptions.js +6 -1
- package/dist/core/adminOptions.js.map +1 -1
- package/dist/core/capture.d.ts +3 -1
- package/dist/core/contract.d.ts +13 -1
- package/dist/core/contract.js.map +1 -1
- package/dist/core/options.d.ts +37 -5
- package/dist/core/options.js +6 -2
- package/dist/core/options.js.map +1 -1
- package/dist/core/registry.js.map +1 -1
- package/dist/core/scopeOptions.js +2 -0
- package/dist/core/scopeOptions.js.map +1 -1
- package/dist/core/scopedRead.js +170 -21
- package/dist/core/scopedRead.js.map +1 -1
- package/dist/core/sourceLabel.d.ts +10 -0
- package/dist/core/sourceLabel.js +63 -0
- package/dist/core/sourceLabel.js.map +1 -0
- package/dist/core/sourceOptions.js +18 -6
- package/dist/core/sourceOptions.js.map +1 -1
- package/dist/core/sourcePolicy.d.ts +55 -0
- package/dist/core/sourcePolicy.js +51 -0
- package/dist/core/sourcePolicy.js.map +1 -0
- package/dist/exports/adapters/contract.d.ts +2 -1
- package/dist/exports/adapters/ga4.d.ts +3 -2
- package/dist/exports/adapters/native.d.ts +3 -2
- package/dist/exports/adapters/plausible.d.ts +3 -2
- package/dist/exports/adapters/posthog.d.ts +3 -2
- package/dist/exports/adapters/umami.d.ts +3 -2
- package/dist/exports/client.d.ts +7 -5
- package/dist/exports/client.js +2 -1
- package/dist/exports/next.d.ts +3 -2
- package/dist/exports/rsc.d.ts +7 -6
- package/dist/exports/testing.d.ts +3 -2
- package/dist/exports/types.d.ts +12 -8
- package/dist/fields/AnalyticsPanelClient.js.map +1 -1
- package/dist/fields/AnalyticsPanelField.d.ts +1 -1
- package/dist/fields/AnalyticsPanelField.js +3 -1
- package/dist/fields/AnalyticsPanelField.js.map +1 -1
- package/dist/fields/AnalyticsStatField.d.ts +1 -1
- package/dist/fields/AnalyticsStatField.js +1 -1
- package/dist/fields/PanelContent.js +6 -1
- package/dist/fields/PanelContent.js.map +1 -1
- package/dist/fields/config/fetchSources.d.ts +3 -0
- package/dist/fields/config/fetchSources.js +5 -3
- package/dist/fields/config/fetchSources.js.map +1 -1
- package/dist/fields/readForDocument.d.ts +5 -4
- package/dist/fields/readForDocument.js +6 -2
- package/dist/fields/readForDocument.js.map +1 -1
- package/dist/goals/collection.js +4 -31
- package/dist/goals/collection.js.map +1 -1
- package/dist/goals/resolver.js +2 -2
- package/dist/goals/trackGoalAction.js +1 -1
- package/dist/index.d.ts +14 -11
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/native/geo/maxmindResolver.js +1 -1
- package/dist/native/ingest/normalizeEvent.js +1 -1
- package/dist/native/nativeAdapter.d.ts +6 -0
- package/dist/native/nativeAdapter.js +3 -2
- package/dist/native/nativeAdapter.js.map +1 -1
- package/dist/plugin/createRuntime.js +6 -3
- package/dist/plugin/createRuntime.js.map +1 -1
- package/dist/plugin/documentEndpoint.js +1 -0
- package/dist/plugin/documentEndpoint.js.map +1 -1
- package/dist/plugin/pluginCollections.js +11 -5
- package/dist/plugin/pluginCollections.js.map +1 -1
- package/dist/plugin/queryEndpoint.js +1 -1
- package/dist/plugin/queryEndpoint.js.map +1 -1
- package/dist/plugin/readContextForRequest.d.ts +11 -0
- package/dist/plugin/readContextForRequest.js +25 -15
- package/dist/plugin/readContextForRequest.js.map +1 -1
- package/dist/plugin/runtime.js +13 -5
- package/dist/plugin/runtime.js.map +1 -1
- package/dist/plugin/sourcesEndpoint.js +8 -9
- package/dist/plugin/sourcesEndpoint.js.map +1 -1
- package/dist/providers/ProvidersListNotice.d.ts +11 -0
- package/dist/providers/ProvidersListNotice.js +36 -0
- package/dist/providers/ProvidersListNotice.js.map +1 -0
- package/dist/providers/collection.d.ts +9 -1
- package/dist/providers/collection.js +111 -42
- package/dist/providers/collection.js.map +1 -1
- package/dist/providers/factory.d.ts +1 -1
- package/dist/providers/factory.js +8 -11
- package/dist/providers/factory.js.map +1 -1
- package/dist/providers/probe.js +5 -1
- package/dist/providers/probe.js.map +1 -1
- package/dist/providers/registry.js +49 -39
- package/dist/providers/registry.js.map +1 -1
- package/dist/providers/resolver.js +6 -3
- package/dist/providers/resolver.js.map +1 -1
- package/dist/providers/scopeUnique.js +41 -0
- package/dist/providers/scopeUnique.js.map +1 -0
- package/dist/query/fetchQuery.d.ts +1 -1
- package/dist/surfacing/rebucket.js +1 -1
- package/dist/tracker/config.d.ts +5 -0
- package/dist/tracker/config.js.map +1 -1
- package/dist/tracker/sinks/createSink.js +4 -1
- package/dist/tracker/sinks/createSink.js.map +1 -1
- package/dist/tracker/sinks/ga4.js +2 -2
- package/dist/tracker/sinks/posthog.js +30 -2
- package/dist/tracker/sinks/posthog.js.map +1 -1
- package/dist/tracker/sinks/vendor.js +2 -2
- package/dist/tracker/sinks/vendor.js.map +1 -1
- package/dist/translations/ar.js +6 -0
- package/dist/translations/ar.js.map +1 -1
- package/dist/translations/de.js +6 -0
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +6 -0
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +6 -0
- package/dist/translations/es.js.map +1 -1
- package/dist/translations/fr.js +6 -0
- package/dist/translations/fr.js.map +1 -1
- package/dist/translations/id.js +6 -0
- package/dist/translations/id.js.map +1 -1
- package/dist/translations/keys.d.ts +6 -0
- package/dist/translations/keys.js +7 -1
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +6 -0
- package/dist/translations/ko.js.map +1 -1
- package/dist/translations/pt.js +6 -0
- package/dist/translations/pt.js.map +1 -1
- package/dist/translations/ru.js +6 -0
- package/dist/translations/ru.js.map +1 -1
- package/dist/translations/uk.js +6 -0
- package/dist/translations/uk.js.map +1 -1
- package/dist/translations/zh.js +6 -0
- package/dist/translations/zh.js.map +1 -1
- package/dist/ui/analytics.css +5 -0
- package/dist/ui/components/SourcesNoticeBanner.js +20 -0
- package/dist/ui/components/SourcesNoticeBanner.js.map +1 -0
- package/dist/view/ViewRoot.js +2 -0
- package/dist/view/ViewRoot.js.map +1 -1
- package/dist/view/registerView.js +5 -4
- package/dist/view/registerView.js.map +1 -1
- package/dist/view/viewContext.d.ts +1 -1
- package/dist/view/viewProps.d.ts +1 -1
- package/dist/view/viewProps.js +3 -2
- package/dist/view/viewProps.js.map +1 -1
- package/dist/widgets/AnalyticsBreakdownWidget.js +1 -0
- package/dist/widgets/AnalyticsBreakdownWidget.js.map +1 -1
- package/dist/widgets/AnalyticsGoalsWidget.js +1 -0
- package/dist/widgets/AnalyticsGoalsWidget.js.map +1 -1
- package/dist/widgets/AnalyticsMetricWidget.js +1 -0
- package/dist/widgets/AnalyticsMetricWidget.js.map +1 -1
- package/dist/widgets/AnalyticsRealtimeWidget.js +15 -7
- package/dist/widgets/AnalyticsRealtimeWidget.js.map +1 -1
- package/dist/widgets/AnalyticsTrendWidget.js +1 -0
- package/dist/widgets/AnalyticsTrendWidget.js.map +1 -1
- package/dist/widgets/defaultLayout.d.ts +26 -0
- package/dist/widgets/defaultLayout.js +51 -0
- package/dist/widgets/defaultLayout.js.map +1 -0
- package/dist/widgets/notices.js +1 -0
- package/dist/widgets/notices.js.map +1 -1
- package/dist/widgets/prepareWidgetRead.d.ts +14 -1
- package/dist/widgets/prepareWidgetRead.js +6 -2
- package/dist/widgets/prepareWidgetRead.js.map +1 -1
- package/dist/widgets/readForWidget.d.ts +4 -4
- package/dist/widgets/readForWidget.js +3 -1
- package/dist/widgets/readForWidget.js.map +1 -1
- package/dist/widgets/readForWidgetBreakdown.d.ts +4 -4
- package/dist/widgets/readForWidgetBreakdown.js +3 -1
- package/dist/widgets/readForWidgetBreakdown.js.map +1 -1
- package/dist/widgets/readForWidgetGoals.d.ts +4 -4
- package/dist/widgets/readForWidgetGoals.js +3 -1
- package/dist/widgets/readForWidgetGoals.js.map +1 -1
- package/dist/widgets/readForWidgetRealtime.d.ts +4 -3
- package/dist/widgets/readForWidgetRealtime.js +3 -1
- package/dist/widgets/readForWidgetRealtime.js.map +1 -1
- package/dist/widgets/readForWidgetSeries.d.ts +4 -4
- package/dist/widgets/readForWidgetSeries.js +3 -1
- package/dist/widgets/readForWidgetSeries.js.map +1 -1
- package/dist/widgets/registerWidgets.js +3 -1
- package/dist/widgets/registerWidgets.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/providers/ProvidersListNotice.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The providers list's note to a tenant reading the platform's source until it adds its own. Read
|
|
4
|
+
* past the shared cache: this list is where a source is added, and a cached listing outlives that.
|
|
5
|
+
*
|
|
6
|
+
* @beta
|
|
7
|
+
*/
|
|
8
|
+
declare function ProvidersListNotice(): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ProvidersListNotice };
|
|
11
|
+
//# sourceMappingURL=ProvidersListNotice.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { analyticsRoutes } from "../plugin/routes.js";
|
|
3
|
+
import { apiPath } from "../plugin/apiPath.js";
|
|
4
|
+
import { useRequestScope } from "../ui/data/useRequestScope.js";
|
|
5
|
+
import { requestSources } from "../fields/config/fetchSources.js";
|
|
6
|
+
import { SourcesNoticeBanner } from "../ui/components/SourcesNoticeBanner.js";
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
import { useConfig } from "@payloadcms/ui";
|
|
10
|
+
//#region src/providers/ProvidersListNotice.tsx
|
|
11
|
+
/**
|
|
12
|
+
* The providers list's note to a tenant reading the platform's source until it adds its own. Read
|
|
13
|
+
* past the shared cache: this list is where a source is added, and a cached listing outlives that.
|
|
14
|
+
*
|
|
15
|
+
* @beta
|
|
16
|
+
*/
|
|
17
|
+
function ProvidersListNotice() {
|
|
18
|
+
const { config } = useConfig();
|
|
19
|
+
const url = apiPath(config, analyticsRoutes(config).sources);
|
|
20
|
+
const scope = useRequestScope();
|
|
21
|
+
const [read, setRead] = useState();
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!scope) return;
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
requestSources(url, controller.signal).then((listing) => setRead({
|
|
26
|
+
scope,
|
|
27
|
+
notice: listing.notice
|
|
28
|
+
}), () => {});
|
|
29
|
+
return () => controller.abort();
|
|
30
|
+
}, [url, scope]);
|
|
31
|
+
return /* @__PURE__ */ jsx(SourcesNoticeBanner, { notice: read?.scope === scope ? read.notice : void 0 });
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { ProvidersListNotice };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=ProvidersListNotice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProvidersListNotice.js","names":[],"sources":["../../src/providers/ProvidersListNotice.tsx"],"sourcesContent":["'use client'\n\nimport { useConfig } from '@payloadcms/ui'\nimport { useEffect, useState } from 'react'\nimport { requestSources, type SourcesNotice } from '../fields/config/fetchSources'\nimport { apiPath } from '../plugin/apiPath'\nimport { analyticsRoutes } from '../plugin/routes'\nimport { SourcesNoticeBanner } from '../ui/components/SourcesNoticeBanner'\nimport { useRequestScope } from '../ui/data/useRequestScope'\n\n/**\n * The providers list's note to a tenant reading the platform's source until it adds its own. Read\n * past the shared cache: this list is where a source is added, and a cached listing outlives that.\n *\n * @beta\n */\nexport function ProvidersListNotice() {\n\tconst { config } = useConfig()\n\tconst url = apiPath(config, analyticsRoutes(config).sources)\n\tconst scope = useRequestScope()\n\tconst [read, setRead] = useState<{ scope: string; notice: SourcesNotice | undefined }>()\n\n\tuseEffect(() => {\n\t\tif (!scope) {\n\t\t\treturn\n\t\t}\n\t\tconst controller = new AbortController()\n\t\t// A listing that fails says nothing here: the list itself works without the note.\n\t\trequestSources(url, controller.signal).then(\n\t\t\t(listing) => setRead({ scope, notice: listing.notice }),\n\t\t\t() => {}\n\t\t)\n\t\treturn () => controller.abort()\n\t}, [url, scope])\n\n\treturn <SourcesNoticeBanner notice={read?.scope === scope ? read.notice : undefined} />\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,sBAAsB;CACrC,MAAM,EAAE,WAAW,UAAU;CAC7B,MAAM,MAAM,QAAQ,QAAQ,gBAAgB,MAAM,EAAE,OAAO;CAC3D,MAAM,QAAQ,gBAAgB;CAC9B,MAAM,CAAC,MAAM,WAAW,SAA+D;CAEvF,gBAAgB;EACf,IAAI,CAAC,OACJ;EAED,MAAM,aAAa,IAAI,gBAAgB;EAEvC,eAAe,KAAK,WAAW,MAAM,EAAE,MACrC,YAAY,QAAQ;GAAE;GAAO,QAAQ,QAAQ;EAAO,CAAC,SAChD,CAAC,CACR;EACA,aAAa,WAAW,MAAM;CAC/B,GAAG,CAAC,KAAK,KAAK,CAAC;CAEf,OAAO,oBAAC,qBAAD,EAAqB,QAAQ,MAAM,UAAU,QAAQ,KAAK,SAAS,KAAA,EAAY,CAAA;AACvF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CollectionFieldOverride } from "../plugin/collectionFields.js";
|
|
2
|
+
import { ProviderId } from "./factory.js";
|
|
2
3
|
import { CollectionConfig, Field, FieldAccess, PayloadRequest, TextField, TextareaField } from "payload";
|
|
3
4
|
|
|
4
5
|
//#region src/providers/collection.d.ts
|
|
@@ -14,6 +15,8 @@ interface ProviderCollectionFieldOverrides {
|
|
|
14
15
|
name?: ProviderFieldOverride;
|
|
15
16
|
provider?: ProviderFieldOverride;
|
|
16
17
|
enabled?: ProviderFieldOverride;
|
|
18
|
+
/** The "Default for this site" checkbox, which only a scoped install's collection carries. */
|
|
19
|
+
isDefault?: ProviderFieldOverride;
|
|
17
20
|
}
|
|
18
21
|
/** Field access on the fields that decide where a provider document connects (`CONNECTION_PATHS`). */
|
|
19
22
|
interface ConnectionFieldAccess {
|
|
@@ -29,7 +32,7 @@ interface ProviderFieldsOptions {
|
|
|
29
32
|
*/
|
|
30
33
|
buildSecret?: BuildSecretField;
|
|
31
34
|
/** Replaces one of the default fields, applied per field. */
|
|
32
|
-
fields?: ProviderCollectionFieldOverrides
|
|
35
|
+
fields?: Omit<ProviderCollectionFieldOverrides, 'isDefault'>;
|
|
33
36
|
/** Adds the plugin's own hidden `scope` text field. Off by default. */
|
|
34
37
|
scopeField?: boolean;
|
|
35
38
|
/**
|
|
@@ -42,6 +45,11 @@ interface ProviderFieldsOptions {
|
|
|
42
45
|
* and update alike, or `{ create, update }`.
|
|
43
46
|
*/
|
|
44
47
|
connectionAccess?: ConnectionAccess;
|
|
48
|
+
/**
|
|
49
|
+
* The provider types the select offers, the first being its default; a document saved with any
|
|
50
|
+
* other type is refused. Default: every type, `native` first.
|
|
51
|
+
*/
|
|
52
|
+
types?: ProviderId[];
|
|
45
53
|
}
|
|
46
54
|
/**
|
|
47
55
|
* Provider-settings fields alone, for a host that stores them elsewhere and feeds them back through
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { kindOf } from "../core/values.js";
|
|
1
|
+
import { isOneOf, kindOf, listOf } from "../core/values.js";
|
|
2
2
|
import { keys } from "../translations/keys.js";
|
|
3
3
|
import { optionsObject } from "../core/optionChecks.js";
|
|
4
4
|
import { providerCreateAccess, providerRowAccess } from "./access.js";
|
|
5
|
-
import { labelForKey } from "../translations/server.js";
|
|
5
|
+
import { asTranslate, labelForKey } from "../translations/server.js";
|
|
6
6
|
import { builtInStaticLabel } from "../translations/staticLabel.js";
|
|
7
7
|
import { validateMeasurementId } from "../adapters/ga4/measurementId.js";
|
|
8
8
|
import { validateScriptId } from "../adapters/plausible/scriptId.js";
|
|
@@ -10,10 +10,15 @@ import { validateCurrency } from "../goals/currency.js";
|
|
|
10
10
|
import { overrideField } from "../plugin/collectionFields.js";
|
|
11
11
|
import { docScope } from "../plugin/scopeChange.js";
|
|
12
12
|
import { validateProviderHost } from "./hosts.js";
|
|
13
|
+
import { PROVIDER_IDS } from "./factory.js";
|
|
13
14
|
import { retargetSecrets } from "./retarget.js";
|
|
15
|
+
import { takenInScope } from "./scopeUnique.js";
|
|
14
16
|
import { stampScope } from "./stampScope.js";
|
|
17
|
+
import { ValidationError, validations } from "payload";
|
|
15
18
|
//#region src/providers/collection.ts
|
|
16
19
|
const PROVIDERS_SLUG = "analytics-providers";
|
|
20
|
+
/** The list's note to a tenant reading the platform's source in `fallback`. */
|
|
21
|
+
const PROVIDERS_LIST_NOTICE_COMPONENT = "@10x-media/analytics/client#ProvidersListNotice";
|
|
17
22
|
/** `connectionAccess` in its object form, checked at boot; undefined while unset. */
|
|
18
23
|
const connectionFieldAccess = (path, option) => {
|
|
19
24
|
if (option === void 0) return;
|
|
@@ -33,6 +38,22 @@ const connectionFieldAccess = (path, option) => {
|
|
|
33
38
|
...update ? { update } : {}
|
|
34
39
|
};
|
|
35
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* The provider types documents may be saved with: every type `available` serves, narrowed to
|
|
43
|
+
* `option` in its order when given, checked at boot.
|
|
44
|
+
*/
|
|
45
|
+
const servedProviderTypes = (path, option, available = PROVIDER_IDS) => {
|
|
46
|
+
if (option === void 0) return [...available];
|
|
47
|
+
if (!Array.isArray(option)) throw new Error(`analytics: ${path} must be a list of provider types such as ['plausible', 'umami'], got ${kindOf(option)}`);
|
|
48
|
+
const listed = [];
|
|
49
|
+
for (const type of option) {
|
|
50
|
+
if (!isOneOf(PROVIDER_IDS, type)) throw new Error(`analytics: ${path} lists ${kindOf(type)}, which is no provider type; use ${listOf(PROVIDER_IDS.map((id) => `"${id}"`))}`);
|
|
51
|
+
listed.push(type);
|
|
52
|
+
}
|
|
53
|
+
const served = [...new Set(listed)].filter((type) => available.includes(type));
|
|
54
|
+
if (served.length === 0) throw new Error(`analytics: ${path} leaves no provider type this install serves, which are ${listOf(available.map((id) => `"${id}"`))}; "native" needs native() in adapters`);
|
|
55
|
+
return served;
|
|
56
|
+
};
|
|
36
57
|
const plainSecret = (source) => [source];
|
|
37
58
|
const textField = (name, label, opts = {}) => ({
|
|
38
59
|
name,
|
|
@@ -124,44 +145,53 @@ const nameField = () => ({
|
|
|
124
145
|
label: labelForKey(keys.providerFieldName),
|
|
125
146
|
admin: { description: labelForKey(keys.providerFieldNameHelp) }
|
|
126
147
|
});
|
|
148
|
+
const PROVIDER_NAMES = {
|
|
149
|
+
native: keys.providerNameNative,
|
|
150
|
+
plausible: keys.providerNamePlausible,
|
|
151
|
+
umami: keys.providerNameUmami,
|
|
152
|
+
ga4: keys.providerNameGa4,
|
|
153
|
+
posthog: keys.providerNamePosthog
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Names the refusal of a stored type the install no longer serves (native() removed, `types`
|
|
157
|
+
* narrowed), which the select's own check would only call an invalid selection.
|
|
158
|
+
*/
|
|
159
|
+
const validateServed = (types) => (value, options) => typeof value === "string" && value !== "" && !types.includes(value) ? asTranslate(options.req.t)(keys.providerErrorTypeUnserved) : validations.select(value, options);
|
|
160
|
+
/**
|
|
161
|
+
* The values a narrowed select offers: the served types, and a stored type no longer served so its
|
|
162
|
+
* save is refused by name. Values only, since form state carries the result to the client, where
|
|
163
|
+
* a label function cannot cross; Payload's select reads nothing else from it.
|
|
164
|
+
*/
|
|
165
|
+
const offeredTypes = (types, stored) => isOneOf(PROVIDER_IDS, stored) && !types.includes(stored) ? [...types, stored] : [...types];
|
|
127
166
|
/**
|
|
128
167
|
* Sits in the sidebar with `enabled`: every body field is conditional on the provider and
|
|
129
|
-
* meaningless while `enabled` is off.
|
|
168
|
+
* meaningless while `enabled` is off. The schema keeps every type (options, groups, a static
|
|
169
|
+
* default while `native` leads), so narrowing the offer neither alters a column nor drops settings.
|
|
130
170
|
*/
|
|
131
|
-
const providerField = (access, staticLabel) =>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
label: labelForKey(keys.providerNameGa4),
|
|
153
|
-
value: "ga4"
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
label: labelForKey(keys.providerNamePosthog),
|
|
157
|
-
value: "posthog"
|
|
171
|
+
const providerField = (access, staticLabel, types) => {
|
|
172
|
+
const [first = "native"] = types;
|
|
173
|
+
const narrowed = types.length < PROVIDER_IDS.length;
|
|
174
|
+
return {
|
|
175
|
+
name: "provider",
|
|
176
|
+
type: "select",
|
|
177
|
+
required: true,
|
|
178
|
+
label: labelForKey(keys.providerFieldProvider),
|
|
179
|
+
defaultValue: first === "native" ? first : () => first,
|
|
180
|
+
...access ? { access } : {},
|
|
181
|
+
...narrowed ? {
|
|
182
|
+
validate: validateServed(types),
|
|
183
|
+
filterOptions: ({ data }) => offeredTypes(types, data?.provider)
|
|
184
|
+
} : {},
|
|
185
|
+
options: PROVIDER_IDS.map((type) => ({
|
|
186
|
+
label: labelForKey(PROVIDER_NAMES[type]),
|
|
187
|
+
value: type
|
|
188
|
+
})),
|
|
189
|
+
admin: {
|
|
190
|
+
position: "sidebar",
|
|
191
|
+
description: staticLabel(keys.providerFieldProviderHelp)
|
|
158
192
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
position: "sidebar",
|
|
162
|
-
description: staticLabel(keys.providerFieldProviderHelp)
|
|
163
|
-
}
|
|
164
|
-
});
|
|
193
|
+
};
|
|
194
|
+
};
|
|
165
195
|
const enabledField = () => ({
|
|
166
196
|
name: "enabled",
|
|
167
197
|
type: "checkbox",
|
|
@@ -172,12 +202,45 @@ const enabledField = () => ({
|
|
|
172
202
|
description: labelForKey(keys.providerFieldEnabledHelp)
|
|
173
203
|
}
|
|
174
204
|
});
|
|
205
|
+
const isDefaultField = (access) => ({
|
|
206
|
+
name: "isDefault",
|
|
207
|
+
type: "checkbox",
|
|
208
|
+
defaultValue: false,
|
|
209
|
+
label: labelForKey(keys.providerFieldIsDefault),
|
|
210
|
+
...access ? { access } : {},
|
|
211
|
+
admin: {
|
|
212
|
+
position: "sidebar",
|
|
213
|
+
description: labelForKey(keys.providerFieldIsDefaultHelp)
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
/**
|
|
217
|
+
* At most one document per scope is the default, checked at collection level so a replaced
|
|
218
|
+
* `isDefault` field keeps it. No index backs it: a unique one would also cover the unflagged rows.
|
|
219
|
+
*/
|
|
220
|
+
const checkSingleDefault = (args) => {
|
|
221
|
+
return async ({ data, originalDoc, req }) => {
|
|
222
|
+
if ((data?.isDefault ?? originalDoc?.isDefault) !== true) return data;
|
|
223
|
+
if (await takenInScope(args, {
|
|
224
|
+
data,
|
|
225
|
+
originalDoc,
|
|
226
|
+
req
|
|
227
|
+
}, { isDefault: { equals: true } })) throw new ValidationError({
|
|
228
|
+
collection: args.slug,
|
|
229
|
+
errors: [{
|
|
230
|
+
label: labelForKey(keys.providerFieldIsDefault),
|
|
231
|
+
message: asTranslate(req.t)(keys.providerErrorDefaultTaken),
|
|
232
|
+
path: "isDefault"
|
|
233
|
+
}]
|
|
234
|
+
});
|
|
235
|
+
return data;
|
|
236
|
+
};
|
|
237
|
+
};
|
|
175
238
|
/**
|
|
176
239
|
* Provider-settings fields alone, for a host that stores them elsewhere and feeds them back through
|
|
177
240
|
* `providers.resolve`; {@link adapterFromProviderDoc} reads the result as is.
|
|
178
241
|
*/
|
|
179
|
-
const analyticsProviderFields = (options = {}) => providerFields(options, builtInStaticLabel);
|
|
180
|
-
const providerFields = (options, staticLabel) => {
|
|
242
|
+
const analyticsProviderFields = (options = {}) => providerFields(options, builtInStaticLabel, { types: servedProviderTypes("analyticsProviderFields({ types })", options.types) });
|
|
243
|
+
const providerFields = (options, staticLabel, list) => {
|
|
181
244
|
const buildSecret = options.buildSecret ?? plainSecret;
|
|
182
245
|
const access = connectionFieldAccess("analyticsProviderFields({ connectionAccess })", options.connectionAccess);
|
|
183
246
|
const allowPrivateNetwork = options.allowPrivateNetwork === true;
|
|
@@ -189,8 +252,9 @@ const providerFields = (options, staticLabel) => {
|
|
|
189
252
|
});
|
|
190
253
|
return [
|
|
191
254
|
overrideField(nameField(), options.fields?.name),
|
|
192
|
-
overrideField(providerField(access, staticLabel), options.fields?.provider),
|
|
255
|
+
overrideField(providerField(access, staticLabel, list.types), options.fields?.provider),
|
|
193
256
|
overrideField(enabledField(), options.fields?.enabled),
|
|
257
|
+
...list.isDefault ? [list.isDefault] : [],
|
|
194
258
|
...scopeField(options.scopeField === true),
|
|
195
259
|
nativeNote(),
|
|
196
260
|
providerGroup("plausible", keys.providerNamePlausible, [
|
|
@@ -316,7 +380,8 @@ const buildProvidersCollection = (args) => {
|
|
|
316
380
|
"enabled"
|
|
317
381
|
],
|
|
318
382
|
group: staticLabel(keys.adminGroup),
|
|
319
|
-
description: staticLabel(keys.providersCollectionDescription)
|
|
383
|
+
description: staticLabel(keys.providersCollectionDescription),
|
|
384
|
+
...args.listNotice ? { components: { beforeList: [PROVIDERS_LIST_NOTICE_COMPONENT] } } : {}
|
|
320
385
|
},
|
|
321
386
|
access: {
|
|
322
387
|
read: providerRowAccess(args),
|
|
@@ -326,6 +391,7 @@ const buildProvidersCollection = (args) => {
|
|
|
326
391
|
...args.access
|
|
327
392
|
},
|
|
328
393
|
hooks: {
|
|
394
|
+
...args.scoped ? { beforeValidate: [checkSingleDefault(args)] } : {},
|
|
329
395
|
beforeChange: [stampScope(args), retargetSecrets({
|
|
330
396
|
scopeField: args.scopeField,
|
|
331
397
|
isSealed: args.isSealed
|
|
@@ -348,11 +414,14 @@ const buildProvidersCollection = (args) => {
|
|
|
348
414
|
scopeField: args.scopeField === "scope",
|
|
349
415
|
allowPrivateNetwork: args.allowPrivateNetwork === true,
|
|
350
416
|
...args.connectionAccess ? { connectionAccess: args.connectionAccess } : {}
|
|
351
|
-
}, staticLabel
|
|
417
|
+
}, staticLabel, {
|
|
418
|
+
types: args.types ?? PROVIDER_IDS,
|
|
419
|
+
...args.scoped ? { isDefault: overrideField(isDefaultField(args.defaultAccess), args.fields?.isDefault) } : {}
|
|
420
|
+
})
|
|
352
421
|
};
|
|
353
422
|
return args.overrides ? args.overrides(collection) : collection;
|
|
354
423
|
};
|
|
355
424
|
//#endregion
|
|
356
|
-
export { PROVIDERS_SLUG, analyticsProviderFields, buildProvidersCollection, connectionFieldAccess };
|
|
425
|
+
export { PROVIDERS_SLUG, analyticsProviderFields, buildProvidersCollection, connectionFieldAccess, servedProviderTypes };
|
|
357
426
|
|
|
358
427
|
//# sourceMappingURL=collection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.js","names":[],"sources":["../../src/providers/collection.ts"],"sourcesContent":["import type {\n\tCollectionConfig,\n\tField,\n\tFieldAccess,\n\tPayloadRequest,\n\tTextareaField,\n\tTextField,\n\tTextFieldSingleValidation,\n} from 'payload'\nimport { validateMeasurementId } from '../adapters/ga4/measurementId'\nimport { validateScriptId } from '../adapters/plausible/scriptId'\nimport { optionsObject } from '../core/optionChecks'\nimport { kindOf } from '../core/values'\nimport { validateCurrency } from '../goals/currency'\nimport { type CollectionFieldOverride, overrideField } from '../plugin/collectionFields'\nimport { docScope, type ScopeChange } from '../plugin/scopeChange'\nimport { keys, type SingularKey, type TranslationKey } from '../translations/keys'\nimport { labelForKey } from '../translations/server'\nimport { builtInStaticLabel, type StaticLabelFor } from '../translations/staticLabel'\nimport { type ProviderAccessArgs, providerCreateAccess, providerRowAccess } from './access'\nimport type { ProviderId } from './factory'\nimport { validateProviderHost } from './hosts'\nimport { retargetSecrets } from './retarget'\nimport { stampScope } from './stampScope'\n\nexport const PROVIDERS_SLUG = 'analytics-providers'\n\n/** Builds the sealed variant of a secret source field; injected so the fields peer stays lazy. */\nexport type BuildSecretField = (source: TextField | TextareaField) => Field[]\n\n/**\n * Replaces a default field; it receives the plugin's own field to spread and may return any field\n * type (a `row`, a `collapsible`) that still holds a field of that name.\n */\nexport type ProviderFieldOverride = CollectionFieldOverride\n\nexport interface ProviderCollectionFieldOverrides {\n\tname?: ProviderFieldOverride\n\tprovider?: ProviderFieldOverride\n\tenabled?: ProviderFieldOverride\n}\n\n/** Field access on the fields that decide where a provider document connects (`CONNECTION_PATHS`). */\nexport interface ConnectionFieldAccess {\n\tcreate?: FieldAccess\n\tupdate?: FieldAccess\n}\n\n/** One field access function for create and update alike, or `{ create, update }`. */\nexport type ConnectionAccess = FieldAccess | ConnectionFieldAccess\n\n/** `connectionAccess` in its object form, checked at boot; undefined while unset. */\nexport const connectionFieldAccess = (\n\tpath: string,\n\toption: ConnectionAccess | undefined\n): ConnectionFieldAccess | undefined => {\n\tif (option === undefined) {\n\t\treturn undefined\n\t}\n\tif (typeof option === 'function') {\n\t\treturn { create: option, update: option }\n\t}\n\tconst halves = optionsObject(option, {\n\t\tpath,\n\t\tknown: ['create', 'update'],\n\t\texample: 'a function, or { create, update } with a function in each',\n\t})\n\tfor (const [half, access] of Object.entries(halves)) {\n\t\tif (access !== undefined && typeof access !== 'function') {\n\t\t\tthrow new Error(\n\t\t\t\t`analytics: ${path}.${half} must be a field access function, got ${kindOf(access)}`\n\t\t\t)\n\t\t}\n\t}\n\tconst { create, update } = option\n\treturn { ...(create ? { create } : {}), ...(update ? { update } : {}) }\n}\n\nexport interface BuildProvidersCollectionArgs extends ProviderAccessArgs {\n\tslug: string\n\taccess?: Partial<CollectionConfig['access']>\n\t/** Per-field overrides, applied before the whole-collection `overrides`. */\n\tfields?: ProviderCollectionFieldOverrides\n\toverrides?: (collection: CollectionConfig) => CollectionConfig\n\t/**\n\t * Called after any change or delete with the scopes the write touched and the request that\n\t * wrote, so that request's own Payload instance reads those scopes again once the write commits.\n\t */\n\tonChange: (change: ScopeChange, req: PayloadRequest) => void | Promise<void>\n\tbuildSecret: BuildSecretField\n\t/** The fields plugin's test for a sealed value, which tells a resent secret from a kept one. */\n\tisSealed: (value: unknown) => boolean\n\t/** `providers.hosts.allowPrivateNetwork`: the `host` fields accept `http://` too. */\n\tallowPrivateNetwork?: boolean\n\tconnectionAccess?: ConnectionFieldAccess\n\t/** The install's static labels; the built-in strings alone when absent. */\n\tstaticLabel?: StaticLabelFor\n}\n\nconst plainSecret: BuildSecretField = (source) => [source]\n\nconst textField = (\n\tname: string,\n\tlabel: TranslationKey,\n\topts: { width?: string; help?: TranslationKey; access?: ConnectionFieldAccess } = {}\n): Field => ({\n\tname,\n\ttype: 'text',\n\tlabel: labelForKey(label),\n\t...(opts.access ? { access: opts.access } : {}),\n\t...(opts.width || opts.help\n\t\t? {\n\t\t\t\tadmin: {\n\t\t\t\t\t...(opts.width ? { width: opts.width } : {}),\n\t\t\t\t\t...(opts.help ? { description: labelForKey(opts.help) } : {}),\n\t\t\t\t},\n\t\t\t}\n\t\t: {}),\n})\n\n/**\n * A sealed credential. Its help is a string per locale: Payload drops a function description from\n * the client field, which the write-only editor renders.\n */\nconst secretField = (\n\tbuildSecret: BuildSecretField,\n\tstaticLabel: StaticLabelFor,\n\topts: { name: string; label: TranslationKey; help: SingularKey; width?: string }\n): Field[] =>\n\tbuildSecret({\n\t\tname: opts.name,\n\t\ttype: 'text',\n\t\tlabel: labelForKey(opts.label),\n\t\tadmin: {\n\t\t\tdescription: staticLabel(opts.help),\n\t\t\t...(opts.width ? { width: opts.width } : {}),\n\t\t},\n\t})\n\n/**\n * Public capture config, plain text because the tracker config serves it to the browser. An adapter\n * declares `capture` only once its public field is filled.\n */\nconst captureField = (\n\tname: string,\n\tlabel: TranslationKey,\n\topts: { width?: string; validate?: TextFieldSingleValidation; help?: TranslationKey } = {}\n): Field => ({\n\tname,\n\ttype: 'text',\n\tlabel: labelForKey(label),\n\t...(opts.validate ? { validate: opts.validate } : {}),\n\tadmin: {\n\t\tdescription: labelForKey(opts.help ?? keys.providerFieldCaptureHelp),\n\t\t...(opts.width ? { width: opts.width } : {}),\n\t},\n})\n\n/**\n * Only when `scopeField` names the plugin's own field: a host-owned scope field is the host's to\n * register, and shadowing it would store the scope twice.\n */\nconst scopeField = (include: boolean): Field[] =>\n\tinclude\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\t// Written by scoped setups; hidden because single-site installs never touch it.\n\t\t\t\t\tname: 'scope',\n\t\t\t\t\ttype: 'text',\n\t\t\t\t\tindex: true,\n\t\t\t\t\tlabel: labelForKey(keys.providerFieldScope),\n\t\t\t\t\tadmin: { hidden: true },\n\t\t\t\t},\n\t\t\t]\n\t\t: []\n\nconst hostField = (\n\tallowPrivateNetwork: boolean,\n\taccess: ConnectionFieldAccess | undefined\n): Field => ({\n\tname: 'host',\n\ttype: 'text',\n\tlabel: labelForKey(keys.providerFieldHost),\n\tvalidate: validateProviderHost(allowPrivateNetwork),\n\t...(access ? { access } : {}),\n\tadmin: { description: labelForKey(keys.providerFieldHostHelp) },\n})\n\nconst currencyField = (name: string, help: TranslationKey): Field => ({\n\tname,\n\ttype: 'text',\n\tlabel: labelForKey(keys.providerFieldRevenueCurrency),\n\tvalidate: validateCurrency,\n\tadmin: { description: labelForKey(help) },\n})\n\nconst providerGroup = (provider: ProviderId, label: TranslationKey, fields: Field[]): Field => ({\n\tname: provider,\n\ttype: 'group',\n\tlabel: labelForKey(label),\n\tadmin: { condition: (data) => data?.provider === provider },\n\tfields,\n})\n\n/**\n * The native choice configures nothing, so it gets a note in place of a settings group:\n * an unnamed group stores no data and reads as the section its siblings occupy.\n */\nconst nativeNote = (): Field => ({\n\ttype: 'group',\n\tlabel: labelForKey(keys.providerNameNative),\n\tadmin: {\n\t\tcondition: (data) => data?.provider === 'native',\n\t\tdescription: labelForKey(keys.providerNameNativeHelp),\n\t},\n\tfields: [],\n})\n\nconst nameField = (): Field => ({\n\tname: 'name',\n\ttype: 'text',\n\trequired: true,\n\tlabel: labelForKey(keys.providerFieldName),\n\tadmin: { description: labelForKey(keys.providerFieldNameHelp) },\n})\n\n/**\n * Sits in the sidebar with `enabled`: every body field is conditional on the provider and\n * meaningless while `enabled` is off.\n */\nconst providerField = (\n\taccess: ConnectionFieldAccess | undefined,\n\tstaticLabel: StaticLabelFor\n): Field => ({\n\tname: 'provider',\n\ttype: 'select',\n\trequired: true,\n\tlabel: labelForKey(keys.providerFieldProvider),\n\tdefaultValue: 'native',\n\t...(access ? { access } : {}),\n\toptions: [\n\t\t{ label: labelForKey(keys.providerNameNative), value: 'native' },\n\t\t{ label: labelForKey(keys.providerNamePlausible), value: 'plausible' },\n\t\t{ label: labelForKey(keys.providerNameUmami), value: 'umami' },\n\t\t{ label: labelForKey(keys.providerNameGa4), value: 'ga4' },\n\t\t{ label: labelForKey(keys.providerNamePosthog), value: 'posthog' },\n\t],\n\t// `admin.description` on a select is read where a label function never runs.\n\tadmin: { position: 'sidebar', description: staticLabel(keys.providerFieldProviderHelp) },\n})\n\nconst enabledField = (): Field => ({\n\tname: 'enabled',\n\ttype: 'checkbox',\n\tdefaultValue: true,\n\tlabel: labelForKey(keys.providerFieldEnabled),\n\tadmin: { position: 'sidebar', description: labelForKey(keys.providerFieldEnabledHelp) },\n})\n\nexport interface ProviderFieldsOptions {\n\t/**\n\t * Seals each credential field, normally `encryptedField` from `@10x-media/fields` in write-only\n\t * mode. Left out, credentials are plain text and securing them is the host's job.\n\t */\n\tbuildSecret?: BuildSecretField\n\t/** Replaces one of the default fields, applied per field. */\n\tfields?: ProviderCollectionFieldOverrides\n\t/** Adds the plugin's own hidden `scope` text field. Off by default. */\n\tscopeField?: boolean\n\t/**\n\t * Accepts `http://` in a `host` field, for a vendor on a private network. Set it together with\n\t * `providers.hosts.allowPrivateNetwork`, which lets the plugin connect there. Off, https only.\n\t */\n\tallowPrivateNetwork?: boolean\n\t/**\n\t * Field access on every `CONNECTION_PATHS` field except the scope field. One function for create\n\t * and update alike, or `{ create, update }`.\n\t */\n\tconnectionAccess?: ConnectionAccess\n}\n\n/**\n * Provider-settings fields alone, for a host that stores them elsewhere and feeds them back through\n * `providers.resolve`; {@link adapterFromProviderDoc} reads the result as is.\n */\nexport const analyticsProviderFields = (options: ProviderFieldsOptions = {}): Field[] =>\n\tproviderFields(options, builtInStaticLabel)\n\nconst providerFields = (options: ProviderFieldsOptions, staticLabel: StaticLabelFor): Field[] => {\n\tconst buildSecret = options.buildSecret ?? plainSecret\n\tconst access = connectionFieldAccess(\n\t\t'analyticsProviderFields({ connectionAccess })',\n\t\toptions.connectionAccess\n\t)\n\tconst allowPrivateNetwork = options.allowPrivateNetwork === true\n\tconst apiKeyField = (): Field[] =>\n\t\tsecretField(buildSecret, staticLabel, {\n\t\t\tname: 'apiKey',\n\t\t\tlabel: keys.providerFieldApiKey,\n\t\t\thelp: keys.providerFieldApiKeyHelp,\n\t\t\twidth: '50%',\n\t\t})\n\treturn [\n\t\toverrideField(nameField(), options.fields?.name),\n\t\toverrideField(providerField(access, staticLabel), options.fields?.provider),\n\t\toverrideField(enabledField(), options.fields?.enabled),\n\t\t...scopeField(options.scopeField === true),\n\t\tnativeNote(),\n\t\tproviderGroup('plausible', keys.providerNamePlausible, [\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\ttextField('siteId', keys.providerFieldSiteId, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldSiteIdHelp,\n\t\t\t\t\t\taccess,\n\t\t\t\t\t}),\n\t\t\t\t\t...apiKeyField(),\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\tcaptureField('domain', keys.providerFieldDomain, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldDomainHelp,\n\t\t\t\t\t}),\n\t\t\t\t\tcaptureField('scriptId', keys.providerFieldScriptId, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldScriptIdHelp,\n\t\t\t\t\t\tvalidate: validateScriptId,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t},\n\t\t\tcurrencyField('revenueCurrency', keys.providerFieldRevenueCurrencyHelp),\n\t\t\thostField(allowPrivateNetwork, access),\n\t\t]),\n\t\tproviderGroup('umami', keys.providerNameUmami, [\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\ttextField('websiteId', keys.providerFieldWebsiteId, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldWebsiteIdHelp,\n\t\t\t\t\t\taccess,\n\t\t\t\t\t}),\n\t\t\t\t\t...apiKeyField(),\n\t\t\t\t],\n\t\t\t},\n\t\t\t...secretField(buildSecret, staticLabel, {\n\t\t\t\tname: 'token',\n\t\t\t\tlabel: keys.providerFieldToken,\n\t\t\t\thelp: keys.providerFieldTokenHelp,\n\t\t\t}),\n\t\t\thostField(allowPrivateNetwork, access),\n\t\t]),\n\t\tproviderGroup('ga4', keys.providerNameGa4, [\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\ttextField('propertyId', keys.providerFieldPropertyId, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldPropertyIdHelp,\n\t\t\t\t\t\taccess,\n\t\t\t\t\t}),\n\t\t\t\t\ttextField('projectId', keys.providerFieldProjectId, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldProjectIdHelp,\n\t\t\t\t\t\taccess,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t},\n\t\t\ttextField('clientEmail', keys.providerFieldClientEmail, {\n\t\t\t\thelp: keys.providerFieldClientEmailHelp,\n\t\t\t\taccess,\n\t\t\t}),\n\t\t\tcaptureField('measurementId', keys.providerFieldMeasurementId, {\n\t\t\t\tvalidate: validateMeasurementId,\n\t\t\t}),\n\t\t\tcurrencyField('currency', keys.providerFieldGa4CurrencyHelp),\n\t\t\t...buildSecret({\n\t\t\t\tname: 'privateKey',\n\t\t\t\ttype: 'textarea',\n\t\t\t\tlabel: labelForKey(keys.providerFieldPrivateKey),\n\t\t\t\tadmin: { description: staticLabel(keys.providerFieldPrivateKeyHelp) },\n\t\t\t}),\n\t\t]),\n\t\tproviderGroup('posthog', keys.providerNamePosthog, [\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\ttextField('projectId', keys.providerFieldProjectId, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldProjectIdHelp,\n\t\t\t\t\t\taccess,\n\t\t\t\t\t}),\n\t\t\t\t\t...apiKeyField(),\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\tcaptureField('projectToken', keys.providerFieldProjectToken, { width: '50%' }),\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'region',\n\t\t\t\t\t\ttype: 'select',\n\t\t\t\t\t\tlabel: labelForKey(keys.providerFieldRegion),\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{ label: 'US', value: 'us' },\n\t\t\t\t\t\t\t{ label: 'EU', value: 'eu' },\n\t\t\t\t\t\t],\n\t\t\t\t\t\t...(access ? { access } : {}),\n\t\t\t\t\t\tadmin: {\n\t\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\t\tdescription: staticLabel(keys.providerFieldRegionHelp),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\ttextField('scopeProperty', keys.providerFieldScopeProperty, {\n\t\t\t\thelp: keys.providerFieldScopePropertyHelp,\n\t\t\t\taccess,\n\t\t\t}),\n\t\t\thostField(allowPrivateNetwork, access),\n\t\t]),\n\t]\n}\n\n/**\n * Runtime provider-settings collection, one document per provider (and scope). Admin-only by\n * default; `access` overrides single operations, `overrides` reshapes the whole config last.\n */\nexport const buildProvidersCollection = (args: BuildProvidersCollectionArgs): CollectionConfig => {\n\tconst staticLabel = args.staticLabel ?? builtInStaticLabel\n\tconst collection: CollectionConfig = {\n\t\tslug: args.slug,\n\t\tlabels: {\n\t\t\tsingular: labelForKey(keys.providersCollectionSingular),\n\t\t\tplural: labelForKey(keys.providersCollectionPlural),\n\t\t},\n\t\tdisableDuplicate: true,\n\t\tadmin: {\n\t\t\tuseAsTitle: 'name',\n\t\t\tdefaultColumns: ['name', 'provider', 'enabled'],\n\t\t\tgroup: staticLabel(keys.adminGroup),\n\t\t\tdescription: staticLabel(keys.providersCollectionDescription),\n\t\t},\n\t\taccess: {\n\t\t\tread: providerRowAccess(args),\n\t\t\tcreate: providerCreateAccess(args),\n\t\t\tupdate: providerRowAccess(args),\n\t\t\tdelete: providerRowAccess(args),\n\t\t\t...args.access,\n\t\t},\n\t\thooks: {\n\t\t\tbeforeChange: [\n\t\t\t\tstampScope(args),\n\t\t\t\tretargetSecrets({ scopeField: args.scopeField, isSealed: args.isSealed }),\n\t\t\t],\n\t\t\tafterChange: [\n\t\t\t\tasync ({ doc, operation, previousDoc, req }) => {\n\t\t\t\t\tawait args.onChange(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tscope: docScope(doc, args.scopeField),\n\t\t\t\t\t\t\t...(operation === 'update'\n\t\t\t\t\t\t\t\t? { previousScope: docScope(previousDoc, args.scopeField) }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t\treq\n\t\t\t\t\t)\n\t\t\t\t\treturn doc\n\t\t\t\t},\n\t\t\t],\n\t\t\tafterDelete: [\n\t\t\t\tasync ({ doc, req }) => {\n\t\t\t\t\tawait args.onChange({ scope: docScope(doc, args.scopeField) }, req)\n\t\t\t\t\treturn doc\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\tfields: providerFields(\n\t\t\t{\n\t\t\t\tbuildSecret: args.buildSecret,\n\t\t\t\t...(args.fields ? { fields: args.fields } : {}),\n\t\t\t\tscopeField: args.scopeField === 'scope',\n\t\t\t\tallowPrivateNetwork: args.allowPrivateNetwork === true,\n\t\t\t\t...(args.connectionAccess ? { connectionAccess: args.connectionAccess } : {}),\n\t\t\t},\n\t\t\tstaticLabel\n\t\t),\n\t}\n\treturn args.overrides ? args.overrides(collection) : collection\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,MAAa,iBAAiB;;AA2B9B,MAAa,yBACZ,MACA,WACuC;CACvC,IAAI,WAAW,KAAA,GACd;CAED,IAAI,OAAO,WAAW,YACrB,OAAO;EAAE,QAAQ;EAAQ,QAAQ;CAAO;CAEzC,MAAM,SAAS,cAAc,QAAQ;EACpC;EACA,OAAO,CAAC,UAAU,QAAQ;EAC1B,SAAS;CACV,CAAC;CACD,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,MAAM,GACjD,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAC7C,MAAM,IAAI,MACT,cAAc,KAAK,GAAG,KAAK,wCAAwC,OAAO,MAAM,GACjF;CAGF,MAAM,EAAE,QAAQ,WAAW;CAC3B,OAAO;EAAE,GAAI,SAAS,EAAE,OAAO,IAAI,CAA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AAK,iBAAiB,IAAI,CAAC;EAC5E,GACA,WACD;CACD;CACA,OAAO,KAAK,YAAY,KAAK,UAAU,UAAU,IAAI;AACtD"}
|
|
1
|
+
{"version":3,"file":"collection.js","names":[],"sources":["../../src/providers/collection.ts"],"sourcesContent":["import {\n\ttype CollectionBeforeValidateHook,\n\ttype CollectionConfig,\n\ttype Field,\n\ttype FieldAccess,\n\ttype PayloadRequest,\n\ttype SelectField,\n\ttype SelectFieldSingleValidation,\n\ttype TextareaField,\n\ttype TextField,\n\ttype TextFieldSingleValidation,\n\tValidationError,\n\tvalidations,\n} from 'payload'\nimport { validateMeasurementId } from '../adapters/ga4/measurementId'\nimport { validateScriptId } from '../adapters/plausible/scriptId'\nimport { optionsObject } from '../core/optionChecks'\nimport { isOneOf, kindOf, listOf } from '../core/values'\nimport { validateCurrency } from '../goals/currency'\nimport { type CollectionFieldOverride, overrideField } from '../plugin/collectionFields'\nimport { docScope, type ScopeChange } from '../plugin/scopeChange'\nimport { keys, type SingularKey, type TranslationKey } from '../translations/keys'\nimport { asTranslate, labelForKey } from '../translations/server'\nimport { builtInStaticLabel, type StaticLabelFor } from '../translations/staticLabel'\nimport { type ProviderAccessArgs, providerCreateAccess, providerRowAccess } from './access'\nimport { PROVIDER_IDS, type ProviderId } from './factory'\nimport { validateProviderHost } from './hosts'\nimport { retargetSecrets } from './retarget'\nimport { takenInScope } from './scopeUnique'\nimport { stampScope } from './stampScope'\n\nexport const PROVIDERS_SLUG = 'analytics-providers'\n\n/** The list's note to a tenant reading the platform's source in `fallback`. */\nexport const PROVIDERS_LIST_NOTICE_COMPONENT = '@10x-media/analytics/client#ProvidersListNotice'\n\n/** Builds the sealed variant of a secret source field; injected so the fields peer stays lazy. */\nexport type BuildSecretField = (source: TextField | TextareaField) => Field[]\n\n/**\n * Replaces a default field; it receives the plugin's own field to spread and may return any field\n * type (a `row`, a `collapsible`) that still holds a field of that name.\n */\nexport type ProviderFieldOverride = CollectionFieldOverride\n\nexport interface ProviderCollectionFieldOverrides {\n\tname?: ProviderFieldOverride\n\tprovider?: ProviderFieldOverride\n\tenabled?: ProviderFieldOverride\n\t/** The \"Default for this site\" checkbox, which only a scoped install's collection carries. */\n\tisDefault?: ProviderFieldOverride\n}\n\n/** Field access on the fields that decide where a provider document connects (`CONNECTION_PATHS`). */\nexport interface ConnectionFieldAccess {\n\tcreate?: FieldAccess\n\tupdate?: FieldAccess\n}\n\n/** One field access function for create and update alike, or `{ create, update }`. */\nexport type ConnectionAccess = FieldAccess | ConnectionFieldAccess\n\n/** `connectionAccess` in its object form, checked at boot; undefined while unset. */\nexport const connectionFieldAccess = (\n\tpath: string,\n\toption: ConnectionAccess | undefined\n): ConnectionFieldAccess | undefined => {\n\tif (option === undefined) {\n\t\treturn undefined\n\t}\n\tif (typeof option === 'function') {\n\t\treturn { create: option, update: option }\n\t}\n\tconst halves = optionsObject(option, {\n\t\tpath,\n\t\tknown: ['create', 'update'],\n\t\texample: 'a function, or { create, update } with a function in each',\n\t})\n\tfor (const [half, access] of Object.entries(halves)) {\n\t\tif (access !== undefined && typeof access !== 'function') {\n\t\t\tthrow new Error(\n\t\t\t\t`analytics: ${path}.${half} must be a field access function, got ${kindOf(access)}`\n\t\t\t)\n\t\t}\n\t}\n\tconst { create, update } = option\n\treturn { ...(create ? { create } : {}), ...(update ? { update } : {}) }\n}\n\n/**\n * The provider types documents may be saved with: every type `available` serves, narrowed to\n * `option` in its order when given, checked at boot.\n */\nexport const servedProviderTypes = (\n\tpath: string,\n\toption: unknown,\n\tavailable: readonly ProviderId[] = PROVIDER_IDS\n): ProviderId[] => {\n\tif (option === undefined) {\n\t\treturn [...available]\n\t}\n\tif (!Array.isArray(option)) {\n\t\tthrow new Error(\n\t\t\t`analytics: ${path} must be a list of provider types such as ['plausible', 'umami'], got ${kindOf(option)}`\n\t\t)\n\t}\n\tconst listed: ProviderId[] = []\n\tfor (const type of option) {\n\t\tif (!isOneOf(PROVIDER_IDS, type)) {\n\t\t\tthrow new Error(\n\t\t\t\t`analytics: ${path} lists ${kindOf(type)}, which is no provider type; use ${listOf(PROVIDER_IDS.map((id) => `\"${id}\"`))}`\n\t\t\t)\n\t\t}\n\t\tlisted.push(type)\n\t}\n\tconst served = [...new Set(listed)].filter((type) => available.includes(type))\n\tif (served.length === 0) {\n\t\tthrow new Error(\n\t\t\t`analytics: ${path} leaves no provider type this install serves, which are ${listOf(available.map((id) => `\"${id}\"`))}; \"native\" needs native() in adapters`\n\t\t)\n\t}\n\treturn served\n}\n\nexport interface BuildProvidersCollectionArgs extends ProviderAccessArgs {\n\tslug: string\n\taccess?: Partial<CollectionConfig['access']>\n\t/** Per-field overrides, applied before the whole-collection `overrides`. */\n\tfields?: ProviderCollectionFieldOverrides\n\toverrides?: (collection: CollectionConfig) => CollectionConfig\n\t/**\n\t * Called after any change or delete with the scopes the write touched and the request that\n\t * wrote, so that request's own Payload instance reads those scopes again once the write commits.\n\t */\n\tonChange: (change: ScopeChange, req: PayloadRequest) => void | Promise<void>\n\tbuildSecret: BuildSecretField\n\t/** The fields plugin's test for a sealed value, which tells a resent secret from a kept one. */\n\tisSealed: (value: unknown) => boolean\n\t/** `providers.hosts.allowPrivateNetwork`: the `host` fields accept `http://` too. */\n\tallowPrivateNetwork?: boolean\n\tconnectionAccess?: ConnectionFieldAccess\n\t/** The provider types a document may be saved with; every type when absent. */\n\ttypes?: readonly ProviderId[]\n\t/** Field access on `isDefault`, which a scoped install's collection carries. */\n\tdefaultAccess?: ConnectionFieldAccess\n\t/** The install's static labels; the built-in strings alone when absent. */\n\tstaticLabel?: StaticLabelFor\n\t/** Mount the list's note on the platform fallback, for an install with a `fallback` policy. */\n\tlistNotice?: boolean\n}\n\nconst plainSecret: BuildSecretField = (source) => [source]\n\nconst textField = (\n\tname: string,\n\tlabel: TranslationKey,\n\topts: { width?: string; help?: TranslationKey; access?: ConnectionFieldAccess } = {}\n): Field => ({\n\tname,\n\ttype: 'text',\n\tlabel: labelForKey(label),\n\t...(opts.access ? { access: opts.access } : {}),\n\t...(opts.width || opts.help\n\t\t? {\n\t\t\t\tadmin: {\n\t\t\t\t\t...(opts.width ? { width: opts.width } : {}),\n\t\t\t\t\t...(opts.help ? { description: labelForKey(opts.help) } : {}),\n\t\t\t\t},\n\t\t\t}\n\t\t: {}),\n})\n\n/**\n * A sealed credential. Its help is a string per locale: Payload drops a function description from\n * the client field, which the write-only editor renders.\n */\nconst secretField = (\n\tbuildSecret: BuildSecretField,\n\tstaticLabel: StaticLabelFor,\n\topts: { name: string; label: TranslationKey; help: SingularKey; width?: string }\n): Field[] =>\n\tbuildSecret({\n\t\tname: opts.name,\n\t\ttype: 'text',\n\t\tlabel: labelForKey(opts.label),\n\t\tadmin: {\n\t\t\tdescription: staticLabel(opts.help),\n\t\t\t...(opts.width ? { width: opts.width } : {}),\n\t\t},\n\t})\n\n/**\n * Public capture config, plain text because the tracker config serves it to the browser. An adapter\n * declares `capture` only once its public field is filled.\n */\nconst captureField = (\n\tname: string,\n\tlabel: TranslationKey,\n\topts: { width?: string; validate?: TextFieldSingleValidation; help?: TranslationKey } = {}\n): Field => ({\n\tname,\n\ttype: 'text',\n\tlabel: labelForKey(label),\n\t...(opts.validate ? { validate: opts.validate } : {}),\n\tadmin: {\n\t\tdescription: labelForKey(opts.help ?? keys.providerFieldCaptureHelp),\n\t\t...(opts.width ? { width: opts.width } : {}),\n\t},\n})\n\n/**\n * Only when `scopeField` names the plugin's own field: a host-owned scope field is the host's to\n * register, and shadowing it would store the scope twice.\n */\nconst scopeField = (include: boolean): Field[] =>\n\tinclude\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\t// Written by scoped setups; hidden because single-site installs never touch it.\n\t\t\t\t\tname: 'scope',\n\t\t\t\t\ttype: 'text',\n\t\t\t\t\tindex: true,\n\t\t\t\t\tlabel: labelForKey(keys.providerFieldScope),\n\t\t\t\t\tadmin: { hidden: true },\n\t\t\t\t},\n\t\t\t]\n\t\t: []\n\nconst hostField = (\n\tallowPrivateNetwork: boolean,\n\taccess: ConnectionFieldAccess | undefined\n): Field => ({\n\tname: 'host',\n\ttype: 'text',\n\tlabel: labelForKey(keys.providerFieldHost),\n\tvalidate: validateProviderHost(allowPrivateNetwork),\n\t...(access ? { access } : {}),\n\tadmin: { description: labelForKey(keys.providerFieldHostHelp) },\n})\n\nconst currencyField = (name: string, help: TranslationKey): Field => ({\n\tname,\n\ttype: 'text',\n\tlabel: labelForKey(keys.providerFieldRevenueCurrency),\n\tvalidate: validateCurrency,\n\tadmin: { description: labelForKey(help) },\n})\n\nconst providerGroup = (provider: ProviderId, label: TranslationKey, fields: Field[]): Field => ({\n\tname: provider,\n\ttype: 'group',\n\tlabel: labelForKey(label),\n\tadmin: { condition: (data) => data?.provider === provider },\n\tfields,\n})\n\n/**\n * The native choice configures nothing, so it gets a note in place of a settings group:\n * an unnamed group stores no data and reads as the section its siblings occupy.\n */\nconst nativeNote = (): Field => ({\n\ttype: 'group',\n\tlabel: labelForKey(keys.providerNameNative),\n\tadmin: {\n\t\tcondition: (data) => data?.provider === 'native',\n\t\tdescription: labelForKey(keys.providerNameNativeHelp),\n\t},\n\tfields: [],\n})\n\nconst nameField = (): Field => ({\n\tname: 'name',\n\ttype: 'text',\n\trequired: true,\n\tlabel: labelForKey(keys.providerFieldName),\n\tadmin: { description: labelForKey(keys.providerFieldNameHelp) },\n})\n\nconst PROVIDER_NAMES: Record<ProviderId, TranslationKey> = {\n\tnative: keys.providerNameNative,\n\tplausible: keys.providerNamePlausible,\n\tumami: keys.providerNameUmami,\n\tga4: keys.providerNameGa4,\n\tposthog: keys.providerNamePosthog,\n}\n\n/**\n * Names the refusal of a stored type the install no longer serves (native() removed, `types`\n * narrowed), which the select's own check would only call an invalid selection.\n */\nconst validateServed =\n\t(types: readonly string[]): SelectFieldSingleValidation =>\n\t(value, options) =>\n\t\ttypeof value === 'string' && value !== '' && !types.includes(value)\n\t\t\t? asTranslate(options.req.t)(keys.providerErrorTypeUnserved)\n\t\t\t: validations.select(value, options)\n\n/**\n * The values a narrowed select offers: the served types, and a stored type no longer served so its\n * save is refused by name. Values only, since form state carries the result to the client, where\n * a label function cannot cross; Payload's select reads nothing else from it.\n */\nconst offeredTypes = (types: readonly ProviderId[], stored: unknown): ProviderId[] =>\n\tisOneOf(PROVIDER_IDS, stored) && !types.includes(stored) ? [...types, stored] : [...types]\n\n/**\n * Sits in the sidebar with `enabled`: every body field is conditional on the provider and\n * meaningless while `enabled` is off. The schema keeps every type (options, groups, a static\n * default while `native` leads), so narrowing the offer neither alters a column nor drops settings.\n */\nconst providerField = (\n\taccess: ConnectionFieldAccess | undefined,\n\tstaticLabel: StaticLabelFor,\n\ttypes: readonly ProviderId[]\n): SelectField => {\n\tconst [first = 'native'] = types\n\tconst narrowed = types.length < PROVIDER_IDS.length\n\treturn {\n\t\tname: 'provider',\n\t\ttype: 'select',\n\t\trequired: true,\n\t\tlabel: labelForKey(keys.providerFieldProvider),\n\t\tdefaultValue: first === 'native' ? first : () => first,\n\t\t...(access ? { access } : {}),\n\t\t...(narrowed\n\t\t\t? {\n\t\t\t\t\tvalidate: validateServed(types),\n\t\t\t\t\tfilterOptions: ({ data }) => offeredTypes(types, data?.provider),\n\t\t\t\t}\n\t\t\t: {}),\n\t\toptions: PROVIDER_IDS.map((type) => ({\n\t\t\tlabel: labelForKey(PROVIDER_NAMES[type]),\n\t\t\tvalue: type,\n\t\t})),\n\t\t// `admin.description` on a select is read where a label function never runs.\n\t\tadmin: { position: 'sidebar', description: staticLabel(keys.providerFieldProviderHelp) },\n\t}\n}\n\nconst enabledField = (): Field => ({\n\tname: 'enabled',\n\ttype: 'checkbox',\n\tdefaultValue: true,\n\tlabel: labelForKey(keys.providerFieldEnabled),\n\tadmin: { position: 'sidebar', description: labelForKey(keys.providerFieldEnabledHelp) },\n})\n\nconst isDefaultField = (access: ConnectionFieldAccess | undefined): Field => ({\n\tname: 'isDefault',\n\ttype: 'checkbox',\n\tdefaultValue: false,\n\tlabel: labelForKey(keys.providerFieldIsDefault),\n\t...(access ? { access } : {}),\n\tadmin: { position: 'sidebar', description: labelForKey(keys.providerFieldIsDefaultHelp) },\n})\n\n/**\n * At most one document per scope is the default, checked at collection level so a replaced\n * `isDefault` field keeps it. No index backs it: a unique one would also cover the unflagged rows.\n */\nconst checkSingleDefault = (args: BuildProvidersCollectionArgs): CollectionBeforeValidateHook => {\n\treturn async ({ data, originalDoc, req }) => {\n\t\tif ((data?.isDefault ?? originalDoc?.isDefault) !== true) {\n\t\t\treturn data\n\t\t}\n\t\tif (await takenInScope(args, { data, originalDoc, req }, { isDefault: { equals: true } })) {\n\t\t\tthrow new ValidationError({\n\t\t\t\tcollection: args.slug,\n\t\t\t\terrors: [\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: labelForKey(keys.providerFieldIsDefault),\n\t\t\t\t\t\tmessage: asTranslate(req.t)(keys.providerErrorDefaultTaken),\n\t\t\t\t\t\tpath: 'isDefault',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t})\n\t\t}\n\t\treturn data\n\t}\n}\n\nexport interface ProviderFieldsOptions {\n\t/**\n\t * Seals each credential field, normally `encryptedField` from `@10x-media/fields` in write-only\n\t * mode. Left out, credentials are plain text and securing them is the host's job.\n\t */\n\tbuildSecret?: BuildSecretField\n\t/** Replaces one of the default fields, applied per field. */\n\tfields?: Omit<ProviderCollectionFieldOverrides, 'isDefault'>\n\t/** Adds the plugin's own hidden `scope` text field. Off by default. */\n\tscopeField?: boolean\n\t/**\n\t * Accepts `http://` in a `host` field, for a vendor on a private network. Set it together with\n\t * `providers.hosts.allowPrivateNetwork`, which lets the plugin connect there. Off, https only.\n\t */\n\tallowPrivateNetwork?: boolean\n\t/**\n\t * Field access on every `CONNECTION_PATHS` field except the scope field. One function for create\n\t * and update alike, or `{ create, update }`.\n\t */\n\tconnectionAccess?: ConnectionAccess\n\t/**\n\t * The provider types the select offers, the first being its default; a document saved with any\n\t * other type is refused. Default: every type, `native` first.\n\t */\n\ttypes?: ProviderId[]\n}\n\n/** What the field list takes beyond the public options. */\ninterface FieldListArgs {\n\ttypes: readonly ProviderId[]\n\t/** The `isDefault` checkbox, overridden, placed after `enabled`; only a scoped collection has it. */\n\tisDefault?: Field\n}\n\n/**\n * Provider-settings fields alone, for a host that stores them elsewhere and feeds them back through\n * `providers.resolve`; {@link adapterFromProviderDoc} reads the result as is.\n */\nexport const analyticsProviderFields = (options: ProviderFieldsOptions = {}): Field[] =>\n\tproviderFields(options, builtInStaticLabel, {\n\t\ttypes: servedProviderTypes('analyticsProviderFields({ types })', options.types),\n\t})\n\nconst providerFields = (\n\toptions: ProviderFieldsOptions,\n\tstaticLabel: StaticLabelFor,\n\tlist: FieldListArgs\n): Field[] => {\n\tconst buildSecret = options.buildSecret ?? plainSecret\n\tconst access = connectionFieldAccess(\n\t\t'analyticsProviderFields({ connectionAccess })',\n\t\toptions.connectionAccess\n\t)\n\tconst allowPrivateNetwork = options.allowPrivateNetwork === true\n\tconst apiKeyField = (): Field[] =>\n\t\tsecretField(buildSecret, staticLabel, {\n\t\t\tname: 'apiKey',\n\t\t\tlabel: keys.providerFieldApiKey,\n\t\t\thelp: keys.providerFieldApiKeyHelp,\n\t\t\twidth: '50%',\n\t\t})\n\treturn [\n\t\toverrideField(nameField(), options.fields?.name),\n\t\toverrideField(providerField(access, staticLabel, list.types), options.fields?.provider),\n\t\toverrideField(enabledField(), options.fields?.enabled),\n\t\t...(list.isDefault ? [list.isDefault] : []),\n\t\t...scopeField(options.scopeField === true),\n\t\tnativeNote(),\n\t\tproviderGroup('plausible', keys.providerNamePlausible, [\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\ttextField('siteId', keys.providerFieldSiteId, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldSiteIdHelp,\n\t\t\t\t\t\taccess,\n\t\t\t\t\t}),\n\t\t\t\t\t...apiKeyField(),\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\tcaptureField('domain', keys.providerFieldDomain, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldDomainHelp,\n\t\t\t\t\t}),\n\t\t\t\t\tcaptureField('scriptId', keys.providerFieldScriptId, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldScriptIdHelp,\n\t\t\t\t\t\tvalidate: validateScriptId,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t},\n\t\t\tcurrencyField('revenueCurrency', keys.providerFieldRevenueCurrencyHelp),\n\t\t\thostField(allowPrivateNetwork, access),\n\t\t]),\n\t\tproviderGroup('umami', keys.providerNameUmami, [\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\ttextField('websiteId', keys.providerFieldWebsiteId, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldWebsiteIdHelp,\n\t\t\t\t\t\taccess,\n\t\t\t\t\t}),\n\t\t\t\t\t...apiKeyField(),\n\t\t\t\t],\n\t\t\t},\n\t\t\t...secretField(buildSecret, staticLabel, {\n\t\t\t\tname: 'token',\n\t\t\t\tlabel: keys.providerFieldToken,\n\t\t\t\thelp: keys.providerFieldTokenHelp,\n\t\t\t}),\n\t\t\thostField(allowPrivateNetwork, access),\n\t\t]),\n\t\tproviderGroup('ga4', keys.providerNameGa4, [\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\ttextField('propertyId', keys.providerFieldPropertyId, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldPropertyIdHelp,\n\t\t\t\t\t\taccess,\n\t\t\t\t\t}),\n\t\t\t\t\ttextField('projectId', keys.providerFieldProjectId, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldProjectIdHelp,\n\t\t\t\t\t\taccess,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t},\n\t\t\ttextField('clientEmail', keys.providerFieldClientEmail, {\n\t\t\t\thelp: keys.providerFieldClientEmailHelp,\n\t\t\t\taccess,\n\t\t\t}),\n\t\t\tcaptureField('measurementId', keys.providerFieldMeasurementId, {\n\t\t\t\tvalidate: validateMeasurementId,\n\t\t\t}),\n\t\t\tcurrencyField('currency', keys.providerFieldGa4CurrencyHelp),\n\t\t\t...buildSecret({\n\t\t\t\tname: 'privateKey',\n\t\t\t\ttype: 'textarea',\n\t\t\t\tlabel: labelForKey(keys.providerFieldPrivateKey),\n\t\t\t\tadmin: { description: staticLabel(keys.providerFieldPrivateKeyHelp) },\n\t\t\t}),\n\t\t]),\n\t\tproviderGroup('posthog', keys.providerNamePosthog, [\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\ttextField('projectId', keys.providerFieldProjectId, {\n\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\thelp: keys.providerFieldProjectIdHelp,\n\t\t\t\t\t\taccess,\n\t\t\t\t\t}),\n\t\t\t\t\t...apiKeyField(),\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: 'row',\n\t\t\t\tfields: [\n\t\t\t\t\tcaptureField('projectToken', keys.providerFieldProjectToken, { width: '50%' }),\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'region',\n\t\t\t\t\t\ttype: 'select',\n\t\t\t\t\t\tlabel: labelForKey(keys.providerFieldRegion),\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{ label: 'US', value: 'us' },\n\t\t\t\t\t\t\t{ label: 'EU', value: 'eu' },\n\t\t\t\t\t\t],\n\t\t\t\t\t\t...(access ? { access } : {}),\n\t\t\t\t\t\tadmin: {\n\t\t\t\t\t\t\twidth: '50%',\n\t\t\t\t\t\t\tdescription: staticLabel(keys.providerFieldRegionHelp),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\ttextField('scopeProperty', keys.providerFieldScopeProperty, {\n\t\t\t\thelp: keys.providerFieldScopePropertyHelp,\n\t\t\t\taccess,\n\t\t\t}),\n\t\t\thostField(allowPrivateNetwork, access),\n\t\t]),\n\t]\n}\n\n/**\n * Runtime provider-settings collection, one document per provider (and scope). Admin-only by\n * default; `access` overrides single operations, `overrides` reshapes the whole config last.\n */\nexport const buildProvidersCollection = (args: BuildProvidersCollectionArgs): CollectionConfig => {\n\tconst staticLabel = args.staticLabel ?? builtInStaticLabel\n\tconst collection: CollectionConfig = {\n\t\tslug: args.slug,\n\t\tlabels: {\n\t\t\tsingular: labelForKey(keys.providersCollectionSingular),\n\t\t\tplural: labelForKey(keys.providersCollectionPlural),\n\t\t},\n\t\tdisableDuplicate: true,\n\t\tadmin: {\n\t\t\tuseAsTitle: 'name',\n\t\t\tdefaultColumns: ['name', 'provider', 'enabled'],\n\t\t\tgroup: staticLabel(keys.adminGroup),\n\t\t\tdescription: staticLabel(keys.providersCollectionDescription),\n\t\t\t...(args.listNotice ? { components: { beforeList: [PROVIDERS_LIST_NOTICE_COMPONENT] } } : {}),\n\t\t},\n\t\taccess: {\n\t\t\tread: providerRowAccess(args),\n\t\t\tcreate: providerCreateAccess(args),\n\t\t\tupdate: providerRowAccess(args),\n\t\t\tdelete: providerRowAccess(args),\n\t\t\t...args.access,\n\t\t},\n\t\thooks: {\n\t\t\t...(args.scoped ? { beforeValidate: [checkSingleDefault(args)] } : {}),\n\t\t\tbeforeChange: [\n\t\t\t\tstampScope(args),\n\t\t\t\tretargetSecrets({ scopeField: args.scopeField, isSealed: args.isSealed }),\n\t\t\t],\n\t\t\tafterChange: [\n\t\t\t\tasync ({ doc, operation, previousDoc, req }) => {\n\t\t\t\t\tawait args.onChange(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tscope: docScope(doc, args.scopeField),\n\t\t\t\t\t\t\t...(operation === 'update'\n\t\t\t\t\t\t\t\t? { previousScope: docScope(previousDoc, args.scopeField) }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t\treq\n\t\t\t\t\t)\n\t\t\t\t\treturn doc\n\t\t\t\t},\n\t\t\t],\n\t\t\tafterDelete: [\n\t\t\t\tasync ({ doc, req }) => {\n\t\t\t\t\tawait args.onChange({ scope: docScope(doc, args.scopeField) }, req)\n\t\t\t\t\treturn doc\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\tfields: providerFields(\n\t\t\t{\n\t\t\t\tbuildSecret: args.buildSecret,\n\t\t\t\t...(args.fields ? { fields: args.fields } : {}),\n\t\t\t\tscopeField: args.scopeField === 'scope',\n\t\t\t\tallowPrivateNetwork: args.allowPrivateNetwork === true,\n\t\t\t\t...(args.connectionAccess ? { connectionAccess: args.connectionAccess } : {}),\n\t\t\t},\n\t\t\tstaticLabel,\n\t\t\t{\n\t\t\t\ttypes: args.types ?? PROVIDER_IDS,\n\t\t\t\t// A default is picked per scope: an unscoped install has one site and nothing to pick.\n\t\t\t\t...(args.scoped\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tisDefault: overrideField(isDefaultField(args.defaultAccess), args.fields?.isDefault),\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t}\n\t\t),\n\t}\n\treturn args.overrides ? args.overrides(collection) : collection\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,MAAa,iBAAiB;;AAG9B,MAAa,kCAAkC;;AA6B/C,MAAa,yBACZ,MACA,WACuC;CACvC,IAAI,WAAW,KAAA,GACd;CAED,IAAI,OAAO,WAAW,YACrB,OAAO;EAAE,QAAQ;EAAQ,QAAQ;CAAO;CAEzC,MAAM,SAAS,cAAc,QAAQ;EACpC;EACA,OAAO,CAAC,UAAU,QAAQ;EAC1B,SAAS;CACV,CAAC;CACD,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,MAAM,GACjD,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAC7C,MAAM,IAAI,MACT,cA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ract.js";
|
|
|
4
4
|
import { ProviderHostPolicy } from "./hosts.js";
|
|
5
5
|
|
|
6
6
|
//#region src/providers/factory.d.ts
|
|
7
|
+
type ProviderId = 'native' | 'plausible' | 'umami' | 'ga4' | 'posthog';
|
|
7
8
|
declare const PROVIDER_IDS: readonly ["native", "plausible", "umami", "ga4", "posthog"];
|
|
8
|
-
type ProviderId = (typeof PROVIDER_IDS)[number];
|
|
9
9
|
/** The provider-settings document shape the adapter factory reads (depth 0, secrets revealed). */
|
|
10
10
|
type ProviderDoc = {
|
|
11
11
|
id?: number | string;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { isRecord } from "../core/values.js";
|
|
2
2
|
import { HostRefusedError } from "../core/sourceErrors.js";
|
|
3
|
-
import {
|
|
3
|
+
import { withFixedLabel } from "../core/sourceLabel.js";
|
|
4
4
|
import { ga4 } from "../adapters/ga4/ga4.js";
|
|
5
5
|
import { plausible } from "../adapters/plausible/plausible.js";
|
|
6
6
|
import { posthog } from "../adapters/posthog/posthog.js";
|
|
7
7
|
import { umami } from "../adapters/umami/umami.js";
|
|
8
|
+
import { checkDocumentHost } from "./hosts.js";
|
|
8
9
|
//#region src/providers/factory.ts
|
|
9
10
|
const PROVIDER_IDS = [
|
|
10
11
|
"native",
|
|
@@ -26,22 +27,18 @@ const shortId = (id) => String(id).slice(-6);
|
|
|
26
27
|
/** The registry id of a provider document's adapter, which grants and stand-ins must match. */
|
|
27
28
|
const documentAdapterId = (provider, id) => `${String(provider)}:${String(id)}`;
|
|
28
29
|
/** A lent `native` adapter under the document's name, so a source reads as its tenant named it. */
|
|
29
|
-
const withDocumentLabel = (adapter, doc) => doc.name ?
|
|
30
|
-
...adapter,
|
|
31
|
-
label: doc.name
|
|
32
|
-
} : adapter;
|
|
30
|
+
const withDocumentLabel = (adapter, doc) => doc.name ? withFixedLabel(adapter, doc.name) : adapter;
|
|
33
31
|
/** Per-document ids keep two projects of one provider type apart in a registry. */
|
|
34
32
|
const withInstanceIdentity = (adapter, doc) => {
|
|
35
33
|
if (doc.id === void 0 || doc.id === null || doc.id === "") return adapter;
|
|
36
34
|
return {
|
|
37
|
-
...adapter,
|
|
38
|
-
id: documentAdapterId(doc.provider, doc.id)
|
|
39
|
-
label: doc.name || `${adapter.label} ${shortId(doc.id)}`
|
|
35
|
+
...withFixedLabel(adapter, doc.name || `${adapter.label} ${shortId(doc.id)}`),
|
|
36
|
+
id: documentAdapterId(doc.provider, doc.id)
|
|
40
37
|
};
|
|
41
38
|
};
|
|
42
39
|
/**
|
|
43
|
-
* Keeps `shape`'s identity
|
|
44
|
-
* `error()` and it declares no capture, so its proxy mount
|
|
40
|
+
* Keeps `shape`'s identity, capabilities and `isConfigured` (configured when absent) so the source
|
|
41
|
+
* still lists, but every read throws `error()` and it declares no capture, so its proxy mount 404s.
|
|
45
42
|
*/
|
|
46
43
|
const failingAdapter = (shape, error) => {
|
|
47
44
|
const fail = async () => {
|
|
@@ -51,7 +48,7 @@ const failingAdapter = (shape, error) => {
|
|
|
51
48
|
id: shape.id,
|
|
52
49
|
label: shape.label,
|
|
53
50
|
capabilities: shape.capabilities,
|
|
54
|
-
isConfigured: () => true,
|
|
51
|
+
isConfigured: shape.isConfigured ?? (() => true),
|
|
55
52
|
query: fail,
|
|
56
53
|
...shape.realtime ? { realtime: fail } : {}
|
|
57
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","names":[],"sources":["../../src/providers/factory.ts"],"sourcesContent":["import { ga4 } from '../adapters/ga4/ga4'\nimport { plausible } from '../adapters/plausible/plausible'\nimport { posthog } from '../adapters/posthog/posthog'\nimport { umami } from '../adapters/umami/umami'\nimport type { AnalyticsAdapter, AnalyticsResult } from '../core/contract'\nimport type { FetchLike } from '../core/fetch'\nimport type { AnalyticsSdks } from '../core/sdks'\nimport { HostRefusedError } from '../core/sourceErrors'\nimport { isRecord } from '../core/values'\nimport { checkDocumentHost, type DocumentHost, type ProviderHostPolicy } from './hosts'\n\nexport const PROVIDER_IDS = ['native', 'plausible', 'umami', 'ga4', 'posthog'] as const\nexport type ProviderId = (typeof PROVIDER_IDS)[number]\n\n/** The provider-settings document shape the adapter factory reads (depth 0, secrets revealed). */\nexport type ProviderDoc = {\n\tid?: number | string\n\tname?: string | null\n\tprovider?: string | null\n\tenabled?: boolean | null\n\tscope?: string | null\n\tplausible?: {\n\t\tsiteId?: string | null\n\t\tapiKey?: string | null\n\t\thost?: string | null\n\t\tdomain?: string | null\n\t\tscriptId?: string | null\n\t\trevenueCurrency?: string | null\n\t} | null\n\tumami?: {\n\t\twebsiteId?: string | null\n\t\tapiKey?: string | null\n\t\ttoken?: string | null\n\t\thost?: string | null\n\t} | null\n\tga4?: {\n\t\tpropertyId?: string | null\n\t\tclientEmail?: string | null\n\t\tprivateKey?: string | null\n\t\tprojectId?: string | null\n\t\tmeasurementId?: string | null\n\t\tcurrency?: string | null\n\t} | null\n\tposthog?: {\n\t\tprojectId?: string | null\n\t\tapiKey?: string | null\n\t\thost?: string | null\n\t\tprojectToken?: string | null\n\t\tregion?: string | null\n\t\tscopeProperty?: string | null\n\t} | null\n}\n\n/** A stored blank reads as unset. */\nconst orUndefined = (value: string | null | undefined): string | undefined => value || undefined\n\n/** An unset or unrecognized stored region falls back to host-derived detection. */\nconst posthogRegion = (value: string | null | undefined): 'us' | 'eu' | undefined =>\n\tvalue === 'us' || value === 'eu' ? value : undefined\n\n/**\n * Keys pasted from a service-account JSON often carry escaped newlines; the gRPC\n * client needs real ones.\n */\nexport const normalizePrivateKey = (key: string): string => key.replace(/\\\\n/g, '\\n')\n\nconst shortId = (id: number | string): string => String(id).slice(-6)\n\n/** The registry id of a provider document's adapter, which grants and stand-ins must match. */\nexport const documentAdapterId = (provider: unknown, id: unknown): string =>\n\t`${String(provider)}:${String(id)}`\n\n/** A lent `native` adapter under the document's name, so a source reads as its tenant named it. */\nconst withDocumentLabel = (adapter: AnalyticsAdapter, doc: ProviderDoc): AnalyticsAdapter =>\n\tdoc.name ? { ...adapter, label: doc.name } : adapter\n\n/** Per-document ids keep two projects of one provider type apart in a registry. */\nconst withInstanceIdentity = (adapter: AnalyticsAdapter, doc: ProviderDoc): AnalyticsAdapter => {\n\tif (doc.id === undefined || doc.id === null || doc.id === '') {\n\t\treturn adapter\n\t}\n\treturn {\n\t\t...adapter,\n\t\tid: documentAdapterId(doc.provider, doc.id),\n\t\tlabel: doc.name || `${adapter.label} ${shortId(doc.id)}`,\n\t}\n}\n\n/**\n * Keeps `shape`'s identity and capabilities so the source still lists, but every read throws\n * `error()` and it declares no capture, so its proxy mount answers 404.\n */\nexport const failingAdapter = (\n\tshape: Pick<AnalyticsAdapter, 'id' | 'label' | 'capabilities' | 'realtime'>,\n\terror: () => Error\n): AnalyticsAdapter => {\n\tconst fail = async (): Promise<AnalyticsResult> => {\n\t\tthrow error()\n\t}\n\treturn {\n\t\tid: shape.id,\n\t\tlabel: shape.label,\n\t\tcapabilities: shape.capabilities,\n\t\tisConfigured: () => true,\n\t\tquery: fail,\n\t\t...(shape.realtime ? { realtime: fail } : {}),\n\t}\n}\n\n/**\n * Builds a hosted vendor's adapter on the address its host check allowed, none being the vendor's\n * cloud; a refused host builds one whose reads fail with a `HostRefusedError`.\n */\nconst onDocumentHost = (\n\tverdict: DocumentHost,\n\tbuild: (host: string | undefined) => AnalyticsAdapter\n): AnalyticsAdapter => {\n\tif (verdict.ok) {\n\t\treturn build(verdict.address ?? undefined)\n\t}\n\tconst { host, reason } = verdict\n\treturn failingAdapter(build(undefined), () => new HostRefusedError(host, reason))\n}\n\nconst buildBaseAdapter = (\n\tdoc: ProviderDoc,\n\tctx: ProviderFactoryContext\n): AnalyticsAdapter | null => {\n\tswitch (doc.provider) {\n\t\tcase 'native':\n\t\t\treturn ctx.native ?? null\n\t\tcase 'plausible': {\n\t\t\tconst cfg = doc.plausible ?? {}\n\t\t\treturn onDocumentHost(checkDocumentHost('plausible', cfg.host, ctx.hosts), (host) =>\n\t\t\t\tplausible({\n\t\t\t\t\tsiteId: cfg.siteId ?? '',\n\t\t\t\t\tapiKey: cfg.apiKey ?? '',\n\t\t\t\t\thost,\n\t\t\t\t\tdomain: orUndefined(cfg.domain),\n\t\t\t\t\tscriptId: orUndefined(cfg.scriptId),\n\t\t\t\t\trevenueCurrency: orUndefined(cfg.revenueCurrency),\n\t\t\t\t\tfetch: ctx.fetch,\n\t\t\t\t})\n\t\t\t)\n\t\t}\n\t\tcase 'umami': {\n\t\t\tconst cfg = doc.umami ?? {}\n\t\t\treturn onDocumentHost(checkDocumentHost('umami', cfg.host, ctx.hosts), (host) =>\n\t\t\t\tumami({\n\t\t\t\t\twebsiteId: cfg.websiteId ?? '',\n\t\t\t\t\tapiKey: orUndefined(cfg.apiKey),\n\t\t\t\t\ttoken: orUndefined(cfg.token),\n\t\t\t\t\thost,\n\t\t\t\t\tfetch: ctx.fetch,\n\t\t\t\t})\n\t\t\t)\n\t\t}\n\t\tcase 'ga4': {\n\t\t\tconst cfg = doc.ga4 ?? {}\n\t\t\treturn ga4({\n\t\t\t\tpropertyId: cfg.propertyId ?? '',\n\t\t\t\tcredentials: {\n\t\t\t\t\tclient_email: cfg.clientEmail ?? '',\n\t\t\t\t\tprivate_key: normalizePrivateKey(cfg.privateKey ?? ''),\n\t\t\t\t},\n\t\t\t\tprojectId: orUndefined(cfg.projectId),\n\t\t\t\tmeasurementId: orUndefined(cfg.measurementId),\n\t\t\t\tcurrency: orUndefined(cfg.currency),\n\t\t\t\t...(ctx.sdks?.ga4 ? { sdk: ctx.sdks.ga4 } : {}),\n\t\t\t})\n\t\t}\n\t\tcase 'posthog': {\n\t\t\tconst cfg = doc.posthog ?? {}\n\t\t\treturn onDocumentHost(checkDocumentHost('posthog', cfg.host, ctx.hosts), (host) =>\n\t\t\t\tposthog({\n\t\t\t\t\tprojectId: cfg.projectId ?? '',\n\t\t\t\t\tapiKey: cfg.apiKey ?? '',\n\t\t\t\t\thost,\n\t\t\t\t\tprojectToken: orUndefined(cfg.projectToken),\n\t\t\t\t\tregion: posthogRegion(cfg.region),\n\t\t\t\t\tscopeProperty: orUndefined(cfg.scopeProperty?.trim()),\n\t\t\t\t\tfetch: ctx.fetch,\n\t\t\t\t})\n\t\t\t)\n\t\t}\n\t\tdefault:\n\t\t\treturn null\n\t}\n}\n\n/**\n * What the factory needs to build a document's adapter: `fetch` and `hosts` keep a stored key on a\n * host the install allows.\n *\n * @beta\n */\nexport interface ProviderFactoryContext {\n\t/** The guarded fetch `providers.resolve` receives, or one from `createGuardedFetch`. */\n\tfetch: FetchLike\n\t/**\n\t * The policy `providers.resolve` receives, or one from `resolveHostPolicy`: a host outside it\n\t * builds an adapter that reads as `source_misconfigured` and captures nothing.\n\t */\n\thosts: ProviderHostPolicy\n\t/**\n\t * The install's config native adapter, which a `native` document grants rather than building a\n\t * second one.\n\t */\n\tnative?: AnalyticsAdapter\n\t/** The plugin's `sdks`: a GA4 document's adapter reads through `sdks.ga4`. */\n\tsdks?: AnalyticsSdks\n}\n\n/** Checked at runtime: a JavaScript caller can leave the guards out, which would go out unguarded. */\nconst isGuarded = (ctx: unknown): ctx is ProviderFactoryContext =>\n\tisRecord(ctx) &&\n\ttypeof ctx.fetch === 'function' &&\n\tisRecord(ctx.hosts) &&\n\tArray.isArray(ctx.hosts.allow)\n\n/**\n * Builds a provider document's adapter: missing credentials read as `isConfigured() === false`, an\n * unknown provider as null, and a `native` document lends the config adapter under its label.\n */\nexport const adapterFromProviderDoc = (\n\tdoc: ProviderDoc,\n\tctx: ProviderFactoryContext\n): AnalyticsAdapter | null => {\n\tif (!isGuarded(ctx)) {\n\t\tthrow new Error(\n\t\t\t'analytics: adapterFromProviderDoc needs { fetch, hosts }: pass the ones providers.resolve receives'\n\t\t)\n\t}\n\tconst base = buildBaseAdapter(doc, ctx)\n\tif (!base) {\n\t\treturn null\n\t}\n\treturn doc.provider === 'native' ? withDocumentLabel(base, doc) : withInstanceIdentity(base, doc)\n}\n"],"mappings":";;;;;;;;AAWA,MAAa,eAAe;CAAC;CAAU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ACZ,CAAC,CACF;EACD;EACA,SACC,OAAO;CACT;AACD;;AA0BA,MAAM,aAAa,QAClB,SAAS,GAAG,KACZ,OAAO,IAAI,UAAU,cACrB,SAAS,IAAI,KAAK,KAClB,MAAM,QAAQ,IAAI,MAAM,KAAK;;;;;AAM9B,MAAa,0BACZ,KACA,QAC6B;CAC7B,IAAI,CAAC,UAAU,GAAG,GACjB,MAAM,IAAI,MACT,oGACD;CAED,MAAM,OAAO,iBAAiB,KAAK,GAAG;CACtC,IAAI,CAAC,MACJ,OAAO;CAER,OAAO,IAAI,aAAa,WAAW,kBAAkB,MAAM,GAAG,IAAI,qBAAqB,MAAM,GAAG;AACjG"}
|
|
1
|
+
{"version":3,"file":"factory.js","names":[],"sources":["../../src/providers/factory.ts"],"sourcesContent":["import { ga4 } from '../adapters/ga4/ga4'\nimport { plausible } from '../adapters/plausible/plausible'\nimport { posthog } from '../adapters/posthog/posthog'\nimport { umami } from '../adapters/umami/umami'\nimport type { AnalyticsAdapter, AnalyticsResult } from '../core/contract'\nimport type { FetchLike } from '../core/fetch'\nimport type { AnalyticsSdks } from '../core/sdks'\nimport { HostRefusedError } from '../core/sourceErrors'\nimport { withFixedLabel } from '../core/sourceLabel'\nimport { isRecord } from '../core/values'\nimport { checkDocumentHost, type DocumentHost, type ProviderHostPolicy } from './hosts'\n\nexport type ProviderId = 'native' | 'plausible' | 'umami' | 'ga4' | 'posthog'\nexport const PROVIDER_IDS = [\n\t'native',\n\t'plausible',\n\t'umami',\n\t'ga4',\n\t'posthog',\n] as const satisfies readonly ProviderId[]\n\n/** The provider-settings document shape the adapter factory reads (depth 0, secrets revealed). */\nexport type ProviderDoc = {\n\tid?: number | string\n\tname?: string | null\n\tprovider?: string | null\n\tenabled?: boolean | null\n\tscope?: string | null\n\tplausible?: {\n\t\tsiteId?: string | null\n\t\tapiKey?: string | null\n\t\thost?: string | null\n\t\tdomain?: string | null\n\t\tscriptId?: string | null\n\t\trevenueCurrency?: string | null\n\t} | null\n\tumami?: {\n\t\twebsiteId?: string | null\n\t\tapiKey?: string | null\n\t\ttoken?: string | null\n\t\thost?: string | null\n\t} | null\n\tga4?: {\n\t\tpropertyId?: string | null\n\t\tclientEmail?: string | null\n\t\tprivateKey?: string | null\n\t\tprojectId?: string | null\n\t\tmeasurementId?: string | null\n\t\tcurrency?: string | null\n\t} | null\n\tposthog?: {\n\t\tprojectId?: string | null\n\t\tapiKey?: string | null\n\t\thost?: string | null\n\t\tprojectToken?: string | null\n\t\tregion?: string | null\n\t\tscopeProperty?: string | null\n\t} | null\n}\n\n/** A stored blank reads as unset. */\nconst orUndefined = (value: string | null | undefined): string | undefined => value || undefined\n\n/** An unset or unrecognized stored region falls back to host-derived detection. */\nconst posthogRegion = (value: string | null | undefined): 'us' | 'eu' | undefined =>\n\tvalue === 'us' || value === 'eu' ? value : undefined\n\n/**\n * Keys pasted from a service-account JSON often carry escaped newlines; the gRPC\n * client needs real ones.\n */\nexport const normalizePrivateKey = (key: string): string => key.replace(/\\\\n/g, '\\n')\n\nconst shortId = (id: number | string): string => String(id).slice(-6)\n\n/** The registry id of a provider document's adapter, which grants and stand-ins must match. */\nexport const documentAdapterId = (provider: unknown, id: unknown): string =>\n\t`${String(provider)}:${String(id)}`\n\n/** A lent `native` adapter under the document's name, so a source reads as its tenant named it. */\nconst withDocumentLabel = (adapter: AnalyticsAdapter, doc: ProviderDoc): AnalyticsAdapter =>\n\tdoc.name ? withFixedLabel(adapter, doc.name) : adapter\n\n/** Per-document ids keep two projects of one provider type apart in a registry. */\nconst withInstanceIdentity = (adapter: AnalyticsAdapter, doc: ProviderDoc): AnalyticsAdapter => {\n\tif (doc.id === undefined || doc.id === null || doc.id === '') {\n\t\treturn adapter\n\t}\n\treturn {\n\t\t...withFixedLabel(adapter, doc.name || `${adapter.label} ${shortId(doc.id)}`),\n\t\tid: documentAdapterId(doc.provider, doc.id),\n\t}\n}\n\n/**\n * Keeps `shape`'s identity, capabilities and `isConfigured` (configured when absent) so the source\n * still lists, but every read throws `error()` and it declares no capture, so its proxy mount 404s.\n */\nexport const failingAdapter = (\n\tshape: Pick<AnalyticsAdapter, 'id' | 'label' | 'capabilities' | 'realtime'> &\n\t\tPartial<Pick<AnalyticsAdapter, 'isConfigured'>>,\n\terror: () => Error\n): AnalyticsAdapter => {\n\tconst fail = async (): Promise<AnalyticsResult> => {\n\t\tthrow error()\n\t}\n\treturn {\n\t\tid: shape.id,\n\t\tlabel: shape.label,\n\t\tcapabilities: shape.capabilities,\n\t\tisConfigured: shape.isConfigured ?? (() => true),\n\t\tquery: fail,\n\t\t...(shape.realtime ? { realtime: fail } : {}),\n\t}\n}\n\n/**\n * Builds a hosted vendor's adapter on the address its host check allowed, none being the vendor's\n * cloud; a refused host builds one whose reads fail with a `HostRefusedError`.\n */\nconst onDocumentHost = (\n\tverdict: DocumentHost,\n\tbuild: (host: string | undefined) => AnalyticsAdapter\n): AnalyticsAdapter => {\n\tif (verdict.ok) {\n\t\treturn build(verdict.address ?? undefined)\n\t}\n\tconst { host, reason } = verdict\n\treturn failingAdapter(build(undefined), () => new HostRefusedError(host, reason))\n}\n\nconst buildBaseAdapter = (\n\tdoc: ProviderDoc,\n\tctx: ProviderFactoryContext\n): AnalyticsAdapter | null => {\n\tswitch (doc.provider) {\n\t\tcase 'native':\n\t\t\treturn ctx.native ?? null\n\t\tcase 'plausible': {\n\t\t\tconst cfg = doc.plausible ?? {}\n\t\t\treturn onDocumentHost(checkDocumentHost('plausible', cfg.host, ctx.hosts), (host) =>\n\t\t\t\tplausible({\n\t\t\t\t\tsiteId: cfg.siteId ?? '',\n\t\t\t\t\tapiKey: cfg.apiKey ?? '',\n\t\t\t\t\thost,\n\t\t\t\t\tdomain: orUndefined(cfg.domain),\n\t\t\t\t\tscriptId: orUndefined(cfg.scriptId),\n\t\t\t\t\trevenueCurrency: orUndefined(cfg.revenueCurrency),\n\t\t\t\t\tfetch: ctx.fetch,\n\t\t\t\t})\n\t\t\t)\n\t\t}\n\t\tcase 'umami': {\n\t\t\tconst cfg = doc.umami ?? {}\n\t\t\treturn onDocumentHost(checkDocumentHost('umami', cfg.host, ctx.hosts), (host) =>\n\t\t\t\tumami({\n\t\t\t\t\twebsiteId: cfg.websiteId ?? '',\n\t\t\t\t\tapiKey: orUndefined(cfg.apiKey),\n\t\t\t\t\ttoken: orUndefined(cfg.token),\n\t\t\t\t\thost,\n\t\t\t\t\tfetch: ctx.fetch,\n\t\t\t\t})\n\t\t\t)\n\t\t}\n\t\tcase 'ga4': {\n\t\t\tconst cfg = doc.ga4 ?? {}\n\t\t\treturn ga4({\n\t\t\t\tpropertyId: cfg.propertyId ?? '',\n\t\t\t\tcredentials: {\n\t\t\t\t\tclient_email: cfg.clientEmail ?? '',\n\t\t\t\t\tprivate_key: normalizePrivateKey(cfg.privateKey ?? ''),\n\t\t\t\t},\n\t\t\t\tprojectId: orUndefined(cfg.projectId),\n\t\t\t\tmeasurementId: orUndefined(cfg.measurementId),\n\t\t\t\tcurrency: orUndefined(cfg.currency),\n\t\t\t\t...(ctx.sdks?.ga4 ? { sdk: ctx.sdks.ga4 } : {}),\n\t\t\t})\n\t\t}\n\t\tcase 'posthog': {\n\t\t\tconst cfg = doc.posthog ?? {}\n\t\t\treturn onDocumentHost(checkDocumentHost('posthog', cfg.host, ctx.hosts), (host) =>\n\t\t\t\tposthog({\n\t\t\t\t\tprojectId: cfg.projectId ?? '',\n\t\t\t\t\tapiKey: cfg.apiKey ?? '',\n\t\t\t\t\thost,\n\t\t\t\t\tprojectToken: orUndefined(cfg.projectToken),\n\t\t\t\t\tregion: posthogRegion(cfg.region),\n\t\t\t\t\tscopeProperty: orUndefined(cfg.scopeProperty?.trim()),\n\t\t\t\t\tfetch: ctx.fetch,\n\t\t\t\t})\n\t\t\t)\n\t\t}\n\t\tdefault:\n\t\t\treturn null\n\t}\n}\n\n/**\n * What the factory needs to build a document's adapter: `fetch` and `hosts` keep a stored key on a\n * host the install allows.\n *\n * @beta\n */\nexport interface ProviderFactoryContext {\n\t/** The guarded fetch `providers.resolve` receives, or one from `createGuardedFetch`. */\n\tfetch: FetchLike\n\t/**\n\t * The policy `providers.resolve` receives, or one from `resolveHostPolicy`: a host outside it\n\t * builds an adapter that reads as `source_misconfigured` and captures nothing.\n\t */\n\thosts: ProviderHostPolicy\n\t/**\n\t * The install's config native adapter, which a `native` document grants rather than building a\n\t * second one.\n\t */\n\tnative?: AnalyticsAdapter\n\t/** The plugin's `sdks`: a GA4 document's adapter reads through `sdks.ga4`. */\n\tsdks?: AnalyticsSdks\n}\n\n/** Checked at runtime: a JavaScript caller can leave the guards out, which would go out unguarded. */\nconst isGuarded = (ctx: unknown): ctx is ProviderFactoryContext =>\n\tisRecord(ctx) &&\n\ttypeof ctx.fetch === 'function' &&\n\tisRecord(ctx.hosts) &&\n\tArray.isArray(ctx.hosts.allow)\n\n/**\n * Builds a provider document's adapter: missing credentials read as `isConfigured() === false`, an\n * unknown provider as null, and a `native` document lends the config adapter under its label.\n */\nexport const adapterFromProviderDoc = (\n\tdoc: ProviderDoc,\n\tctx: ProviderFactoryContext\n): AnalyticsAdapter | null => {\n\tif (!isGuarded(ctx)) {\n\t\tthrow new Error(\n\t\t\t'analytics: adapterFromProviderDoc needs { fetch, hosts }: pass the ones providers.resolve receives'\n\t\t)\n\t}\n\tconst base = buildBaseAdapter(doc, ctx)\n\tif (!base) {\n\t\treturn null\n\t}\n\treturn doc.provider === 'native' ? withDocumentLabel(base, doc) : withInstanceIdentity(base, doc)\n}\n"],"mappings":";;;;;;;;;AAaA,MAAa,eAAe;CAC3B;CACA;CACA;CACA;CACA;AACD;;AA0CA,MAAM,eAAe,UAAyD,SAAS,KAAA;;AAGvF,MAAM,iBAAiB,UACtB,UAAU,QAAQ,UAAU,OAAO,QAAQ,KAAA;;;;;AAM5C,MAAa,uBAAuB,QAAwB,IAAI,QAAQ,QAAQ,IAAI;AAEpF,MAAM,WAAW,OAAgC,OAAO,EAAE,EAAE,MAAM,EAAE;;AAGpE,MAAa,qBAAqB,UAAmB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AED,MAAM,OAAO,iBAAiB,KAAK,GAAG;CACtC,IAAI,CAAC,MACJ,OAAO;CAER,OAAO,IAAI,aAAa,WAAW,kBAAkB,MAAM,GAAG,IAAI,qBAAqB,MAAM,GAAG;AACjG"}
|
package/dist/providers/probe.js
CHANGED
|
@@ -35,7 +35,10 @@ const createCollectionProbe = (options) => {
|
|
|
35
35
|
updatedAt: true,
|
|
36
36
|
enabled: true,
|
|
37
37
|
[scopeField]: true,
|
|
38
|
-
...options.provider ? {
|
|
38
|
+
...options.provider ? {
|
|
39
|
+
provider: true,
|
|
40
|
+
isDefault: true
|
|
41
|
+
} : {}
|
|
39
42
|
};
|
|
40
43
|
const memo = /* @__PURE__ */ new Map();
|
|
41
44
|
const expedited = /* @__PURE__ */ new Map();
|
|
@@ -44,6 +47,7 @@ const createCollectionProbe = (options) => {
|
|
|
44
47
|
updatedAt: versionOf(doc.updatedAt),
|
|
45
48
|
enabled: doc.enabled === true,
|
|
46
49
|
...options.provider ? { provider: typeof doc.provider === "string" ? doc.provider : "" } : {},
|
|
50
|
+
...options.provider && doc.isDefault === true ? { isDefault: true } : {},
|
|
47
51
|
scope: docScope(doc, scopeField)
|
|
48
52
|
});
|
|
49
53
|
const query = async (scope) => {
|