Skip to content

Commit

Permalink
Matej/pushed updates (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meemaw authored Mar 4, 2022
1 parent 3094e25 commit dab3472
Show file tree
Hide file tree
Showing 26 changed files with 15,992 additions and 6,077 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
lib
dist
15 changes: 0 additions & 15 deletions .eslintrc

This file was deleted.

18 changes: 18 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
env: {
browser: true,
node: true
},
root: true,
reportUnusedDisableDirectives: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended'
],
rules: {
'prettier/prettier': 2
}
};
18 changes: 12 additions & 6 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
## Change Overview

<!-- Describe the change clearly and succinctly, why it is needed, and what the result of the change will do -->

## Impact of Change

<!-- Check all that apply and add other impacts that might not be listed -->

- [ ] Bug fix
- [ ] External Facing (resolves an issue customers are currently experiencing)
- [ ] Security Impact (fixes a potential vulnerability)
- [ ] External Facing (resolves an issue customers are currently experiencing)
- [ ] Security Impact (fixes a potential vulnerability)
- [ ] Feature
- [ ] Visible Change (changes semver of API surface or other change that would impact user/dev experience)
- [ ] High Usage (impacts a major part of the core workflow for users)
- [ ] Visible Change (changes semver of API surface or other change that would impact user/dev experience)
- [ ] High Usage (impacts a major part of the core workflow for users)
- [ ] Performance Improvement
- [ ] Refactoring
- [ ] Other: *Describe here*
- [ ] Other: _Describe here_

## Detailed Technical Description of Change

<!-- Detail the technical approach and rationale for the change that you are working on. Are there are known limitations to the implementation or usage? -->

## Testing Approach and Results

<!-- Outline how you will test the change, provide rationale for whether unit / dev / system tests are needed (or why not), and post the evidence of your testing -->

## Collateral Work or Changes

<!-- Provide analysis of the overall impacts caused by your change. Does another system need to be updated to support the change? Does a configuration file need to be updated? etc -->

## Operational Impact
<!-- Are new metrics available with this change? Are they being logged? Do new dashboards or operational alerts need to be setup? -->

<!-- Are new metrics available with this change? Are they being logged? Do new dashboards or operational alerts need to be setup? -->
52 changes: 52 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: code-quality
on:
push:
branches:
- master
pull_request:

env:
CI: true

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.11.0'

- name: Install dependencies
run: npm ci
- name: Run linters
run: npm run lint:check

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.11.0'

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm run test -- --coverage --ci --runInBand

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.11.0'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules

dist
coverage

# Logs
Expand All @@ -18,4 +18,4 @@ yarn-error.log*
# Yarn Integrity file
.yarn-integrity

.nyc_output

4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn check-types
4 changes: 0 additions & 4 deletions .mocharc.json

This file was deleted.

8 changes: 0 additions & 8 deletions .nycrc.json

This file was deleted.

1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"files.insertFinalNewline": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
145 changes: 89 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,102 +1,135 @@
# OpenSea Push Client

A Javascript SDK for receiving updates from OpenSea pushed over websocket. We currently support the following event types for collections:
[![https://badges.frapsoft.com/os/mit/mit.svg?v=102](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://opensource.org/licenses/MIT)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

- item listed
- item sold
A Javascript SDK for receiving updates from OpenSea pushed over websocket. We currently support the following event types for collections:

- item listed
- item sold
- item transferred
- item metadata updates
- item metadata updates
- item cancelled

This is a best effort delievery messaging system. Messages that are not received due to connection errors will not be re-sent. Messages may be delievered out of order.
This is a best effort delievery messaging system. Messages that are not received due to connection errors will not be re-sent. Messages may be delievered out of order.

# Setup
# Setup

Run `nvm use`
And then `npm install`
And then `npm install`

# Getting Started

# Getting Started
For our beta test users we are only using basic authentication. To get started, request the basic authentication token and base endpoint from us. Later on we will align authentication with our API.

For our beta test users we are only using basic authentication. To get started, request the basic authentication token and base endpoint from us. Later on we will align authentication with our API.
## Create a client

## Start a socket connection
```javascript
import { OpenSeaPushClient } from 'opensea-push-client'
import { WebSocket } from 'ws';
```javascript
import { OpenSeaPushClient } from '@opensea/pushed-updates-sdk';

const client = new OpenSeaPushClient('dummy_token', {
const client = new OpenSeaPushClient({
apiUrl: 'apiURL',
socketOptions: {
transport: WebSocket
}
token: 'dummyToken'
});
```

After successfully connecting to our websocket it is time to listen to specific events you're interested in!
## Manually connecting to the socket (optional)

Client will automatically connect to the socket as soon as you subscribe to the first channel.
If you would like to connect to the socket manually (before that), you can do so:

```javascript
client.connect();
```

## Streaming metadata updates
After successfully connecting to our websocket it is time to listen to specific events you're interested in!

```javascript
client.subscribeItemMetadataUpdates('collection-slug', (myEvent) => {
// Your use case
console.log(myEvent);
## Streaming metadata updates

```javascript
client.onItemMetadataUpdated('collection-slug', (event) => {
// handle event
});
```

## Streaming item listed events
## Streaming item listed events

```javascript
client.subscribeItemListedEvents('collection-slug', (myEvent) => {
console.log(myEvent);
```javascript
client.onItemListed('collection-slug', (event) => {
// handle event
});
```

## Streaming item sold events
## Streaming item sold events

```javascript
client.subscribeItemSoldEvents('collection-slug', (myEvent) => {
console.log(myEvent);
```javascript
client.onItemSold('collection-slug', (event) => {
// handle event
});
```

## Streaming item transferred events
## Streaming item transferred events

```javascript
client.subscribeItemTransferredEvents('collection-slug', (myEvent) => {
console.log(myEvent);
```javascript
client.onItemTransferred('collection-slug', (event) => {
// handle event
});
```

## Streaming all item events
## Streaming bids and offers

```javascript
client.onItemReceivedBid('collection-slug', (event) => {
// handle event
});

```javascript
client.subscribeAllItemEvents('collection-slug', (myEvent) => {
console.log(myEvent);
client.onItemReceivedOffer('collection-slug', (event) => {
// handle event
});
```

## Streaming bids and offers
```javascript
client.subscribeItemReceivedBidEvents('collection-slug', (myEvent) => {
// do something
})
client.subscribeItemReceivedOfferEvents('collection-slug', (myEvent) => {
// do something
})
## Streaming multiple event types

```javascript
client.onEvents(
'collection-slug',
[EventType.ITEM_RECEIVED_OFFER, EventType.ITEM_TRANSFERRED],
(event) => {
// handle event
}
);
```

## Streaming auction cancellations events
```javascript
client.subscribeItemCancelledEvents('collection-slug', (myEvent) => {
// do something
})
## Streaming auction cancellations events

```javascript
client.onItemCancelled('collection-slug', (event) => {
// handle event
});
```

# Subscribing to events from all collections
# Subscribing to events from all collections

If you'd like to listen to an event from all collections use wildcard `*` for the `collectionSlug` parameter.

# Types

Types are included to work with our event payload objects easier.

If you'd like to listen to an event from all collections use wildcard `*` for the `collection_slug` parameter.
# Disconnecting

# Types
## From a specific stream

Types are included to work with our event payload objects easier.
All subscription methods return a callback function that will unsubscribe from a stream when invoked.

```javascript
const unsubscribe = client.onItemMetadataUpdated('collection-slug', noop);

unsubscribe();
```

## From the socket

```javascript
client.disconnect();
```
14 changes: 14 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import type { Config } from '@jest/types';

const pack = require('./package');

const config: Config.InitialOptions = {
displayName: pack.name,
name: pack.name,
modulePaths: ['<rootDir>/src'],
preset: 'ts-jest',
testEnvironment: 'jsdom'
};

export default config;
Loading

0 comments on commit dab3472

Please sign in to comment.