Skip to content

Commit

Permalink
Validation events (#285)
Browse files Browse the repository at this point in the history
* Add validation event types

* fix log message

* Bump minor version

* Fix linter
  • Loading branch information
JoshuaSchmidt-OpenSea authored May 31, 2023
1 parent 6e85077 commit faeda9a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ A Javascript SDK for receiving updates from the OpenSea Stream API - pushed over
- item received offer
- item received bid

Thise types are currently be expiremented with and for now are released on a small number of collections:

- order_invalidate
- order_revalidate

This is a best effort delivery messaging system. Messages that are not received due to connection errors will not be re-sent. Messages may be delievered out of order. This SDK is offered as a beta experience as we work with developers in the ecosystem to make this a more robust and reliable system.

# Installation
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opensea/stream-js",
"version": "0.0.26",
"version": "0.1.0",
"description": "An SDK to receive pushed updates from OpenSea over websocket",
"license": "MIT",
"author": "OpenSea Developers",
Expand Down
23 changes: 22 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
Callback,
LogLevel,
Network,
OnClientEvent
OnClientEvent,
OrderValidationEvent
} from './types';
import { ENDPOINTS } from './constants';

Expand Down Expand Up @@ -208,6 +209,26 @@ export class OpenSeaStreamClient {
return this.on(EventType.TRAIT_OFFER, collectionSlug, callback);
};

public onOrderInvalidate = (
collectionSlug: string,
callback: Callback<OrderValidationEvent>
) => {
this.debug(
`Listening for order invalidation events on "${collectionSlug}"`
);
return this.on(EventType.ORDER_INVALIDATE, collectionSlug, callback);
};

public onOrderRevalidate = (
collectionSlug: string,
callback: Callback<OrderValidationEvent>
) => {
this.debug(
`Listening for order revalidation events on "${collectionSlug}"`
);
return this.on(EventType.ORDER_REVALIDATE, collectionSlug, callback);
};

public onEvents = (
collectionSlug: string,
eventTypes: EventType[],
Expand Down
19 changes: 18 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export enum EventType {
ITEM_RECEIVED_BID = 'item_received_bid',
ITEM_CANCELLED = 'item_cancelled',
COLLECTION_OFFER = 'collection_offer',
TRAIT_OFFER = 'trait_offer'
TRAIT_OFFER = 'trait_offer',
ORDER_INVALIDATE = 'order_invalidate',
ORDER_REVALIDATE = 'order_revalidate'
}

interface BaseItemMetadataType {
Expand Down Expand Up @@ -236,6 +238,21 @@ export interface TraitOfferEventPayload extends Payload {

export type TraitOfferEvent = BaseStreamMessage<TraitOfferEventPayload>;

export interface OrderValidationEventPayload {
event_timestamp: string;
order_hash: string;
protocol_address: string;
chain: {
name: string;
};
collection: {
slug: string;
};
}

export type OrderValidationEvent =
BaseStreamMessage<OrderValidationEventPayload>;

export type Callback<Event> = (event: Event) => unknown;

export enum LogLevel {
Expand Down

0 comments on commit faeda9a

Please sign in to comment.