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 4 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
95 changes: 66 additions & 29 deletions src/classes/VendorCommunicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,68 @@ export enum VendorEvent {
ContactDesigner = 'ContactDesigner',
DirtyStateChanged = 'DirtyStateChanged',
iFrameLoaded = 'iFrameLoaded',
iFrameRedirect = 'iFrameRedirect',
ProjectDeleted = 'ProjectDeleted',
ProjectSaved = 'ProjectSaved',
TrackingEvent = 'TrackingEvent',
TokenRefreshRequested = 'TokenRefreshRequested',
UnauthorizedToken = 'UnauthorizedToken',
}

interface Metadata {
source?: string;
interface CommonPayload {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@NothingButThyme I took a pass at creating general/common interfaces that are extended for specific events. This commit is a proposal for us to discuss, not intended to unilaterally override the commit you pushed up (didn't think a whole separate PR for it was warranted). Thoughts appreciated!

The main point to get across here is the requirement for token and customerId be included in the majority of event payloads (excluding non-customer-centric events like tracking) so we can validate the token and make sure it's intended for the right customer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The changes look good. I don't have any objections.

I am curious what future-proofing is being accomplished by CommonMedata vs CabinetsMetadata, because 'source' and 'area' seem like they would apply to other things besides cabinets.

message?: string;
token: string;
customerId: string;
}

interface CommonMetadata {
title: string;
brand: string;
style: string;
color: string;
thumbnailUrl: string;
price: number;
retailPrice?: number;
thumbnailUrl?: string;
[key: string]: string | number | undefined;
}

interface CabinetsMetadata extends CommonMetadata {
source?: string;
area?: number;
price?: number;
}

interface EventPayload {
interface SnapshotPayload<M extends CommonMetadata> extends CommonPayload {
schema: string;
token: string;
customerId: string;
projectId: string;
versionId: string;
metadata: Metadata;
bom?: any;
metadata: M;
bom: string;
}

interface ProjectSavedPayload extends CommonPayload {
projectId: string;
versionId?: string;
}

interface ProjectDeletedPayload extends CommonPayload {
projectId: string;
}

interface TrackingEvent {
interface DirtyStateChangedPayload extends CommonPayload {
projectId: string;
isDirty: boolean;
}

interface iFrameRedirectPayload extends CommonPayload {
app: string;
key: string;
}

interface TokenRefreshRequestedPayload extends CommonPayload {
requestId: string;
}

interface TrackingEventPayload {
actionName: string;
actionData: Record<string, unknown>;
}
Expand All @@ -46,43 +79,47 @@ export class VendorCommunicator extends Communicator {
this.origin = origin;
}

addToCart(payload: EventPayload): void {
this.post({type: VendorEvent.AddToCart, payload});
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

}

appInitialized(): void {
this.post({type: VendorEvent.AddToCart});
addToCart(payload: SnapshotPayload<CabinetsMetadata>): void {
this.post({type: VendorEvent.AddToCart, payload});
}

contactDesigner(payload: EventPayload): void {
contactDesigner(payload: SnapshotPayload<CabinetsMetadata>): void {
this.post({type: VendorEvent.ContactDesigner, payload});
}

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

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

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

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

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

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

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

unauthorizedToken(error: string): void {
this.post({type: VendorEvent.UnauthorizedToken, payload: error});
trackEvent(payload: TrackingEventPayload): void {
this.post({type: VendorEvent.TrackingEvent, payload});
}
}