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

More Events for each entity #1219

Closed
Draykee opened this issue Nov 11, 2021 · 12 comments · Fixed by #1222
Closed

More Events for each entity #1219

Draykee opened this issue Nov 11, 2021 · 12 comments · Fixed by #1222

Comments

@Draykee
Copy link
Contributor

Draykee commented Nov 11, 2021

Is your feature request related to a problem? Please describe.
I would like to know when a user get's verified. Currently there is no event for this. Having more events can be extremly helpful for analyzing activities.

Describe the solution you'd like
A event for each entity and every special activity (like coupon code usage, promotions, etc.)
Maybe we should make a list first, but implementing it should be easy.

Describe alternatives you've considered
Overwriting each resolver. But that's a hughe overhead

@michaelbromley
Copy link
Member

Yes I totally agree. I've so far added events on a kinda ad-hoc basis, whenever I realized I needed one, I added it.

But now a more systematic approach makes sense, because there are infinite use-cases so we better just add all the events that could reasonably be needed. Do you want to have a go at making a list?

@Draykee
Copy link
Contributor Author

Draykee commented Nov 11, 2021

@michaelbromley somehow like this?

So at first I think we can generalize it to this:

class EntityEvent<T> extends VendureEvent {
  type: 'created' | 'updated' | 'deleted',
  entity: T;
  input?: any; //< maybe for update event it's nice to know what changed, or the create input to react on custom fields
}

I also had the idea to add a initiator: User property. This might be obsolet if we would just add the request context used.


Address
Example: Maybe a plugin that groups customer by locations

  • CustomerAddressEvent

Administrator
Example: Maybe to add notifications for more security

  • AdministratorEvent (EntityEvent<Administrator>)

Asset
Example: Maybe the creator is important for copyrights

  • AssetEvent (maybe also reword with EntityEvent and the initiator: User)

Channel
Example: For all marketplace plugins to create additional data for a newly generated channel

  • ChannelEvent (EntityEvent<Channel>, initiator: User)

Collection
Example: Maybe a plugin that auto disables a collection after some time, so we need to start a cronjob when created

  • CollectionEvent (EntityEvent<Collection>, initiator: User)
  • CollectionModificationEvent

Country
Example: - no clue -

  • CountryEvent (EntityEvent<Country>)

Customer

  • CustomerEvent

CustomerGroup

  • CustomerGroupEvent

Facet

  • FacetEvent (EntityEvent<Facet>, initiator: User)

FacetValue

  • FacetValueEvent (EntityEvent<FacetValue>, initiator: User)

Fulfillment

  • FulfillmentStateTransitionEvent
  • FulfillmentEvent (EntityEvent<Fulfillment>, initiator: User)

GlobalSettings

  • GlobalSettingsUpdateEvent (because this is not created/deleted)

HistoryEntry

  • HistoryEntryEvent (EntityEvent<HistoryEntry>, historyType: 'order' | 'customer' )
    @michaelbromley Is it possible to create more HistoryEntry types?

Order

  • OrderStateTransitionEvent (will also cover "created" and "cancel")
  • OrderActivity (One or multiple Event to track activities in the order entity without state transition)

OrderLine

  • OrderLineEvent (EntityEvent<OrderLine>)

OrderItem

  • OrderItemEvent (EntityEvent<OrderItem>)

Payment

  • PaymentEvent (EntityEvent<Payment>, initiator: User)
  • PaymentStateTransitionEvent

PaymentMethod
Example: Maybe it can be used to run some connection tests or something when a api key changed

  • PaymentMethodEvent (EntityEvent<PaymentMethod>, initiator: User)

Product

  • ProductEvent
  • ProductEvent
  • ProductChannelEvent
    ProductVariant
  • ProductVariantChannelEvent
  • ProductVariantEvent

Promotion

  • PromotionEvent (EntityEvent<Promotion>)

Refund

  • RefundStateTransitionEvent
  • RefundEvent (EntityEvent<Refund>)

Role

  • RoleEvent (EntityEvent<Role>, initiator: User)
  • RoleChangeEvent (type: 'assigned | removed like CustomerGroupEvent )

Session
I'm not sure about this one...

ShippingLine

  • ShippingLineEvent (EntityEvent<ShippingLine>, initiator: User)

ShippingMethod

  • ShippingMethodEvent (EntityEvent<ShippingMethod>, initiator: User)

StockMovement

  • StockMovementEvent

Surcharge

  • SurchargeEvent (EntityEvent<Surcharge>, initiator: User)

Tag
@michaelbromley I'm not sure how this work. Maybe a TagAssignedEvent?

TaxCategory

  • TaxCategoryEvent (EntityEvent<TaxCategory>, initiator: User)

TaxRate

  • TaxRateModificationEvent
  • TaxRateEvent (EntityEvent<TaxRate>, initiator: User)

User

  • LoginEvent
  • LogoutEvent
  • AttemptedLoginEvent
  • IdentifierChangeEvent
  • IdentifierChangeRequestEvent
  • PasswordResetEvent
  • VerifiedEvent (when email was verified)
  • UserUpdateEvent (I think create/delete doesn't need to be covered, but changes in customFields )
  • RequestPasswordResetEvent

Zone
Can we create own zones?

  • ZoneEvent (EntityEvent<Zone>, initiator: User)

@michaelbromley
Copy link
Member

Yes perfect, though I don't think we need to list examples.

@Draykee
Copy link
Contributor Author

Draykee commented Nov 12, 2021

I've updated the list. Maybe we can ask on slack if someone needs a special event. (We need a UserVerifiedEvent for example)

@Draykee
Copy link
Contributor Author

Draykee commented Nov 13, 2021

What do you think about this:

class VendureEntityEvent<T> extends VendureEvent {
  type: 'created' | 'updated' | 'deleted',
  entity: T;
  input?: any; // the mutation input used for the event
  initiator?: User; // the user that initiated the entity operation
}

Optional properties input and initiator:
PRO: More information on the context where/how the event was published
CON: It's only optional and maybe not always present

@michaelbromley
Copy link
Member

@Draykee yes this makes sense. We could deprecate the specific <entity type>Event events and replace them with this. For now we'd have to publish both, but remove the specific versions in v2.0.

Rather than the initiator field, why not include ctx, since it is possible to get the initiatior from that object using ctx.activeUserId already, plus RequestContext provides a whole bunch of other useful info, like which API & channel was being used etc.

@Draykee
Copy link
Contributor Author

Draykee commented Nov 15, 2021

@michaelbromley This feature is pretty urgent for my master thesis about gamification. So maybe I'll start working on this soon.

One more question, shall I place every event inside the events directory? Or inside the related entity directory?

@michaelbromley
Copy link
Member

Put any new events next to the existing ones in the "events" dir. If you want to work on this, make a PR against the minor branch and we can get this into the v1.4 release, which I expect to land in the next month-ish.

Draykee pushed a commit to Draykee/vendure that referenced this issue Nov 15, 2021
@Draykee
Copy link
Contributor Author

Draykee commented Nov 15, 2021

In an type: 'update' event, is it better to store the "before" entity or the "updated" entity? I think the "before" entity might be better, because the event subscriber can still get the new updated one from database but not the one before updating it. Furthermore the input property can be used to understand what changed.

EDIT: I saw that other events are using the "before" entity in the event too. I think I will go with this approach and document that.

@Draykee
Copy link
Contributor Author

Draykee commented Nov 15, 2021

Are ProductOptionGroups and ProductOptions never deleted? At least I couldn't find a function for that inside the services.

@Draykee
Copy link
Contributor Author

Draykee commented Nov 17, 2021

@michaelbromley I think I've covered most of the entity events now. I just would like to ask for assitance with the Order entity.
I don't really know what operations can be executed and which one are covered by the stage transition events.

@michaelbromley michaelbromley linked a pull request Nov 22, 2021 that will close this issue
michaelbromley pushed a commit that referenced this issue Nov 23, 2021
Relates to #1219 

* feat(core): Added Vendure entity event base class (#1219)

* feat(core): Implemented CustomerAddressEvent with new entity event base class (#1219)

* feat(core): Implemented AssetEvent with new entity event base class (#1219)

* fix: Removed illegal import from src

* feat(core): Added verified-event (#1219)

* feat(core): Added multiple events (#1219)

* feat(core): Added role-change and zone entity events (#1219)

* chore(core): Updated documentation of new events and added todo

Co-authored-by: Kevin <[email protected]>
@Draykee
Copy link
Contributor Author

Draykee commented Nov 23, 2021

Resolved with: #1222

@Draykee Draykee closed this as completed Nov 23, 2021
michaelbromley added a commit that referenced this issue Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants