Skip to content

Commit

Permalink
feat: change bid receive notification (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
Melisa Anabella Rossi authored Aug 5, 2024
1 parent 7ac893f commit ef293ea
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 82 deletions.
41 changes: 31 additions & 10 deletions report/schemas.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export type BaseBid = {
// @public (undocumented)
export type BaseEvent = {
type: Events.Type;
subType: Events.SubType.Blockchain | Events.SubType.CatalystDeployment | Events.SubType.Client;
subType: Events.SubType.Blockchain | Events.SubType.CatalystDeployment | Events.SubType.Client | Events.SubType.Marketplace;
key: string;
timestamp: number;
};
Expand Down Expand Up @@ -296,7 +296,7 @@ export namespace Bid {
export type BidAcceptedEvent = BaseEvent & {
type: Events.Type.BLOCKCHAIN;
subType: Events.SubType.Blockchain.BID_ACCEPTED;
metadata: BidMetadata;
metadata: BidEventMetadata;
};

// @public (undocumented)
Expand All @@ -307,6 +307,23 @@ export namespace BidAcceptedEvent {
validate: ValidateFunction<BidAcceptedEvent>;
}

// Warning: (ae-missing-release-tag) "BidEventMetadata" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type BidEventMetadata = {
address: string;
image: string;
seller: string;
category: string;
rarity?: string;
link: string;
nftName?: string;
price: string;
title: string;
description: string;
network: string;
};

// Warning: (ae-missing-release-tag) "BidFilters" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand All @@ -328,9 +345,9 @@ export type BidFilters = {
//
// @public (undocumented)
export type BidReceivedEvent = BaseEvent & {
type: Events.Type.BLOCKCHAIN;
subType: Events.SubType.Blockchain.BID_RECEIVED;
metadata: BidMetadata;
type: Events.Type.MARKETPLACE;
subType: Events.SubType.Marketplace.BID_RECEIVED;
metadata: BidEventMetadata;
};

// @public (undocumented)
Expand Down Expand Up @@ -953,8 +970,6 @@ export namespace Events {
// (undocumented)
BID_ACCEPTED = "bid-accepted",
// (undocumented)
BID_RECEIVED = "bid-received",
// (undocumented)
COLLECTION_CREATED = "collection-created",
// (undocumented)
ITEM_SOLD = "item-sold",
Expand Down Expand Up @@ -985,6 +1000,11 @@ export namespace Events {
// (undocumented)
MOVE_TO_PARCEL = "move-to-parcel"
}
// (undocumented)
export enum Marketplace {
// (undocumented)
BID_RECEIVED = "bid-received"
}
}
// (undocumented)
export enum Type {
Expand All @@ -993,7 +1013,9 @@ export namespace Events {
// (undocumented)
CATALYST_DEPLOYMENT = "catalyst-deployment",
// (undocumented)
CLIENT = "client"
CLIENT = "client",
// (undocumented)
MARKETPLACE = "marketplace"
}
}

Expand Down Expand Up @@ -3379,8 +3401,7 @@ export namespace WorldConfiguration {
// src/dapps/trade.ts:79:3 - (ae-incompatible-release-tags) The symbol "chainId" is marked as @public, but its signature references "ChainId" which is marked as @alpha
// src/dapps/trade.ts:90:3 - (ae-incompatible-release-tags) The symbol "network" is marked as @public, but its signature references "Network" which is marked as @alpha
// src/dapps/trade.ts:91:3 - (ae-incompatible-release-tags) The symbol "chainId" is marked as @public, but its signature references "ChainId" which is marked as @alpha
// src/platform/events/blockchain.ts:21:3 - (ae-forgotten-export) The symbol "BidMetadata" needs to be exported by the entry point index.d.ts
// src/platform/events/blockchain.ts:163:3 - (ae-forgotten-export) The symbol "RentalMetadata" needs to be exported by the entry point index.d.ts
// src/platform/events/blockchain.ts:124:3 - (ae-forgotten-export) The symbol "RentalMetadata" needs to be exported by the entry point index.d.ts
// src/platform/item/emote/adr74/emote-data-adr74.ts:7:3 - (ae-incompatible-release-tags) The symbol "representations" is marked as @public, but its signature references "EmoteRepresentationADR74" which is marked as @alpha
// src/platform/item/linked-wearable-mappings.ts:251:3 - (ae-incompatible-release-tags) The symbol "getMappings" is marked as @public, but its signature references "Mappings" which is marked as @alpha
// src/platform/item/linked-wearable-mappings.ts:252:3 - (ae-incompatible-release-tags) The symbol "addMapping" is marked as @public, but its signature references "ContractNetwork" which is marked as @alpha
Expand Down
16 changes: 12 additions & 4 deletions src/platform/events/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
BidAcceptedEvent,
BidReceivedEvent,
CollectionCreatedEvent,
ItemSoldEvent,
RentalEndedEvent,
Expand All @@ -9,25 +8,30 @@ import {
} from './blockchain'
import { CatalystDeploymentEvent } from './catalyst'
import { MoveToParcelEvent } from './client'
import { BidReceivedEvent } from './marketplace'

export namespace Events {
export enum Type {
BLOCKCHAIN = 'blockchain',
CATALYST_DEPLOYMENT = 'catalyst-deployment',
CLIENT = 'client'
CLIENT = 'client',
MARKETPLACE = 'marketplace'
}

export namespace SubType {
export enum Blockchain {
BID_ACCEPTED = 'bid-accepted',
BID_RECEIVED = 'bid-received',
ITEM_SOLD = 'item-sold',
RENTAL_ENDED = 'land-rental-ended',
RENTAL_STARTED = 'land-rental-started',
ROYALTIES_EARNED = 'royalties-earned',
COLLECTION_CREATED = 'collection-created'
}

export enum Marketplace {
BID_RECEIVED = 'bid-received'
}

export enum CatalystDeployment {
SCENE = 'scene',
PROFILE = 'profile',
Expand All @@ -45,7 +49,11 @@ export namespace Events {

export type BaseEvent = {
type: Events.Type
subType: Events.SubType.Blockchain | Events.SubType.CatalystDeployment | Events.SubType.Client
subType:
| Events.SubType.Blockchain
| Events.SubType.CatalystDeployment
| Events.SubType.Client
| Events.SubType.Marketplace
key: string
timestamp: number
}
Expand Down
43 changes: 2 additions & 41 deletions src/platform/events/blockchain.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { generateLazyValidator, JSONSchema, ValidateFunction } from '../../validation'
import { BaseEvent, Events } from './base'

type BidMetadata = {
export type BidEventMetadata = {
address: string
image: string
seller: string
Expand All @@ -18,7 +18,7 @@ type BidMetadata = {
export type BidAcceptedEvent = BaseEvent & {
type: Events.Type.BLOCKCHAIN
subType: Events.SubType.Blockchain.BID_ACCEPTED
metadata: BidMetadata
metadata: BidEventMetadata
}

export namespace BidAcceptedEvent {
Expand Down Expand Up @@ -54,45 +54,6 @@ export namespace BidAcceptedEvent {
export const validate: ValidateFunction<BidAcceptedEvent> = generateLazyValidator(schema)
}

export type BidReceivedEvent = BaseEvent & {
type: Events.Type.BLOCKCHAIN
subType: Events.SubType.Blockchain.BID_RECEIVED
metadata: BidMetadata
}

export namespace BidReceivedEvent {
export const schema: JSONSchema<BidReceivedEvent> = {
type: 'object',
properties: {
type: { type: 'string', const: Events.Type.BLOCKCHAIN },
subType: { type: 'string', const: Events.SubType.Blockchain.BID_RECEIVED },
key: { type: 'string' },
timestamp: { type: 'number', minimum: 0 },
metadata: {
type: 'object',
properties: {
address: { type: 'string' },
image: { type: 'string' },
seller: { type: 'string' },
category: { type: 'string' },
rarity: { type: 'string', nullable: true },
link: { type: 'string' },
nftName: { type: 'string', nullable: true },
price: { type: 'string' },
title: { type: 'string' },
description: { type: 'string' },
network: { type: 'string' }
},
required: ['address', 'image', 'seller', 'category', 'link', 'price', 'title', 'network']
}
},
required: ['type', 'subType', 'key', 'timestamp', 'metadata'],
additionalProperties: false
}

export const validate: ValidateFunction<BidReceivedEvent> = generateLazyValidator(schema)
}

export type ItemSoldEvent = BaseEvent & {
type: Events.Type.BLOCKCHAIN
subType: Events.SubType.Blockchain.ITEM_SOLD
Expand Down
1 change: 1 addition & 0 deletions src/platform/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './base'
export * from './blockchain'
export * from './catalyst'
export * from './client'
export * from './marketplace'
42 changes: 42 additions & 0 deletions src/platform/events/marketplace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { generateLazyValidator, JSONSchema, ValidateFunction } from '../../validation'
import { BaseEvent, Events } from './base'
import { BidEventMetadata } from './blockchain'

export type BidReceivedEvent = BaseEvent & {
type: Events.Type.MARKETPLACE
subType: Events.SubType.Marketplace.BID_RECEIVED
metadata: BidEventMetadata
}

export namespace BidReceivedEvent {
export const schema: JSONSchema<BidReceivedEvent> = {
type: 'object',
properties: {
type: { type: 'string', const: Events.Type.MARKETPLACE },
subType: { type: 'string', const: Events.SubType.Marketplace.BID_RECEIVED },
key: { type: 'string' },
timestamp: { type: 'number', minimum: 0 },
metadata: {
type: 'object',
properties: {
address: { type: 'string' },
image: { type: 'string' },
seller: { type: 'string' },
category: { type: 'string' },
rarity: { type: 'string', nullable: true },
link: { type: 'string' },
nftName: { type: 'string', nullable: true },
price: { type: 'string' },
title: { type: 'string' },
description: { type: 'string' },
network: { type: 'string' }
},
required: ['address', 'image', 'seller', 'category', 'link', 'price', 'title', 'network']
}
},
required: ['type', 'subType', 'key', 'timestamp', 'metadata'],
additionalProperties: false
}

export const validate: ValidateFunction<BidReceivedEvent> = generateLazyValidator(schema)
}
27 changes: 0 additions & 27 deletions test/platform/events/blockchain.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import expect from 'expect'
import {
BidAcceptedEvent,
BidReceivedEvent,
CollectionCreatedEvent,
Events,
ItemSoldEvent,
Expand Down Expand Up @@ -37,32 +36,6 @@ describe('Blockchain Events tests', () => {
expect(BidAcceptedEvent.validate({})).toEqual(false)
})

it('BidReceivedEvent static tests must pass', () => {
const event: BidReceivedEvent = {
type: Events.Type.BLOCKCHAIN,
subType: Events.SubType.Blockchain.BID_RECEIVED,
key: 'key',
timestamp: 1,
metadata: {
address: 'address',
image: 'image',
seller: 'seller',
category: 'category',
rarity: 'rarity',
link: 'link',
nftName: 'nftName',
price: '1',
title: 'title',
description: 'description',
network: 'network'
}
}

expect(BidReceivedEvent.validate(event)).toEqual(true)
expect(BidReceivedEvent.validate(null)).toEqual(false)
expect(BidReceivedEvent.validate({})).toEqual(false)
})

it('ItemSold static tests must pass', () => {
const event: ItemSoldEvent = {
type: Events.Type.BLOCKCHAIN,
Expand Down
30 changes: 30 additions & 0 deletions test/platform/events/marketplace.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import expect from 'expect'
import { BidReceivedEvent, Events } from '../../../src'

describe('Marketplace Events tests', () => {
it('BidReceivedEvent static tests must pass', () => {
const event: BidReceivedEvent = {
type: Events.Type.MARKETPLACE,
subType: Events.SubType.Marketplace.BID_RECEIVED,
key: 'key',
timestamp: 1,
metadata: {
address: 'address',
image: 'image',
seller: 'seller',
category: 'category',
rarity: 'rarity',
link: 'link',
nftName: 'nftName',
price: '1',
title: 'title',
description: 'description',
network: 'network'
}
}

expect(BidReceivedEvent.validate(event)).toEqual(true)
expect(BidReceivedEvent.validate(null)).toEqual(false)
expect(BidReceivedEvent.validate({})).toEqual(false)
})
})

0 comments on commit ef293ea

Please sign in to comment.