diff --git a/package.json b/package.json index dcc0a6c..e517b37 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@techniker-me/pcast-api", - "version": "2025.0.7", + "version": "2025.0.8", "type": "module", "scripts": { "ci-build": "bun run build:node && bun run build:browser && bun run build:types", diff --git a/src/pcast/Channels.ts b/src/pcast/Channels.ts index 83c0348..31bf540 100644 --- a/src/pcast/Channels.ts +++ b/src/pcast/Channels.ts @@ -56,24 +56,6 @@ export class Channels { this.initialize(); } - private async initialize() { - try { - const channelsList = await this.list(); - if (!channelsList) { - console.warn('[Channels] Failed to initialize cache - no channels returned'); - return; - } - - for (const channel of channelsList) { - this._channelsByAlias.set(channel.alias, channel); - } - - this._initialized = true; - } catch (error) { - console.error('[Channels] Failed to initialize cache:', error); - } - } - public async createChannel(name: string, description: string, channelOptions: string[] = []): Promise { // Input validation if (!name || name.trim().length === 0) { @@ -159,7 +141,7 @@ export class Channels { return parseInt(response, 10); } - public async getMembers(channelId: string): Promise { + public async getChannelMembers(channelId: string): Promise { if (!channelId || channelId.trim().length === 0) { throw new ChannelError('Channel ID cannot be empty', 'INVALID_CHANNEL_ID'); } @@ -173,6 +155,16 @@ export class Channels { return response.members; } + public async getChannelMembersByAlias(alias: string): Promise { + const channel = await this.get({alias}); + + if (!channel) { + throw new ChannelError(`Channel not found: ${alias}`, 'CHANNEL_NOT_FOUND'); + } + + return this.getChannelMembers(channel.channelId); + } + public async deleteChannel(channelId: string): Promise { return this.delete(channelId); } @@ -210,4 +202,22 @@ export class Channels { public getCacheSize(): number { return this._channelsByAlias.size; } + + private async initialize() { + try { + const channelsList = await this.list(); + if (!channelsList) { + console.warn('[Channels] Failed to initialize cache - no channels returned'); + return; + } + + for (const channel of channelsList) { + this._channelsByAlias.set(channel.alias, channel); + } + + this._initialized = true; + } catch (error) { + console.error('[Channels] Failed to initialize cache:', error); + } + } }