@ipcom/asterisk-ari 0.0.140 → 0.0.142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -1005,6 +1005,7 @@ var Bridges = class {
1005
1005
 
1006
1006
  // src/ari-client/resources/channels.ts
1007
1007
  import { EventEmitter } from "events";
1008
+ import { isAxiosError as isAxiosError2 } from "axios";
1008
1009
 
1009
1010
  // node_modules/uuid/dist/esm/stringify.js
1010
1011
  var byteToHex = [];
@@ -1059,7 +1060,6 @@ function toQueryParams2(options) {
1059
1060
  }
1060
1061
 
1061
1062
  // src/ari-client/resources/channels.ts
1062
- import { isAxiosError as isAxiosError2 } from "axios";
1063
1063
  var getErrorMessage = (error) => {
1064
1064
  if (isAxiosError2(error)) {
1065
1065
  return error.response?.data?.message || error.message || "An axios error occurred";
@@ -1107,7 +1107,9 @@ var ChannelInstance = class {
1107
1107
  }
1108
1108
  };
1109
1109
  this.eventEmitter.once(event, wrappedListener);
1110
- console.log(`One-time event listener registered for ${event} on channel ${this.id}`);
1110
+ console.log(
1111
+ `One-time event listener registered for ${event} on channel ${this.id}`
1112
+ );
1111
1113
  }
1112
1114
  /**
1113
1115
  * Removes event listener(s) for a specific WebSocket event type.
@@ -1124,7 +1126,9 @@ var ChannelInstance = class {
1124
1126
  }
1125
1127
  if (listener) {
1126
1128
  this.eventEmitter.off(event, listener);
1127
- console.log(`Specific listener removed for ${event} on channel ${this.id}`);
1129
+ console.log(
1130
+ `Specific listener removed for ${event} on channel ${this.id}`
1131
+ );
1128
1132
  } else {
1129
1133
  this.eventEmitter.removeAllListeners(event);
1130
1134
  console.log(`All listeners removed for ${event} on channel ${this.id}`);
@@ -1178,8 +1182,13 @@ var ChannelInstance = class {
1178
1182
  throw new Error("Channel has already been created");
1179
1183
  }
1180
1184
  try {
1181
- this.channelData = await this.baseClient.post("/channels", data);
1182
- console.log(`Channel originated successfully with ID: ${this.channelData.id}`);
1185
+ this.channelData = await this.baseClient.post(
1186
+ "/channels",
1187
+ data
1188
+ );
1189
+ console.log(
1190
+ `Channel originated successfully with ID: ${this.channelData.id}`
1191
+ );
1183
1192
  return this.channelData;
1184
1193
  } catch (error) {
1185
1194
  const message = getErrorMessage(error);
@@ -1223,13 +1232,18 @@ var ChannelInstance = class {
1223
1232
  if (!this.id) {
1224
1233
  throw new Error("No channel ID associated with this instance");
1225
1234
  }
1226
- const details = await this.baseClient.get(`/channels/${this.id}`);
1235
+ const details = await this.baseClient.get(
1236
+ `/channels/${this.id}`
1237
+ );
1227
1238
  this.channelData = details;
1228
1239
  console.log(`Retrieved channel details for ${this.id}`);
1229
1240
  return details;
1230
1241
  } catch (error) {
1231
1242
  const message = getErrorMessage(error);
1232
- console.error(`Error retrieving channel details for ${this.id}:`, message);
1243
+ console.error(
1244
+ `Error retrieving channel details for ${this.id}:`,
1245
+ message
1246
+ );
1233
1247
  throw new Error(`Failed to get channel details: ${message}`);
1234
1248
  }
1235
1249
  }
@@ -1438,10 +1452,23 @@ var Channels = class {
1438
1452
  }
1439
1453
  channelInstances = /* @__PURE__ */ new Map();
1440
1454
  /**
1441
- * Creates or retrieves a ChannelInstance based on the provided id.
1455
+ * Creates or retrieves a ChannelInstance.
1456
+ *
1457
+ * @param {Object} [params] - Optional parameters for getting/creating a channel instance
1458
+ * @param {string} [params.id] - Optional ID of an existing channel
1459
+ * @returns {ChannelInstance} The requested or new channel instance
1460
+ * @throws {Error} If channel creation/retrieval fails
1461
+ *
1462
+ * @example
1463
+ * // Create new channel without ID
1464
+ * const channel1 = client.channels.Channel();
1465
+ *
1466
+ * // Create/retrieve channel with specific ID
1467
+ * const channel2 = client.channels.Channel({ id: 'some-id' });
1442
1468
  */
1443
- Channel({ id }) {
1469
+ Channel(params) {
1444
1470
  try {
1471
+ const id = params?.id;
1445
1472
  if (!id) {
1446
1473
  const instance = new ChannelInstance(this.client, this.baseClient);
1447
1474
  this.channelInstances.set(instance.id, instance);
@@ -1462,6 +1489,27 @@ var Channels = class {
1462
1489
  throw new Error(`Failed to manage channel instance: ${message}`);
1463
1490
  }
1464
1491
  }
1492
+ /**
1493
+ * Retrieves the details of a specific channel.
1494
+ *
1495
+ * @param {string} id - The unique identifier of the channel to retrieve.
1496
+ * @returns {Promise<Channel>} A promise that resolves to the Channel object containing the channel details.
1497
+ * @throws {Error} If no channel ID is associated with this instance or if there's an error retrieving the channel details.
1498
+ */
1499
+ async get(id) {
1500
+ try {
1501
+ if (id) {
1502
+ throw new Error("No channel ID associated with this instance");
1503
+ }
1504
+ const details = await this.baseClient.get(`/channels/${id}`);
1505
+ console.log(`Retrieved channel details for ${id}`);
1506
+ return details;
1507
+ } catch (error) {
1508
+ const message = getErrorMessage(error);
1509
+ console.error(`Error retrieving channel details for ${id}:`, message);
1510
+ throw new Error(`Failed to get channel details: ${message}`);
1511
+ }
1512
+ }
1465
1513
  /**
1466
1514
  * Removes a channel instance from the collection.
1467
1515
  */
@@ -1490,7 +1538,9 @@ var Channels = class {
1490
1538
  const instance = this.channelInstances.get(event.channel.id);
1491
1539
  if (instance) {
1492
1540
  instance.emitEvent(event);
1493
- console.log(`Event propagated to channel ${event.channel.id}: ${event.type}`);
1541
+ console.log(
1542
+ `Event propagated to channel ${event.channel.id}: ${event.type}`
1543
+ );
1494
1544
  } else {
1495
1545
  console.warn(`No instance found for channel ${event.channel.id}`);
1496
1546
  }
@@ -1997,7 +2047,9 @@ var PlaybackInstance = class {
1997
2047
  }
1998
2048
  };
1999
2049
  this.eventEmitter.on(event, wrappedListener);
2000
- console.log(`Event listener registered for ${event} on playback ${this.id}`);
2050
+ console.log(
2051
+ `Event listener registered for ${event} on playback ${this.id}`
2052
+ );
2001
2053
  }
2002
2054
  /**
2003
2055
  * Registers a one-time event listener for a specific WebSocket event type.
@@ -2015,7 +2067,9 @@ var PlaybackInstance = class {
2015
2067
  }
2016
2068
  };
2017
2069
  this.eventEmitter.once(event, wrappedListener);
2018
- console.log(`One-time event listener registered for ${event} on playback ${this.id}`);
2070
+ console.log(
2071
+ `One-time event listener registered for ${event} on playback ${this.id}`
2072
+ );
2019
2073
  }
2020
2074
  /**
2021
2075
  * Removes event listener(s) for a specific WebSocket event type.
@@ -2029,7 +2083,9 @@ var PlaybackInstance = class {
2029
2083
  }
2030
2084
  if (listener) {
2031
2085
  this.eventEmitter.off(event, listener);
2032
- console.log(`Specific listener removed for ${event} on playback ${this.id}`);
2086
+ console.log(
2087
+ `Specific listener removed for ${event} on playback ${this.id}`
2088
+ );
2033
2089
  } else {
2034
2090
  this.eventEmitter.removeAllListeners(event);
2035
2091
  console.log(`All listeners removed for ${event} on playback ${this.id}`);
@@ -2086,7 +2142,9 @@ var PlaybackInstance = class {
2086
2142
  await this.baseClient.post(
2087
2143
  `/playbacks/${this.id}/control?operation=${operation}`
2088
2144
  );
2089
- console.log(`Operation ${operation} executed successfully on playback ${this.id}`);
2145
+ console.log(
2146
+ `Operation ${operation} executed successfully on playback ${this.id}`
2147
+ );
2090
2148
  } catch (error) {
2091
2149
  const message = getErrorMessage2(error);
2092
2150
  console.error(`Error controlling playback ${this.id}:`, message);
@@ -2144,12 +2202,13 @@ var Playbacks = class {
2144
2202
  playbackInstances = /* @__PURE__ */ new Map();
2145
2203
  /**
2146
2204
  * Gets or creates a playback instance
2147
- * @param {Object} params - Parameters for getting/creating a playback instance
2205
+ * @param {Object} [params] - Optional parameters for getting/creating a playback instance
2148
2206
  * @param {string} [params.id] - Optional ID of an existing playback
2149
2207
  * @returns {PlaybackInstance} The requested or new playback instance
2150
2208
  */
2151
- Playback({ id }) {
2209
+ Playback(params) {
2152
2210
  try {
2211
+ const id = params?.id;
2153
2212
  if (!id) {
2154
2213
  const instance = new PlaybackInstance(this.client, this.baseClient);
2155
2214
  this.playbackInstances.set(instance.id, instance);
@@ -2201,7 +2260,9 @@ var Playbacks = class {
2201
2260
  const instance = this.playbackInstances.get(event.playback.id);
2202
2261
  if (instance) {
2203
2262
  instance.emitEvent(event);
2204
- console.log(`Event propagated to playback ${event.playback.id}: ${event.type}`);
2263
+ console.log(
2264
+ `Event propagated to playback ${event.playback.id}: ${event.type}`
2265
+ );
2205
2266
  } else {
2206
2267
  console.warn(`No instance found for playback ${event.playback.id}`);
2207
2268
  }