@10x-media/analytics 1.0.0-beta.12 → 1.0.0-beta.13
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 +67 -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 +107 -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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","names":[],"sources":["../../src/core/registry.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\nimport type { AnalyticsAdapter } from './contract'\n\nexport interface AdapterRegistry {\n\tget(id: string): AnalyticsAdapter\n\tdefault(): AnalyticsAdapter\n\tall(): AnalyticsAdapter[]\n\tisMultiProvider(): boolean\n}\n\nexport type ResolveRegistryArgs = {\n\tpayload: Payload\n\treq?: PayloadRequest\n\t/** The analytics boundary to resolve adapters for; null is the whole install. */\n\tscope: string | null\n}\n\n/**\n * One scope's adapters, and which its own provider documents put there. A `native` document grants\n * the config native adapter, so a granted id can name a config adapter.\n */\nexport interface ScopeRegistry {\n\tregistry: AdapterRegistry\n\t/** Adapter id to the id of the provider document granting it to this scope. */\n\tgrants: ReadonlyMap<string, string>\n}\n\n/** The grants of a registry no provider document adds to. */\nexport const NO_GRANTS: ReadonlyMap<string, string> = new Map()\n\n/**\n * The seam every read resolves its adapters through: the config registry for all scopes, with\n * runtime provider sources layered per scope on top.\n */\nexport type RegistryResolver = (args: ResolveRegistryArgs) => Promise<ScopeRegistry>\n\n/**\n * The registry minus the adapters `keep` rejects, or null when it rejects all. The default survives\n * only if kept.\n */\nexport const filterRegistry = (\n\tregistry: AdapterRegistry,\n\tkeep: (adapter: AnalyticsAdapter) => boolean\n): AdapterRegistry | null => {\n\tconst kept = registry.all().filter(keep)\n\tif (kept.length === 0) {\n\t\treturn null\n\t}\n\tif (kept.length === registry.all().length) {\n\t\treturn registry\n\t}\n\tconst defaultId = registry.default().id\n\treturn createRegistry(kept, kept.some((a) => a.id === defaultId) ? defaultId : undefined)\n}\n\n/**\n * Each adapter's copy without revenue, made once: reads reach a source through a lane keyed on the\n * adapter object, so one adapter must narrow to one object however many registries are built.\n */\nconst withoutRevenueCopies = new WeakMap<AnalyticsAdapter, AnalyticsAdapter>()\n\nconst dropRevenue = (adapter: AnalyticsAdapter): AnalyticsAdapter => {\n\tif (!adapter.capabilities.metrics.has('revenue')) {\n\t\treturn adapter\n\t}\n\tconst made = withoutRevenueCopies.get(adapter)\n\tif (made) {\n\t\treturn made\n\t}\n\tconst copy: AnalyticsAdapter = {\n\t\t...adapter,\n\t\tcapabilities: {\n\t\t\t...adapter.capabilities,\n\t\t\tmetrics: new Set([...adapter.capabilities.metrics].filter((metric) => metric !== 'revenue')),\n\t\t},\n\t}\n\twithoutRevenueCopies.set(adapter, copy)\n\treturn copy\n}\n\n/**\n * The registry with `revenue` gone from every adapter: the one place an install measuring no money\n * hides the metric from every reader at once.\n */\nexport const withoutRevenue = (registry: AdapterRegistry): AdapterRegistry => {\n\tconst all = registry.all()\n\tif (!all.some((adapter) => adapter.capabilities.metrics.has('revenue'))) {\n\t\treturn registry\n\t}\n\treturn createRegistry(all.map(dropRevenue), registry.default().id)\n}\n\n/** A registry over `adapters`, reading through `defaultId` or else the first when none is named. */\nexport function createRegistry(adapters: AnalyticsAdapter[], defaultId?: string): AdapterRegistry {\n\tconst [first] = adapters\n\tif (first === undefined) throw new Error('analytics: at least one adapter is required')\n\tconst byId = new Map(adapters.map((a) => [a.id, a]))\n\tif (defaultId !== undefined && !byId.has(defaultId)) {\n\t\tthrow new Error(`analytics: unknown default adapter \"${defaultId}\"`)\n\t}\n\tconst fallback = defaultId ?? first.id\n\treturn {\n\t\tget(id) {\n\t\t\tconst a = byId.get(id)\n\t\t\tif (!a) throw new Error(`analytics: unknown adapter \"${id}\"`)\n\t\t\treturn a\n\t\t},\n\t\tdefault: () => byId.get(fallback) ?? first,\n\t\tall: () => adapters,\n\t\tisMultiProvider: () => adapters.length > 1,\n\t}\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"registry.js","names":[],"sources":["../../src/core/registry.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\nimport type { AnalyticsAdapter } from './contract'\n\nexport interface AdapterRegistry {\n\tget(id: string): AnalyticsAdapter\n\tdefault(): AnalyticsAdapter\n\tall(): AnalyticsAdapter[]\n\tisMultiProvider(): boolean\n}\n\nexport type ResolveRegistryArgs = {\n\tpayload: Payload\n\treq?: PayloadRequest\n\t/** The analytics boundary to resolve adapters for; null is the whole install. */\n\tscope: string | null\n}\n\n/**\n * One scope's adapters, and which its own provider documents put there. A `native` document grants\n * the config native adapter, so a granted id can name a config adapter.\n */\nexport interface ScopeRegistry {\n\tregistry: AdapterRegistry\n\t/** Adapter id to the id of the provider document granting it to this scope. */\n\tgrants: ReadonlyMap<string, string>\n\t/**\n\t * Adapter id granted by the scope's enabled, available provider document flagged the default.\n\t * It wins a tenant scope's default over `defaultSource` wherever the reader may read it.\n\t */\n\tdefaultGrant?: string\n}\n\n/** The grants of a registry no provider document adds to. */\nexport const NO_GRANTS: ReadonlyMap<string, string> = new Map()\n\n/**\n * The seam every read resolves its adapters through: the config registry for all scopes, with\n * runtime provider sources layered per scope on top.\n */\nexport type RegistryResolver = (args: ResolveRegistryArgs) => Promise<ScopeRegistry>\n\n/**\n * The registry minus the adapters `keep` rejects, or null when it rejects all. The default survives\n * only if kept.\n */\nexport const filterRegistry = (\n\tregistry: AdapterRegistry,\n\tkeep: (adapter: AnalyticsAdapter) => boolean\n): AdapterRegistry | null => {\n\tconst kept = registry.all().filter(keep)\n\tif (kept.length === 0) {\n\t\treturn null\n\t}\n\tif (kept.length === registry.all().length) {\n\t\treturn registry\n\t}\n\tconst defaultId = registry.default().id\n\treturn createRegistry(kept, kept.some((a) => a.id === defaultId) ? defaultId : undefined)\n}\n\n/**\n * Each adapter's copy without revenue, made once: reads reach a source through a lane keyed on the\n * adapter object, so one adapter must narrow to one object however many registries are built.\n */\nconst withoutRevenueCopies = new WeakMap<AnalyticsAdapter, AnalyticsAdapter>()\n\nconst dropRevenue = (adapter: AnalyticsAdapter): AnalyticsAdapter => {\n\tif (!adapter.capabilities.metrics.has('revenue')) {\n\t\treturn adapter\n\t}\n\tconst made = withoutRevenueCopies.get(adapter)\n\tif (made) {\n\t\treturn made\n\t}\n\tconst copy: AnalyticsAdapter = {\n\t\t...adapter,\n\t\tcapabilities: {\n\t\t\t...adapter.capabilities,\n\t\t\tmetrics: new Set([...adapter.capabilities.metrics].filter((metric) => metric !== 'revenue')),\n\t\t},\n\t}\n\twithoutRevenueCopies.set(adapter, copy)\n\treturn copy\n}\n\n/**\n * The registry with `revenue` gone from every adapter: the one place an install measuring no money\n * hides the metric from every reader at once.\n */\nexport const withoutRevenue = (registry: AdapterRegistry): AdapterRegistry => {\n\tconst all = registry.all()\n\tif (!all.some((adapter) => adapter.capabilities.metrics.has('revenue'))) {\n\t\treturn registry\n\t}\n\treturn createRegistry(all.map(dropRevenue), registry.default().id)\n}\n\n/** A registry over `adapters`, reading through `defaultId` or else the first when none is named. */\nexport function createRegistry(adapters: AnalyticsAdapter[], defaultId?: string): AdapterRegistry {\n\tconst [first] = adapters\n\tif (first === undefined) throw new Error('analytics: at least one adapter is required')\n\tconst byId = new Map(adapters.map((a) => [a.id, a]))\n\tif (defaultId !== undefined && !byId.has(defaultId)) {\n\t\tthrow new Error(`analytics: unknown default adapter \"${defaultId}\"`)\n\t}\n\tconst fallback = defaultId ?? first.id\n\treturn {\n\t\tget(id) {\n\t\t\tconst a = byId.get(id)\n\t\t\tif (!a) throw new Error(`analytics: unknown adapter \"${id}\"`)\n\t\t\treturn a\n\t\t},\n\t\tdefault: () => byId.get(fallback) ?? first,\n\t\tall: () => adapters,\n\t\tisMultiProvider: () => adapters.length > 1,\n\t}\n}\n"],"mappings":";;AAiCA,MAAa,4BAAyC,IAAI,IAAI;;;;;AAY9D,MAAa,kBACZ,UACA,SAC4B;CAC5B,MAAM,OAAO,SAAS,IAAI,EAAE,OAAO,IAAI;CACvC,IAAI,KAAK,WAAW,GACnB,OAAO;CAER,IAAI,KAAK,WAAW,SAAS,IAAI,EAAE,QAClC,OAAO;CAER,MAAM,YAAY,SAAS,QAAQ,EAAE;CACrC,OAAO,eAAe,MAAM,KAAK,MAAM,MAAM,EAAE,OAAO,SAAS,IAAI,YAAY,KAAA,CAAS;AACzF;;;;;AAMA,MAAM,uCAAuB,IAAI,QAA4C;AAE7E,MAAM,eAAe,YAAgD;CACpE,IAAI,CAAC,QAAQ,aAAa,QAAQ,IAAI,SAAS,GAC9C,OAAO;CAER,MAAM,OAAO,qBAAqB,IAAI,OAAO;CAC7C,IAAI,MACH,OAAO;CAER,MAAM,OAAyB;EAC9B,GAAG;EACH,cAAc;GACb,GAAG,QAAQ;GACX,SAAS,IAAI,IAAI,CAAC,GAAG,QAAQ,aAAa,OAAO,EAAE,QAAQ,WAAW,WAAW,SAAS,CAAC;EAC5F;CACD;CACA,qBAAqB,IAAI,SAAS,IAAI;CACtC,OAAO;AACR;;;;;AAMA,MAAa,kBAAkB,aAA+C;CAC7E,MAAM,MAAM,SAAS,IAAI;CACzB,IAAI,CAAC,IAAI,MAAM,YAAY,QAAQ,aAAa,QAAQ,IAAI,SAAS,CAAC,GACrE,OAAO;CAER,OAAO,eAAe,IAAI,IAAI,WAAW,GAAG,SAAS,QAAQ,EAAE,EAAE;AAClE;;AAGA,SAAgB,eAAe,UAA8B,WAAqC;CACjG,MAAM,CAAC,SAAS;CAChB,IAAI,UAAU,KAAA,GAAW,MAAM,IAAI,MAAM,6CAA6C;CACtF,MAAM,OAAO,IAAI,IAAI,SAAS,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;CACnD,IAAI,cAAc,KAAA,KAAa,CAAC,KAAK,IAAI,SAAS,GACjD,MAAM,IAAI,MAAM,uCAAuC,UAAU,EAAE;CAEpE,MAAM,WAAW,aAAa,MAAM;CACpC,OAAO;EACN,IAAI,IAAI;GACP,MAAM,IAAI,KAAK,IAAI,EAAE;GACrB,IAAI,CAAC,GAAG,MAAM,IAAI,MAAM,+BAA+B,GAAG,EAAE;GAC5D,OAAO;EACR;EACA,eAAe,KAAK,IAAI,QAAQ,KAAK;EACrC,WAAW;EACX,uBAAuB,SAAS,SAAS;CAC1C;AACD"}
|
|
@@ -64,6 +64,7 @@ const assertScopedOnlyOptions = (options) => {
|
|
|
64
64
|
"member"
|
|
65
65
|
]) if (options.scope?.[key] !== void 0) paths.push(`scope.${key}`);
|
|
66
66
|
if (options.access?.crossScope !== void 0) paths.push("access.crossScope");
|
|
67
|
+
for (const key of ["sources", "defaultSource"]) if (options[key] !== void 0) paths.push(key);
|
|
67
68
|
if (typeof options.capture?.slots?.tenant === "string") paths.push("capture.slots.tenant");
|
|
68
69
|
if (options.capture?.paths?.tenant !== void 0) paths.push("capture.paths.tenant");
|
|
69
70
|
for (const [slug, binding] of Object.entries(options.collections ?? {})) if (binding?.scopeField !== void 0 && binding.scopeField !== false) paths.push(`collections.${slug}.scopeField`);
|
|
@@ -71,6 +72,7 @@ const assertScopedOnlyOptions = (options) => {
|
|
|
71
72
|
if (isRecord(goalsCollection) && goalsCollection.scopeField !== void 0) paths.push("goals.collection.scopeField");
|
|
72
73
|
const providersCollection = options.providers?.collection;
|
|
73
74
|
if (isRecord(providersCollection) && providersCollection.scopeField !== void 0) paths.push("providers.collection.scopeField");
|
|
75
|
+
if (isRecord(providersCollection) && providersCollection.fields?.isDefault !== void 0) paths.push("providers.collection.fields.isDefault");
|
|
74
76
|
if (paths.length > 0) {
|
|
75
77
|
const one = paths.length === 1;
|
|
76
78
|
throw new Error(`analytics: ${paths.join(", ")} ${one ? "only applies" : "only apply"} to a scoped install. Set scope.resolve, or remove ${one ? "it" : "them"}.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scopeOptions.js","names":[],"sources":["../../src/core/scopeOptions.ts"],"sourcesContent":["import { isAdminUser } from '../access/adminUser'\nimport type { ScopeDecision } from '../plugin/runtime'\nimport { PLATFORM_SCOPE } from './contract'\nimport { keysOf, optionalFunction, optionsObject } from './optionChecks'\nimport type {\n\tAnalyticsAccessOptions,\n\tAnalyticsPluginOptions,\n\tAnalyticsReadAccess,\n\tAnalyticsScopeOptions,\n\tCrossScopeAccess,\n\tResolvedCrossScope,\n\tResolvedOptions,\n\tResolvedScope,\n\tScopeResolver,\n} from './options'\nimport { isRecord, kindOf } from './values'\n\nconst SCOPE_KEYS = keysOf<AnalyticsScopeOptions>({\n\tresolve: true,\n\tmember: true,\n\tlist: true,\n\tlabel: true,\n})\n\nconst ACCESS_KEYS = keysOf<AnalyticsAccessOptions>({ read: true, view: true, crossScope: true })\n\nconst CROSS_SCOPE_GATES = keysOf<Record<ScopeDecision, true>>({\n\tnamed: true,\n\taggregate: true,\n\tunscopedSource: true,\n})\n\nconst MEMBER_REQUIRED =\n\t\"analytics: scope.member is required with scope.resolve. scope.resolve picks which scope a request is for; scope.member decides whether its user belongs to that scope, and every read and every write to the plugin's collections asks it. With @payloadcms/plugin-multi-tenant, pass tenantMembership() from '@10x-media/analytics'. Pass () => true only when scope.resolve derives the scope from req.user itself, so a user can never select a scope they do not belong to.\"\n\n/** One access function for all three cross-scope gates, which is what the function form means. */\nexport const allCrossScope = (access: CrossScopeAccess): ResolvedCrossScope => ({\n\tnamed: access,\n\taggregate: access,\n\tunscopedSource: access,\n})\n\n/** The `'*'` marker is a reader's request for every scope, never a request's own scope. */\nconst refusingWildcard =\n\t(resolve: ScopeResolver): ScopeResolver =>\n\tasync (args) => {\n\t\tconst scope = await resolve(args)\n\t\tif (scope === PLATFORM_SCOPE) {\n\t\t\tthrow new Error(\n\t\t\t\t`analytics: scope.resolve returned \"${PLATFORM_SCOPE}\", which names every scope at once; return one scope id, or null for the install-wide scope`\n\t\t\t)\n\t\t}\n\t\treturn scope\n\t}\n\n/** `scope`: unset resolves every request to the install-wide scope; set, it needs `member`. */\nexport const resolveScope = (option: AnalyticsPluginOptions['scope']): ResolvedScope => {\n\tif (option !== undefined) {\n\t\toptionsObject(option, {\n\t\t\tpath: 'scope',\n\t\t\tknown: SCOPE_KEYS,\n\t\t\texample: 'an object such as { resolve, member }',\n\t\t})\n\t}\n\tconst resolve = optionalFunction(option?.resolve, 'scope.resolve')\n\tconst list = optionalFunction(option?.list, 'scope.list')\n\tconst label = optionalFunction(option?.label, 'scope.label')\n\tconst member = optionalFunction(option?.member, 'scope.member')\n\tif (!resolve) {\n\t\treturn { resolve: () => null }\n\t}\n\tif (member === undefined) {\n\t\tthrow new Error(MEMBER_REQUIRED)\n\t}\n\treturn {\n\t\tresolve: refusingWildcard(resolve),\n\t\tmember,\n\t\t...(list ? { list } : {}),\n\t\t...(label ? { label } : {}),\n\t}\n}\n\n/**\n * Refuses the options that only mean something on a scoped install: an unscoped config carrying one\n * almost always forgot `scope.resolve`, so it fails the boot rather than doing nothing.\n */\nexport const assertScopedOnlyOptions = (options: AnalyticsPluginOptions): void => {\n\tconst paths: string[] = []\n\tfor (const key of ['list', 'label', 'member'] as const) {\n\t\tif (options.scope?.[key] !== undefined) {\n\t\t\tpaths.push(`scope.${key}`)\n\t\t}\n\t}\n\tif (options.access?.crossScope !== undefined) {\n\t\tpaths.push('access.crossScope')\n\t}\n\tif (typeof options.capture?.slots?.tenant === 'string') {\n\t\tpaths.push('capture.slots.tenant')\n\t}\n\tif (options.capture?.paths?.tenant !== undefined) {\n\t\tpaths.push('capture.paths.tenant')\n\t}\n\tfor (const [slug, binding] of Object.entries(options.collections ?? {})) {\n\t\tif (binding?.scopeField !== undefined && binding.scopeField !== false) {\n\t\t\tpaths.push(`collections.${slug}.scopeField`)\n\t\t}\n\t}\n\tconst goalsCollection = Array.isArray(options.goals) ? undefined : options.goals?.collection\n\tif (isRecord(goalsCollection) && goalsCollection.scopeField !== undefined) {\n\t\tpaths.push('goals.collection.scopeField')\n\t}\n\tconst providersCollection = options.providers?.collection\n\tif (isRecord(providersCollection) && providersCollection.scopeField !== undefined) {\n\t\tpaths.push('providers.collection.scopeField')\n\t}\n\tif (paths.length > 0) {\n\t\tconst one = paths.length === 1\n\t\tthrow new Error(\n\t\t\t`analytics: ${paths.join(', ')} ${one ? 'only applies' : 'only apply'} to a scoped install. Set scope.resolve, or remove ${one ? 'it' : 'them'}.`\n\t\t)\n\t}\n}\n\n/** Unset gates deny on a scoped install and admit `isAdminUser` on an unscoped one. */\nconst resolveCrossScope = (\n\toption: AnalyticsAccessOptions['crossScope'],\n\tscoped: boolean\n): ResolvedCrossScope => {\n\tconst fallback: CrossScopeAccess = scoped ? () => false : isAdminUser\n\tif (option === undefined) {\n\t\treturn allCrossScope(fallback)\n\t}\n\tif (typeof option === 'function') {\n\t\treturn allCrossScope(option)\n\t}\n\tif (!isRecord(option)) {\n\t\tthrow new Error(\n\t\t\t`analytics: access.crossScope must be a function or an object, got ${kindOf(option)}`\n\t\t)\n\t}\n\tfor (const [gate, access] of Object.entries(option)) {\n\t\tif (!CROSS_SCOPE_GATES.includes(gate)) {\n\t\t\tthrow new Error(\n\t\t\t\t`analytics: access.crossScope has no \"${gate}\" gate; the gates are named, aggregate and unscopedSource`\n\t\t\t)\n\t\t}\n\t\tif (access !== undefined && typeof access !== 'function') {\n\t\t\tthrow new Error(`analytics: access.crossScope.${gate} must be a function`)\n\t\t}\n\t}\n\treturn {\n\t\tnamed: option.named ?? fallback,\n\t\taggregate: option.aggregate ?? fallback,\n\t\tunscopedSource: option.unscopedSource ?? fallback,\n\t}\n}\n\n/** `access`: the read gate, the view gate (the read gate unless set) and the cross-scope gates. */\nexport const resolveAccess = (\n\toption: AnalyticsAccessOptions | undefined,\n\tscoped: boolean\n): ResolvedOptions['access'] => {\n\tif (option !== undefined) {\n\t\toptionsObject(option, {\n\t\t\tpath: 'access',\n\t\t\tknown: ACCESS_KEYS,\n\t\t\texample: 'an object such as { read: isAdminUser }',\n\t\t})\n\t}\n\tconst read: AnalyticsReadAccess = optionalFunction(option?.read, 'access.read') ?? isAdminUser\n\treturn {\n\t\tread,\n\t\tview: optionalFunction(option?.view, 'access.view') ?? read,\n\t\tcrossScope: resolveCrossScope(option?.crossScope, scoped),\n\t}\n}\n"],"mappings":";;;;;AAiBA,MAAM,aAAa,OAA8B;CAChD,SAAS;CACT,QAAQ;CACR,MAAM;CACN,OAAO;AACR,CAAC;AAED,MAAM,cAAc,OAA+B;CAAE,MAAM;CAAM,MAAM;CAAM,YAAY;AAAK,CAAC;AAE/F,MAAM,oBAAoB,OAAoC;CAC7D,OAAO;CACP,WAAW;CACX,gBAAgB;AACjB,CAAC;AAED,MAAM,kBACL;;AAGD,MAAa,iBAAiB,YAAkD;CAC/E,OAAO;CACP,WAAW;CACX,gBAAgB;AACjB;;AAGA,MAAM,oBACJ,YACD,OAAO,SAAS;CACf,MAAM,QAAQ,MAAM,QAAQ,IAAI;CAChC,IAAI,UAAA,KACH,MAAM,IAAI,MACT,iIACD;CAED,OAAO;AACR;;AAGD,MAAa,gBAAgB,WAA2D;CACvF,IAAI,WAAW,KAAA,GACd,cAAc,QAAQ;EACrB,MAAM;EACN,O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oBAAoB,eAAe,KAAA,GACvE,MAAM,KAAK,iCAAiC;CAE7C,IAAI,MAAM,SAAS,GAAG;EACrB,MAAM,MAAM,MAAM,WAAW;EAC7B,MAAM,IAAI,MACT,cAAc,MAAM,KAAK,IAAI,EAAE,GAAG,MAAM,iBAAiB,aAAa,qDAAqD,MAAM,OAAO,OAAO,EAChJ;CACD;AACD;;AAGA,MAAM,qBACL,QACA,WACwB;CACxB,MAAM,WAA6B,eAAe,QAAQ;CAC1D,IAAI,WAAW,KAAA,GACd,OAAO,cAAc,QAAQ;CAE9B,IAAI,OAAO,WAAW,YACrB,OAAO,cAAc,MAAM;CAE5B,IAAI,CAAC,SAAS,MAAM,GACnB,MAAM,IAAI,MACT,qEAAqE,OAAO,MAAM,GACnF;CAED,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,MAAM,GAAG;EACpD,IAAI,CAAC,kBAAkB,SAAS,IAAI,GACnC,MAAM,IAAI,MACT,wCAAwC,KAAK,0DAC9C;EAED,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAC7C,MAAM,IAAI,MAAM,gCAAgC,KAAK,oBAAoB;CAE3E;CACA,OAAO;EACN,OAAO,OAAO,SAAS;EACvB,WAAW,OAAO,aAAa;EAC/B,gBAAgB,OAAO,kBAAkB;CAC1C;AACD;;AAGA,MAAa,iBACZ,QACA,WAC+B;CAC/B,IAAI,WAAW,KAAA,GACd,cAAc,QAAQ;EACrB,MAAM;EACN,OAAO;EACP,SAAS;CACV,CAAC;CAEF,MAAM,OAA4B,iBAAiB,QAAQ,MAAM,aAAa,KAAK;CACnF,OAAO;EACN;EACA,MAAM,iBAAiB,QAAQ,MAAM,aAAa,KAAK;EACvD,YAAY,kBAAkB,QAAQ,YAAY,MAAM;CACzD;AACD"}
|
|
1
|
+
{"version":3,"file":"scopeOptions.js","names":[],"sources":["../../src/core/scopeOptions.ts"],"sourcesContent":["import { isAdminUser } from '../access/adminUser'\nimport type { ScopeDecision } from '../plugin/runtime'\nimport { PLATFORM_SCOPE } from './contract'\nimport { keysOf, optionalFunction, optionsObject } from './optionChecks'\nimport type {\n\tAnalyticsAccessOptions,\n\tAnalyticsPluginOptions,\n\tAnalyticsReadAccess,\n\tAnalyticsScopeOptions,\n\tCrossScopeAccess,\n\tResolvedCrossScope,\n\tResolvedOptions,\n\tResolvedScope,\n\tScopeResolver,\n} from './options'\nimport { isRecord, kindOf } from './values'\n\nconst SCOPE_KEYS = keysOf<AnalyticsScopeOptions>({\n\tresolve: true,\n\tmember: true,\n\tlist: true,\n\tlabel: true,\n})\n\nconst ACCESS_KEYS = keysOf<AnalyticsAccessOptions>({ read: true, view: true, crossScope: true })\n\nconst CROSS_SCOPE_GATES = keysOf<Record<ScopeDecision, true>>({\n\tnamed: true,\n\taggregate: true,\n\tunscopedSource: true,\n})\n\nconst MEMBER_REQUIRED =\n\t\"analytics: scope.member is required with scope.resolve. scope.resolve picks which scope a request is for; scope.member decides whether its user belongs to that scope, and every read and every write to the plugin's collections asks it. With @payloadcms/plugin-multi-tenant, pass tenantMembership() from '@10x-media/analytics'. Pass () => true only when scope.resolve derives the scope from req.user itself, so a user can never select a scope they do not belong to.\"\n\n/** One access function for all three cross-scope gates, which is what the function form means. */\nexport const allCrossScope = (access: CrossScopeAccess): ResolvedCrossScope => ({\n\tnamed: access,\n\taggregate: access,\n\tunscopedSource: access,\n})\n\n/** The `'*'` marker is a reader's request for every scope, never a request's own scope. */\nconst refusingWildcard =\n\t(resolve: ScopeResolver): ScopeResolver =>\n\tasync (args) => {\n\t\tconst scope = await resolve(args)\n\t\tif (scope === PLATFORM_SCOPE) {\n\t\t\tthrow new Error(\n\t\t\t\t`analytics: scope.resolve returned \"${PLATFORM_SCOPE}\", which names every scope at once; return one scope id, or null for the install-wide scope`\n\t\t\t)\n\t\t}\n\t\treturn scope\n\t}\n\n/** `scope`: unset resolves every request to the install-wide scope; set, it needs `member`. */\nexport const resolveScope = (option: AnalyticsPluginOptions['scope']): ResolvedScope => {\n\tif (option !== undefined) {\n\t\toptionsObject(option, {\n\t\t\tpath: 'scope',\n\t\t\tknown: SCOPE_KEYS,\n\t\t\texample: 'an object such as { resolve, member }',\n\t\t})\n\t}\n\tconst resolve = optionalFunction(option?.resolve, 'scope.resolve')\n\tconst list = optionalFunction(option?.list, 'scope.list')\n\tconst label = optionalFunction(option?.label, 'scope.label')\n\tconst member = optionalFunction(option?.member, 'scope.member')\n\tif (!resolve) {\n\t\treturn { resolve: () => null }\n\t}\n\tif (member === undefined) {\n\t\tthrow new Error(MEMBER_REQUIRED)\n\t}\n\treturn {\n\t\tresolve: refusingWildcard(resolve),\n\t\tmember,\n\t\t...(list ? { list } : {}),\n\t\t...(label ? { label } : {}),\n\t}\n}\n\n/**\n * Refuses the options that only mean something on a scoped install: an unscoped config carrying one\n * almost always forgot `scope.resolve`, so it fails the boot rather than doing nothing.\n */\nexport const assertScopedOnlyOptions = (options: AnalyticsPluginOptions): void => {\n\tconst paths: string[] = []\n\tfor (const key of ['list', 'label', 'member'] as const) {\n\t\tif (options.scope?.[key] !== undefined) {\n\t\t\tpaths.push(`scope.${key}`)\n\t\t}\n\t}\n\tif (options.access?.crossScope !== undefined) {\n\t\tpaths.push('access.crossScope')\n\t}\n\tfor (const key of ['sources', 'defaultSource'] as const) {\n\t\tif (options[key] !== undefined) {\n\t\t\tpaths.push(key)\n\t\t}\n\t}\n\tif (typeof options.capture?.slots?.tenant === 'string') {\n\t\tpaths.push('capture.slots.tenant')\n\t}\n\tif (options.capture?.paths?.tenant !== undefined) {\n\t\tpaths.push('capture.paths.tenant')\n\t}\n\tfor (const [slug, binding] of Object.entries(options.collections ?? {})) {\n\t\tif (binding?.scopeField !== undefined && binding.scopeField !== false) {\n\t\t\tpaths.push(`collections.${slug}.scopeField`)\n\t\t}\n\t}\n\tconst goalsCollection = Array.isArray(options.goals) ? undefined : options.goals?.collection\n\tif (isRecord(goalsCollection) && goalsCollection.scopeField !== undefined) {\n\t\tpaths.push('goals.collection.scopeField')\n\t}\n\tconst providersCollection = options.providers?.collection\n\tif (isRecord(providersCollection) && providersCollection.scopeField !== undefined) {\n\t\tpaths.push('providers.collection.scopeField')\n\t}\n\tif (isRecord(providersCollection) && providersCollection.fields?.isDefault !== undefined) {\n\t\tpaths.push('providers.collection.fields.isDefault')\n\t}\n\tif (paths.length > 0) {\n\t\tconst one = paths.length === 1\n\t\tthrow new Error(\n\t\t\t`analytics: ${paths.join(', ')} ${one ? 'only applies' : 'only apply'} to a scoped install. Set scope.resolve, or remove ${one ? 'it' : 'them'}.`\n\t\t)\n\t}\n}\n\n/** Unset gates deny on a scoped install and admit `isAdminUser` on an unscoped one. */\nconst resolveCrossScope = (\n\toption: AnalyticsAccessOptions['crossScope'],\n\tscoped: boolean\n): ResolvedCrossScope => {\n\tconst fallback: CrossScopeAccess = scoped ? () => false : isAdminUser\n\tif (option === undefined) {\n\t\treturn allCrossScope(fallback)\n\t}\n\tif (typeof option === 'function') {\n\t\treturn allCrossScope(option)\n\t}\n\tif (!isRecord(option)) {\n\t\tthrow new Error(\n\t\t\t`analytics: access.crossScope must be a function or an object, got ${kindOf(option)}`\n\t\t)\n\t}\n\tfor (const [gate, access] of Object.entries(option)) {\n\t\tif (!CROSS_SCOPE_GATES.includes(gate)) {\n\t\t\tthrow new Error(\n\t\t\t\t`analytics: access.crossScope has no \"${gate}\" gate; the gates are named, aggregate and unscopedSource`\n\t\t\t)\n\t\t}\n\t\tif (access !== undefined && typeof access !== 'function') {\n\t\t\tthrow new Error(`analytics: access.crossScope.${gate} must be a function`)\n\t\t}\n\t}\n\treturn {\n\t\tnamed: option.named ?? fallback,\n\t\taggregate: option.aggregate ?? fallback,\n\t\tunscopedSource: option.unscopedSource ?? fallback,\n\t}\n}\n\n/** `access`: the read gate, the view gate (the read gate unless set) and the cross-scope gates. */\nexport const resolveAccess = (\n\toption: AnalyticsAccessOptions | undefined,\n\tscoped: boolean\n): ResolvedOptions['access'] => {\n\tif (option !== undefined) {\n\t\toptionsObject(option, {\n\t\t\tpath: 'access',\n\t\t\tknown: ACCESS_KEYS,\n\t\t\texample: 'an object such as { read: isAdminUser }',\n\t\t})\n\t}\n\tconst read: AnalyticsReadAccess = optionalFunction(option?.read, 'access.read') ?? isAdminUser\n\treturn {\n\t\tread,\n\t\tview: optionalFunction(option?.view, 'access.view') ?? read,\n\t\tcrossScope: resolveCrossScope(option?.crossScope, scoped),\n\t}\n}\n"],"mappings":";;;;;AAiBA,MAAM,aAAa,OAA8B;CAChD,SAAS;CACT,QAAQ;CACR,MAAM;CACN,OAAO;AACR,CAAC;AAED,MAAM,cAAc,OAA+B;CAAE,MAAM;CAAM,MAAM;CAAM,YAAY;AAAK,CAAC;AAE/F,MAAM,oBAAoB,OAAoC;CAC7D,OAAO;CACP,WAAW;CACX,gBAAgB;AACjB,CAAC;AAED,MAAM,kBACL;;AAGD,MAAa,iBAAiB,YAAkD;CAC/E,OAAO;CACP,WAAW;CACX,gBAAgB;AACjB;;AAGA,MAAM,oBACJ,YACD,OAAO,SAAS;CACf,MAAM,QAAQ,MAAM,QAAQ,IAAI;CAChC,IAAI,UAAA,KACH,MAAM,IAAI,MACT,iIACD;CAED,OAAO;AACR;;AAGD,MAAa,gBAAgB,WAA2D;CACvF,IAAI,WAAW,KAAA,GACd,cAAc,QAAQ;EACrB,MAAM;EACN,OAAO;EACP,SAAS;CACV,CAAC;CAEF,MAAM,UAAU,iBAAiB,QAAQ,SAAS,eAAe;CACjE,MAAM,OAAO,iBAAiB,QAAQ,MAAM,YAAY;CACxD,MAAM,QAAQ,iBAAiB,QAAQ,OAAO,aAAa;CAC3D,MAAM,SAAS,iBAAiB,QAAQ,QAAQ,cAAc;CAC9D,IAAI,CAAC,SACJ,OAAO,EAAE,eAAe,KAAK;CAE9B,IAAI,WAAW,KAAA,GACd,MAAM,IAAI,MAAM,eAAe;CAEhC,OAAO;EACN,SAAS,iBAAiB,OAAO;EACjC;EACA,GAAI,OAAO,EAAE,KAAK,IAAI,CAAC;EACvB,GAAI,QAAQ,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;AAGA,MAAM,qBACL,QACA,WACwB;CACxB,MAAM,WAA6B,eAAe,QAAQ;CAC1D,IAAI,WAAW,KAAA,GACd,OAAO,cAAc,QAAQ;CAE9B,IAAI,OAAO,WAAW,YACrB,OAAO,cAAc,MAAM;CAE5B,IAAI,CAAC,SAAS,MAAM,GACnB,MAAM,IAAI,MACT,qEAAqE,OAAO,MAAM,GACnF;CAED,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,MAAM,GAAG;EACpD,IAAI,CAAC,kBAAkB,SAAS,IAAI,GACnC,MAAM,IAAI,MACT,wCAAwC,KAAK,0DAC9C;EAED,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAC7C,MAAM,IAAI,MAAM,gCAAgC,KAAK,oBAAoB;CAE3E;CACA,OAAO;EACN,OAAO,OAAO,SAAS;EACvB,WAAW,OAAO,aAAa;EAC/B,gBAAgB,OAAO,kBAAkB;CAC1C;AACD;;AAGA,MAAa,iBACZ,QACA,WAC+B;CAC/B,IAAI,WAAW,KAAA,GACd,cAAc,QAAQ;EACrB,MAAM;EACN,OAAO;EACP,SAAS;CACV,CAAC;CAEF,MAAM,OAA4B,iBAAiB,QAAQ,MAAM,aAAa,KAAK;CACnF,OAAO;EACN;EACA,MAAM,iBAAiB,QAAQ,MAAM,aAAa,KAAK;EACvD,YAAY,kBAAkB,QAAQ,YAAY,MAAM;CACzD;AACD"}
|
package/dist/core/scopedRead.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { requestMemo } from "../plugin/requestMemo.js";
|
|
2
|
+
import { decideOnce } from "../access/decideOnce.js";
|
|
1
3
|
import { readGate } from "../access/readGate.js";
|
|
2
4
|
import "./contract.js";
|
|
3
5
|
import { isScopeMember } from "../access/membership.js";
|
|
4
6
|
import { SYSTEM, isGatedScope, mintGatedScope } from "../access/principal.js";
|
|
5
|
-
import { filterRegistry } from "./registry.js";
|
|
7
|
+
import { createRegistry, filterRegistry } from "./registry.js";
|
|
6
8
|
import { readableProviderDocIds } from "../plugin/readableProviders.js";
|
|
7
9
|
import { resolvableScope, resolveRegistryFor, resolveScopeFor, scopeGates } from "../plugin/runtime.js";
|
|
10
|
+
import { sourceLabelFor, sourceRefFor } from "./sourceLabel.js";
|
|
8
11
|
//#region src/core/scopedRead.ts
|
|
9
12
|
const cleared = (scope) => ({
|
|
10
13
|
ok: true,
|
|
@@ -20,7 +23,7 @@ const resolveRequestedScope = async (args) => {
|
|
|
20
23
|
const gates = args.gates ?? scopeGates(runtime, req);
|
|
21
24
|
const named = typeof args.raw === "string" ? args.raw.trim() : "";
|
|
22
25
|
if (named !== "") {
|
|
23
|
-
if (named === "*") return await gates.aggregate() ? cleared(named) : {
|
|
26
|
+
if (named === "*") return await gates.aggregate({ scope: "*" }) ? cleared(named) : {
|
|
24
27
|
ok: false,
|
|
25
28
|
reason: "named"
|
|
26
29
|
};
|
|
@@ -28,7 +31,7 @@ const resolveRequestedScope = async (args) => {
|
|
|
28
31
|
ok: false,
|
|
29
32
|
reason: "named"
|
|
30
33
|
};
|
|
31
|
-
if (await gates.named()) return cleared(named);
|
|
34
|
+
if (await gates.named({ scope: named })) return cleared(named);
|
|
32
35
|
const own = await resolveScopeFor(runtime, req).catch(() => null);
|
|
33
36
|
if (own === null || own === "*" || own !== named) return {
|
|
34
37
|
ok: false,
|
|
@@ -48,11 +51,11 @@ const resolveRequestedScope = async (args) => {
|
|
|
48
51
|
reason: "failed"
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
|
-
if (scope === "*" || scope === null) return (scope === "*" || runtime.scoped === true) && !await gates.aggregate() ? {
|
|
54
|
+
if (scope === "*" || scope === null) return (scope === "*" || runtime.scoped === true) && !await gates.aggregate({ scope }) ? {
|
|
52
55
|
ok: false,
|
|
53
56
|
reason: "unresolved"
|
|
54
57
|
} : cleared(scope);
|
|
55
|
-
if (await isScopeMember(runtime.member, req, scope) || await gates.named()) return cleared(scope);
|
|
58
|
+
if (await isScopeMember(runtime.member, req, scope) || await gates.named({ scope })) return cleared(scope);
|
|
56
59
|
return {
|
|
57
60
|
ok: false,
|
|
58
61
|
reason: "not-member"
|
|
@@ -72,33 +75,174 @@ const SYSTEM_GATES = {
|
|
|
72
75
|
aggregate: () => Promise.resolve(true),
|
|
73
76
|
unscopedSource: () => Promise.resolve(false)
|
|
74
77
|
};
|
|
78
|
+
const NONE_ADMITTED = /* @__PURE__ */ new Set();
|
|
75
79
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
80
|
+
* Whether `sources.<id>.tenants` lets this member of `scope` read through a shared adapter none
|
|
81
|
+
* of its documents grants; asked once per request, scope and adapter. A policy that throws denies.
|
|
82
|
+
*/
|
|
83
|
+
const policyAdmits = async (args) => {
|
|
84
|
+
const { runtime, req, scope, adapter, own } = args;
|
|
85
|
+
const policy = runtime.sourcePolicies?.get(adapter.id);
|
|
86
|
+
if (policy === void 0 || !runtime.configAdapterIds.has(adapter.id) || adapter.capabilities.scopedQueries !== true || !await isScopeMember(runtime.member, req, scope)) return false;
|
|
87
|
+
return decideOnce(req, {
|
|
88
|
+
owner: runtime,
|
|
89
|
+
key: `sourcePolicy:${JSON.stringify(scope)}:${adapter.id}`,
|
|
90
|
+
decide: async () => {
|
|
91
|
+
if (policy === "tenant") return true;
|
|
92
|
+
if (policy === "fallback") return own.length === 0;
|
|
93
|
+
try {
|
|
94
|
+
const ownSources = await Promise.all(own.map(async (granted) => ({
|
|
95
|
+
id: granted.adapter.id,
|
|
96
|
+
label: await sourceLabelFor(granted.adapter, {
|
|
97
|
+
req,
|
|
98
|
+
scope
|
|
99
|
+
}),
|
|
100
|
+
docId: granted.docId
|
|
101
|
+
})));
|
|
102
|
+
return await policy({
|
|
103
|
+
req,
|
|
104
|
+
scope,
|
|
105
|
+
adapterId: adapter.id,
|
|
106
|
+
ownSources
|
|
107
|
+
}) === true;
|
|
108
|
+
} catch (err) {
|
|
109
|
+
req.payload.logger?.warn(`analytics: sources.${adapter.id}.tenants threw for scope "${scope}", which counts as no: ${String(err)}`);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
const pickedDefaults = requestMemo("defaultSources");
|
|
116
|
+
/** The `defaultSource` function's pick, asked once per request, scope and set of sources. */
|
|
117
|
+
const pickDefault = (args) => {
|
|
118
|
+
const { runtime, req, resolved, scope, visible, pick } = args;
|
|
119
|
+
const listed = visible.all();
|
|
120
|
+
return pickedDefaults(req, {
|
|
121
|
+
owner: pick,
|
|
122
|
+
key: `${JSON.stringify(scope)}:${listed.map((adapter) => adapter.id).join(",")}`,
|
|
123
|
+
compute: async () => {
|
|
124
|
+
try {
|
|
125
|
+
return await pick({
|
|
126
|
+
req,
|
|
127
|
+
scope,
|
|
128
|
+
sources: await Promise.all(listed.map((adapter) => sourceRefFor(adapter, {
|
|
129
|
+
req,
|
|
130
|
+
scope,
|
|
131
|
+
configIds: runtime.configAdapterIds,
|
|
132
|
+
docId: resolved.grants.get(adapter.id)
|
|
133
|
+
})))
|
|
134
|
+
});
|
|
135
|
+
} catch (err) {
|
|
136
|
+
req.payload.logger?.warn(`analytics: defaultSource threw for scope "${scope}", which keeps the default: ${String(err)}`);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* A tenant scope's default among the sources a reader sees: its document flagged the default, else
|
|
144
|
+
* the `defaultSource` rule's pick, else undefined for the registry's own.
|
|
78
145
|
*/
|
|
79
|
-
const
|
|
146
|
+
const scopeDefaultId = async (args) => {
|
|
147
|
+
const { runtime, resolved, visible } = args;
|
|
148
|
+
const all = visible.all();
|
|
149
|
+
const sees = (id) => id !== void 0 && all.some((adapter) => adapter.id === id);
|
|
150
|
+
if (sees(resolved.defaultGrant)) return resolved.defaultGrant;
|
|
151
|
+
const rule = runtime.defaultSource;
|
|
152
|
+
if (rule === void 0) return;
|
|
153
|
+
if (rule === "tenantFirst") return all.find((adapter) => resolved.grants.has(adapter.id))?.id;
|
|
154
|
+
if (rule === "platformFirst") return sees(runtime.platformAdapterId) ? runtime.platformAdapterId : void 0;
|
|
155
|
+
const picked = await pickDefault({
|
|
156
|
+
...args,
|
|
157
|
+
pick: rule
|
|
158
|
+
});
|
|
159
|
+
return sees(picked) ? picked : void 0;
|
|
160
|
+
};
|
|
161
|
+
/** `visible` reading through the scope's chosen default; the very registry when it already does. */
|
|
162
|
+
const withScopeDefault = async (args) => {
|
|
163
|
+
const { visible } = args;
|
|
164
|
+
if (!visible) return null;
|
|
165
|
+
const chosen = await scopeDefaultId({
|
|
166
|
+
...args,
|
|
167
|
+
visible
|
|
168
|
+
});
|
|
169
|
+
return chosen === void 0 || chosen === visible.default().id ? visible : createRegistry(visible.all(), chosen);
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* {@link visibleRegistryFor}, also naming the shared adapters only a `fallback` policy admitted,
|
|
173
|
+
* which a listing says so about.
|
|
174
|
+
*/
|
|
175
|
+
const visibleSourcesFor = async (args) => {
|
|
80
176
|
const { runtime, req, resolved, scope } = args;
|
|
81
177
|
const { registry, grants } = resolved;
|
|
82
|
-
if (runtime.scoped !== true || scope === null || scope === "*") return
|
|
83
|
-
|
|
178
|
+
if (runtime.scoped !== true || scope === null || scope === "*") return {
|
|
179
|
+
registry,
|
|
180
|
+
fallbackAdmitted: NONE_ADMITTED
|
|
181
|
+
};
|
|
182
|
+
if (args.principal === SYSTEM) return {
|
|
183
|
+
registry: await withScopeDefault({
|
|
184
|
+
runtime,
|
|
185
|
+
req,
|
|
186
|
+
resolved,
|
|
187
|
+
scope,
|
|
188
|
+
visible: filterRegistry(registry, (adapter) => grants.has(adapter.id) || !needsUnscopedSourceAccess(runtime, adapter, scope))
|
|
189
|
+
}),
|
|
190
|
+
fallbackAdmitted: NONE_ADMITTED
|
|
191
|
+
};
|
|
84
192
|
const gates = args.gates ?? scopeGates(runtime, req);
|
|
85
193
|
const readable = await readableProviderDocIds(runtime, req, scope);
|
|
86
|
-
const
|
|
194
|
+
const own = [];
|
|
87
195
|
for (const adapter of registry.all()) {
|
|
88
196
|
const docId = grants.get(adapter.id);
|
|
89
|
-
if (docId !== void 0) {
|
|
90
|
-
|
|
197
|
+
if (docId !== void 0 && (readable === null || readable.has(docId))) own.push({
|
|
198
|
+
adapter,
|
|
199
|
+
docId
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
const keep = new Set(own.map((granted) => granted.adapter.id));
|
|
203
|
+
const fallbackAdmitted = /* @__PURE__ */ new Set();
|
|
204
|
+
for (const adapter of registry.all()) {
|
|
205
|
+
if (grants.has(adapter.id)) continue;
|
|
206
|
+
if (!runtime.providersCollection && adapter.capabilities.scopedQueries) {
|
|
207
|
+
keep.add(adapter.id);
|
|
91
208
|
continue;
|
|
92
209
|
}
|
|
93
|
-
if (
|
|
210
|
+
if (await gates.unscopedSource({
|
|
211
|
+
scope,
|
|
212
|
+
adapterId: adapter.id
|
|
213
|
+
})) {
|
|
94
214
|
keep.add(adapter.id);
|
|
95
215
|
continue;
|
|
96
216
|
}
|
|
97
|
-
if (await
|
|
217
|
+
if (await policyAdmits({
|
|
218
|
+
runtime,
|
|
219
|
+
req,
|
|
220
|
+
scope,
|
|
221
|
+
adapter,
|
|
222
|
+
own
|
|
223
|
+
})) {
|
|
224
|
+
keep.add(adapter.id);
|
|
225
|
+
if (runtime.sourcePolicies?.get(adapter.id) === "fallback") fallbackAdmitted.add(adapter.id);
|
|
226
|
+
}
|
|
98
227
|
}
|
|
99
|
-
return
|
|
228
|
+
return {
|
|
229
|
+
registry: await withScopeDefault({
|
|
230
|
+
runtime,
|
|
231
|
+
req,
|
|
232
|
+
resolved,
|
|
233
|
+
scope,
|
|
234
|
+
visible: filterRegistry(registry, (adapter) => keep.has(adapter.id))
|
|
235
|
+
}),
|
|
236
|
+
fallbackAdmitted
|
|
237
|
+
};
|
|
100
238
|
};
|
|
101
239
|
/**
|
|
240
|
+
* The adapters a request may read through in one tenant scope, or null for none: the scope's own
|
|
241
|
+
* sources follow the providers' read access (`sourceAccess`), a config adapter `unscopedSource` or
|
|
242
|
+
* its `sources` policy. A tenant scope reads through its chosen default (see `defaultSource`).
|
|
243
|
+
*/
|
|
244
|
+
const visibleRegistryFor = async (args) => (await visibleSourcesFor(args)).registry;
|
|
245
|
+
/**
|
|
102
246
|
* The sources a job reads one scope through as {@link SYSTEM}, or null when the scope holds
|
|
103
247
|
* none: exactly what `resolveReadContext` lets a system read choose from.
|
|
104
248
|
*/
|
|
@@ -122,9 +266,12 @@ const systemRegistryFor = async (runtime, req, scope) => {
|
|
|
122
266
|
const resolveQueryScope = async (args) => {
|
|
123
267
|
const { runtime, req, scope, adapter } = args;
|
|
124
268
|
const gates = args.gates ?? scopeGates(runtime, req);
|
|
125
|
-
if (scope === "*") return await gates.aggregate() ? { ok: true } : { ok: false };
|
|
269
|
+
if (scope === "*") return await gates.aggregate({ scope }) ? { ok: true } : { ok: false };
|
|
126
270
|
if (scope === null) return { ok: true };
|
|
127
|
-
if (needsUnscopedSourceAccess(runtime, adapter, scope)) return await gates.unscopedSource(
|
|
271
|
+
if (needsUnscopedSourceAccess(runtime, adapter, scope)) return await gates.unscopedSource({
|
|
272
|
+
scope,
|
|
273
|
+
adapterId: adapter.id
|
|
274
|
+
}) ? { ok: true } : { ok: false };
|
|
128
275
|
return {
|
|
129
276
|
ok: true,
|
|
130
277
|
queryScope: scope
|
|
@@ -212,7 +359,8 @@ const resolveReadContext = async (args) => {
|
|
|
212
359
|
};
|
|
213
360
|
const fallback = registry.default();
|
|
214
361
|
const preferred = args.prefer && !args.prefer(fallback) ? registry.all().find(args.prefer) : void 0;
|
|
215
|
-
const
|
|
362
|
+
const substitutedFrom = adapterId && args.fallbackWhenUnreadable && !registry.all().some((a) => a.id === adapterId) ? adapterId : void 0;
|
|
363
|
+
const adapter = adapterId && substitutedFrom === void 0 ? registry.get(adapterId) : preferred ?? fallback;
|
|
216
364
|
const decision = await resolveQueryScope({
|
|
217
365
|
runtime,
|
|
218
366
|
req,
|
|
@@ -226,7 +374,8 @@ const resolveReadContext = async (args) => {
|
|
|
226
374
|
adapter,
|
|
227
375
|
scope: registryScope,
|
|
228
376
|
queryScope: decision.queryScope,
|
|
229
|
-
pin
|
|
377
|
+
pin,
|
|
378
|
+
...substitutedFrom === void 0 ? {} : { substitutedFrom }
|
|
230
379
|
};
|
|
231
380
|
} catch (err) {
|
|
232
381
|
req.payload.logger?.warn(`analytics: read context resolution failed: ${String(err)}`);
|
|
@@ -234,6 +383,6 @@ const resolveReadContext = async (args) => {
|
|
|
234
383
|
}
|
|
235
384
|
};
|
|
236
385
|
//#endregion
|
|
237
|
-
export { needsUnscopedSourceAccess, resolveQueryScope, resolveReadContext, resolveRequestedScope, systemRegistryFor,
|
|
386
|
+
export { needsUnscopedSourceAccess, resolveQueryScope, resolveReadContext, resolveRequestedScope, systemRegistryFor, visibleSourcesFor };
|
|
238
387
|
|
|
239
388
|
//# sourceMappingURL=scopedRead.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scopedRead.js","names":[],"sources":["../../src/core/scopedRead.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { isScopeMember } from '../access/membership'\nimport {\n\ttype GatedScope,\n\tisGatedScope,\n\tmintGatedScope,\n\ttype ReadPrincipal,\n\tSYSTEM,\n} from '../access/principal'\nimport { readGate } from '../access/readGate'\nimport { readableProviderDocIds } from '../plugin/readableProviders'\nimport {\n\ttype AnalyticsRuntime,\n\tresolvableScope,\n\tresolveRegistryFor,\n\tresolveScopeFor,\n\ttype ScopeGates,\n\tscopeGates,\n} from '../plugin/runtime'\nimport { MAX_SCOPE_LENGTH } from '../query/limits'\nimport { type AnalyticsAdapter, PLATFORM_SCOPE } from './contract'\nimport { type AdapterRegistry, filterRegistry, type ScopeRegistry } from './registry'\n\nexport type ReadContext =\n\t| {\n\t\t\tok: true\n\t\t\tadapter: AnalyticsAdapter\n\t\t\tscope: string | null\n\t\t\t/** The scope to stamp on the adapter query; undefined for install-wide reads. */\n\t\t\tqueryScope?: string\n\t\t\t/**\n\t\t\t * The read's principal and scope, for the reads it makes on its behalf: handing this on\n\t\t\t * keeps every one of them on exactly this scope without deciding it again.\n\t\t\t */\n\t\t\tpin: ReadPrincipal\n\t }\n\t| {\n\t\t\tok: false\n\t\t\t/**\n\t\t\t * Why the read was refused: `no-sources` (nothing this reader may read), `no-access`,\n\t\t\t * `not-member`, or `no-scope` (no single scope resolved, no cross-scope read).\n\t\t\t */\n\t\t\treason?: 'no-sources' | 'no-access' | 'not-member' | 'no-scope'\n\t }\n\ntype ResolveReadContextArgs = {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\tadapterId?: string\n\t/**\n\t * Without an `adapterId`, the source to read through is the scope's default when this accepts\n\t * it, else the first visible source it accepts, else the default all the same.\n\t */\n\tprefer?: (adapter: AnalyticsAdapter) => boolean\n} & ReadPrincipal\n\ninterface QueryScopeArgs {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\t/** The read's resolved scope; `'*'` is the explicit cross-scope marker. */\n\tscope: string | null\n\tadapter: AnalyticsAdapter\n\t/** Shared cross-scope decisions; one set is created per call when omitted. */\n\tgates?: ScopeGates\n}\n\n/**\n * A scope a request may act on, or why not: `named` and `unresolved` are denied cross-scope gates,\n * `failed` a throwing `scope.resolve`, `not-member` a scope its user does not belong to.\n */\nexport type RequestedScope =\n\t| {\n\t\t\tok: true\n\t\t\tscope: string | null\n\t\t\t/** The same scope as a token the reads below accept without deciding it again. */\n\t\t\tgated: GatedScope\n\t }\n\t| { ok: false; reason: 'named' | 'unresolved' | 'failed' | 'not-member' }\n\ninterface RequestedScopeArgs {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\t/** The `scope` the request carried, untrimmed; null or undefined when it carried none. */\n\traw?: string | null\n\t/** Shared cross-scope decisions; one set is created per call when omitted. */\n\tgates?: ScopeGates\n}\n\nconst cleared = (scope: string | null): RequestedScope => ({\n\tok: true,\n\tscope,\n\tgated: mintGatedScope(scope),\n})\n\n/**\n * The scope one request may act on, for every endpoint taking a caller's `scope`, and the only\n * place a {@link GatedScope} is minted. A scoped install's null, no tenant selected, fails closed.\n */\nexport const resolveRequestedScope = async (args: RequestedScopeArgs): Promise<RequestedScope> => {\n\tconst { runtime, req } = args\n\tconst gates = args.gates ?? scopeGates(runtime, req)\n\tconst named = typeof args.raw === 'string' ? args.raw.trim() : ''\n\tif (named !== '') {\n\t\t// The wildcard is never the request's own scope in this sense: it names every scope,\n\t\t// whatever the resolver answered, and stays behind the aggregate gate.\n\t\tif (named === PLATFORM_SCOPE) {\n\t\t\treturn (await gates.aggregate()) ? cleared(named) : { ok: false, reason: 'named' }\n\t\t}\n\t\t// An install without tenants has no scope to name, and no tenant id runs this long.\n\t\tif (runtime.scoped !== true || named.length > MAX_SCOPE_LENGTH) {\n\t\t\treturn { ok: false, reason: 'named' }\n\t\t}\n\t\tif (await gates.named()) {\n\t\t\treturn cleared(named)\n\t\t}\n\t\t// Only after the gate has said no, so a platform reader still costs one resolution.\n\t\tconst own = await resolveScopeFor(runtime, req).catch(() => null)\n\t\tif (own === null || own === PLATFORM_SCOPE || own !== named) {\n\t\t\treturn { ok: false, reason: 'named' }\n\t\t}\n\t\treturn (await isScopeMember(runtime.member, req, own))\n\t\t\t? cleared(own)\n\t\t\t: { ok: false, reason: 'not-member' }\n\t}\n\tlet scope: string | null\n\ttry {\n\t\tscope = await resolveScopeFor(runtime, req)\n\t} catch {\n\t\treturn { ok: false, reason: 'failed' }\n\t}\n\tif (scope === PLATFORM_SCOPE || scope === null) {\n\t\tconst crossScope = scope === PLATFORM_SCOPE || runtime.scoped === true\n\t\treturn crossScope && !(await gates.aggregate())\n\t\t\t? { ok: false, reason: 'unresolved' }\n\t\t\t: cleared(scope)\n\t}\n\tif ((await isScopeMember(runtime.member, req, scope)) || (await gates.named())) {\n\t\treturn cleared(scope)\n\t}\n\treturn { ok: false, reason: 'not-member' }\n}\n\n/**\n * True for a shared config adapter that cannot narrow its query, read under a tenant scope: it\n * would answer with every scope's data, so reading or listing it takes `unscopedSource`.\n */\nexport const needsUnscopedSourceAccess = (\n\truntime: AnalyticsRuntime,\n\tadapter: AnalyticsAdapter,\n\tscope: string | null\n): boolean =>\n\tscope !== null &&\n\tscope !== PLATFORM_SCOPE &&\n\truntime.configAdapterIds.has(adapter.id) &&\n\t!adapter.capabilities.scopedQueries\n\n/**\n * {@link SYSTEM} reads any scope, but never a tenant through a shared adapter that cannot narrow\n * to it: a job would store that adapter's install-wide numbers as the tenant's own.\n */\nconst SYSTEM_GATES: ScopeGates = {\n\tnamed: () => Promise.resolve(true),\n\taggregate: () => Promise.resolve(true),\n\tunscopedSource: () => Promise.resolve(false),\n}\n\n/**\n * The adapters a request may read through in one tenant scope, or null for none: the scope's own\n * sources follow the providers' read access (`sourceAccess`), a config adapter `unscopedSource`.\n */\nexport const visibleRegistryFor = async (args: {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\tresolved: ScopeRegistry\n\tscope: string | null\n\tgates?: ScopeGates\n\tprincipal?: typeof SYSTEM\n}): Promise<AdapterRegistry | null> => {\n\tconst { runtime, req, resolved, scope } = args\n\tconst { registry, grants } = resolved\n\tif (runtime.scoped !== true || scope === null || scope === PLATFORM_SCOPE) {\n\t\treturn registry\n\t}\n\tif (args.principal === SYSTEM) {\n\t\treturn filterRegistry(\n\t\t\tregistry,\n\t\t\t(adapter) => grants.has(adapter.id) || !needsUnscopedSourceAccess(runtime, adapter, scope)\n\t\t)\n\t}\n\tconst gates = args.gates ?? scopeGates(runtime, req)\n\tconst readable = await readableProviderDocIds(runtime, req, scope)\n\tconst keep = new Set<string>()\n\tfor (const adapter of registry.all()) {\n\t\tconst docId = grants.get(adapter.id)\n\t\tif (docId !== undefined) {\n\t\t\tif (readable === null || readable.has(docId)) {\n\t\t\t\tkeep.add(adapter.id)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tif (!runtime.providersCollection && adapter.capabilities.scopedQueries) {\n\t\t\tkeep.add(adapter.id)\n\t\t\tcontinue\n\t\t}\n\t\tif (await gates.unscopedSource()) {\n\t\t\tkeep.add(adapter.id)\n\t\t}\n\t}\n\treturn filterRegistry(registry, (adapter) => keep.has(adapter.id))\n}\n\n/**\n * The sources a job reads one scope through as {@link SYSTEM}, or null when the scope holds\n * none: exactly what `resolveReadContext` lets a system read choose from.\n */\nexport const systemRegistryFor = async (\n\truntime: AnalyticsRuntime,\n\treq: PayloadRequest,\n\tscope: string | null\n): Promise<AdapterRegistry | null> => {\n\tconst resolved = await resolveRegistryFor(runtime, {\n\t\tpayload: req.payload,\n\t\treq,\n\t\tscope: resolvableScope(scope),\n\t})\n\treturn visibleRegistryFor({ runtime, req, resolved, scope, principal: SYSTEM })\n}\n\n/**\n * The scope to stamp on one adapter query, or a refusal. Every read path decides it here, so\n * widgets and the query endpoint cannot drift on what counts as cross-scope.\n */\nexport const resolveQueryScope = async (\n\targs: QueryScopeArgs\n): Promise<{ ok: true; queryScope?: string } | { ok: false }> => {\n\tconst { runtime, req, scope, adapter } = args\n\tconst gates = args.gates ?? scopeGates(runtime, req)\n\tif (scope === PLATFORM_SCOPE) {\n\t\treturn (await gates.aggregate()) ? { ok: true } : { ok: false }\n\t}\n\tif (scope === null) {\n\t\treturn { ok: true }\n\t}\n\tif (needsUnscopedSourceAccess(runtime, adapter, scope)) {\n\t\treturn (await gates.unscopedSource()) ? { ok: true } : { ok: false }\n\t}\n\treturn { ok: true, queryScope: scope }\n}\n\ntype PrincipalScope =\n\t| { ok: true; scope: string | null; pin: ReadPrincipal }\n\t| Extract<ReadContext, { ok: false }>\n\n/**\n * The read's scope: the system's own, one already cleared, or the one the request asks for. Checked\n * at runtime, since a JavaScript caller or a cast can pass anything; anything else is refused.\n */\nconst principalScope = async (\n\targs: ResolveReadContextArgs,\n\tgates: ScopeGates\n): Promise<PrincipalScope> => {\n\tconst { scope } = args\n\tif (args.principal === SYSTEM) {\n\t\treturn typeof scope === 'string' || scope === null\n\t\t\t? { ok: true, scope, pin: { principal: SYSTEM, scope } }\n\t\t\t: { ok: false }\n\t}\n\tif (isGatedScope(scope)) {\n\t\treturn { ok: true, scope: scope.value, pin: { scope } }\n\t}\n\tif (scope !== undefined && scope !== null && typeof scope !== 'string') {\n\t\treturn { ok: false }\n\t}\n\tconst requested = await resolveRequestedScope({\n\t\truntime: args.runtime,\n\t\treq: args.req,\n\t\tgates,\n\t\traw: scope,\n\t})\n\tif (!requested.ok) {\n\t\tswitch (requested.reason) {\n\t\t\tcase 'not-member':\n\t\t\t\treturn { ok: false, reason: 'not-member' }\n\t\t\tcase 'named':\n\t\t\t\treturn { ok: false, reason: 'no-access' }\n\t\t\tcase 'unresolved':\n\t\t\t\treturn { ok: false, reason: 'no-scope' }\n\t\t\tcase 'failed':\n\t\t\t\treturn { ok: false }\n\t\t}\n\t}\n\treturn { ok: true, scope: requested.scope, pin: { scope: requested.gated } }\n}\n\n/**\n * One read's scope and adapter, behind `access.read` and `resolveRequestedScope` unless the\n * principal is {@link SYSTEM}. Any failure answers `{ ok: false }`, so a surface never throws.\n */\nexport const resolveReadContext = async (args: ResolveReadContextArgs): Promise<ReadContext> => {\n\tconst { runtime, req, adapterId } = args\n\tconst system = args.principal === SYSTEM\n\tconst gates = system ? SYSTEM_GATES : scopeGates(runtime, req)\n\ttry {\n\t\tif (!system && !(await readGate(runtime, req))) {\n\t\t\treturn { ok: false, reason: 'no-access' }\n\t\t}\n\t\tconst decided = await principalScope(args, gates)\n\t\tif (!decided.ok) {\n\t\t\treturn decided\n\t\t}\n\t\tconst { scope, pin } = decided\n\t\tconst registryScope = resolvableScope(scope)\n\t\tconst resolved = await resolveRegistryFor(runtime, {\n\t\t\tpayload: req.payload,\n\t\t\treq,\n\t\t\tscope: registryScope,\n\t\t})\n\t\t// The default is picked out of what this reader may actually read, so a scope whose\n\t\t// leading source is the platform's own shared one still serves a tenant admin.\n\t\tconst registry = await visibleRegistryFor({\n\t\t\truntime,\n\t\t\treq,\n\t\t\tresolved,\n\t\t\tscope,\n\t\t\tgates,\n\t\t\t...(system ? { principal: SYSTEM } : {}),\n\t\t})\n\t\tif (!registry) {\n\t\t\treturn { ok: false, reason: 'no-sources' }\n\t\t}\n\t\tconst fallback = registry.default()\n\t\tconst preferred =\n\t\t\targs.prefer && !args.prefer(fallback) ? registry.all().find(args.prefer) : undefined\n\t\tconst adapter = adapterId ? registry.get(adapterId) : (preferred ?? fallback)\n\t\tconst decision = await resolveQueryScope({\n\t\t\truntime,\n\t\t\treq,\n\t\t\tscope,\n\t\t\tadapter,\n\t\t\tgates,\n\t\t})\n\t\tif (!decision.ok) {\n\t\t\treturn { ok: false }\n\t\t}\n\t\treturn { ok: true, adapter, scope: registryScope, queryScope: decision.queryScope, pin }\n\t} catch (err) {\n\t\treq.payload.logger?.warn(`analytics: read context resolution failed: ${String(err)}`)\n\t\treturn { ok: false }\n\t}\n}\n"],"mappings":";;;;;;;;AAwFA,MAAM,WAAW,WAA0C;CAC1D,IAAI;CACJ;CACA,OAAO,eAAe,KAAK;AAC5B;;;;;AAMA,MAAa,wBAAwB,OAAO,SAAsD;CACjG,MAAM,EAAE,SAAS,QAAQ;CACzB,MAAM,QAAQ,KAAK,SAAS,WAAW,SAAS,GAAG;CACnD,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW,KAAK,IAAI,KAAK,IAAI;CAC/D,IAAI,UAAU,IAAI;EAGjB,IAAI,UAAA,KACH,OAAQ,MAAM,MAAM,UAAU,IAAK,QAAQ,KAAK,IAAI;GAAE,IAAI;GAAO,QAAQ;EAAQ;EAGlF,IAAI,QAAQ,WAAW,QAAQ,MAAM,SAAA,KACpC,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAQ;EAErC,IAAI,MAAM,MAAM,MAAM,GACrB,OAAO,QAAQ,KAAK;EAGrB,MAAM,MAAM,MAAM,gBAAgB,SAAS,GAAG,EAAE,YAAY,IAAI;EAChE,IAAI,QAAQ,QAAQ,QAAA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UAAA,MAVsB,mBAAmB,SAAS;IAClD,SAAS,IAAI;IACb;IACA,OAAO;GACR,CAAC;GAOA;GACA;GACA,GAAI,SAAS,EAAE,WAAW,OAAO,IAAI,CAAC;EACvC,CAAC;EACD,IAAI,CAAC,UACJ,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAa;EAE1C,MAAM,WAAW,SAAS,QAAQ;EAClC,MAAM,YACL,KAAK,UAAU,CAAC,KAAK,OAAO,QAAQ,IAAI,SAAS,IAAI,EAAE,KAAK,KAAK,MAAM,IAAI,KAAA;EAC5E,MAAM,UAAU,YAAY,SAAS,IAAI,SAAS,IAAK,aAAa;EACpE,MAAM,WAAW,MAAM,kBAAkB;GACxC;GACA;GACA;GACA;GACA;EACD,CAAC;EACD,IAAI,CAAC,SAAS,IACb,OAAO,EAAE,IAAI,MAAM;EAEpB,OAAO;GAAE,IAAI;GAAM;GAAS,OAAO;GAAe,YAAY,SAAS;GAAY;EAAI;CACxF,SAAS,KAAK;EACb,IAAI,QAAQ,QAAQ,KAAK,8CAA8C,OAAO,GAAG,GAAG;EACpF,OAAO,EAAE,IAAI,MAAM;CACpB;AACD"}
|
|
1
|
+
{"version":3,"file":"scopedRead.js","names":[],"sources":["../../src/core/scopedRead.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { decideOnce } from '../access/decideOnce'\nimport { isScopeMember } from '../access/membership'\nimport {\n\ttype GatedScope,\n\tisGatedScope,\n\tmintGatedScope,\n\ttype ReadPrincipal,\n\tSYSTEM,\n} from '../access/principal'\nimport { readGate } from '../access/readGate'\nimport { readableProviderDocIds } from '../plugin/readableProviders'\nimport { requestMemo } from '../plugin/requestMemo'\nimport {\n\ttype AnalyticsRuntime,\n\tresolvableScope,\n\tresolveRegistryFor,\n\tresolveScopeFor,\n\ttype ScopeGates,\n\tscopeGates,\n} from '../plugin/runtime'\nimport { MAX_SCOPE_LENGTH } from '../query/limits'\nimport { type AnalyticsAdapter, PLATFORM_SCOPE } from './contract'\nimport {\n\ttype AdapterRegistry,\n\tcreateRegistry,\n\tfilterRegistry,\n\ttype ScopeRegistry,\n} from './registry'\nimport { sourceLabelFor, sourceRefFor } from './sourceLabel'\nimport type { DefaultSourceFunction, SourceRef } from './sourcePolicy'\n\nexport type ReadContext =\n\t| {\n\t\t\tok: true\n\t\t\tadapter: AnalyticsAdapter\n\t\t\tscope: string | null\n\t\t\t/** The scope to stamp on the adapter query; undefined for install-wide reads. */\n\t\t\tqueryScope?: string\n\t\t\t/**\n\t\t\t * The read's principal and scope, for the reads it makes on its behalf: handing this on\n\t\t\t * keeps every one of them on exactly this scope without deciding it again.\n\t\t\t */\n\t\t\tpin: ReadPrincipal\n\t\t\t/** The source asked for, which this reader cannot read, when the scope default read instead. */\n\t\t\tsubstitutedFrom?: string\n\t }\n\t| {\n\t\t\tok: false\n\t\t\t/**\n\t\t\t * Why the read was refused: `no-sources` (nothing this reader may read), `no-access`,\n\t\t\t * `not-member`, or `no-scope` (no single scope resolved, no cross-scope read).\n\t\t\t */\n\t\t\treason?: 'no-sources' | 'no-access' | 'not-member' | 'no-scope'\n\t }\n\ntype ResolveReadContextArgs = {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\tadapterId?: string\n\t/**\n\t * Without an `adapterId`, the source to read through is the scope's default when this accepts\n\t * it, else the first visible source it accepts, else the default all the same.\n\t */\n\tprefer?: (adapter: AnalyticsAdapter) => boolean\n\t/**\n\t * An `adapterId` this reader cannot read is read as if none were named, the substitution\n\t * reported as `substitutedFrom`: for a stored choice, never a caller's explicit one.\n\t */\n\tfallbackWhenUnreadable?: boolean\n} & ReadPrincipal\n\ninterface QueryScopeArgs {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\t/** The read's resolved scope; `'*'` is the explicit cross-scope marker. */\n\tscope: string | null\n\tadapter: AnalyticsAdapter\n\t/** Shared cross-scope decisions; one set is created per call when omitted. */\n\tgates?: ScopeGates\n}\n\n/**\n * A scope a request may act on, or why not: `named` and `unresolved` are denied cross-scope gates,\n * `failed` a throwing `scope.resolve`, `not-member` a scope its user does not belong to.\n */\nexport type RequestedScope =\n\t| {\n\t\t\tok: true\n\t\t\tscope: string | null\n\t\t\t/** The same scope as a token the reads below accept without deciding it again. */\n\t\t\tgated: GatedScope\n\t }\n\t| { ok: false; reason: 'named' | 'unresolved' | 'failed' | 'not-member' }\n\ninterface RequestedScopeArgs {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\t/** The `scope` the request carried, untrimmed; null or undefined when it carried none. */\n\traw?: string | null\n\t/** Shared cross-scope decisions; one set is created per call when omitted. */\n\tgates?: ScopeGates\n}\n\nconst cleared = (scope: string | null): RequestedScope => ({\n\tok: true,\n\tscope,\n\tgated: mintGatedScope(scope),\n})\n\n/**\n * The scope one request may act on, for every endpoint taking a caller's `scope`, and the only\n * place a {@link GatedScope} is minted. A scoped install's null, no tenant selected, fails closed.\n */\nexport const resolveRequestedScope = async (args: RequestedScopeArgs): Promise<RequestedScope> => {\n\tconst { runtime, req } = args\n\tconst gates = args.gates ?? scopeGates(runtime, req)\n\tconst named = typeof args.raw === 'string' ? args.raw.trim() : ''\n\tif (named !== '') {\n\t\t// The wildcard is never the request's own scope in this sense: it names every scope,\n\t\t// whatever the resolver answered, and stays behind the aggregate gate.\n\t\tif (named === PLATFORM_SCOPE) {\n\t\t\treturn (await gates.aggregate({ scope: PLATFORM_SCOPE }))\n\t\t\t\t? cleared(named)\n\t\t\t\t: { ok: false, reason: 'named' }\n\t\t}\n\t\t// An install without tenants has no scope to name, and no tenant id runs this long.\n\t\tif (runtime.scoped !== true || named.length > MAX_SCOPE_LENGTH) {\n\t\t\treturn { ok: false, reason: 'named' }\n\t\t}\n\t\tif (await gates.named({ scope: named })) {\n\t\t\treturn cleared(named)\n\t\t}\n\t\t// Only after the gate has said no, so a platform reader still costs one resolution.\n\t\tconst own = await resolveScopeFor(runtime, req).catch(() => null)\n\t\tif (own === null || own === PLATFORM_SCOPE || own !== named) {\n\t\t\treturn { ok: false, reason: 'named' }\n\t\t}\n\t\treturn (await isScopeMember(runtime.member, req, own))\n\t\t\t? cleared(own)\n\t\t\t: { ok: false, reason: 'not-member' }\n\t}\n\tlet scope: string | null\n\ttry {\n\t\tscope = await resolveScopeFor(runtime, req)\n\t} catch {\n\t\treturn { ok: false, reason: 'failed' }\n\t}\n\tif (scope === PLATFORM_SCOPE || scope === null) {\n\t\tconst crossScope = scope === PLATFORM_SCOPE || runtime.scoped === true\n\t\treturn crossScope && !(await gates.aggregate({ scope }))\n\t\t\t? { ok: false, reason: 'unresolved' }\n\t\t\t: cleared(scope)\n\t}\n\tif ((await isScopeMember(runtime.member, req, scope)) || (await gates.named({ scope }))) {\n\t\treturn cleared(scope)\n\t}\n\treturn { ok: false, reason: 'not-member' }\n}\n\n/**\n * True for a shared config adapter that cannot narrow its query, read under a tenant scope: it\n * would answer with every scope's data, so reading or listing it takes `unscopedSource`.\n */\nexport const needsUnscopedSourceAccess = (\n\truntime: AnalyticsRuntime,\n\tadapter: AnalyticsAdapter,\n\tscope: string | null\n): boolean =>\n\tscope !== null &&\n\tscope !== PLATFORM_SCOPE &&\n\truntime.configAdapterIds.has(adapter.id) &&\n\t!adapter.capabilities.scopedQueries\n\n/**\n * {@link SYSTEM} reads any scope, but never a tenant through a shared adapter that cannot narrow\n * to it: a job would store that adapter's install-wide numbers as the tenant's own.\n */\nconst SYSTEM_GATES: ScopeGates = {\n\tnamed: () => Promise.resolve(true),\n\taggregate: () => Promise.resolve(true),\n\tunscopedSource: () => Promise.resolve(false),\n}\n\ninterface VisibleArgs {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\tresolved: ScopeRegistry\n\tscope: string | null\n\tgates?: ScopeGates\n\tprincipal?: typeof SYSTEM\n}\n\n/** The adapters one reader sees in a scope, and which of them a `fallback` policy alone admitted. */\nexport interface VisibleSources {\n\tregistry: AdapterRegistry | null\n\t/** Shared adapters listed only because a `fallback` policy let a member of the scope in. */\n\tfallbackAdmitted: ReadonlySet<string>\n}\n\nconst NONE_ADMITTED: ReadonlySet<string> = new Set()\n\n/** A source the reader reads a scope through by one of the scope's own provider documents. */\ninterface Granted {\n\tadapter: AnalyticsAdapter\n\tdocId: string\n}\n\n/**\n * Whether `sources.<id>.tenants` lets this member of `scope` read through a shared adapter none\n * of its documents grants; asked once per request, scope and adapter. A policy that throws denies.\n */\nconst policyAdmits = async (args: {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\tscope: string\n\tadapter: AnalyticsAdapter\n\town: readonly Granted[]\n}): Promise<boolean> => {\n\tconst { runtime, req, scope, adapter, own } = args\n\tconst policy = runtime.sourcePolicies?.get(adapter.id)\n\t// The boot refuses a policy on an adapter that cannot narrow; a tenant must never read totals\n\t// spanning every tenant, so a runtime built any other way is held to it too.\n\tif (\n\t\tpolicy === undefined ||\n\t\t!runtime.configAdapterIds.has(adapter.id) ||\n\t\tadapter.capabilities.scopedQueries !== true ||\n\t\t!(await isScopeMember(runtime.member, req, scope))\n\t) {\n\t\treturn false\n\t}\n\treturn decideOnce(req, {\n\t\towner: runtime,\n\t\tkey: `sourcePolicy:${JSON.stringify(scope)}:${adapter.id}`,\n\t\tdecide: async () => {\n\t\t\tif (policy === 'tenant') {\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif (policy === 'fallback') {\n\t\t\t\treturn own.length === 0\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst ownSources = await Promise.all(\n\t\t\t\t\town.map(async (granted) => ({\n\t\t\t\t\t\tid: granted.adapter.id,\n\t\t\t\t\t\tlabel: await sourceLabelFor(granted.adapter, { req, scope }),\n\t\t\t\t\t\tdocId: granted.docId,\n\t\t\t\t\t}))\n\t\t\t\t)\n\t\t\t\treturn (await policy({ req, scope, adapterId: adapter.id, ownSources })) === true\n\t\t\t} catch (err) {\n\t\t\t\treq.payload.logger?.warn(\n\t\t\t\t\t`analytics: sources.${adapter.id}.tenants threw for scope \"${scope}\", which counts as no: ${String(err)}`\n\t\t\t\t)\n\t\t\t\treturn false\n\t\t\t}\n\t\t},\n\t})\n}\n\nconst pickedDefaults = requestMemo<string | undefined>('defaultSources')\n\n/** The `defaultSource` function's pick, asked once per request, scope and set of sources. */\nconst pickDefault = (args: {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\tresolved: ScopeRegistry\n\tscope: string\n\tvisible: AdapterRegistry\n\tpick: DefaultSourceFunction\n}): Promise<string | undefined> => {\n\tconst { runtime, req, resolved, scope, visible, pick } = args\n\tconst listed = visible.all()\n\treturn pickedDefaults(req, {\n\t\towner: pick,\n\t\tkey: `${JSON.stringify(scope)}:${listed.map((adapter) => adapter.id).join(',')}`,\n\t\tcompute: async () => {\n\t\t\ttry {\n\t\t\t\tconst sources: SourceRef[] = await Promise.all(\n\t\t\t\t\tlisted.map((adapter) =>\n\t\t\t\t\t\tsourceRefFor(adapter, {\n\t\t\t\t\t\t\treq,\n\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t\tconfigIds: runtime.configAdapterIds,\n\t\t\t\t\t\t\tdocId: resolved.grants.get(adapter.id),\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\treturn await pick({ req, scope, sources })\n\t\t\t} catch (err) {\n\t\t\t\treq.payload.logger?.warn(\n\t\t\t\t\t`analytics: defaultSource threw for scope \"${scope}\", which keeps the default: ${String(err)}`\n\t\t\t\t)\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t},\n\t})\n}\n\ninterface ScopeDefaultArgs {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\tresolved: ScopeRegistry\n\tscope: string\n\tvisible: AdapterRegistry\n}\n\n/**\n * A tenant scope's default among the sources a reader sees: its document flagged the default, else\n * the `defaultSource` rule's pick, else undefined for the registry's own.\n */\nconst scopeDefaultId = async (args: ScopeDefaultArgs): Promise<string | undefined> => {\n\tconst { runtime, resolved, visible } = args\n\tconst all = visible.all()\n\tconst sees = (id: string | undefined): id is string =>\n\t\tid !== undefined && all.some((adapter) => adapter.id === id)\n\tif (sees(resolved.defaultGrant)) {\n\t\treturn resolved.defaultGrant\n\t}\n\tconst rule = runtime.defaultSource\n\tif (rule === undefined) {\n\t\treturn undefined\n\t}\n\tif (rule === 'tenantFirst') {\n\t\treturn all.find((adapter) => resolved.grants.has(adapter.id))?.id\n\t}\n\tif (rule === 'platformFirst') {\n\t\treturn sees(runtime.platformAdapterId) ? runtime.platformAdapterId : undefined\n\t}\n\tconst picked = await pickDefault({ ...args, pick: rule })\n\treturn sees(picked) ? picked : undefined\n}\n\n/** `visible` reading through the scope's chosen default; the very registry when it already does. */\nconst withScopeDefault = async (\n\targs: Omit<ScopeDefaultArgs, 'visible'> & { visible: AdapterRegistry | null }\n): Promise<AdapterRegistry | null> => {\n\tconst { visible } = args\n\tif (!visible) {\n\t\treturn null\n\t}\n\tconst chosen = await scopeDefaultId({ ...args, visible })\n\treturn chosen === undefined || chosen === visible.default().id\n\t\t? visible\n\t\t: createRegistry(visible.all(), chosen)\n}\n\n/**\n * {@link visibleRegistryFor}, also naming the shared adapters only a `fallback` policy admitted,\n * which a listing says so about.\n */\nexport const visibleSourcesFor = async (args: VisibleArgs): Promise<VisibleSources> => {\n\tconst { runtime, req, resolved, scope } = args\n\tconst { registry, grants } = resolved\n\tif (runtime.scoped !== true || scope === null || scope === PLATFORM_SCOPE) {\n\t\treturn { registry, fallbackAdmitted: NONE_ADMITTED }\n\t}\n\tif (args.principal === SYSTEM) {\n\t\tconst visible = filterRegistry(\n\t\t\tregistry,\n\t\t\t(adapter) => grants.has(adapter.id) || !needsUnscopedSourceAccess(runtime, adapter, scope)\n\t\t)\n\t\treturn {\n\t\t\tregistry: await withScopeDefault({ runtime, req, resolved, scope, visible }),\n\t\t\tfallbackAdmitted: NONE_ADMITTED,\n\t\t}\n\t}\n\tconst gates = args.gates ?? scopeGates(runtime, req)\n\tconst readable = await readableProviderDocIds(runtime, req, scope)\n\tconst own: Granted[] = []\n\tfor (const adapter of registry.all()) {\n\t\tconst docId = grants.get(adapter.id)\n\t\tif (docId !== undefined && (readable === null || readable.has(docId))) {\n\t\t\town.push({ adapter, docId })\n\t\t}\n\t}\n\tconst keep = new Set(own.map((granted) => granted.adapter.id))\n\tconst fallbackAdmitted = new Set<string>()\n\tfor (const adapter of registry.all()) {\n\t\tif (grants.has(adapter.id)) {\n\t\t\tcontinue\n\t\t}\n\t\tif (!runtime.providersCollection && adapter.capabilities.scopedQueries) {\n\t\t\tkeep.add(adapter.id)\n\t\t\tcontinue\n\t\t}\n\t\tif (await gates.unscopedSource({ scope, adapterId: adapter.id })) {\n\t\t\tkeep.add(adapter.id)\n\t\t\tcontinue\n\t\t}\n\t\tif (await policyAdmits({ runtime, req, scope, adapter, own })) {\n\t\t\tkeep.add(adapter.id)\n\t\t\tif (runtime.sourcePolicies?.get(adapter.id) === 'fallback') {\n\t\t\t\tfallbackAdmitted.add(adapter.id)\n\t\t\t}\n\t\t}\n\t}\n\tconst visible = filterRegistry(registry, (adapter) => keep.has(adapter.id))\n\treturn {\n\t\tregistry: await withScopeDefault({ runtime, req, resolved, scope, visible }),\n\t\tfallbackAdmitted,\n\t}\n}\n\n/**\n * The adapters a request may read through in one tenant scope, or null for none: the scope's own\n * sources follow the providers' read access (`sourceAccess`), a config adapter `unscopedSource` or\n * its `sources` policy. A tenant scope reads through its chosen default (see `defaultSource`).\n */\nexport const visibleRegistryFor = async (args: VisibleArgs): Promise<AdapterRegistry | null> =>\n\t(await visibleSourcesFor(args)).registry\n\n/**\n * The sources a job reads one scope through as {@link SYSTEM}, or null when the scope holds\n * none: exactly what `resolveReadContext` lets a system read choose from.\n */\nexport const systemRegistryFor = async (\n\truntime: AnalyticsRuntime,\n\treq: PayloadRequest,\n\tscope: string | null\n): Promise<AdapterRegistry | null> => {\n\tconst resolved = await resolveRegistryFor(runtime, {\n\t\tpayload: req.payload,\n\t\treq,\n\t\tscope: resolvableScope(scope),\n\t})\n\treturn visibleRegistryFor({ runtime, req, resolved, scope, principal: SYSTEM })\n}\n\n/**\n * The scope to stamp on one adapter query, or a refusal. Every read path decides it here, so\n * widgets and the query endpoint cannot drift on what counts as cross-scope.\n */\nexport const resolveQueryScope = async (\n\targs: QueryScopeArgs\n): Promise<{ ok: true; queryScope?: string } | { ok: false }> => {\n\tconst { runtime, req, scope, adapter } = args\n\tconst gates = args.gates ?? scopeGates(runtime, req)\n\tif (scope === PLATFORM_SCOPE) {\n\t\treturn (await gates.aggregate({ scope })) ? { ok: true } : { ok: false }\n\t}\n\tif (scope === null) {\n\t\treturn { ok: true }\n\t}\n\tif (needsUnscopedSourceAccess(runtime, adapter, scope)) {\n\t\treturn (await gates.unscopedSource({ scope, adapterId: adapter.id }))\n\t\t\t? { ok: true }\n\t\t\t: { ok: false }\n\t}\n\treturn { ok: true, queryScope: scope }\n}\n\ntype PrincipalScope =\n\t| { ok: true; scope: string | null; pin: ReadPrincipal }\n\t| Extract<ReadContext, { ok: false }>\n\n/**\n * The read's scope: the system's own, one already cleared, or the one the request asks for. Checked\n * at runtime, since a JavaScript caller or a cast can pass anything; anything else is refused.\n */\nconst principalScope = async (\n\targs: ResolveReadContextArgs,\n\tgates: ScopeGates\n): Promise<PrincipalScope> => {\n\tconst { scope } = args\n\tif (args.principal === SYSTEM) {\n\t\treturn typeof scope === 'string' || scope === null\n\t\t\t? { ok: true, scope, pin: { principal: SYSTEM, scope } }\n\t\t\t: { ok: false }\n\t}\n\tif (isGatedScope(scope)) {\n\t\treturn { ok: true, scope: scope.value, pin: { scope } }\n\t}\n\tif (scope !== undefined && scope !== null && typeof scope !== 'string') {\n\t\treturn { ok: false }\n\t}\n\tconst requested = await resolveRequestedScope({\n\t\truntime: args.runtime,\n\t\treq: args.req,\n\t\tgates,\n\t\traw: scope,\n\t})\n\tif (!requested.ok) {\n\t\tswitch (requested.reason) {\n\t\t\tcase 'not-member':\n\t\t\t\treturn { ok: false, reason: 'not-member' }\n\t\t\tcase 'named':\n\t\t\t\treturn { ok: false, reason: 'no-access' }\n\t\t\tcase 'unresolved':\n\t\t\t\treturn { ok: false, reason: 'no-scope' }\n\t\t\tcase 'failed':\n\t\t\t\treturn { ok: false }\n\t\t}\n\t}\n\treturn { ok: true, scope: requested.scope, pin: { scope: requested.gated } }\n}\n\n/**\n * One read's scope and adapter, behind `access.read` and `resolveRequestedScope` unless the\n * principal is {@link SYSTEM}. Any failure answers `{ ok: false }`, so a surface never throws.\n */\nexport const resolveReadContext = async (args: ResolveReadContextArgs): Promise<ReadContext> => {\n\tconst { runtime, req, adapterId } = args\n\tconst system = args.principal === SYSTEM\n\tconst gates = system ? SYSTEM_GATES : scopeGates(runtime, req)\n\ttry {\n\t\tif (!system && !(await readGate(runtime, req))) {\n\t\t\treturn { ok: false, reason: 'no-access' }\n\t\t}\n\t\tconst decided = await principalScope(args, gates)\n\t\tif (!decided.ok) {\n\t\t\treturn decided\n\t\t}\n\t\tconst { scope, pin } = decided\n\t\tconst registryScope = resolvableScope(scope)\n\t\tconst resolved = await resolveRegistryFor(runtime, {\n\t\t\tpayload: req.payload,\n\t\t\treq,\n\t\t\tscope: registryScope,\n\t\t})\n\t\t// The default is picked out of what this reader may actually read, so a scope whose\n\t\t// leading source is the platform's own shared one still serves a tenant admin.\n\t\tconst registry = await visibleRegistryFor({\n\t\t\truntime,\n\t\t\treq,\n\t\t\tresolved,\n\t\t\tscope,\n\t\t\tgates,\n\t\t\t...(system ? { principal: SYSTEM } : {}),\n\t\t})\n\t\tif (!registry) {\n\t\t\treturn { ok: false, reason: 'no-sources' }\n\t\t}\n\t\tconst fallback = registry.default()\n\t\tconst preferred =\n\t\t\targs.prefer && !args.prefer(fallback) ? registry.all().find(args.prefer) : undefined\n\t\tconst substitutedFrom =\n\t\t\tadapterId && args.fallbackWhenUnreadable && !registry.all().some((a) => a.id === adapterId)\n\t\t\t\t? adapterId\n\t\t\t\t: undefined\n\t\tconst adapter =\n\t\t\tadapterId && substitutedFrom === undefined ? registry.get(adapterId) : (preferred ?? fallback)\n\t\tconst decision = await resolveQueryScope({\n\t\t\truntime,\n\t\t\treq,\n\t\t\tscope,\n\t\t\tadapter,\n\t\t\tgates,\n\t\t})\n\t\tif (!decision.ok) {\n\t\t\treturn { ok: false }\n\t\t}\n\t\treturn {\n\t\t\tok: true,\n\t\t\tadapter,\n\t\t\tscope: registryScope,\n\t\t\tqueryScope: decision.queryScope,\n\t\t\tpin,\n\t\t\t...(substitutedFrom === undefined ? {} : { substitutedFrom }),\n\t\t}\n\t} catch (err) {\n\t\treq.payload.logger?.warn(`analytics: read context resolution failed: ${String(err)}`)\n\t\treturn { ok: false }\n\t}\n}\n"],"mappings":";;;;;;;;;;;AAwGA,MAAM,WAAW,WAA0C;CAC1D,IAAI;CACJ;CACA,OAAO,eAAe,KAAK;AAC5B;;;;;AAMA,MAAa,wBAAwB,OAAO,SAAsD;CACjG,MAAM,EAAE,SAAS,QAAQ;CACzB,MAAM,QAAQ,KAAK,SAAS,WAAW,SAAS,GAAG;CACnD,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW,KAAK,IAAI,KAAK,IAAI;CAC/D,IAAI,UAAU,IAAI;EAGjB,IAAI,UAAA,KACH,OAAQ,MAAM,MAAM,UAAU,EAAE,OAAA,IAAsB,CAAC,IACpD,QAAQ,KAAK,IACb;GAAE,IAAI;GAAO,QAAQ;EAAQ;EAGjC,IAAI,QAAQ,WAAW,QAAQ,MAAM,SAAA,KACpC,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAQ;EAErC,IAAI,MAAM,MAAM,MAAM,EAAE,OAAO,MAAM,CAAC,GACrC,OAAO,QAAQ,KAAK;EAGrB,MAAM,MAAM,MAAM,gBAAgB,SAAS,GAAG,EAAE,YAAY,IAAI;EAChE,IAAI,QAAQ,QAAQ,QAAA,OAA0B,QAAQ,OACrD,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAQ;EAErC,OAAQ,MAAM,cAAc,QAAQ,QAAQ,KAAK,GAAG,IACjD,QAAQ,GAAG,IACX;GAAE,IAAI;GAAO,QAAQ;EAAa;CACtC;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;GACN,IAAI;GACJ;GACA,OAAO;GACP,YAAY,SAAS;GACrB;GACA,GAAI,oBAAoB,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB;EAC5D;CACD,SAAS,KAAK;EACb,IAAI,QAAQ,QAAQ,KAAK,8CAA8C,OAAO,GAAG,GAAG;EACpF,OAAO,EAAE,IAAI,MAAM;CACpB;AACD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AdapterLabelArgs } from "./contract.js";
|
|
2
|
+
//#region src/core/sourceLabel.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* A built-in adapter's `label` option: one name, a name per admin language (read like
|
|
5
|
+
* `view.navLabel`), or a function naming the source for each reader.
|
|
6
|
+
*/
|
|
7
|
+
type AdapterLabelOption = string | Record<string, string> | ((args: AdapterLabelArgs) => string | Promise<string>);
|
|
8
|
+
//#endregion
|
|
9
|
+
export { AdapterLabelOption };
|
|
10
|
+
//# sourceMappingURL=sourceLabel.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isRecord, kindOf } from "./values.js";
|
|
2
|
+
import { pickLabel } from "../translations/labelMap.js";
|
|
3
|
+
//#region src/core/sourceLabel.ts
|
|
4
|
+
const filled = (value) => typeof value === "string" && value.trim() !== "";
|
|
5
|
+
const isLabelMap = (value) => isRecord(value) && !Array.isArray(value) && Object.values(value).every((text) => typeof text === "string");
|
|
6
|
+
/**
|
|
7
|
+
* The label fields a factory spreads into its adapter: `label` for surfaces with no reader (the
|
|
8
|
+
* string, else the map's `en` or first entry, else `vendor`) and `labelFor` per reader. A blank
|
|
9
|
+
* string counts as unset, as `view.navLabel` reads one.
|
|
10
|
+
*/
|
|
11
|
+
const adapterLabel = (option, vendor, owner) => {
|
|
12
|
+
if (option === void 0) return { label: vendor };
|
|
13
|
+
if (typeof option === "string") return { label: filled(option) ? option : vendor };
|
|
14
|
+
if (typeof option === "function") return {
|
|
15
|
+
label: vendor,
|
|
16
|
+
labelFor: option
|
|
17
|
+
};
|
|
18
|
+
if (isLabelMap(option)) {
|
|
19
|
+
const label = pickLabel(option, "en") ?? Object.values(option).find(filled) ?? vendor;
|
|
20
|
+
return {
|
|
21
|
+
label,
|
|
22
|
+
labelFor: ({ req }) => pickLabel(option, req.i18n?.language, req.i18n?.fallbackLanguage) ?? label
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`analytics: ${owner} must be a label, a map of labels by language such as { en: 'Traffic' }, or a label function, got ${kindOf(option)}`);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A source's name for one reader. A `labelFor` that throws or names nothing reads as `label`, with
|
|
29
|
+
* a warning, so one host function cannot blank a listing.
|
|
30
|
+
*/
|
|
31
|
+
const sourceLabelFor = async (adapter, args) => {
|
|
32
|
+
if (!adapter.labelFor) return adapter.label;
|
|
33
|
+
try {
|
|
34
|
+
const label = await adapter.labelFor(args);
|
|
35
|
+
if (filled(label)) return label;
|
|
36
|
+
args.req.payload.logger?.warn(`analytics: label of source "${adapter.id}" named ${kindOf(label)}, using "${adapter.label}"`);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
args.req.payload.logger?.warn(`analytics: label of source "${adapter.id}" failed, using "${adapter.label}": ${String(err)}`);
|
|
39
|
+
}
|
|
40
|
+
return adapter.label;
|
|
41
|
+
};
|
|
42
|
+
/** A source as this reader is shown it; `configIds` tells an adapter every scope shares. */
|
|
43
|
+
const sourceRefFor = async (adapter, args) => ({
|
|
44
|
+
id: adapter.id,
|
|
45
|
+
label: await sourceLabelFor(adapter, args),
|
|
46
|
+
kind: args.configIds.has(adapter.id) ? "config" : "runtime",
|
|
47
|
+
...args.docId === void 0 ? {} : { docId: args.docId }
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* The adapter under one fixed name for every reader, as a provider document names its source:
|
|
51
|
+
* a `labelFor` it carried would otherwise rename it per request.
|
|
52
|
+
*/
|
|
53
|
+
const withFixedLabel = (adapter, label) => {
|
|
54
|
+
const { labelFor: _perReader, ...fixed } = adapter;
|
|
55
|
+
return {
|
|
56
|
+
...fixed,
|
|
57
|
+
label
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
//#endregion
|
|
61
|
+
export { adapterLabel, sourceLabelFor, sourceRefFor, withFixedLabel };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=sourceLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourceLabel.js","names":[],"sources":["../../src/core/sourceLabel.ts"],"sourcesContent":["import { pickLabel } from '../translations/labelMap'\nimport type { AdapterLabelArgs, AnalyticsAdapter } from './contract'\nimport type { SourceRef } from './sourcePolicy'\nimport { isRecord, kindOf } from './values'\n\n/**\n * A built-in adapter's `label` option: one name, a name per admin language (read like\n * `view.navLabel`), or a function naming the source for each reader.\n */\nexport type AdapterLabelOption =\n\t| string\n\t| Record<string, string>\n\t| ((args: AdapterLabelArgs) => string | Promise<string>)\n\ntype LabelFields = Pick<AnalyticsAdapter, 'label' | 'labelFor'>\n\nconst filled = (value: unknown): value is string => typeof value === 'string' && value.trim() !== ''\n\nconst isLabelMap = (value: unknown): value is Record<string, string> =>\n\tisRecord(value) &&\n\t!Array.isArray(value) &&\n\tObject.values(value).every((text) => typeof text === 'string')\n\n/**\n * The label fields a factory spreads into its adapter: `label` for surfaces with no reader (the\n * string, else the map's `en` or first entry, else `vendor`) and `labelFor` per reader. A blank\n * string counts as unset, as `view.navLabel` reads one.\n */\nexport const adapterLabel = (\n\toption: AdapterLabelOption | undefined,\n\tvendor: string,\n\towner: string\n): LabelFields => {\n\tif (option === undefined) {\n\t\treturn { label: vendor }\n\t}\n\tif (typeof option === 'string') {\n\t\treturn { label: filled(option) ? option : vendor }\n\t}\n\tif (typeof option === 'function') {\n\t\treturn { label: vendor, labelFor: option }\n\t}\n\tif (isLabelMap(option)) {\n\t\tconst label = pickLabel(option, 'en') ?? Object.values(option).find(filled) ?? vendor\n\t\treturn {\n\t\t\tlabel,\n\t\t\tlabelFor: ({ req }) =>\n\t\t\t\tpickLabel(option, req.i18n?.language, req.i18n?.fallbackLanguage) ?? label,\n\t\t}\n\t}\n\tthrow new Error(\n\t\t`analytics: ${owner} must be a label, a map of labels by language such as { en: 'Traffic' }, or a label function, got ${kindOf(option)}`\n\t)\n}\n\n/**\n * A source's name for one reader. A `labelFor` that throws or names nothing reads as `label`, with\n * a warning, so one host function cannot blank a listing.\n */\nexport const sourceLabelFor = async (\n\tadapter: Pick<AnalyticsAdapter, 'id' | 'label' | 'labelFor'>,\n\targs: AdapterLabelArgs\n): Promise<string> => {\n\tif (!adapter.labelFor) {\n\t\treturn adapter.label\n\t}\n\ttry {\n\t\tconst label: unknown = await adapter.labelFor(args)\n\t\tif (filled(label)) {\n\t\t\treturn label\n\t\t}\n\t\targs.req.payload.logger?.warn(\n\t\t\t`analytics: label of source \"${adapter.id}\" named ${kindOf(label)}, using \"${adapter.label}\"`\n\t\t)\n\t} catch (err) {\n\t\targs.req.payload.logger?.warn(\n\t\t\t`analytics: label of source \"${adapter.id}\" failed, using \"${adapter.label}\": ${String(err)}`\n\t\t)\n\t}\n\treturn adapter.label\n}\n\n/** A source as this reader is shown it; `configIds` tells an adapter every scope shares. */\nexport const sourceRefFor = async (\n\tadapter: AnalyticsAdapter,\n\targs: AdapterLabelArgs & { configIds: ReadonlySet<string>; docId?: string }\n): Promise<SourceRef> => ({\n\tid: adapter.id,\n\tlabel: await sourceLabelFor(adapter, args),\n\tkind: args.configIds.has(adapter.id) ? 'config' : 'runtime',\n\t...(args.docId === undefined ? {} : { docId: args.docId }),\n})\n\n/**\n * The adapter under one fixed name for every reader, as a provider document names its source:\n * a `labelFor` it carried would otherwise rename it per request.\n */\nexport const withFixedLabel = (adapter: AnalyticsAdapter, label: string): AnalyticsAdapter => {\n\tconst { labelFor: _perReader, ...fixed } = adapter\n\treturn { ...fixed, label }\n}\n"],"mappings":";;;AAgBA,MAAM,UAAU,UAAoC,OAAO,UAAU,YAAY,MAAM,KAAK,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