-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Expand the range of events published by the EventBus (#1222)
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
Showing
58 changed files
with
1,100 additions
and
82 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/core/src/event-bus/events/account-verified-event.ts
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 |
---|---|---|
@@ -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(); | ||
} | ||
} |
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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 |
---|---|---|
@@ -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
27
packages/core/src/event-bus/events/change-channel-event.ts
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 |
---|---|---|
@@ -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(); | ||
} | ||
} |
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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 |
---|---|---|
@@ -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
31
packages/core/src/event-bus/events/customer-address-event.ts
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 |
---|---|---|
@@ -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; | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
packages/core/src/event-bus/events/customer-group-entity-event.ts
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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
Oops, something went wrong.