@reactionary/google-analytics 0.3.18 → 0.6.2
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/core/initialize.js +21 -4
- package/core/initialize.types.js +7 -0
- package/index.js +1 -0
- package/package.json +2 -2
- package/schema/capabilities.schema.js +7 -0
- package/src/core/initialize.d.ts +6 -4
- package/src/core/initialize.types.d.ts +24 -0
- package/src/index.d.ts +1 -0
- package/src/schema/capabilities.schema.d.ts +19 -3
package/core/initialize.js
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GoogleAnalyticsCapabilitiesSchema
|
|
3
|
+
} from "../schema/capabilities.schema.js";
|
|
1
4
|
import { GoogleAnalyticsAnalyticsProvider } from "../providers/analytics.provider.js";
|
|
2
|
-
|
|
5
|
+
import {
|
|
6
|
+
resolveProviderOnlyCapability
|
|
7
|
+
} from "./initialize.types.js";
|
|
8
|
+
function withGoogleAnalyticsCapabilities(configuration, capabilities) {
|
|
3
9
|
return (cache, context) => {
|
|
4
10
|
const client = {};
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
const caps = GoogleAnalyticsCapabilitiesSchema.parse(capabilities);
|
|
12
|
+
if (caps.analytics?.enabled) {
|
|
13
|
+
client.analytics = resolveProviderOnlyCapability(
|
|
14
|
+
capabilities.analytics,
|
|
15
|
+
(args) => new GoogleAnalyticsAnalyticsProvider(args.cache, args.context, args.config),
|
|
16
|
+
{
|
|
17
|
+
cache,
|
|
18
|
+
context,
|
|
19
|
+
config: configuration
|
|
20
|
+
}
|
|
21
|
+
);
|
|
7
22
|
}
|
|
8
23
|
return client;
|
|
9
24
|
};
|
|
10
25
|
}
|
|
26
|
+
const googleAnalyticsCapabilities = withGoogleAnalyticsCapabilities;
|
|
11
27
|
export {
|
|
12
|
-
googleAnalyticsCapabilities
|
|
28
|
+
googleAnalyticsCapabilities,
|
|
29
|
+
withGoogleAnalyticsCapabilities
|
|
13
30
|
};
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/google-analytics",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@reactionary/core": "0.
|
|
7
|
+
"@reactionary/core": "0.6.2",
|
|
8
8
|
"zod": "4.1.9"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { CapabilitiesSchema } from "@reactionary/core";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
const AnalyticsCapabilitySchema = z.looseObject({
|
|
4
|
+
enabled: z.boolean(),
|
|
5
|
+
provider: z.unknown().optional()
|
|
6
|
+
});
|
|
2
7
|
const GoogleAnalyticsCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
3
8
|
analytics: true
|
|
9
|
+
}).extend({
|
|
10
|
+
analytics: AnalyticsCapabilitySchema.optional()
|
|
4
11
|
}).partial();
|
|
5
12
|
export {
|
|
6
13
|
GoogleAnalyticsCapabilitiesSchema
|
package/src/core/initialize.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { Cache,
|
|
2
|
-
import type
|
|
3
|
-
import type { GoogleAnalyticsConfiguration } from
|
|
4
|
-
|
|
1
|
+
import type { Cache, RequestContext } from '@reactionary/core';
|
|
2
|
+
import { type GoogleAnalyticsCapabilities } from '../schema/capabilities.schema.js';
|
|
3
|
+
import type { GoogleAnalyticsConfiguration } from '../schema/configuration.schema.js';
|
|
4
|
+
import { type GoogleAnalyticsClientFromCapabilities } from './initialize.types.js';
|
|
5
|
+
export declare function withGoogleAnalyticsCapabilities<T extends GoogleAnalyticsCapabilities>(configuration: GoogleAnalyticsConfiguration, capabilities: T): (cache: Cache, context: RequestContext) => GoogleAnalyticsClientFromCapabilities<T>;
|
|
6
|
+
export declare const googleAnalyticsCapabilities: typeof withGoogleAnalyticsCapabilities;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ClientFromCapabilities } from '@reactionary/core';
|
|
2
|
+
import type { GoogleAnalyticsCapabilities } from '../schema/capabilities.schema.js';
|
|
3
|
+
import type { GoogleAnalyticsAnalyticsProvider } from '../providers/analytics.provider.js';
|
|
4
|
+
type EnabledCapability<TCapability> = TCapability extends {
|
|
5
|
+
enabled: true;
|
|
6
|
+
} ? true : false;
|
|
7
|
+
type NormalizeConfiguredCapabilities<T extends GoogleAnalyticsCapabilities> = Omit<T, 'analytics'> & {
|
|
8
|
+
analytics?: EnabledCapability<T['analytics']>;
|
|
9
|
+
};
|
|
10
|
+
type ExtractCapabilityProvider<TCapability, TDefaultProvider> = TCapability extends {
|
|
11
|
+
enabled: true;
|
|
12
|
+
provider?: infer TProviderFactory;
|
|
13
|
+
} ? TProviderFactory extends (...args: unknown[]) => infer TProvider ? TProvider : TDefaultProvider : TDefaultProvider;
|
|
14
|
+
type CapabilityOverride<TCapability, TKey extends string, TProvider> = TCapability extends {
|
|
15
|
+
enabled: true;
|
|
16
|
+
} ? {
|
|
17
|
+
[K in TKey]: TProvider;
|
|
18
|
+
} : Record<never, never>;
|
|
19
|
+
type AnalyticsProviderFor<T extends GoogleAnalyticsCapabilities> = ExtractCapabilityProvider<T['analytics'], GoogleAnalyticsAnalyticsProvider>;
|
|
20
|
+
export type GoogleAnalyticsClientFromCapabilities<T extends GoogleAnalyticsCapabilities> = Omit<ClientFromCapabilities<NormalizeConfiguredCapabilities<T>>, 'analytics'> & CapabilityOverride<T['analytics'], 'analytics', AnalyticsProviderFor<T>>;
|
|
21
|
+
export declare function resolveProviderOnlyCapability<TProvider, TProviderArgs>(capability: {
|
|
22
|
+
provider?: (args: TProviderArgs) => TProvider;
|
|
23
|
+
} | undefined, defaultProvider: (args: TProviderArgs) => TProvider, args: TProviderArgs): TProvider;
|
|
24
|
+
export {};
|
package/src/index.d.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type { AnalyticsProvider, Cache, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type { GoogleAnalyticsConfiguration } from './configuration.schema.js';
|
|
3
|
+
import * as z from 'zod';
|
|
2
4
|
export declare const GoogleAnalyticsCapabilitiesSchema: z.ZodObject<{
|
|
3
|
-
analytics: z.ZodOptional<z.
|
|
5
|
+
analytics: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
6
|
+
enabled: z.ZodBoolean;
|
|
7
|
+
provider: z.ZodOptional<z.ZodUnknown>;
|
|
8
|
+
}, z.core.$loose>>>;
|
|
4
9
|
}, z.core.$loose>;
|
|
5
|
-
export
|
|
10
|
+
export interface GoogleAnalyticsProviderFactoryArgs {
|
|
11
|
+
cache: Cache;
|
|
12
|
+
context: RequestContext;
|
|
13
|
+
config: GoogleAnalyticsConfiguration;
|
|
14
|
+
}
|
|
15
|
+
export interface GoogleAnalyticsAnalyticsCapabilityConfig<TProvider extends AnalyticsProvider = AnalyticsProvider> {
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
provider?: (args: GoogleAnalyticsProviderFactoryArgs) => TProvider;
|
|
18
|
+
}
|
|
19
|
+
export type GoogleAnalyticsCapabilities<TAnalyticsProvider extends AnalyticsProvider = AnalyticsProvider> = {
|
|
20
|
+
analytics?: GoogleAnalyticsAnalyticsCapabilityConfig<TAnalyticsProvider>;
|
|
21
|
+
};
|