0.0.36 • Published 3 years ago

@cuser/client v0.0.36

Weekly downloads
1
License
ISC
Repository
-
Last release
3 years ago

@cuser/client

Status

codecov npm npm-downloads

Class: CuserClient

Cuser client instance which provides an interface to read, publish, edit and delete messages through ipfs. By default the client will be only allowed to read messages unless you provide a CuserServer url, which will enable the publishing capabilities to the users.

Note To enable publisher capabilities, you need deploy a CuserServer, please refer to getting started section to gets more information.

example

const { create } = require('ipfs');

const node = create({ ...ipfsOptions });
const cuserId = 'CUSER_SERVER_IDENTIFIER';
const client = new CuserClient(node, cuserId);
const topicId = 'custom-topic-id';

client.getMessages(topicId).then((messages) => {
 console.log(messages);
 // should return empty array when no comments
});

Hierarchy

Index

Constructors

Properties

Methods

Constructors

constructor

+ new CuserClient(node: IPFSAPI | Promise<IPFSAPI>, cuserId: string, opts?: CuserClientOptions & CuserReaderOptions & CuserCoreOptions): CuserClient

Overrides void

Defined in client/client.js:53

Parameters:

NameTypeDefault value
nodeIPFSAPI | Promise<IPFSAPI>-
cuserIdstring-
optsCuserClientOptions & CuserReaderOptions & CuserCoreOptions{}

Returns: CuserClient

Properties

_core

_core: CuserCore

Inherited from CuserClient._core

Defined in reader/reader.d.ts:44


_process

_process: (message: any, cursor: string) => Promise<CuserReaderMessageIteratorResult>

Inherited from CuserClient._process

Defined in reader/reader.d.ts:48

Methods

authenticate

authenticate(username: string, avatar: string): Promise<any>

Defined in client/client.js:80

Authenticates a user with the required fields of username and avatar, this will epect to recieve an access_token to be used in publishing operations

Parameters:

NameTypeDescription
usernamestring
avatarstringdata url scheme https://tools.ietf.org/html/rfc2397

Returns: Promise<any>


deleteMessage

deleteMessage(topicId: string, accessToken: string, messageId: string): Promise<any, Response>

Defined in client/client.js:142

Deletes message for certain topic using topicId as identifier and accessToken to identify the user

Parameters:

NameType
topicIdstring
accessTokenstring
messageIdstring

Returns: Promise<any, Response>


getMessage

getMessage(cid: string): Promise<GraphMessage>

Inherited from CuserClient.getMessage

Defined in reader/reader.d.ts:76

Gets the message from ipfs using the CID given by parameter

Parameters:

NameType
cidstring

Returns: Promise<GraphMessage>


getMessages

getMessages(topicId: string, opts: CuserReaderMessagesIteratorOptions): Promise<CuserReaderMessageIteratorResult[]> | AsyncIterable<CuserReaderMessageIteratorResult>

Inherited from CuserClient.getMessages

Defined in reader/reader.d.ts:70

Gets messages from ipfs layer

example

Array

const messages = reader.getMessages('custom_topic_id');
console.log(messages);

Iterator

const messages = reader.getMessages('custom_topic_id', {
  iterator: true,
});
for await (let value of messages) {
  console.log(value);
}

Parameters:

NameType
topicIdstring
optsCuserReaderMessagesIteratorOptions

Returns: Promise<CuserReaderMessageIteratorResult[]> | AsyncIterable<CuserReaderMessageIteratorResult>


publishMessage

publishMessage(topicId: string, accessToken: string, content: string): Promise<any, Response>

Defined in client/client.js:97

Publish a new message for certain topic using topicId as identifier and accessToken to identify the user

Parameters:

NameType
topicIdstring
accessTokenstring
contentstring

Returns: Promise<any, Response>


subscribe

subscribe(topicId: string, subscriber: CuserClientSubscriber): function

Defined in client/client.js:184

Subscribe to message changes of a certain topic.

example This will attach the listener to three types of events:

  • created when a user publish a message
  • updated when a user updates a message
  • deleted when a user removes a message
client.subscribe('CUSTOM_TOPIC_ID', ({ type, messageCid }) => {
 switch(type) {
   case 'created':
     // when a user publish a message
     // console.log(client.getMessage(messageCid));
     break;
   case 'updated':
     // when a user updates a message
     // console.log(client.getMessage(messageCid));
     break;
   case 'deleted':
     // when a user removes a message
     // console.log(client.getMessage(messageCid));
     break;
 }
});

Parameters:

NameTypeDescription
topicIdstringtopic identifier
subscriberCuserClientSubscriberfunction event subscriber

Returns: function


updateMessage

updateMessage(topicId: string, accessToken: string, messageId: string, content: string): Promise<any, Response>

Defined in client/client.js:120

Updates message for certain topic using topicId as identifier and accessToken to identify the user

Parameters:

NameType
topicIdstring
accessTokenstring
messageIdstring
contentstring

Returns: Promise<any, Response>

0.0.30

3 years ago

0.0.31

3 years ago

0.0.32

3 years ago

0.0.33

3 years ago

0.0.34

3 years ago

0.0.35

3 years ago

0.0.36

3 years ago

0.0.29

3 years ago

0.0.27

3 years ago

0.0.25

3 years ago

0.0.26

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.12

3 years ago

0.0.8

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago