@pushprotocol/restapi
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -5,2 +5,17 @@ # Changelog | ||
# [0.6.0](https://github.com/ethereum-push-notification-service/push-sdk/compare/restapi-0.4.0...restapi-0.5.0) (2023-02-15) | ||
### Bug Fixes | ||
* **component:** get-subscribers-api page, limit improvements ([#156](https://github.com/ethereum-push-notification-service/push-sdk/issues/156)) ([a396fa4](https://github.com/ethereum-push-notification-service/push-sdk/commit/a396fa4343a79239b2ef0ffba3ace57f7b5f9dcc)) | ||
* **component:** group chat SDK changes and improvements ([#154](https://github.com/ethereum-push-notification-service/push-sdk/issues/154)) ([e94fab9](https://github.com/ethereum-push-notification-service/push-sdk/commit/e94fab906eba9fa5672e3171871cf94259a95992)) | ||
### Features | ||
* **component:** group chat - update group, conversation hash ([#150](https://github.com/ethereum-push-notification-service/push-sdk/issues/150)) ([fc24618](https://github.com/ethereum-push-notification-service/push-sdk/commit/fc2461847bb86d7e0384ace5a484675480f00503)) | ||
# [0.5.0](https://github.com/ethereum-push-notification-service/push-sdk/compare/restapi-0.4.0...restapi-0.5.0) (2023-02-14) | ||
@@ -7,0 +22,0 @@ |
{ | ||
"name": "@pushprotocol/restapi", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
402
README.md
# restapi | ||
This package gives access to Push backend APIs | ||
This package gives access to Push Protocol (Push Nodes) APIs. Visit [Developer Docs](https://docs.push.org/developers) or [Push.org](https://push.org) to learn more. | ||
## How to use in your app? | ||
# Index | ||
- [How to use in your app?](#how-to-use-in-your-app) | ||
- [Installation](#installation) | ||
- [About blockchain agnostic address format](#about-blockchain-agnostic-address-format) | ||
- [About generating the signer object for different platforms](#about-generating-the-signer-object-for-different-platforms) | ||
- [SDK Features](#sdk-features) | ||
- [Notification](#for-notification) | ||
- [Fetching user notifications](#fetching-user-notifications) | ||
- [Fetching user spam notifications](#fetching-user-spam-notifications) | ||
- [Fetching user subscriptions](#fetching-user-subscriptions) | ||
- [Fetching channel details](#fetching-channel-details) | ||
- [Searching for channel(s)](#searching-for-channels) | ||
- [Opt in to a channel](#opt-in-to-a-channel) | ||
- [Opt out to a channel](#opt-out-to-a-channel) | ||
- [Sending notification](#sending-notification) | ||
- [Direct payload for single recipient(target)](#direct-payload-for-single-recipienttarget) | ||
- [Direct payload for group of recipients(subset)](#direct-payload-for-group-of-recipientssubset) | ||
- [Direct payload for all recipients(broadcast)](#direct-payload-for-all-recipientsbroadcast) | ||
- [IPFS payload for single recipient(target)](#ipfs-payload-for-single-recipienttarget) | ||
- [IPFS payload for group of recipients(subset)](#ipfs-payload-for-group-of-recipientssubset) | ||
- [IPFS payload for all recipients(broadcast)](#ipfs-payload-for-all-recipientsbroadcast) | ||
- [Minimal payload for single recipient(target)](#minimal-payload-for-single-recipienttarget) | ||
- [Minimal payload for a group of recipient(subset)](#minimal-payload-for-a-group-of-recipientsubset) | ||
- [Minimal payload for all recipients(broadcast)](#minimal-payload-for-all-recipientsbroadcast) | ||
- [Graph payload for single recipient(target)](#graph-payload-for-single-recipienttarget) | ||
- [Graph payload for group of recipients(subset)](#graph-payload-for-group-of-recipientssubset) | ||
- [Graph payload for all recipients(broadcast)](#graph-payload-for-all-recipientsbroadcast) | ||
- [Notification helper utils](#notification-helper-utils) | ||
- [Parsing notifications](#parsing-notifications) | ||
- [Advanced Notification (WIP)](#advanced-notifications-wip) | ||
- [**Deprecated** Get a channel’s subscriber list of addresses](#get-a-channels-subscriber-list-of-addresses) | ||
- [Chat](#for-chat) | ||
- [Create user for chat](#create-user-for-chat) | ||
- [Get user data for chat](#get-user-data-for-chat) | ||
- [Fetching list of user chats](#fetching-list-of-user-chats) | ||
- [Fetching list of user chat requests](#fetching-list-of-user-chat-requests) | ||
- [Fetching conversation hash between two users](#fetching-conversation-hash-between-two-users) | ||
- [Fetching history between two users](#fetching-history-between-two-users) | ||
- [Fetching latest chat between two users](#fetching-latest-chat-between-two-users) | ||
- [To approve a chat request](#to-approve-a-chat-request) | ||
- [To send a message](#to-send-a-message) | ||
- [To create a group](#to-create-a-group) | ||
- [To update group details](#to-update-group-details) | ||
- [Chat helper utils](#chat-helper-utils) | ||
- [Decrypting encrypted pgp private key](#decrypting-encrypted-pgp-private-key) | ||
- [Decrypting messages](#decrypting-messages) | ||
### Installation | ||
# How to use in your app? | ||
## Installation | ||
``` | ||
@@ -19,7 +65,9 @@ yarn add @pushprotocol/restapi ethers | ||
### **NOTE on Addresses:** | ||
## **About blockchain agnostic address format** | ||
In any of the below methods (unless explicitly stated otherwise) we accept either - | ||
- [CAIP format](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md#test-cases): for any on chain addresses ***We strongly recommend using this address format***. | ||
- [CAIP format](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md#test-cases): for any on chain addresses ***We strongly recommend using this address format***. [Learn more about the format and examples](https://docs.push.org/developers/concepts/web3-notifications). | ||
(Example : `eip155:1:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb`) | ||
**Note** - For chat related restapis, the address is in the format: eip155:<address> instead of eip155:<chainId>:<address> | ||
@@ -31,5 +79,5 @@ - ETH address format: only for backwards compatibility. | ||
### **NOTE on generating the "signer" object for different platforms:** | ||
## **About generating the "signer" object for different platforms** | ||
#### When using in SERVER-SIDE code: | ||
### When using in SERVER-SIDE code: | ||
```typescript | ||
@@ -41,3 +89,3 @@ const ethers = require('ethers'); | ||
``` | ||
#### When using in FRONT-END code: | ||
### When using in FRONT-END code: | ||
```typescript | ||
@@ -53,5 +101,6 @@ // any other web3 ui lib is also acceptable | ||
### MAIN FEATURES | ||
# SDK Features | ||
## For Notification | ||
#### **fetching user notifications** | ||
### **Fetching user notifications** | ||
```typescript | ||
@@ -64,3 +113,3 @@ const notifications = await PushAPI.user.getFeeds({ | ||
#### **fetching user spam notifications** | ||
### **Fetching user spam notifications** | ||
```typescript | ||
@@ -84,3 +133,3 @@ const spams = await PushAPI.user.getFeeds({ | ||
#### **fetching user subscriptions** | ||
### **Fetching user subscriptions** | ||
```typescript | ||
@@ -104,3 +153,3 @@ const subscriptions = await PushAPI.user.getSubscriptions({ | ||
#### **fetching channel details** | ||
### **Fetching channel details** | ||
```typescript | ||
@@ -120,3 +169,3 @@ const channelData = await PushAPI.channels.getChannel({ | ||
#### **searching for channel(s)** | ||
### **Searching for channel(s)** | ||
```typescript | ||
@@ -140,3 +189,3 @@ const channelsData = await PushAPI.channels.search({ | ||
#### **opt in to a channel** | ||
### **Opt in to a channel** | ||
```typescript | ||
@@ -169,3 +218,3 @@ await PushAPI.channels.subscribe({ | ||
#### **opt out to a channel** | ||
### **Opt out to a channel** | ||
```typescript | ||
@@ -204,6 +253,6 @@ await PushAPI.channels.unsubscribe({ | ||
#### **sending notification** | ||
### **Sending notification** | ||
##### **direct payload for single recipient(target)** | ||
#### **Direct payload for single recipient(target)** | ||
```typescript | ||
@@ -231,3 +280,3 @@ // apiResponse?.status === 204, if sent successfully! | ||
##### **direct payload for group of recipients(subset)** | ||
#### **Direct payload for group of recipients(subset)** | ||
```typescript | ||
@@ -255,3 +304,3 @@ // apiResponse?.status === 204, if sent successfully! | ||
##### **direct payload for all recipients(broadcast)** | ||
#### **Direct payload for all recipients(broadcast)** | ||
```typescript | ||
@@ -278,3 +327,3 @@ // apiResponse?.status === 204, if sent successfully! | ||
##### **IPFS payload for single recipient(target)** | ||
#### **IPFS payload for single recipient(target)** | ||
```typescript | ||
@@ -293,3 +342,3 @@ // apiResponse?.status === 204, if sent successfully! | ||
##### **IPFS payload for group of recipients(subset)** | ||
#### **IPFS payload for group of recipients(subset)** | ||
```typescript | ||
@@ -308,3 +357,3 @@ // apiResponse?.status === 204, if sent successfully! | ||
##### **IPFS payload for all recipients(broadcast)** | ||
#### **IPFS payload for all recipients(broadcast)** | ||
```typescript | ||
@@ -322,3 +371,3 @@ // apiResponse?.status === 204, if sent successfully! | ||
##### **minimal payload for single recipient(target)** | ||
#### **Minimal payload for single recipient(target)** | ||
```typescript | ||
@@ -346,3 +395,3 @@ // apiResponse?.status === 204, if sent successfully! | ||
##### **minimal payload for a group of recipient(subset)** | ||
#### **Minimal payload for a group of recipient(subset)** | ||
```typescript | ||
@@ -370,3 +419,3 @@ // apiResponse?.status === 204, if sent successfully! | ||
##### **minimal payload for all recipients(broadcast)** | ||
#### **Minimal payload for all recipients(broadcast)** | ||
```typescript | ||
@@ -393,3 +442,3 @@ // apiResponse?.status === 204, if sent successfully! | ||
##### **graph payload for single recipient(target)** | ||
#### **Graph payload for single recipient(target)** | ||
***Make sure the channel has the graph id you are providing!!*** | ||
@@ -412,3 +461,3 @@ ```typescript | ||
##### **graph payload for group of recipients(subset)** | ||
#### **Graph payload for group of recipients(subset)** | ||
***Make sure the channel has the graph id you are providing!!*** | ||
@@ -431,3 +480,3 @@ ```typescript | ||
##### **graph payload for all recipients(broadcast)** | ||
#### **Graph payload for all recipients(broadcast)** | ||
***Make sure the channel has the graph id you are providing!!*** | ||
@@ -473,4 +522,4 @@ ```typescript | ||
### UTILS | ||
#### **parsing notifications** | ||
### Notification Helper Utils | ||
#### **Parsing notifications** | ||
Utils method to parse raw Push Feeds API response into a pre-defined shape as below. | ||
@@ -507,10 +556,6 @@ ```typescript | ||
<br /> | ||
### Advanced Notifications (WIP) | ||
### ADVANCED (WIP) | ||
### DEPRECATED | ||
#### **get a channel's subscriber list of addresses** | ||
#### **Get a channel's subscriber list of addresses** | ||
```typescript | ||
@@ -530,2 +575,285 @@ const subscribers = await PushAPI.channels._getSubscribers({ | ||
## For Chat | ||
### **Create user for chat** | ||
```typescript | ||
const user = await PushAPI.user.create({ | ||
account: '0xFe6C8E9e25f7bcF374412c5C81B2578aC473C0F7', | ||
env: 'staging', | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| account* | string | - | user address | | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
### **Get user data for chat** | ||
```typescript | ||
const user = await PushAPI.user.get({ | ||
account: '0xFe6C8E9e25f7bcF374412c5C81B2578aC473C0F7', | ||
env: 'staging', | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| account* | string | - | user address | | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
### **Fetching list of user chats** | ||
```typescript | ||
const chats = await PushAPI.chat.chats({ | ||
account: 0xFe6C8E9e25f7bcF374412c5C81B2578aC473C0F7, | ||
pgpPrivateKey: decryptedPvtKey, | ||
toDecrypt: true, | ||
env: 'staging', | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| account* | string | - | user address | | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
| toDecrypt | boolean | false | if "true" the method will return decrypted message content in response| | ||
| pgpPrivateKey | string | null | mandatory for users having pgp keys| | ||
### **Fetching list of user chat requests** | ||
```typescript | ||
const chats = await PushAPI.chat.requests({ | ||
account: 0xFe6C8E9e25f7bcF374412c5C81B2578aC473C0F7, | ||
pgpPrivateKey: decryptedPvtKey, | ||
toDecrypt: true, | ||
env: 'staging', | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| account* | string | - | user address | | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
| toDecrypt | boolean | false | if "true" the method will return decrypted message content in response| | ||
| pgpPrivateKey | string | null | mandatory for users having pgp keys| | ||
### **Fetching conversation hash between two users** | ||
```typescript | ||
const threadhash = await PushAPI.chat.conversationHash({ | ||
account: '20x18C0Ab0809589c423Ac9eb42897258757b6b3d3d', | ||
conversationId: '0xFA3F8E79fb9B03e7a04295594785b91588Aa4DC8', // receiver's address or chatId of a group | ||
env, | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| account* | string | - | user address | | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
| conversationId* | string | - | receiver's address or chatId of a group| | ||
### **Fetching history between two users** | ||
```typescript | ||
const chatHistory = await PushAPI.chat.history({ | ||
threadhash:threadhash.threadHash, | ||
account: '0xFe6C8E9e25f7bcF374412c5C81B2578aC473C0F7', | ||
pgpPrivateKey: decryptedPvtKey, | ||
limit:2, | ||
toDecrypt:true, | ||
env:'staging', | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| account* | string | - | user address | | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
| threadhash* | string | - | conversation hash between two users | | ||
| toDecrypt | boolean | false | if "true" the method will return decrypted message content in response| | ||
| pgpPrivateKey | string | null | mandatory for users having pgp keys| | ||
| limit | number | 10 | number of messages between two users | | ||
### **Fetching latest chat between two users** | ||
```typescript | ||
const chatHistory = await PushAPI.chat.latest({ | ||
threadhash:threadhash.threadHash, | ||
account: '0xFe6C8E9e25f7bcF374412c5C81B2578aC473C0F7', | ||
pgpPrivateKey: decryptedPvtKey, | ||
limit:2, | ||
toDecrypt:true, | ||
env:'staging', | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| account* | string | - | user address | | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
| threadhash* | string | - | conversation hash between two users | | ||
| toDecrypt | boolean | false | if "true" the method will return decrypted message content in response| | ||
| pgpPrivateKey | string | null | mandatory for users having pgp keys| | ||
### **To approve a chat request** | ||
```typescript | ||
const response = await PushAPI.chat.approve({ | ||
status: 'Approved', | ||
account: '0x18C0Ab0809589c423Ac9eb42897258757b6b3d3d', | ||
senderAddress : '0x873a538254f8162377296326BB3eDDbA7d00F8E9', // receiver's address or chatId of a group | ||
env:'staging', | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| account* | string | - | user address | | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
| senderAddress* | string | - | receiver's address or chatId of a group | | ||
| status | 'Approved' | 'Approved' | flag for approving and rejecting chat request, supports only approving for now| | ||
### **To send a message** | ||
```typescript | ||
const response = await PushAPI.chat.send({ | ||
messageContent: 'Hi', | ||
messageType: 'Text', | ||
receiverAddress: '0x08E834a388Cee21d4d7571075146841C8eE621a4', // receiver's address or chatId of a group | ||
account: '0x57eAd5826B1E0A7074E1aBf1A062714A2dE0f8B4', | ||
pgpPrivateKey: decryptedPvtKey, | ||
apiKey:"tAWEnggQ9Z.UaDBNjrvlJZx3giBTIQDcT8bKQo1O1518uF1Tea7rPwfzXv2ouV5rX9ViwgJUrXm" | ||
env: 'staging', | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| account* | string | - | user address | | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
| senderAddress* | string | - | receiver's address or chatId of a group | | ||
| messageContent | string | '' | message to be sent | | ||
| messageType | 'Text' | 'Image' | 'File' | 'GIF' | 'Text'| type of messageContent | | ||
| pgpPrivateKey | string | null | mandatory for users having pgp keys| | ||
| apiKey | string | '' | apiKey for using chat| | ||
### **To create a group** | ||
```typescript | ||
const response = await PushAPI.chat.createGroup({ | ||
groupName:'Push Protocol group', | ||
groupDescription:'This is the oficial group for Push Protocol, | ||
members: ['0x9e60c47edF21fa5e5Af33347680B3971F2FfD464','0x3829E53A15856d1846e1b52d3Bdf5839705c29e5'], | ||
groupImage: <group image link> , | ||
admins: ['0x3829E53A15856d1846e1b52d3Bdf5839705c29e5'], | ||
isPublic: true, | ||
groupCreator: '0xD993eb61B8843439A23741C0A3b5138763aE11a4' , | ||
account: '0xD993eb61B8843439A23741C0A3b5138763aE11a4', | ||
env: 'staging', | ||
pgpPrivateKey: decryptedPvtKey, //decrypted private key | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| account* | string | - | user address | | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
| groupName* | string | - | group name | | ||
| groupDescription* | string | - | group description | | ||
| groupImage* | string | - | group image link | | ||
| members* | Array<string> | - | wallet addresses of all members except admins and groupCreator | | ||
| admins* | Array<string> | - | wallet addresses of all admins except members and groupCreator | | ||
| groupCreator* | string | - | wallet address groupCreator| | ||
| isPublic* | boolean | - | true for public group, false for private group | | ||
| pgpPrivateKey | string | null | mandatory for users having pgp keys| | ||
### **To get group details by chatId** | ||
```typescript | ||
const response = await PushAPI.chat.getGroup({ | ||
chatId: '190591e84108cdf12e62eecabf02ddb123ea92f1c06fb98ee9b5cf3871f46fa9', | ||
env: 'staging', | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| chatId* | string | - | group chat id | | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
### **To update group details** | ||
Note - updateGroup is an idompotent call | ||
```typescript | ||
const response = await PushAPI.chat.updateGroup({ | ||
groupName:'Push Chat group', | ||
groupDescription:'This is the updated description for Push Chat, | ||
members: ['0x2e60c47edF21fa5e5A333347680B3971F1FfD456','0x3829E53A15856d1846e1b52d3Bdf5839705c29e5'], | ||
groupImage: <group image link> , | ||
admins: ['0x3829E53A15856d1846e1b52d3Bdf5839705c29e5'], | ||
account: '0xD993eb61B8843439A23741C0A3b5138763aE11a4', | ||
env: 'staging', | ||
pgpPrivateKey: decryptedPvtKey, //decrypted private key | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| account* | string | - | user address | | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
| groupName* | string | - | group name | | ||
| groupDescription* | string | - | group description | | ||
| groupImage* | string | - | group image link | | ||
| members* | Array<string> | - | wallet addresses of all members except admins and groupCreator | | ||
| admins* | Array<string> | - | wallet addresses of all admins except members and groupCreator | | ||
| pgpPrivateKey | string | null | mandatory for users having pgp keys| | ||
### Chat Helper Utils | ||
#### **Decrypting encrypted pgp private key** | ||
```typescript | ||
import { IUser } from '@pushprotocol/restapi'; | ||
const decryptedPvtKey = await PushAPI.chat.decryptWithWalletRPCMethod( | ||
(connectedUser as IUser).encryptedPrivateKey, //encrypted private key | ||
'0xFe6C8E9e25f7bcF374412c5C81B2578aC473C0F7' //user address | ||
); | ||
``` | ||
#### **Decrypting messages** | ||
```typescript | ||
import { IUser } from '@pushprotocol/restapi'; | ||
const decryptedChat = await PushAPI.chat.decryptConversation({ | ||
messages: chatHistory, //array of message object fetched from chat.history method | ||
connectedUser, // user meta data object fetched from chat.get method | ||
pgpPrivateKey:decryptedPvtKey, //decrypted private key | ||
env:'staging', | ||
}); | ||
``` | ||
Allowed Options (params with * are mandatory) | ||
| Param | Type | Default | Remarks | | ||
|----------|---------|---------|--------------------------------------------| | ||
| env | string | 'prod' | API env - 'prod', 'staging', 'dev'| | ||
| messages* | string | - | array of message object fetched from chat.history method | | ||
| connectedUser* | IUser | false | user meta data object| | ||
| pgpPrivateKey | string | null | mandatory for users having pgp keys| |
@@ -7,6 +7,6 @@ import { Subscribers } from '../types'; | ||
channel: string; | ||
page: number; | ||
limit: number; | ||
page?: number; | ||
limit?: number; | ||
env?: string; | ||
}; | ||
export declare const getSubscribers: (options: GetChannelSubscribersOptionsType) => Promise<Subscribers>; |
@@ -9,3 +9,3 @@ "use strict"; | ||
const getSubscribers = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { channel, page, limit, env = constants_1.default.ENV.PROD, } = options || {}; | ||
const { channel, page = 1, limit = 10, env = constants_1.default.ENV.PROD, } = options || {}; | ||
try { | ||
@@ -15,2 +15,11 @@ if (channel == null || channel.length == 0) { | ||
} | ||
if (page <= 0) { | ||
throw new Error("page must be greater than 0"); | ||
} | ||
if (limit <= 0) { | ||
throw new Error("limit must be greater than 0"); | ||
} | ||
if (limit > 30) { | ||
throw new Error("limit must be lesser than or equal to 30"); | ||
} | ||
const _channel = (0, helpers_1.getCAIPAddress)(env, channel, 'Channel'); | ||
@@ -17,0 +26,0 @@ const API_BASE_URL = (0, helpers_1.getAPIBaseUrls)(env); |
@@ -13,3 +13,2 @@ import { AccountEnvOptionsType } from '../types'; | ||
isPublic: boolean; | ||
groupCreator: string; | ||
contractAddressNFT?: string; | ||
@@ -16,0 +15,0 @@ numberOfNFTs?: number; |
@@ -11,5 +11,5 @@ "use strict"; | ||
const createGroup = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { groupName, groupDescription, members, groupImage, admins, isPublic, contractAddressNFT, numberOfNFTs, contractAddressERC20, numberOfERC20, groupCreator, account, env = constants_1.default.ENV.PROD, pgpPrivateKey = null, } = options || {}; | ||
const { groupName, groupDescription, members, groupImage, admins, isPublic, contractAddressNFT, numberOfNFTs, contractAddressERC20, numberOfERC20, account, env = constants_1.default.ENV.PROD, pgpPrivateKey = null, } = options || {}; | ||
try { | ||
(0, helpers_2.createGroupRequestValidator)(groupName, groupDescription, members, admins, groupCreator, contractAddressNFT, numberOfNFTs, contractAddressERC20, numberOfERC20); | ||
(0, helpers_2.createGroupRequestValidator)(groupName, groupDescription, members, admins, contractAddressNFT, numberOfNFTs, contractAddressERC20, numberOfERC20); | ||
const convertedMembers = members.map(helpers_1.walletToPCAIP10); | ||
@@ -28,3 +28,3 @@ const convertedAdmins = admins.map(helpers_1.walletToPCAIP10); | ||
numberOfERC20: numberOfERC20 == undefined ? 0 : numberOfERC20, | ||
groupCreator: (0, helpers_1.walletToPCAIP10)(groupCreator) | ||
groupCreator: (0, helpers_1.walletToPCAIP10)(account) | ||
}; | ||
@@ -38,3 +38,3 @@ const connectedUser = yield (0, helpers_2.getConnectedUser)(account, pgpPrivateKey, env); | ||
const apiEndpoint = `${API_BASE_URL}/v1/chat/groups`; | ||
const body = (0, helpers_2.createGroupPayload)(groupName, groupDescription, convertedMembers, groupImage, convertedAdmins, isPublic, (0, helpers_1.walletToPCAIP10)(groupCreator), verificationProof, contractAddressNFT, numberOfNFTs, contractAddressERC20, numberOfERC20); | ||
const body = (0, helpers_2.createGroupPayload)(groupName, groupDescription, convertedMembers, groupImage, convertedAdmins, isPublic, (0, helpers_1.walletToPCAIP10)(account), verificationProof, contractAddressNFT, numberOfNFTs, contractAddressERC20, numberOfERC20); | ||
return axios_1.default | ||
@@ -41,0 +41,0 @@ .post(apiEndpoint, body) |
@@ -37,3 +37,3 @@ import { IConnectedUser } from '../../types'; | ||
groupName: string; | ||
profilePicture: string; | ||
groupImage: string; | ||
members: Array<string>; | ||
@@ -47,2 +47,2 @@ admins: Array<string>; | ||
export declare const createGroupPayload: (groupName: string, groupDescription: string, members: Array<string>, groupImage: string, admins: Array<string>, isPublic: boolean, groupCreator: string, verificationProof: string, contractAddressNFT?: string | undefined, numberOfNFTs?: number | undefined, contractAddressERC20?: string | undefined, numberOfERC20?: number | undefined) => ICreateGroupRequestPayload; | ||
export declare const updateGroupPayload: (groupName: string, profilePicture: string, members: Array<string>, admins: Array<string>, address: string, verificationProof: string) => IUpdateGroupRequestPayload; | ||
export declare const updateGroupPayload: (groupName: string, groupImage: string, groupDescription: string, members: Array<string>, admins: Array<string>, address: string, verificationProof: string) => IUpdateGroupRequestPayload; |
@@ -74,6 +74,7 @@ "use strict"; | ||
exports.createGroupPayload = createGroupPayload; | ||
const updateGroupPayload = (groupName, profilePicture, members, admins, address, verificationProof) => { | ||
const updateGroupPayload = (groupName, groupImage, groupDescription, members, admins, address, verificationProof) => { | ||
const body = { | ||
groupName: groupName, | ||
profilePicture: profilePicture, | ||
groupImage: groupImage, | ||
groupDescription: groupDescription, | ||
members: members, | ||
@@ -80,0 +81,0 @@ admins: admins, |
@@ -1,2 +0,2 @@ | ||
export declare const createGroupRequestValidator: (groupName: string, groupDescription: string, members: Array<string>, admins: Array<string>, groupCreator: string, contractAddressNFT?: string | undefined, numberOfNFTs?: number | undefined, contractAddressERC20?: string | undefined, numberOfERC20?: number | undefined) => void; | ||
export declare const updateGroupRequestValidator: (chatId: string, groupName: string, profilePicture: string, members: Array<string>, admins: Array<string>, address: string) => void; | ||
export declare const createGroupRequestValidator: (groupName: string, groupDescription: string, members: Array<string>, admins: Array<string>, contractAddressNFT?: string | undefined, numberOfNFTs?: number | undefined, contractAddressERC20?: string | undefined, numberOfERC20?: number | undefined) => void; | ||
export declare const updateGroupRequestValidator: (chatId: string, groupName: string, groupDescription: string, profilePicture: string, members: Array<string>, admins: Array<string>, address: string) => void; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const helpers_1 = require("../../helpers"); | ||
const createGroupRequestValidator = (groupName, groupDescription, members, admins, groupCreator, contractAddressNFT, numberOfNFTs, contractAddressERC20, numberOfERC20) => { | ||
const createGroupRequestValidator = (groupName, groupDescription, members, admins, contractAddressNFT, numberOfNFTs, contractAddressERC20, numberOfERC20) => { | ||
if (groupName == null || groupName.length == 0) { | ||
@@ -32,5 +32,2 @@ throw new Error(`groupName cannot be null or empty`); | ||
} | ||
if (!(0, helpers_1.isValidETHAddress)(groupCreator)) { | ||
throw new Error(`Invalid groupCreator address!`); | ||
} | ||
if (contractAddressNFT != null && (contractAddressNFT === null || contractAddressNFT === void 0 ? void 0 : contractAddressNFT.length) > 0 && !(0, helpers_1.isValidETHAddress)(contractAddressNFT)) { | ||
@@ -50,3 +47,3 @@ throw new Error(`Invalid contractAddressNFT address!`); | ||
exports.createGroupRequestValidator = createGroupRequestValidator; | ||
const updateGroupRequestValidator = (chatId, groupName, profilePicture, members, admins, address) => { | ||
const updateGroupRequestValidator = (chatId, groupName, groupDescription, profilePicture, members, admins, address) => { | ||
if (chatId == null || chatId.length == 0) { | ||
@@ -61,5 +58,8 @@ throw new Error(`chatId cannot be null or empty`); | ||
} | ||
if (groupName != null && groupName.length >= 256) { | ||
throw new Error(`groupName cannot be more than 256 characters`); | ||
if (groupName != null && groupName.length >= 50) { | ||
throw new Error(`groupName cannot be more than 50 characters`); | ||
} | ||
if (groupDescription != null && groupDescription.length >= 150) { | ||
throw new Error(`groupDescription cannot be more than 150 characters`); | ||
} | ||
if (members != null && members.length > 0) { | ||
@@ -66,0 +66,0 @@ for (let i = 0; i < members.length; i++) { |
@@ -8,3 +8,4 @@ import { AccountEnvOptionsType } from '../types'; | ||
groupName: string; | ||
profilePicture: string; | ||
groupImage: string; | ||
groupDescription: string; | ||
members: Array<string>; | ||
@@ -11,0 +12,0 @@ admins: Array<string>; |
@@ -10,5 +10,5 @@ "use strict"; | ||
const updateGroup = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { chatId, groupName, profilePicture, members, admins, account, env = constants_1.default.ENV.PROD, pgpPrivateKey = null, } = options || {}; | ||
const { chatId, groupName, groupImage, groupDescription, members, admins, account, env = constants_1.default.ENV.PROD, pgpPrivateKey = null, } = options || {}; | ||
try { | ||
(0, helpers_2.updateGroupRequestValidator)(chatId, groupName, profilePicture, members, admins, account); | ||
(0, helpers_2.updateGroupRequestValidator)(chatId, groupName, groupDescription, groupImage, members, admins, account); | ||
const connectedUser = yield (0, helpers_2.getConnectedUser)(account, pgpPrivateKey, env); | ||
@@ -19,3 +19,4 @@ const convertedMembers = members.map(helpers_1.walletToPCAIP10); | ||
groupName: groupName, | ||
profilePicture: profilePicture, | ||
groupImage: groupImage, | ||
groupDescription: groupDescription, | ||
members: convertedMembers, | ||
@@ -30,3 +31,3 @@ admins: convertedAdmins, | ||
const apiEndpoint = `${API_BASE_URL}/v1/chat/groups/${chatId}`; | ||
const body = (0, helpers_2.updateGroupPayload)(groupName, profilePicture, convertedMembers, convertedAdmins, (0, helpers_1.walletToPCAIP10)(account), verificationProof); | ||
const body = (0, helpers_2.updateGroupPayload)(groupName, groupImage, groupDescription, convertedMembers, convertedAdmins, (0, helpers_1.walletToPCAIP10)(account), verificationProof); | ||
return axios_1.default | ||
@@ -33,0 +34,0 @@ .put(apiEndpoint, body) |
@@ -153,3 +153,2 @@ export declare type ApiNotificationType = { | ||
groupMembers: UserInfo[]; | ||
groupAdmins: UserInfo[]; | ||
isPublic: boolean; | ||
@@ -226,3 +225,3 @@ contractAddressNFT: string; | ||
messageContent?: string; | ||
messageType?: 'Text' | 'Image' | 'File'; | ||
messageType?: 'Text' | 'Image' | 'File' | 'GIF'; | ||
receiverAddress: string; | ||
@@ -241,2 +240,3 @@ pgpPrivateKey?: string; | ||
image: string; | ||
isAdmin: boolean; | ||
} | ||
@@ -260,3 +260,2 @@ export interface Chat { | ||
groupMembers: UserInfo[]; | ||
groupAdmins: UserInfo[]; | ||
isPublic: boolean; | ||
@@ -263,0 +262,0 @@ contractAddressNFT: string; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
237535
3099
835