generated from wayfair-incubator/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
593a17f
Update VendorCommunicator.ts
NothingButThyme 85becf0
Update VendorCommunicator.ts
NothingButThyme 29ad73e
Update VendorCommunicator.ts
NothingButThyme 56feb8b
Proposal for common payloads, extended payloads
712e2f5
fix type
ae01369
Merge branch 'main' into update_payloads
6d49acb
formatting
cadcea9
bump version to 5.0.0
f0d94ea
undo
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
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>; | ||
} | ||
|
@@ -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}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
andcustomerId
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.There was a problem hiding this comment.
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.