From 66a09949eaa7bcbcf54a7f78754d60cf7c635543 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Thu, 21 Nov 2024 23:39:27 -0800 Subject: [PATCH] implementing focus module --- app/sdk/src/net/getChannelTopicDetail.ts | 10 ++++++++++ app/sdk/src/net/getChannelTopics.ts | 15 +++++++++++++++ app/sdk/src/net/getContactChannelTopicDetail.ts | 9 +++++++++ app/sdk/src/net/getContactChannelTopics.ts | 14 ++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 app/sdk/src/net/getChannelTopicDetail.ts create mode 100644 app/sdk/src/net/getChannelTopics.ts create mode 100644 app/sdk/src/net/getContactChannelTopicDetail.ts create mode 100644 app/sdk/src/net/getContactChannelTopics.ts diff --git a/app/sdk/src/net/getChannelTopicDetail.ts b/app/sdk/src/net/getChannelTopicDetail.ts new file mode 100644 index 00000000..eea215ec --- /dev/null +++ b/app/sdk/src/net/getChannelTopicDetail.ts @@ -0,0 +1,10 @@ +import { checkResponse, fetchWithTimeout } from './fetchUtil'; +import { TopicDetailEntity } from '../entities'; + +export async function getChannelTopicDetail(node: string, secure: boolean, token: string, channelId: string, topicId: string): Promise { + const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/topics/${topicId}/detail?agent=${token}`; + const detail = await fetchWithTimeout(endpoint, { method: 'GET' }); + checkResponse(detail.status); + return await detail.json(); +} + diff --git a/app/sdk/src/net/getChannelTopics.ts b/app/sdk/src/net/getChannelTopics.ts new file mode 100644 index 00000000..0213f101 --- /dev/null +++ b/app/sdk/src/net/getChannelTopics.ts @@ -0,0 +1,15 @@ +import { checkResponse, fetchWithTimeout } from './fetchUtil'; +import { TopicEntity } from '../entities'; + +export async function getChannelTopics(node: string, secure: boolean, token: string, channelId: stirng, revision: number | null, count: number | null, begin: number | null, end: number | null): Promise<{marker: number, revision: number, topics: TopicEntity[]}> { + const params = (revision ? `&revision=${revision}` : '') + (count ? `&count=${count}` : '') + (begin ? `&begin=${begin}` : '') + (end ? `&end=${end}` : ''); + const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/topics?agent=${token}${params}`; + const topics = await fetchWithTimeout(endpoint, { method: 'GET' }); + checkResponse(topics.status); + return { + marker: topics.headers.get('topic-marker'), + revision: topics.headers.get('topic-revision'), + topics: await topics.json(), + } +} + diff --git a/app/sdk/src/net/getContactChannelTopicDetail.ts b/app/sdk/src/net/getContactChannelTopicDetail.ts new file mode 100644 index 00000000..14baa9de --- /dev/null +++ b/app/sdk/src/net/getContactChannelTopicDetail.ts @@ -0,0 +1,9 @@ +import { checkResponse, fetchWithTimeout } from './fetchUtil'; +import { TopicDetailEntity } from '../entities'; + +export async function getContactChannelTopicDetail(node: string, secure: boolean, guidToken: string, channelId: string, topicId: string): Promise { + const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/topics/${topicId}/detail?contact=${guidToken}`; + const detail = await fetchWithTimeout(endpoint, { method: 'GET' }); + checkResponse(detail.status); + return await detail.json(); +} diff --git a/app/sdk/src/net/getContactChannelTopics.ts b/app/sdk/src/net/getContactChannelTopics.ts new file mode 100644 index 00000000..21d1132f --- /dev/null +++ b/app/sdk/src/net/getContactChannelTopics.ts @@ -0,0 +1,14 @@ +import { checkResponse, fetchWithTimeout } from './fetchUtil'; +import { TopicEntity } from '../entities'; + +export async function getContactChannelTopics(node: string, secure: boolean, guidToken: string, channelId: string, revision: number | null, count: number | null, begin: number | null, end: number | null): Promise<{ marker: number, revision: number, topics: TopicEntity[]}> { + const params = (revision ? `&revision=${revision}` : '') + (count ? `&count=${count}` : '') + (begin ? `&begin=${begin}` : '') + (end ? `&end=${end}` : ''); + const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/topics?contact=${guidToken}${params}`; + const topics = await fetchWithTimeout(endpoint, { method: 'GET' }); + checkResponse(topics.status); + return { + marker: topics.headers.get('topic-marker'), + revision: topics.headers.get('topic-revision'), + topics: await topics.json(), + } +}