From 4c50b28eef0eecae720fbf56f497f9c567aee5b8 Mon Sep 17 00:00:00 2001 From: Vishal Narkhede Date: Tue, 17 Dec 2024 03:05:22 +0100 Subject: [PATCH] blocklists and phraselists endpoint changes --- src/client.ts | 59 +++++++++++++++++++++++++++++++++++++++++++---- src/moderation.ts | 8 +++---- src/types.ts | 12 ++++++++++ 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/src/client.ts b/src/client.ts index 4f8ee4dec..58705f346 100644 --- a/src/client.ts +++ b/src/client.ts @@ -134,6 +134,8 @@ import { PartialUserUpdate, PermissionAPIResponse, PermissionsAPIResponse, + PhraseList, + PhraseListResponse, PollAnswersAPIResponse, PollData, PollOptionData, @@ -3055,8 +3057,8 @@ export class StreamChat(`${this.baseURL}/blocklists`, blockList); } - listBlockLists() { - return this.get(`${this.baseURL}/blocklists`); + listBlockLists(data?: { team?: string }) { + return this.get(`${this.baseURL}/blocklists`, data); } getBlockList(name: string) { @@ -3069,8 +3071,57 @@ export class StreamChat(`${this.baseURL}/blocklists/${encodeURIComponent(name)}`, data); } - deleteBlockList(name: string) { - return this.delete(`${this.baseURL}/blocklists/${encodeURIComponent(name)}`); + deleteBlockList(name: string, data: { team?: string }) { + return this.delete(`${this.baseURL}/blocklists/${encodeURIComponent(name)}`, data); + } + + /** + * Creates a new phraselist + * @param {PhraseList} phraseList The phraselist data to create + * @returns {Promise} API response + */ + createPhraseList(phraseList: PhraseList) { + return this.post(`${this.baseURL}/phraselists`, phraseList); + } + + /** + * Lists all phraselists + * @param {Object} data Optional parameters like team + * @returns {Promise} List of phraselists + */ + listPhraseLists(data?: { team?: string }) { + return this.get(`${this.baseURL}/phraselists`, data); + } + + /** + * Gets a specific phraselist by name + * @param {string} name The name of the phraselist to retrieve + * @returns {Promise} The requested phraselist + */ + getPhraseList(name: string) { + return this.get( + `${this.baseURL}/phraselists/${encodeURIComponent(name)}`, + ); + } + + /** + * Updates an existing phraselist + * @param {string} name The name of the phraselist to update + * @param {Object} data The update data containing phrases array + * @returns {Promise} API response + */ + updatePhraseList(name: string, data: { phrases: string[] }) { + return this.put(`${this.baseURL}/phraselists/${encodeURIComponent(name)}`, data); + } + + /** + * Deletes a phraselist + * @param {string} name The name of the phraselist to delete + * @param {Object} data Optional parameters like team + * @returns {Promise} API response + */ + deletePhraseList(name: string, data: { team?: string }) { + return this.delete(`${this.baseURL}/phraselists/${encodeURIComponent(name)}`, data); } exportChannels(request: Array, options: ExportChannelOptions = {}) { diff --git a/src/moderation.ts b/src/moderation.ts index f166670f0..a37c4b084 100644 --- a/src/moderation.ts +++ b/src/moderation.ts @@ -180,12 +180,12 @@ export class Moderation(this.client.baseURL + '/api/v2/moderation/config/' + key); + async getConfig(key: string, data?: { team?: string }) { + return await this.client.get(this.client.baseURL + '/api/v2/moderation/config/' + key, data); } - async deleteConfig(key: string) { - return await this.client.delete(this.client.baseURL + '/api/v2/moderation/config/' + key); + async deleteConfig(key: string, data?: { team?: string }) { + return await this.client.delete(this.client.baseURL + '/api/v2/moderation/config/' + key, data); } /** diff --git a/src/types.ts b/src/types.ts index a2405b966..14b529303 100644 --- a/src/types.ts +++ b/src/types.ts @@ -258,6 +258,12 @@ export type BannedUsersResponse; }; +export type PhraseListResponse = PhraseList & { + created_at?: string; + type?: string; + updated_at?: string; +}; + export type BlockListResponse = BlockList & { created_at?: string; type?: string; @@ -2183,6 +2189,12 @@ export type BlockList = { validate?: boolean; }; +export type PhraseList = { + name: string; + phrases: string[]; + team: string; +}; + export type ChannelConfig = ChannelConfigFields & CreatedAtUpdatedAt & { commands?: CommandVariants[];