Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shop object to web pixel init data #1953

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,093 changes: 2,000 additions & 2,093 deletions packages/web-pixels-extension/src/schemas/pixel-events.ts

Large diffs are not rendered by default.

60 changes: 1 addition & 59 deletions packages/web-pixels-extension/src/types/EventBus.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
import type {PixelEvents, CustomEvent, EventType} from './PixelEvents';

export type SchemaVersion = 'v1';

export type PixelEventName = keyof PixelEvents;

type EventNameOfType<T extends EventType> = {
[K in PixelEventName]: PixelEvents[K] extends {type: T} ? K : never;
}[PixelEventName];

export type StandardEventName = EventNameOfType<EventType.Standard>;
export type StandardEvent = PixelEvents[StandardEventName];

export type DomEventName = EventNameOfType<EventType.Dom>;
export type DomEvent = PixelEvents[DomEventName];

export interface StandardEvents extends PixelEvents {
all_events: StandardEvent | CustomEvent | DomEvent;
all_standard_events: StandardEvent;
all_custom_events: CustomEvent;
all_dom_events: DomEvent;
}

export type DomEvents = {
[key in DomEventName]: PixelEvents[key];
};

export interface CustomEvents {
[key: string]: CustomEvent;
}

export type Events = StandardEvents & CustomEvents;

export type KeyOfEvent<T> = Extract<keyof T, string>;

export type PublisherData<P> = P extends {data: infer T} ? T : never;
export type PublisherCustomData<P> = P extends {customData: infer T}
? T
Expand All @@ -47,27 +12,4 @@ export interface PublisherOptions extends Record<string, unknown> {
}

export type SubscriberCallback<T> = (event: T) => void;
export type SubscriberOptions = Record<string, unknown>;

export interface EventBus {
publish<K extends StandardEventName>(
name: K,
payload: PublisherData<PixelEvents[K]>,
options?: PublisherOptions,
): boolean;
publishCustomEvent(
name: string,
payload?: PublisherCustomData<CustomEvent>,
options?: PublisherOptions,
): boolean;
publishDomEvent<K extends DomEventName>(
name: K,
payload: PublisherData<PixelEvents[K]>,
options?: PublisherOptions,
): boolean;
subscribe<K extends KeyOfEvent<Events>>(
name: K,
callback: SubscriberCallback<Events[K]>,
options?: SubscriberOptions,
): () => boolean;
}
export type SubscriberOptions = Record<string, any>;
4 changes: 2 additions & 2 deletions packages/web-pixels-extension/src/types/ExtensionApi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type {Browser} from './PixelEvents';
import type {EventBus} from './EventBus';
import type {WebPixelsManager} from './WebPixelsManager';
import type {RegisterInit} from './RegisterInit';

export interface ExtensionApi {
readonly settings: Record<string, any>;
readonly analytics: {
readonly subscribe: EventBus['subscribe'];
readonly subscribe: WebPixelsManager['subscribe'];
};
readonly browser: Browser;
readonly init: RegisterInit;
Expand Down
Loading
Loading