Skip to content

Commit

Permalink
feat(core): Expand the range of events published by the EventBus (#1222)
Browse files Browse the repository at this point in the history
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 <kevin@fainin.com>
  • Loading branch information
Draykee and Kevin authored Nov 23, 2021
1 parent 2cb9765 commit edc9d69
Show file tree
Hide file tree
Showing 58 changed files with 1,100 additions and 82 deletions.
17 changes: 17 additions & 0 deletions packages/core/src/event-bus/events/account-verified-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { RequestContext } from '../../api/common/request-context';
import { Customer } from '../../entity/customer/customer.entity';
import { VendureEvent } from '../vendure-event';

/**
* @description
* This event is fired when a users email address successfully gets verified after
* the `verifyCustomerAccount` mutation was executed.
*
* @docsCategory events
* @docsPage Event Types
*/
export class AccountVerifiedEvent extends VendureEvent {
constructor(public ctx: RequestContext, public customer: Customer) {
super();
}
}
27 changes: 27 additions & 0 deletions packages/core/src/event-bus/events/administrator-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CreateAdministratorInput, UpdateAdministratorInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Administrator } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type AdministratorInputTypes = CreateAdministratorInput | UpdateAdministratorInput | ID;

/**
* @description
* This event is fired whenever a {@link Administrator} is added, updated or deleted.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class AdministratorEvent extends VendureEntityEvent<Administrator, AdministratorInputTypes> {
constructor(
ctx: RequestContext,
entity: Administrator,
type: 'created' | 'updated' | 'deleted',
input: AdministratorInputTypes,
) {
super(entity, type, ctx, input);
}
}
34 changes: 25 additions & 9 deletions packages/core/src/event-bus/events/asset-event.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
import { RequestContext } from '../../api/common/request-context';
import { CreateAssetInput, DeleteAssetInput, UpdateAssetInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Asset } from '../../entity';
import { VendureEvent } from '../vendure-event';
import { VendureEntityEvent } from '../vendure-entity-event';

type AssetInputTypes = CreateAssetInput | UpdateAssetInput | DeleteAssetInput | ID;

/**
* @description
* This event is fired whenever aa {@link Asset} is added, updated
* or deleted.
* This event is fired whenever a {@link Asset} is added, updated or deleted.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class AssetEvent extends VendureEvent {
export class AssetEvent extends VendureEntityEvent<Asset, AssetInputTypes> {
constructor(
public ctx: RequestContext,
public asset: Asset,
public type: 'created' | 'updated' | 'deleted',
ctx: RequestContext,
entity: Asset,
type: 'created' | 'updated' | 'deleted',
input: AssetInputTypes,
) {
super();
super(entity, type, ctx, input);
}

/**
* Return an asset field to become compatible with the
* deprecated old version of AssetEvent
* @deprecated Use `entity` instead
* @since 1.4
*/
get asset(): Asset {
return this.entity;
}
}
27 changes: 27 additions & 0 deletions packages/core/src/event-bus/events/change-channel-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ID, Type } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { ChannelAware } from '../../common';
import { VendureEntity } from '../../entity';
import { VendureEvent } from '../vendure-event';

/**
* @description
* This event is fired whenever an {@link ChannelAware} entity is assigned or removed
* from a channel. The entity property contains the value before updating the channels.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class ChangeChannelEvent<T extends ChannelAware & VendureEntity> extends VendureEvent {
constructor(
public ctx: RequestContext,
public entity: T,
public channelIds: ID[],
public type: 'assigned' | 'removed',
public entityType?: Type<T>,
) {
super();
}
}
27 changes: 27 additions & 0 deletions packages/core/src/event-bus/events/channel-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CreateChannelInput, UpdateChannelInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Channel } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type ChannelInputTypes = CreateChannelInput | UpdateChannelInput | ID;

/**
* @description
* This event is fired whenever a {@link Channel} is added, updated or deleted.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class ChannelEvent extends VendureEntityEvent<Channel, ChannelInputTypes> {
constructor(
ctx: RequestContext,
entity: Channel,
type: 'created' | 'updated' | 'deleted',
input: ChannelInputTypes,
) {
super(entity, type, ctx, input);
}
}
27 changes: 27 additions & 0 deletions packages/core/src/event-bus/events/collection-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CreateCollectionInput, UpdateCollectionInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Collection } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type CollectionInputTypes = CreateCollectionInput | UpdateCollectionInput | ID;

/**
* @description
* This event is fired whenever a {@link Collection} is added, updated or deleted.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class CollectionEvent extends VendureEntityEvent<Collection, CollectionInputTypes> {
constructor(
ctx: RequestContext,
entity: Collection,
type: 'created' | 'updated' | 'deleted',
input: CollectionInputTypes,
) {
super(entity, type, ctx, input);
}
}
27 changes: 27 additions & 0 deletions packages/core/src/event-bus/events/country-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CreateCountryInput, UpdateCountryInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Country } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type CountryInputTypes = CreateCountryInput | UpdateCountryInput | ID;

/**
* @description
* This event is fired whenever a {@link Country} is added, updated or deleted.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class CountryEvent extends VendureEntityEvent<Country, CountryInputTypes> {
constructor(
ctx: RequestContext,
entity: Country,
type: 'created' | 'updated' | 'deleted',
input: CountryInputTypes,
) {
super(entity, type, ctx, input);
}
}
24 changes: 24 additions & 0 deletions packages/core/src/event-bus/events/coupon-code-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api/common/request-context';
import { VendureEvent } from '../vendure-event';

/**
* @description
* This event is fired whenever an coupon code of an active {@link Promotion}
* is assigned or removed to an {@link Order}.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class CouponCodeEvent extends VendureEvent {
constructor(
public ctx: RequestContext,
public couponCode: string,
public orderId: ID,
public type: 'assigned' | 'removed',
) {
super();
}
}
31 changes: 25 additions & 6 deletions packages/core/src/event-bus/events/customer-address-event.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
import { RequestContext } from '../../api/common/request-context';
import { CreateAddressInput, UpdateAddressInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { Address } from '../../entity/address/address.entity';
import { VendureEvent } from '../vendure-event';
import { VendureEntityEvent } from '../vendure-entity-event';

/**
* Possible input types for Address mutations
*/
type CustomerAddressInputTypes = CreateAddressInput | UpdateAddressInput | ID;

/**
* @description
* This event is fired whenever a {@link Customer} is added, updated
* This event is fired whenever a {@link Address} is added, updated
* or deleted.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class CustomerAddressEvent extends VendureEvent {
export class CustomerAddressEvent extends VendureEntityEvent<Address, CustomerAddressInputTypes> {
constructor(
public ctx: RequestContext,
public address: Address,
public entity: Address,
public type: 'created' | 'updated' | 'deleted',
public input: CustomerAddressInputTypes,
) {
super();
super(entity, type, ctx, input);
}

/**
* Return an address field to become compatible with the
* deprecated old version of CustomerAddressEvent
* @deprecated Use `entity` instead
*/
get address(): Address {
return this.entity;
}
}
32 changes: 26 additions & 6 deletions packages/core/src/event-bus/events/customer-event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { CreateCustomerInput, UpdateCustomerInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api/common/request-context';
import { Customer } from '../../entity/customer/customer.entity';
import { VendureEvent } from '../vendure-event';
import { VendureEntityEvent } from '../vendure-entity-event';

type CustomerInputTypes =
| CreateCustomerInput
| UpdateCustomerInput
| (Partial<CreateCustomerInput> & { emailAddress: string })
| ID;

/**
* @description
Expand All @@ -10,12 +19,23 @@ import { VendureEvent } from '../vendure-event';
* @docsCategory events
* @docsPage Event Types
*/
export class CustomerEvent extends VendureEvent {
export class CustomerEvent extends VendureEntityEvent<Customer, CustomerInputTypes> {
constructor(
public ctx: RequestContext,
public customer: Customer,
public type: 'created' | 'updated' | 'deleted',
ctx: RequestContext,
entity: Customer,
type: 'created' | 'updated' | 'deleted',
input: CustomerInputTypes,
) {
super();
super(entity, type, ctx, input);
}

/**
* Return an customer field to become compatible with the
* deprecated old version of CustomerEvent
* @deprecated Use `entity` instead
* @since 1.4
*/
get customer(): Customer {
return this.entity;
}
}
29 changes: 29 additions & 0 deletions packages/core/src/event-bus/events/customer-group-entity-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { CreateCustomerGroupInput, UpdateCustomerGroupInput } from '@vendure/common/lib/generated-types';
import { ID } from '@vendure/common/lib/shared-types';

import { RequestContext } from '../../api';
import { CustomerGroup } from '../../entity';
import { VendureEntityEvent } from '../vendure-entity-event';

type CustomerGroupInputTypes = CreateCustomerGroupInput | UpdateCustomerGroupInput | ID;

/**
* @description
* This event is fired whenever a {@link CustomerGroup} is added, updated or deleted.
* Use this event instead of {@link CustomerGroupEvent} until the next major version!
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class CustomerGroupEntityEvent extends VendureEntityEvent<CustomerGroup, CustomerGroupInputTypes> {
// TODO: Rename to CustomerGroupEvent in v2
constructor(
ctx: RequestContext,
entity: CustomerGroup,
type: 'created' | 'updated' | 'deleted',
input: CustomerGroupInputTypes,
) {
super(entity, type, ctx, input);
}
}
21 changes: 21 additions & 0 deletions packages/core/src/event-bus/events/customer-group-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { VendureEvent } from '../vendure-event';
*
* @docsCategory events
* @docsPage Event Types
* @deprecated Use {@link CustomerGroupChangeEvent} instead
*/
export class CustomerGroupEvent extends VendureEvent {
constructor(
Expand All @@ -21,3 +22,23 @@ export class CustomerGroupEvent extends VendureEvent {
super();
}
}

/**
* @description
* This event is fired whenever one or more {@link Customer} is assigned to or removed from a
* {@link CustomerGroup}.
*
* @docsCategory events
* @docsPage Event Types
* @since 1.4
*/
export class CustomerGroupChangeEvent extends VendureEvent {
constructor(
public ctx: RequestContext,
public customers: Customer[],
public customGroup: CustomerGroup,
public type: 'assigned' | 'removed',
) {
super();
}
}
Loading

0 comments on commit edc9d69

Please sign in to comment.