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

Update event payloads #14

Merged
merged 9 commits into from
Jan 4, 2023
Merged
Changes from 3 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
89 changes: 72 additions & 17 deletions src/classes/VendorCommunicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ export enum VendorEvent {
ContactDesigner = 'ContactDesigner',
DirtyStateChanged = 'DirtyStateChanged',
iFrameLoaded = 'iFrameLoaded',
iFrameRedirect = 'iFrameRedirect',
ProjectDeleted = 'ProjectDeleted',
ProjectSaved = 'ProjectSaved',
TrackingEvent = 'TrackingEvent',
TokenRefreshRequested = 'TokenRefreshRequested',
UnauthorizedToken = 'UnauthorizedToken',
}

interface Metadata {
interface AddToCartMetadata {
source?: string;
title: string;
brand: string;
Expand All @@ -22,15 +23,36 @@ interface Metadata {
thumbnailUrl: string;
area?: number;
price?: number;
retailPrice?: number;
}

interface EventPayload {
interface AddToCartPayload {
schema: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add message to the EventPayload interface since you are sending it.

token: string;
customerId: string;
projectId: string;
versionId: string;
metadata: Metadata;
metadata: AddToCartMetadata;
bom?: any;
}

interface DesignerMetadata {
source?: string;
title: string;
brand: string;
style: string;
color: string;
thumbnailUrl: string;
area?: number;
}

interface ConsultDesignerPayload {
schema: string;
token: string;
customerId: string;
projectId: string;
versionId: string;
metadata: ConsultDesignerMetadata;
bom?: any;
}

Expand All @@ -39,47 +61,80 @@ interface TrackingEvent {
actionData: Record<string, unknown>;
}

interface ProjectSavedPayload {
message: string;
customerId: string;
projectId: string;
versionId: string;
}

interface ProjectDeletedPayload {
message: string;
customerId: string;
projectId: string;
}

interface DirtyStateChangedPayload {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add projectId

message: string;
isDirty: boolean;
}

interface iFrameRedirectPayload {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to generalize this into a navigation event?

  • One event for when the iframe re-initialized
  • One for internal navigation to update the url

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a small preference to keep them separate, because we want to see a clear difference between an "application exit" event and a navigation tracking event. It's just a convenience on our side for developers to be able to see when an event is expected to trigger a redirect.

message: string;
app: string;
key: string;
}

interface TokenRefreshRequestedPayload {
message: string;
requestId: string;
}

export class VendorCommunicator extends Communicator {
constructor(origin: string) {
super(origin);
this.target = window.parent;
this.origin = origin;
}

addToCart(payload: EventPayload): void {
addToCart(payload: AddToCartPayload): void {
this.post({type: VendorEvent.AddToCart, payload});
}

appInitialized(): void {
this.post({type: VendorEvent.AddToCart});
appInitialized(message: string): void {
this.post({type: VendorEvent.AddToCart, payload: message});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed this should be type: VendorEvent.AppInitialized

}

contactDesigner(payload: EventPayload): void {
contactDesigner(payload: ConsultDesignerPayload): void {
this.post({type: VendorEvent.ContactDesigner, payload});
}

dirtyStateChanged(): void {
this.post({type: VendorEvent.DirtyStateChanged});
dirtyStateChanged(payload: DirtyStateChangedPayload): void {
this.post({type: VendorEvent.DirtyStateChanged, payload});
}

iframeLoaded(): void {
this.post({type: VendorEvent.iFrameLoaded});
iframeLoaded(message: string): void {
this.post({type: VendorEvent.iFrameLoaded, payload: message});
}

iframeRedirect(payload: iFrameRedirectPayload): void {
this.post({type: VendorEvent.iFrameRedirect, payload});
}

projectSaved(): void {
this.post({type: VendorEvent.ProjectSaved});
projectSaved(payload: ProjectSavedPayload): void {
this.post({type: VendorEvent.ProjectSaved, payload});
}

projectDeleted(): void {
this.post({type: VendorEvent.ProjectDeleted});
projectDeleted(payload: ProjectDeletedPayload): void {
this.post({type: VendorEvent.ProjectDeleted, payload});
}

trackEvent(payload: TrackingEvent): void {
this.post({type: VendorEvent.TrackingEvent, payload});
}

tokenRefreshRequested(): void {
this.post({type: VendorEvent.TokenRefreshRequested});
tokenRefreshRequested(payload: TokenRefreshRequestedPayload): void {
this.post({type: VendorEvent.TokenRefreshRequested, payload});
}

unauthorizedToken(error: string): void {
Expand Down