@reactionary/core 0.11.2 → 0.12.0
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/analytics/context.js +173 -0
- package/analytics/dispatcher.js +181 -0
- package/analytics/index.js +6 -0
- package/analytics/legacy-adapter.js +48 -0
- package/analytics/origins.js +64 -0
- package/analytics/recording-subscriber.js +26 -0
- package/analytics/refs.js +14 -0
- package/capabilities/analytics.capability.js +265 -84
- package/capabilities/analytics.provider.js +13 -0
- package/capabilities/index.js +1 -0
- package/client/client-builder.js +45 -16
- package/index.js +1 -0
- package/package.json +1 -1
- package/schemas/models/analytics/consent.model.js +10 -0
- package/schemas/models/analytics/dispatch.model.js +15 -0
- package/schemas/models/analytics/envelope.model.js +38 -0
- package/schemas/models/analytics/event-parts.model.js +47 -0
- package/schemas/models/analytics/event.model.js +255 -0
- package/schemas/models/analytics/index.js +6 -0
- package/schemas/models/analytics/origin.model.js +113 -0
- package/schemas/models/analytics.model.js +0 -2
- package/schemas/models/index.js +1 -0
- package/schemas/mutations/analytics/events/account.mutation.js +66 -0
- package/schemas/mutations/analytics/events/base.mutation.js +10 -0
- package/schemas/mutations/analytics/events/browse.mutation.js +53 -0
- package/schemas/mutations/analytics/events/commerce.mutation.js +79 -0
- package/schemas/mutations/analytics/events/index.js +85 -0
- package/schemas/mutations/analytics/index.js +1 -0
- package/schemas/session.schema.js +3 -1
- package/src/analytics/context.d.ts +85 -0
- package/src/analytics/dispatcher.d.ts +71 -0
- package/src/analytics/index.d.ts +6 -0
- package/src/analytics/legacy-adapter.d.ts +10 -0
- package/src/analytics/origins.d.ts +25 -0
- package/src/analytics/recording-subscriber.d.ts +18 -0
- package/src/analytics/refs.d.ts +8 -0
- package/src/capabilities/analytics.capability.d.ts +64 -17
- package/src/capabilities/analytics.provider.d.ts +24 -0
- package/src/capabilities/index.d.ts +1 -0
- package/src/client/client-builder.d.ts +25 -2
- package/src/index.d.ts +1 -0
- package/src/schemas/capabilities.schema.d.ts +8 -1
- package/src/schemas/models/analytics/consent.model.d.ts +13 -0
- package/src/schemas/models/analytics/dispatch.model.d.ts +29 -0
- package/src/schemas/models/analytics/envelope.model.d.ts +565 -0
- package/src/schemas/models/analytics/event-parts.model.d.ts +248 -0
- package/src/schemas/models/analytics/event.model.d.ts +83182 -0
- package/src/schemas/models/analytics/index.d.ts +6 -0
- package/src/schemas/models/analytics/origin.model.d.ts +275 -0
- package/src/schemas/models/analytics.model.d.ts +1 -2
- package/src/schemas/models/index.d.ts +1 -0
- package/src/schemas/mutations/analytics/events/account.mutation.d.ts +1939 -0
- package/src/schemas/mutations/analytics/events/base.mutation.d.ts +121 -0
- package/src/schemas/mutations/analytics/events/browse.mutation.d.ts +1832 -0
- package/src/schemas/mutations/analytics/events/commerce.mutation.d.ts +30188 -0
- package/src/schemas/mutations/analytics/events/index.d.ts +33928 -0
- package/src/schemas/mutations/analytics/index.d.ts +1 -0
- package/src/schemas/mutations/checkout.mutation.d.ts +4 -4
- package/src/schemas/mutations/product-list.mutation.d.ts +2 -2
- package/src/schemas/session.schema.d.ts +8 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AnalyticsMutationPageViewedSchema,
|
|
3
|
+
AnalyticsMutationSearchResultsViewedSchema,
|
|
4
|
+
AnalyticsMutationAutocompleteSuggestionSelectedSchema,
|
|
5
|
+
AnalyticsMutationCategoryViewedSchema,
|
|
6
|
+
AnalyticsMutationProductCarouselViewedSchema,
|
|
7
|
+
AnalyticsMutationProductClickedSchema,
|
|
8
|
+
AnalyticsMutationProductViewedSchema,
|
|
9
|
+
AnalyticsMutationPromotionViewedSchema,
|
|
10
|
+
AnalyticsMutationPromotionClickedSchema
|
|
11
|
+
} from "./browse.mutation.js";
|
|
12
|
+
import {
|
|
13
|
+
AnalyticsMutationCartItemAddedSchema,
|
|
14
|
+
AnalyticsMutationCartItemRemovedSchema,
|
|
15
|
+
AnalyticsMutationCartItemQuantityChangedSchema,
|
|
16
|
+
AnalyticsMutationCartViewedSchema,
|
|
17
|
+
AnalyticsMutationCouponAppliedSchema,
|
|
18
|
+
AnalyticsMutationCouponRejectedSchema,
|
|
19
|
+
AnalyticsMutationCheckoutStartedSchema,
|
|
20
|
+
AnalyticsMutationShippingInfoAddedSchema,
|
|
21
|
+
AnalyticsMutationPaymentInfoAddedSchema,
|
|
22
|
+
AnalyticsMutationOrderPlacedSchema,
|
|
23
|
+
AnalyticsMutationQuoteRequestedSchema,
|
|
24
|
+
AnalyticsMutationOrderReorderedSchema,
|
|
25
|
+
AnalyticsMutationCompanyRegisteredSchema
|
|
26
|
+
} from "./commerce.mutation.js";
|
|
27
|
+
import {
|
|
28
|
+
AnalyticsMutationUserLoggedInSchema,
|
|
29
|
+
AnalyticsMutationUserLoggedOutSchema,
|
|
30
|
+
AnalyticsMutationUserRegisteredSchema,
|
|
31
|
+
AnalyticsMutationProfileUpdatedSchema,
|
|
32
|
+
AnalyticsMutationConsentChangedSchema,
|
|
33
|
+
AnalyticsMutationNewsletterSubscribedSchema,
|
|
34
|
+
AnalyticsMutationWishlistItemAddedSchema,
|
|
35
|
+
AnalyticsMutationWishlistItemRemovedSchema,
|
|
36
|
+
AnalyticsMutationBackInStockRequestedSchema,
|
|
37
|
+
AnalyticsMutationReviewSubmittedSchema,
|
|
38
|
+
AnalyticsMutationStoreSelectedSchema,
|
|
39
|
+
AnalyticsMutationProductSharedSchema,
|
|
40
|
+
AnalyticsMutationCustomSchema
|
|
41
|
+
} from "./account.mutation.js";
|
|
42
|
+
export * from "./base.mutation.js";
|
|
43
|
+
export * from "./browse.mutation.js";
|
|
44
|
+
export * from "./commerce.mutation.js";
|
|
45
|
+
export * from "./account.mutation.js";
|
|
46
|
+
const AnalyticsEventMutationSchemas = {
|
|
47
|
+
"page-viewed": AnalyticsMutationPageViewedSchema,
|
|
48
|
+
"search-results-viewed": AnalyticsMutationSearchResultsViewedSchema,
|
|
49
|
+
"autocomplete-suggestion-selected": AnalyticsMutationAutocompleteSuggestionSelectedSchema,
|
|
50
|
+
"category-viewed": AnalyticsMutationCategoryViewedSchema,
|
|
51
|
+
"product-carousel-viewed": AnalyticsMutationProductCarouselViewedSchema,
|
|
52
|
+
"product-clicked": AnalyticsMutationProductClickedSchema,
|
|
53
|
+
"product-viewed": AnalyticsMutationProductViewedSchema,
|
|
54
|
+
"promotion-viewed": AnalyticsMutationPromotionViewedSchema,
|
|
55
|
+
"promotion-clicked": AnalyticsMutationPromotionClickedSchema,
|
|
56
|
+
"cart-item-added": AnalyticsMutationCartItemAddedSchema,
|
|
57
|
+
"cart-item-removed": AnalyticsMutationCartItemRemovedSchema,
|
|
58
|
+
"cart-item-quantity-changed": AnalyticsMutationCartItemQuantityChangedSchema,
|
|
59
|
+
"cart-viewed": AnalyticsMutationCartViewedSchema,
|
|
60
|
+
"coupon-applied": AnalyticsMutationCouponAppliedSchema,
|
|
61
|
+
"coupon-rejected": AnalyticsMutationCouponRejectedSchema,
|
|
62
|
+
"checkout-started": AnalyticsMutationCheckoutStartedSchema,
|
|
63
|
+
"shipping-info-added": AnalyticsMutationShippingInfoAddedSchema,
|
|
64
|
+
"payment-info-added": AnalyticsMutationPaymentInfoAddedSchema,
|
|
65
|
+
"order-placed": AnalyticsMutationOrderPlacedSchema,
|
|
66
|
+
"quote-requested": AnalyticsMutationQuoteRequestedSchema,
|
|
67
|
+
"order-reordered": AnalyticsMutationOrderReorderedSchema,
|
|
68
|
+
"company-registered": AnalyticsMutationCompanyRegisteredSchema,
|
|
69
|
+
"user-logged-in": AnalyticsMutationUserLoggedInSchema,
|
|
70
|
+
"user-logged-out": AnalyticsMutationUserLoggedOutSchema,
|
|
71
|
+
"user-registered": AnalyticsMutationUserRegisteredSchema,
|
|
72
|
+
"profile-updated": AnalyticsMutationProfileUpdatedSchema,
|
|
73
|
+
"consent-changed": AnalyticsMutationConsentChangedSchema,
|
|
74
|
+
"newsletter-subscribed": AnalyticsMutationNewsletterSubscribedSchema,
|
|
75
|
+
"wishlist-item-added": AnalyticsMutationWishlistItemAddedSchema,
|
|
76
|
+
"wishlist-item-removed": AnalyticsMutationWishlistItemRemovedSchema,
|
|
77
|
+
"back-in-stock-requested": AnalyticsMutationBackInStockRequestedSchema,
|
|
78
|
+
"review-submitted": AnalyticsMutationReviewSubmittedSchema,
|
|
79
|
+
"store-selected": AnalyticsMutationStoreSelectedSchema,
|
|
80
|
+
"product-shared": AnalyticsMutationProductSharedSchema,
|
|
81
|
+
"custom": AnalyticsMutationCustomSchema
|
|
82
|
+
};
|
|
83
|
+
export {
|
|
84
|
+
AnalyticsEventMutationSchemas
|
|
85
|
+
};
|
|
@@ -17,6 +17,7 @@ export * from "./product-summary-click.mutation.js";
|
|
|
17
17
|
export * from "./product-summary-view.mutation.js";
|
|
18
18
|
export * from "./purchase.mutation.js";
|
|
19
19
|
export * from "./base-event.mutation.js";
|
|
20
|
+
export * from "./events/index.js";
|
|
20
21
|
export {
|
|
21
22
|
AnalyticsMutationSchema
|
|
22
23
|
};
|
|
@@ -3,6 +3,7 @@ import { WebStoreIdentifierSchema } from "./models/identifiers.model.js";
|
|
|
3
3
|
import { CurrencySchema } from "./models/currency.model.js";
|
|
4
4
|
import { IdentitySchema } from "./models/identity.model.js";
|
|
5
5
|
import { PersonalizationProfileSchema } from "./models/personalization-profile.model.js";
|
|
6
|
+
import { AnalyticsConsentSchema } from "./models/analytics/consent.model.js";
|
|
6
7
|
const LanguageContextSchema = z.looseObject({
|
|
7
8
|
locale: z.string().default("en-US").meta({ description: "The locale for the current request, in IETF BCP 47 format (e.g. en-US, fr-FR). This can be used for localization and internationalization purposes." }),
|
|
8
9
|
// TODO: Replace this hardcoded fallback with a configured project/store currency.
|
|
@@ -14,7 +15,8 @@ const IdentityContextSchema = z.looseObject({
|
|
|
14
15
|
});
|
|
15
16
|
const SessionSchema = z.looseObject({
|
|
16
17
|
identityContext: IdentityContextSchema,
|
|
17
|
-
marketingContext: PersonalizationProfileSchema.default(() => PersonalizationProfileSchema.parse({}))
|
|
18
|
+
marketingContext: PersonalizationProfileSchema.default(() => PersonalizationProfileSchema.parse({})),
|
|
19
|
+
consent: AnalyticsConsentSchema.optional().meta({ description: "The visitor's consent for analytics and marketing processing, if known. When absent, the analytics dispatcher applies its configured default." })
|
|
18
20
|
});
|
|
19
21
|
const TaxJurisdictionSchema = z.object({
|
|
20
22
|
countryCode: z.string().default("US"),
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { CartCapability } from '../capabilities/cart.capability.js';
|
|
2
|
+
import type { CategoryCapability } from '../capabilities/category.capability.js';
|
|
3
|
+
import type { CompanyCapability } from '../capabilities/company.capability.js';
|
|
4
|
+
import type { IdentityCapability } from '../capabilities/identity.capability.js';
|
|
5
|
+
import type { InventoryCapability } from '../capabilities/inventory.capability.js';
|
|
6
|
+
import type { OrderCapability } from '../capabilities/order.capability.js';
|
|
7
|
+
import type { PersonalizationProfileCapability } from '../capabilities/personalization-profile.capability.js';
|
|
8
|
+
import type { PriceCapability } from '../capabilities/price.capability.js';
|
|
9
|
+
import type { ProductCapability } from '../capabilities/product.capability.js';
|
|
10
|
+
import type { ProfileCapability } from '../capabilities/profile.capability.js';
|
|
11
|
+
import type { StoreCapability } from '../capabilities/store.capability.js';
|
|
12
|
+
import type { Cart, Category, CategoryIdentifier, Company, Identity, Inventory, NotFoundError, OrderIdentifier, PersonalizationProfile, Price, Product, ProductIdentifier, ProductVariantIdentifier, Profile, RequestContext, Result, Store, StoreIdentifier, Order } from '../schemas/index.js';
|
|
13
|
+
/**
|
|
14
|
+
* The capabilities lookups are bound to. Structural, so the client's own capabilities satisfy it and tests can pass stubs.
|
|
15
|
+
* Anything left out answers lookups with an error Result.
|
|
16
|
+
*/
|
|
17
|
+
export interface AnalyticsLookupCapabilities {
|
|
18
|
+
product?: Pick<ProductCapability, 'getById' | 'getBySKU'>;
|
|
19
|
+
category?: Pick<CategoryCapability, 'getById' | 'getBreadcrumbPathToCategory'>;
|
|
20
|
+
price?: Pick<PriceCapability, 'getCustomerPrice' | 'getListPrice'>;
|
|
21
|
+
inventory?: Pick<InventoryCapability, 'getBySKU'>;
|
|
22
|
+
cart?: Pick<CartCapability, 'getActiveCartId' | 'getById'>;
|
|
23
|
+
order?: Pick<OrderCapability, 'getById'>;
|
|
24
|
+
store?: Pick<StoreCapability, 'getById'>;
|
|
25
|
+
identity?: Pick<IdentityCapability, 'getSelf'>;
|
|
26
|
+
profile?: Pick<ProfileCapability, 'getById'>;
|
|
27
|
+
personalizationProfile?: Pick<PersonalizationProfileCapability, 'getPersonalizationProfile'>;
|
|
28
|
+
company?: Pick<CompanyCapability, 'getById'>;
|
|
29
|
+
}
|
|
30
|
+
export interface AnalyticsPrices {
|
|
31
|
+
customer?: Price;
|
|
32
|
+
list?: Price;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Read-only lookups handed to analytics subscribers so they can enrich events lazily.
|
|
36
|
+
*
|
|
37
|
+
* Every lookup goes through the client's own decorated capabilities (so caching applies), is memoized for the lifetime of
|
|
38
|
+
* this context (one flush) and returns a Result. Subscribers should degrade by sending fewer fields, not by dropping the event.
|
|
39
|
+
* There is no mutation access, and the self.* lookups only ever resolve the current session.
|
|
40
|
+
*/
|
|
41
|
+
export interface AnalyticsContext {
|
|
42
|
+
readonly products: {
|
|
43
|
+
byId(id: ProductIdentifier): Promise<Result<Product>>;
|
|
44
|
+
bySku(variant: ProductVariantIdentifier): Promise<Result<Product>>;
|
|
45
|
+
/** Index-aligned with the input. Concurrency-limited. */
|
|
46
|
+
many(ids: ProductIdentifier[]): Promise<Array<Result<Product>>>;
|
|
47
|
+
};
|
|
48
|
+
readonly categories: {
|
|
49
|
+
byId(id: CategoryIdentifier): Promise<Result<Category, NotFoundError>>;
|
|
50
|
+
path(id: CategoryIdentifier): Promise<Result<Category[]>>;
|
|
51
|
+
};
|
|
52
|
+
readonly prices: {
|
|
53
|
+
forSku(variant: ProductVariantIdentifier): Promise<Result<AnalyticsPrices>>;
|
|
54
|
+
};
|
|
55
|
+
readonly inventory: {
|
|
56
|
+
/** Looks up the fulfilment center of the request's store first. */
|
|
57
|
+
forSku(variant: ProductVariantIdentifier): Promise<Result<Inventory>>;
|
|
58
|
+
};
|
|
59
|
+
readonly cart: {
|
|
60
|
+
active(): Promise<Result<Cart>>;
|
|
61
|
+
};
|
|
62
|
+
readonly orders: {
|
|
63
|
+
byId(id: OrderIdentifier): Promise<Result<Order, NotFoundError>>;
|
|
64
|
+
};
|
|
65
|
+
readonly stores: {
|
|
66
|
+
byId(id: StoreIdentifier): Promise<Result<Store, NotFoundError>>;
|
|
67
|
+
};
|
|
68
|
+
readonly self: {
|
|
69
|
+
identity(): Promise<Result<Identity>>;
|
|
70
|
+
profile(): Promise<Result<Profile>>;
|
|
71
|
+
personalization(): Promise<Result<PersonalizationProfile>>;
|
|
72
|
+
/** Best effort: the company of the active cart, as core has no current company on the request context. */
|
|
73
|
+
company(): Promise<Result<Company>>;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export interface AnalyticsContextDependencies {
|
|
77
|
+
capabilities: AnalyticsLookupCapabilities;
|
|
78
|
+
requestContext: RequestContext;
|
|
79
|
+
/** Maximum parallel product lookups in `products.many`. Defaults to 5. */
|
|
80
|
+
concurrency?: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Creates a context with fresh memoization. The dispatcher creates one per flush.
|
|
84
|
+
*/
|
|
85
|
+
export declare function createAnalyticsContext(dependencies: AnalyticsContextDependencies): AnalyticsContext;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { AnalyticsEventMutationSchemas } from '../schemas/index.js';
|
|
2
|
+
import type { AnalyticsConsent, AnalyticsDispatchOptions, AnalyticsEvent, AnalyticsEventResult, AnalyticsEventType, AnalyticsOutcome, AnalyticsPurpose, EventContextSnapshot, RequestContext, Result } from '../schemas/index.js';
|
|
3
|
+
import type { InferType } from '../zod-utils.js';
|
|
4
|
+
import type { AnalyticsContext } from './context.js';
|
|
5
|
+
/**
|
|
6
|
+
* Receives analytics events from the dispatcher. Providers (Unomi, Algolia, ...) and custom subscribers implement this.
|
|
7
|
+
* Subscriptions are fixed when the client is built.
|
|
8
|
+
*/
|
|
9
|
+
export interface AnalyticsSubscriber<K extends AnalyticsEventType = AnalyticsEventType> {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/** Exact event types, prefix wildcards such as `cart-*`, or `*`. */
|
|
12
|
+
readonly types: ReadonlyArray<K | `${string}*`>;
|
|
13
|
+
readonly purpose: AnalyticsPurpose;
|
|
14
|
+
handle(event: AnalyticsEvent<K>, ctx: AnalyticsContext): Promise<AnalyticsOutcome | void>;
|
|
15
|
+
}
|
|
16
|
+
/** The input of the helper for event type `K`: its required arguments plus `origin` and `properties`. */
|
|
17
|
+
export type AnalyticsEventInput<K extends AnalyticsEventType> = InferType<(typeof AnalyticsEventMutationSchemas)[K]>;
|
|
18
|
+
export interface AnalyticsDispatcherDependencies {
|
|
19
|
+
requestContext: RequestContext;
|
|
20
|
+
subscribers: ReadonlyArray<AnalyticsSubscriber>;
|
|
21
|
+
/** Called once per flush, so lookups are memoized for that flush only. */
|
|
22
|
+
createContext: () => AnalyticsContext;
|
|
23
|
+
options?: AnalyticsDispatchOptions;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Per-emit overrides, for internal callers such as the deprecated `track` adapter. The storefront-facing helpers take none:
|
|
27
|
+
* the visitor's identity is `session.marketingContext`.
|
|
28
|
+
*/
|
|
29
|
+
export interface AnalyticsEmitOptions {
|
|
30
|
+
/** Identifies the visitor for this event instead of `session.marketingContext.identifier`. */
|
|
31
|
+
marketingIdentifier?: EventContextSnapshot['marketingIdentifier'];
|
|
32
|
+
}
|
|
33
|
+
export declare function eventTypeMatches(pattern: string, type: string): boolean;
|
|
34
|
+
export declare function isPurposeAllowed(purpose: AnalyticsPurpose, consent: AnalyticsConsent): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Per-request dispatcher internal to analytics: one per built client, never shared between requests.
|
|
37
|
+
*
|
|
38
|
+
* `emit` validates, snapshots request state, enqueues and schedules a flush, and never throws. Delivery is isolated per
|
|
39
|
+
* subscriber: ordered within a subscriber, parallel across subscribers, and one failing subscriber does not affect another.
|
|
40
|
+
* It is not a general purpose event bus.
|
|
41
|
+
*/
|
|
42
|
+
export declare class AnalyticsDispatcher {
|
|
43
|
+
private readonly requestContext;
|
|
44
|
+
private readonly subscribers;
|
|
45
|
+
private readonly createContext;
|
|
46
|
+
private readonly options;
|
|
47
|
+
private readonly defaultConsent;
|
|
48
|
+
private queue;
|
|
49
|
+
private flushScheduled;
|
|
50
|
+
private readonly tails;
|
|
51
|
+
private readonly inflight;
|
|
52
|
+
constructor(dependencies: AnalyticsDispatcherDependencies);
|
|
53
|
+
/**
|
|
54
|
+
* Validates the input, captures request state, enqueues the event and schedules delivery.
|
|
55
|
+
* Never throws: invalid input and emits made from inside a subscriber are logged and dropped.
|
|
56
|
+
*/
|
|
57
|
+
emit<K extends AnalyticsEventType>(type: K, input: AnalyticsEventInput<K>, options?: AnalyticsEmitOptions): Result<AnalyticsEventResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Delivers everything queued so far and resolves once all deliveries, including ones already in flight, are done.
|
|
60
|
+
* For scripts, tests and runtimes without `waitUntil`. Never rejects.
|
|
61
|
+
*/
|
|
62
|
+
flush(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* A fresh lookup context, for analytics code that has to resolve something before it can emit (the legacy adapter).
|
|
65
|
+
*/
|
|
66
|
+
lookups(): AnalyticsContext;
|
|
67
|
+
private snapshot;
|
|
68
|
+
private scheduleFlush;
|
|
69
|
+
private deliverQueued;
|
|
70
|
+
private runSubscriber;
|
|
71
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AnalyticsEventResult, AnalyticsMutation, Result } from '../schemas/index.js';
|
|
2
|
+
import type { AnalyticsDispatcher } from './dispatcher.js';
|
|
3
|
+
/**
|
|
4
|
+
* Converts a legacy `track` event into the equivalent new event and enqueues it on the dispatcher, exactly like the
|
|
5
|
+
* new helpers do. Nothing is dispatched or awaited here beyond the cart and product lookups `product-cart-add` needs.
|
|
6
|
+
*
|
|
7
|
+
* A legacy event can carry the visitor's `personalizationProfile`. It identifies the visitor for that event only, as it did
|
|
8
|
+
* before; the new helpers take no profile and use `session.marketingContext`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function emitLegacyAnalyticsEvent(event: AnalyticsMutation, dispatcher: AnalyticsDispatcher): Promise<Result<AnalyticsEventResult>>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AssociationKind, CartOriginKind, CategoryIdentifier, FacetValueIdentifier, Origin, OriginAssociations, OriginAutocomplete, OriginCart, OriginCategory, OriginContent, OriginDirect, OriginList, OriginOrder, OriginPdp, OriginProductList, OriginPromotion, OriginQuickOrder, OriginSearch, OrderIdentifier, ProductIdentifier, ProductListIdentifier, ProductRecommendationIdentifier, PromotionIdentifier, QuickOrderKind, SearchIdentifier } from '../schemas/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Constructors for {@link Origin}. `position` is always the absolute 0-based index across pages.
|
|
4
|
+
*/
|
|
5
|
+
export declare function fromSearch(identifier: SearchIdentifier, position: number): OriginSearch;
|
|
6
|
+
export declare function fromAutocomplete(term: string, position: number): OriginAutocomplete;
|
|
7
|
+
export declare function fromCategory(categoryId: CategoryIdentifier, filters: FacetValueIdentifier[], position: number): OriginCategory;
|
|
8
|
+
export declare function fromList(recommendationId: ProductRecommendationIdentifier | undefined, carouselName: string, position: number): OriginList;
|
|
9
|
+
export declare function fromAssociations(productId: ProductIdentifier, kind: AssociationKind, position: number): OriginAssociations;
|
|
10
|
+
export declare function fromProductList(listId: ProductListIdentifier, position: number): OriginProductList;
|
|
11
|
+
export declare function fromPromotion(promotionId: PromotionIdentifier, slot: string): OriginPromotion;
|
|
12
|
+
export declare function fromContent(contentId: string, slot?: string): OriginContent;
|
|
13
|
+
export declare function fromCart(kind?: CartOriginKind): OriginCart;
|
|
14
|
+
export declare function fromOrder(orderId: OrderIdentifier): OriginOrder;
|
|
15
|
+
export declare function fromQuickOrder(kind?: QuickOrderKind): OriginQuickOrder;
|
|
16
|
+
/**
|
|
17
|
+
* Nests the origin of the PDP visit so conversions on the PDP stay attributed to the search or list that led there,
|
|
18
|
+
* e.g. `fromPDP(fromSearch(id, 4))`. The storefront decides how to carry it between pages.
|
|
19
|
+
*/
|
|
20
|
+
export declare function fromPDP(upstream?: Origin): OriginPdp;
|
|
21
|
+
export declare function fromDirect(): OriginDirect;
|
|
22
|
+
/**
|
|
23
|
+
* The search an origin leads back to, looking through `fromPDP(upstream)`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function searchOriginOf(origin: Origin | undefined): OriginSearch | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AnalyticsEvent, AnalyticsEventType, AnalyticsPurpose } from '../schemas/index.js';
|
|
2
|
+
import type { AnalyticsContext } from './context.js';
|
|
3
|
+
import type { AnalyticsSubscriber } from './dispatcher.js';
|
|
4
|
+
/**
|
|
5
|
+
* Subscriber that records what it receives, for tests:
|
|
6
|
+
* `await client.analytics.flush(); expect(recorder.events).toContainEqual(...)`.
|
|
7
|
+
*/
|
|
8
|
+
export declare class RecordingAnalyticsSubscriber implements AnalyticsSubscriber {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly types: ReadonlyArray<AnalyticsEventType | `${string}*`>;
|
|
11
|
+
readonly purpose: AnalyticsPurpose;
|
|
12
|
+
readonly events: AnalyticsEvent[];
|
|
13
|
+
/** Lookup contexts the subscriber was handed, one per flush. */
|
|
14
|
+
readonly contexts: AnalyticsContext[];
|
|
15
|
+
constructor(name?: string, types?: ReadonlyArray<AnalyticsEventType | `${string}*`>, purpose?: AnalyticsPurpose);
|
|
16
|
+
handle(event: AnalyticsEvent, ctx: AnalyticsContext): Promise<'accepted'>;
|
|
17
|
+
eventsOfType<K extends AnalyticsEventType>(type: K): AnalyticsEvent<K>[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AnalyticsCategoryRef, AnalyticsProductRef, AnalyticsStoreRef } from '../schemas/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Events accept a model or just its identifier. These return the key either way, so providers do not
|
|
4
|
+
* need to know which one the storefront passed.
|
|
5
|
+
*/
|
|
6
|
+
export declare function productKey(ref: AnalyticsProductRef): string;
|
|
7
|
+
export declare function categoryKey(ref: AnalyticsCategoryRef): string;
|
|
8
|
+
export declare function storeKey(ref: AnalyticsStoreRef): string;
|
|
@@ -1,21 +1,68 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { BaseCapability } from './base.capability.js';
|
|
1
|
+
import type { AnalyticsDispatcher } from '../analytics/dispatcher.js';
|
|
3
2
|
import type { Cache } from '../cache/cache.interface.js';
|
|
4
|
-
import { type AnalyticsMutation, type
|
|
5
|
-
|
|
3
|
+
import { type AnalyticsMutation, type AnalyticsResult, type AnalyticsEventResult, type AnalyticsMutationPageViewed, type AnalyticsMutationSearchResultsViewed, type AnalyticsMutationAutocompleteSuggestionSelected, type AnalyticsMutationCategoryViewed, type AnalyticsMutationProductCarouselViewed, type AnalyticsMutationProductClicked, type AnalyticsMutationProductViewed, type AnalyticsMutationPromotionViewed, type AnalyticsMutationPromotionClicked, type AnalyticsMutationCartItemAdded, type AnalyticsMutationCartItemRemoved, type AnalyticsMutationCartItemQuantityChanged, type AnalyticsMutationCartViewed, type AnalyticsMutationCouponApplied, type AnalyticsMutationCouponRejected, type AnalyticsMutationCheckoutStarted, type AnalyticsMutationShippingInfoAdded, type AnalyticsMutationPaymentInfoAdded, type AnalyticsMutationOrderPlaced, type AnalyticsMutationQuoteRequested, type AnalyticsMutationOrderReordered, type AnalyticsMutationCompanyRegistered, type AnalyticsMutationUserLoggedIn, type AnalyticsMutationUserLoggedOut, type AnalyticsMutationUserRegistered, type AnalyticsMutationProfileUpdated, type AnalyticsMutationConsentChanged, type AnalyticsMutationNewsletterSubscribed, type AnalyticsMutationWishlistItemAdded, type AnalyticsMutationWishlistItemRemoved, type AnalyticsMutationBackInStockRequested, type AnalyticsMutationReviewSubmitted, type AnalyticsMutationStoreSelected, type AnalyticsMutationProductShared, type AnalyticsMutationCustom, type RequestContext, type Result } from '../schemas/index.js';
|
|
4
|
+
import { BaseCapability } from './base.capability.js';
|
|
5
|
+
/**
|
|
6
|
+
* What storefronts use: `client.analytics.cartItemAdded({ ... })`. Storefronts never know which vendors receive events.
|
|
7
|
+
*
|
|
8
|
+
* Every event comes from an explicit call here; other capabilities never emit analytics events on their own. Each helper
|
|
9
|
+
* validates its payload, enqueues the event on the client's per-request dispatcher and returns its id without waiting for
|
|
10
|
+
* any vendor. Delivery happens after the response via the dispatcher's `waitUntil`, or call {@link flush}.
|
|
11
|
+
*/
|
|
12
|
+
export declare class AnalyticsCapability extends BaseCapability {
|
|
13
|
+
protected readonly dispatcher: AnalyticsDispatcher;
|
|
14
|
+
constructor(cache: Cache, context: RequestContext, dispatcher: AnalyticsDispatcher);
|
|
6
15
|
protected getResourceName(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Delivers everything queued so far and resolves once delivery is done. For scripts, tests and
|
|
18
|
+
* runtimes without `waitUntil`. Never rejects.
|
|
19
|
+
*/
|
|
20
|
+
flush(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use the event helpers, e.g. `productViewed`, `cartItemAdded`, `orderPlaced`.
|
|
23
|
+
*
|
|
24
|
+
* Compatibility is at the API level only: the event is converted to its new equivalent and enqueued exactly like the helpers
|
|
25
|
+
* do, with no immediate dispatch and no waiting on providers. The returned `AnalyticsResult` keeps its shape so callers
|
|
26
|
+
* keep compiling, but its outcomes no longer reflect what providers did: it holds one `accepted` outcome for the analytics
|
|
27
|
+
* capability when the event was enqueued, or `rejected` when it could not be (invalid input, or for `product-cart-add`
|
|
28
|
+
* when the active cart or the product could not be looked up). A `personalizationProfile` on the legacy
|
|
29
|
+
* event identifies the visitor for that event only. Prefer setting `session.marketingContext` to the resolved profile
|
|
30
|
+
* and emitting through the helpers, which take no profile.
|
|
31
|
+
*/
|
|
7
32
|
track(event: AnalyticsMutation): Promise<AnalyticsResult>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
33
|
+
pageViewed(payload: AnalyticsMutationPageViewed): Promise<Result<AnalyticsEventResult>>;
|
|
34
|
+
searchResultsViewed(payload: AnalyticsMutationSearchResultsViewed): Promise<Result<AnalyticsEventResult>>;
|
|
35
|
+
autocompleteSuggestionSelected(payload: AnalyticsMutationAutocompleteSuggestionSelected): Promise<Result<AnalyticsEventResult>>;
|
|
36
|
+
categoryViewed(payload: AnalyticsMutationCategoryViewed): Promise<Result<AnalyticsEventResult>>;
|
|
37
|
+
productCarouselViewed(payload: AnalyticsMutationProductCarouselViewed): Promise<Result<AnalyticsEventResult>>;
|
|
38
|
+
productClicked(payload: AnalyticsMutationProductClicked): Promise<Result<AnalyticsEventResult>>;
|
|
39
|
+
productViewed(payload: AnalyticsMutationProductViewed): Promise<Result<AnalyticsEventResult>>;
|
|
40
|
+
promotionViewed(payload: AnalyticsMutationPromotionViewed): Promise<Result<AnalyticsEventResult>>;
|
|
41
|
+
promotionClicked(payload: AnalyticsMutationPromotionClicked): Promise<Result<AnalyticsEventResult>>;
|
|
42
|
+
cartItemAdded(payload: AnalyticsMutationCartItemAdded): Promise<Result<AnalyticsEventResult>>;
|
|
43
|
+
cartItemRemoved(payload: AnalyticsMutationCartItemRemoved): Promise<Result<AnalyticsEventResult>>;
|
|
44
|
+
cartItemQuantityChanged(payload: AnalyticsMutationCartItemQuantityChanged): Promise<Result<AnalyticsEventResult>>;
|
|
45
|
+
cartViewed(payload: AnalyticsMutationCartViewed): Promise<Result<AnalyticsEventResult>>;
|
|
46
|
+
couponApplied(payload: AnalyticsMutationCouponApplied): Promise<Result<AnalyticsEventResult>>;
|
|
47
|
+
couponRejected(payload: AnalyticsMutationCouponRejected): Promise<Result<AnalyticsEventResult>>;
|
|
48
|
+
checkoutStarted(payload: AnalyticsMutationCheckoutStarted): Promise<Result<AnalyticsEventResult>>;
|
|
49
|
+
shippingInfoAdded(payload: AnalyticsMutationShippingInfoAdded): Promise<Result<AnalyticsEventResult>>;
|
|
50
|
+
paymentInfoAdded(payload: AnalyticsMutationPaymentInfoAdded): Promise<Result<AnalyticsEventResult>>;
|
|
51
|
+
orderPlaced(payload: AnalyticsMutationOrderPlaced): Promise<Result<AnalyticsEventResult>>;
|
|
52
|
+
quoteRequested(payload: AnalyticsMutationQuoteRequested): Promise<Result<AnalyticsEventResult>>;
|
|
53
|
+
orderReordered(payload: AnalyticsMutationOrderReordered): Promise<Result<AnalyticsEventResult>>;
|
|
54
|
+
companyRegistered(payload: AnalyticsMutationCompanyRegistered): Promise<Result<AnalyticsEventResult>>;
|
|
55
|
+
userLoggedIn(payload: AnalyticsMutationUserLoggedIn): Promise<Result<AnalyticsEventResult>>;
|
|
56
|
+
userLoggedOut(payload: AnalyticsMutationUserLoggedOut): Promise<Result<AnalyticsEventResult>>;
|
|
57
|
+
userRegistered(payload: AnalyticsMutationUserRegistered): Promise<Result<AnalyticsEventResult>>;
|
|
58
|
+
profileUpdated(payload: AnalyticsMutationProfileUpdated): Promise<Result<AnalyticsEventResult>>;
|
|
59
|
+
consentChanged(payload: AnalyticsMutationConsentChanged): Promise<Result<AnalyticsEventResult>>;
|
|
60
|
+
newsletterSubscribed(payload: AnalyticsMutationNewsletterSubscribed): Promise<Result<AnalyticsEventResult>>;
|
|
61
|
+
wishlistItemAdded(payload: AnalyticsMutationWishlistItemAdded): Promise<Result<AnalyticsEventResult>>;
|
|
62
|
+
wishlistItemRemoved(payload: AnalyticsMutationWishlistItemRemoved): Promise<Result<AnalyticsEventResult>>;
|
|
63
|
+
backInStockRequested(payload: AnalyticsMutationBackInStockRequested): Promise<Result<AnalyticsEventResult>>;
|
|
64
|
+
reviewSubmitted(payload: AnalyticsMutationReviewSubmitted): Promise<Result<AnalyticsEventResult>>;
|
|
65
|
+
storeSelected(payload: AnalyticsMutationStoreSelected): Promise<Result<AnalyticsEventResult>>;
|
|
66
|
+
productShared(payload: AnalyticsMutationProductShared): Promise<Result<AnalyticsEventResult>>;
|
|
67
|
+
custom(payload: AnalyticsMutationCustom): Promise<Result<AnalyticsEventResult>>;
|
|
21
68
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AnalyticsContext } from '../analytics/context.js';
|
|
2
|
+
import type { AnalyticsSubscriber } from '../analytics/dispatcher.js';
|
|
3
|
+
import type { AnalyticsEvent, AnalyticsEventType, AnalyticsOutcome, AnalyticsPurpose } from '../schemas/index.js';
|
|
4
|
+
import { BaseCapability } from './base.capability.js';
|
|
5
|
+
/**
|
|
6
|
+
* Base class for vendor analytics integrations (Unomi, Algolia, Google Analytics, ...).
|
|
7
|
+
*
|
|
8
|
+
* Providers are not called by the storefront. The `ClientBuilder` registers them as subscribers of the client's
|
|
9
|
+
* per-request dispatcher, which hands them events together with a read-only {@link AnalyticsContext} to enrich from.
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class AnalyticsProvider extends BaseCapability implements AnalyticsSubscriber {
|
|
12
|
+
/** Unique within a client. Used in logs and tracing. Defaults to the resource name. */
|
|
13
|
+
get name(): string;
|
|
14
|
+
/** Event types handled: exact types, prefix wildcards such as `cart-*`, or `*`. */
|
|
15
|
+
abstract readonly types: ReadonlyArray<AnalyticsEventType | `${string}*`>;
|
|
16
|
+
/** What the provider uses events for. The dispatcher skips providers whose purpose lacks consent. */
|
|
17
|
+
abstract readonly purpose: AnalyticsPurpose;
|
|
18
|
+
/**
|
|
19
|
+
* Handles one event. Throwing is safe: the dispatcher isolates failures per provider.
|
|
20
|
+
* Degrade by sending fewer fields when a lookup on `ctx` fails; do not drop the event for that.
|
|
21
|
+
*/
|
|
22
|
+
abstract handle(event: AnalyticsEvent, ctx: AnalyticsContext): Promise<AnalyticsOutcome | void>;
|
|
23
|
+
protected getResourceName(): string;
|
|
24
|
+
}
|
|
@@ -1,25 +1,48 @@
|
|
|
1
1
|
import type { Cache } from '../cache/cache.interface.js';
|
|
2
2
|
import type { Client } from './client.js';
|
|
3
|
+
import type { AnalyticsProvider } from '../capabilities/analytics.provider.js';
|
|
4
|
+
import { type AnalyticsSubscriber } from '../analytics/dispatcher.js';
|
|
5
|
+
import type { AnalyticsDispatchOptions } from '../schemas/models/analytics/dispatch.model.js';
|
|
3
6
|
import { type RequestContext } from '../schemas/session.schema.js';
|
|
4
7
|
export interface ClientBuilderFactoryArgs {
|
|
5
8
|
cache: Cache;
|
|
6
9
|
context: RequestContext;
|
|
7
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* What capability factories return: the client's capabilities, except `analytics`, which is a vendor
|
|
13
|
+
* {@link AnalyticsProvider} the builder registers as a subscriber. `client.analytics` itself is always built by the builder.
|
|
14
|
+
*/
|
|
15
|
+
export type ClientCapabilities = Omit<Partial<Client>, 'analytics'> & {
|
|
16
|
+
analytics?: AnalyticsProvider;
|
|
17
|
+
};
|
|
8
18
|
export type CapabilityFactory<T> = ((cache: Cache, context: RequestContext) => T) | ((args: ClientBuilderFactoryArgs) => T);
|
|
9
|
-
type MergeCapabilities<Acc, New> = Omit<Acc, keyof New> & New
|
|
19
|
+
type MergeCapabilities<Acc, New> = Omit<Acc, keyof New | 'analytics'> & Omit<New, 'analytics'> & Pick<Acc, Extract<'analytics', keyof Acc>>;
|
|
10
20
|
export type CapabilityCollisionStrategy = 'last-wins' | 'first-wins' | 'throw';
|
|
11
21
|
export declare class ClientBuilder<TClient = Client> {
|
|
12
22
|
private factories;
|
|
13
23
|
private cache;
|
|
14
24
|
private context;
|
|
15
25
|
private collisionStrategy;
|
|
26
|
+
private analyticsOptions;
|
|
27
|
+
private analyticsSubscribers;
|
|
16
28
|
constructor(context: RequestContext);
|
|
17
|
-
withCapability<TNew extends
|
|
29
|
+
withCapability<TNew extends ClientCapabilities>(factory: CapabilityFactory<TNew>): ClientBuilder<MergeCapabilities<TClient, TNew>>;
|
|
18
30
|
withCache(cache: Cache): ClientBuilder<TClient>;
|
|
19
31
|
withCollisionStrategy(strategy: CapabilityCollisionStrategy): ClientBuilder<TClient>;
|
|
32
|
+
/**
|
|
33
|
+
* Configures how analytics events are delivered, e.g. `{ waitUntil: after }` in Next.js so vendor calls finish after the
|
|
34
|
+
* response, or a `defaultConsent` for requests whose session carries no consent. Optional.
|
|
35
|
+
*/
|
|
36
|
+
withAnalyticsDispatch(options: AnalyticsDispatchOptions): ClientBuilder<TClient>;
|
|
37
|
+
/**
|
|
38
|
+
* Adds a custom analytics subscriber next to the providers registered by capability factories. Subscriptions are
|
|
39
|
+
* fixed at build time; there is no way to subscribe at runtime.
|
|
40
|
+
*/
|
|
41
|
+
withAnalyticsSubscriber(subscriber: AnalyticsSubscriber): ClientBuilder<TClient>;
|
|
20
42
|
build(): TClient & {
|
|
21
43
|
cache: Cache;
|
|
22
44
|
};
|
|
45
|
+
private clone;
|
|
23
46
|
private resolveFactory;
|
|
24
47
|
private mergeCapabilities;
|
|
25
48
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './client/index.js';
|
|
|
3
3
|
export * from './decorators/index.js';
|
|
4
4
|
export * from './factories/index.js';
|
|
5
5
|
export * from './capabilities/index.js';
|
|
6
|
+
export * from './analytics/index.js';
|
|
6
7
|
export * from './schemas/index.js';
|
|
7
8
|
export * from './initialization.js';
|
|
8
9
|
export * from './metrics/protocol.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
2
|
import type { InferType } from '../zod-utils.js';
|
|
3
3
|
import type { Client } from '../client/client.js';
|
|
4
|
+
import type { AnalyticsProvider } from '../capabilities/analytics.provider.js';
|
|
4
5
|
export declare const CapabilitiesSchema: z.ZodObject<{
|
|
5
6
|
product: z.ZodBoolean;
|
|
6
7
|
productSearch: z.ZodBoolean;
|
|
@@ -24,6 +25,12 @@ export declare const CapabilitiesSchema: z.ZodObject<{
|
|
|
24
25
|
company: z.ZodBoolean;
|
|
25
26
|
}, z.core.$loose>;
|
|
26
27
|
export type Capabilities = InferType<typeof CapabilitiesSchema>;
|
|
28
|
+
/**
|
|
29
|
+
* What a factory provides for a capability key. For `analytics` that is a vendor provider; `client.analytics`
|
|
30
|
+
* itself is the storefront-facing capability the builder creates.
|
|
31
|
+
*/
|
|
32
|
+
type ProvidedCapability<K extends keyof Client> = K extends 'analytics' ? AnalyticsProvider : Client[K];
|
|
27
33
|
export type ClientFromCapabilities<C extends Partial<Capabilities>> = {
|
|
28
|
-
[K in keyof C & keyof Client as C[K] extends true ? K : never]:
|
|
34
|
+
[K in keyof C & keyof Client as C[K] extends true ? K : never]: ProvidedCapability<K>;
|
|
29
35
|
};
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import type { InferType } from '../../../zod-utils.js';
|
|
3
|
+
export declare const AnalyticsPurposeSchema: z.ZodEnum<{
|
|
4
|
+
necessary: "necessary";
|
|
5
|
+
analytics: "analytics";
|
|
6
|
+
marketing: "marketing";
|
|
7
|
+
}>;
|
|
8
|
+
export declare const AnalyticsConsentSchema: z.ZodObject<{
|
|
9
|
+
analytics: z.ZodBoolean;
|
|
10
|
+
marketing: z.ZodBoolean;
|
|
11
|
+
}, z.core.$loose>;
|
|
12
|
+
export type AnalyticsPurpose = InferType<typeof AnalyticsPurposeSchema>;
|
|
13
|
+
export type AnalyticsConsent = InferType<typeof AnalyticsConsentSchema>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import type { InferType } from '../../../zod-utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* Keeps work alive after the response has been sent, e.g. Next's `after`.
|
|
5
|
+
*/
|
|
6
|
+
export type AnalyticsWaitUntil = (promise: Promise<unknown>) => void;
|
|
7
|
+
/**
|
|
8
|
+
* The declarative part of an analytics subscriber. `handle` is a member of the subscriber itself.
|
|
9
|
+
*/
|
|
10
|
+
export declare const AnalyticsSubscriberDescriptorSchema: z.ZodObject<{
|
|
11
|
+
name: z.ZodString;
|
|
12
|
+
types: z.ZodArray<z.ZodString>;
|
|
13
|
+
purpose: z.ZodEnum<{
|
|
14
|
+
necessary: "necessary";
|
|
15
|
+
analytics: "analytics";
|
|
16
|
+
marketing: "marketing";
|
|
17
|
+
}>;
|
|
18
|
+
}, z.core.$loose>;
|
|
19
|
+
export declare const AnalyticsDispatchOptionsSchema: z.ZodObject<{
|
|
20
|
+
waitUntil: z.ZodOptional<z.ZodCustom<AnalyticsWaitUntil, AnalyticsWaitUntil>>;
|
|
21
|
+
defaultConsent: z.ZodOptional<z.ZodObject<{
|
|
22
|
+
analytics: z.ZodBoolean;
|
|
23
|
+
marketing: z.ZodBoolean;
|
|
24
|
+
}, z.core.$loose>>;
|
|
25
|
+
}, z.core.$loose>;
|
|
26
|
+
export type AnalyticsSubscriberDescriptor = InferType<typeof AnalyticsSubscriberDescriptorSchema>;
|
|
27
|
+
export type AnalyticsDispatchOptions = Omit<InferType<typeof AnalyticsDispatchOptionsSchema>, 'waitUntil'> & {
|
|
28
|
+
waitUntil?: AnalyticsWaitUntil;
|
|
29
|
+
};
|