-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Adding SDK support for channel tags APIs (#1347)
* fix: Adding SDK support for channel tags APIs * fix: Remove local dev config for channel tags
- Loading branch information
Showing
8 changed files
with
371 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
getCAIPAddress, | ||
getAPIBaseUrls | ||
} from '../helpers'; | ||
import Constants, { ENV } from '../constants'; | ||
import { axiosGet } from '../utils/axiosUtil'; | ||
|
||
/** | ||
* GET v1/channels/${channelAddressInCAIP}/tags | ||
*/ | ||
export type GetTagsOptionsType = { | ||
/** address of the channel */ | ||
channel: string; | ||
env?: ENV; | ||
} | ||
|
||
/** | ||
* Returns the list of tags associated with the channel | ||
*/ | ||
export const getTags = async ( | ||
options : GetTagsOptionsType | ||
) => { | ||
const { | ||
channel, | ||
env = Constants.ENV.PROD, | ||
} = options || {}; | ||
|
||
const _channel = await getCAIPAddress(env, channel, 'Channel'); | ||
const API_BASE_URL = getAPIBaseUrls(env); | ||
const apiEndpoint = `${API_BASE_URL}/v1/channels`; | ||
const requestUrl = `${apiEndpoint}/${_channel}/tags`; | ||
|
||
return await axiosGet(requestUrl) | ||
.then((response) => response.data?.tags) | ||
.catch((err) => { | ||
console.error(`[EPNS-SDK] - API ${requestUrl}: `, err); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { getAPIBaseUrls, getQueryParams, getLimit } from '../helpers'; | ||
import Constants, {ENV} from '../constants'; | ||
import { axiosGet } from '../utils/axiosUtil'; | ||
|
||
/** | ||
* GET /v1/channels/search/ | ||
* optional params: page=(1)&limit=(20{min:1}{max:30})&query=(searchquery) | ||
*/ | ||
|
||
export type SearchChannelTagsOptionsType = { | ||
query: string; | ||
env?: ENV; | ||
page?: number; | ||
limit?: number; | ||
} | ||
|
||
export const searchTags = async ( | ||
options: SearchChannelTagsOptionsType | ||
) => { | ||
const { | ||
query, | ||
env = Constants.ENV.LOCAL, | ||
page = Constants.PAGINATION.INITIAL_PAGE, | ||
limit = Constants.PAGINATION.LIMIT, | ||
} = options || {}; | ||
|
||
if (!query) throw Error('"query" not provided!'); | ||
const API_BASE_URL = getAPIBaseUrls(env); | ||
const apiEndpoint = `${API_BASE_URL}/v1/channels/search/tags`; | ||
const queryObj = { | ||
page, | ||
limit: getLimit(limit), | ||
query: query | ||
}; | ||
const requestUrl = `${apiEndpoint}?${getQueryParams(queryObj)}`; | ||
return axiosGet(requestUrl) | ||
.then((response) => response.data.channels) | ||
.catch((err) => { | ||
console.error(`[Push SDK] - API ${requestUrl}: `, err); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import Constants, { ENV } from '../constants'; | ||
import { SignerType } from '../types'; | ||
import { ChannelInfoOptions, ChannelSearchOptions } from './PushNotificationTypes'; | ||
import * as PUSH_CHANNEL from '../channels'; | ||
import { PushNotificationBaseClass } from './pushNotificationBase'; | ||
import { Channel } from './channel'; | ||
|
||
export class Tags extends PushNotificationBaseClass { | ||
private channel: Channel; | ||
|
||
constructor(channel: Channel, signer?: SignerType, env?: ENV, account?: string) { | ||
super(signer, env, account); | ||
this.channel = channel; | ||
} | ||
|
||
/** | ||
* @description - Get delegates of a channell | ||
* @param {string} [options.channel] - channel in caip. defaults to account from signer with eth caip | ||
* @returns array of delegates | ||
*/ | ||
get = async (options?: ChannelInfoOptions) => { | ||
try { | ||
this.checkSignerObjectExists(); | ||
const channel = await this.channel.info() | ||
return await PUSH_CHANNEL.getTags({ | ||
channel: channel, | ||
env: this.env, | ||
}); | ||
} catch (error) { | ||
throw new Error(`Push SDK Error: API : tags::get : ${error}`); | ||
} | ||
}; | ||
|
||
/** | ||
* @description adds tags for a channel | ||
* @param {Array<string>} tags - tags to be added | ||
* @returns the tags if the transaction is successfull | ||
*/ | ||
add = async (tags: Array<string>) => { | ||
try { | ||
this.checkSignerObjectExists(); | ||
const channel = await this.channel.info() | ||
|
||
const resp = await this.channel.update({ | ||
name: channel.name, | ||
description: channel.info, | ||
url: channel.url, | ||
icon: channel.icon, | ||
tags: tags | ||
}); | ||
|
||
return { tags } | ||
|
||
} catch (error) { | ||
throw new Error(`Push SDK Error: Contract : tags::add : ${error}`); | ||
} | ||
}; | ||
|
||
/** | ||
* @description update tags for a channel | ||
* @param {Array<string>} tags - tags to be added | ||
* @returns the tags if the transaction is successfull | ||
*/ | ||
update = async (tags: Array<string>) => { | ||
try { | ||
this.checkSignerObjectExists(); | ||
const channel = await this.channel.info() | ||
await this.channel.update({ | ||
name: channel.name, | ||
description: channel.info, | ||
url: channel.url, | ||
icon: channel.icon, | ||
tags: tags | ||
}); | ||
|
||
return { tags } | ||
} catch (error) { | ||
throw new Error(`Push SDK Error: Contract : tags::update : ${error}`); | ||
} | ||
}; | ||
|
||
/** | ||
* @description removes tags from a channel | ||
* @returns status of the request | ||
*/ | ||
remove = async () => { | ||
try { | ||
this.checkSignerObjectExists(); | ||
const channel = await this.channel.info() | ||
await this.channel.update({ | ||
name: channel.name, | ||
description: channel.info, | ||
url: channel.url, | ||
icon: channel.icon, | ||
tags: [] | ||
}); | ||
|
||
return { status: "success" } | ||
|
||
} catch (error) { | ||
throw new Error(`Push SDK Error: Contract : tags::remove : ${error}`); | ||
} | ||
}; | ||
|
||
/** | ||
* @description - returns relevant information as per the query that was passed | ||
* @param {string} query - search query | ||
* @param {number} [options.page] - page number. default is set to Constants.PAGINATION.INITIAL_PAGE | ||
* @param {number} [options.limit] - number of feeds per page. default is set to Constants.PAGINATION.LIMIT | ||
* @returns Array of results relevant to the serach query | ||
*/ | ||
search = async (query: string, options?: ChannelSearchOptions) => { | ||
try { | ||
const { | ||
page = Constants.PAGINATION.INITIAL_PAGE, | ||
limit = Constants.PAGINATION.LIMIT, | ||
} = options || {}; | ||
|
||
return await PUSH_CHANNEL.searchTags({ | ||
query: query, | ||
page: page, | ||
limit: limit, | ||
env: this.env, | ||
}); | ||
} catch (error) { | ||
throw new Error(`Push SDK Error: API : channel::tags::search : ${error}`); | ||
} | ||
} | ||
} |
Oops, something went wrong.