telnyx 2.0.0-alpha.0 → 2.0.0-alpha.2

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.
Files changed (298) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +0 -1
  3. package/VERSION +1 -1
  4. package/dist/Error.js +156 -0
  5. package/{src/TelnyxMethod.basic.ts → dist/TelnyxMethod.basic.js} +12 -17
  6. package/{src/TelnyxMethod.ts → dist/TelnyxMethod.js} +32 -58
  7. package/dist/TelnyxResource.js +393 -0
  8. package/dist/Webhooks.js +52 -0
  9. package/dist/autoPagination.js +201 -0
  10. package/dist/makeRequest.js +108 -0
  11. package/dist/multipart.js +60 -0
  12. package/{src/resources/AccessIpAddress.ts → dist/resources/AccessIpAddress.js} +2 -3
  13. package/{src/resources/AccessIpRanges.ts → dist/resources/AccessIpRanges.js} +2 -3
  14. package/dist/resources/Actions.js +8 -0
  15. package/dist/resources/ActionsSimCards.js +13 -0
  16. package/dist/resources/ActivateDeactivateBulkCredentials.js +15 -0
  17. package/dist/resources/Addresses.js +37 -0
  18. package/dist/resources/AiAssistants.js +21 -0
  19. package/dist/resources/AiAudioTranscriptions.js +5 -0
  20. package/dist/resources/AiChatCompletions.js +5 -0
  21. package/dist/resources/AiEmbeddings.js +11 -0
  22. package/dist/resources/AiEmbeddingsBuckets.js +16 -0
  23. package/dist/resources/AiEmbeddingsSimilaritySearch.js +5 -0
  24. package/dist/resources/AiModels.js +5 -0
  25. package/dist/resources/AiSummarize.js +5 -0
  26. package/{src/resources/AuthenticationProviders.ts → dist/resources/AuthenticationProviders.js} +2 -3
  27. package/dist/resources/AutorespConfigs.js +11 -0
  28. package/{src/resources/AvailablePhoneNumbers.ts → dist/resources/AvailablePhoneNumbers.js} +2 -3
  29. package/{src/resources/Balance.ts → dist/resources/Balance.js} +2 -3
  30. package/{src/resources/BillingGroups.ts → dist/resources/BillingGroups.js} +2 -3
  31. package/dist/resources/Brands.js +57 -0
  32. package/dist/resources/BulkCredentials.js +15 -0
  33. package/dist/resources/BulkSoleProprietorCreation.js +20 -0
  34. package/dist/resources/BulkTelephonyCredentials.js +36 -0
  35. package/dist/resources/BusinessIdentity.js +15 -0
  36. package/dist/resources/CallControlApplications.js +39 -0
  37. package/{src/resources/CallEvents.ts → dist/resources/CallEvents.js} +2 -3
  38. package/dist/resources/CallInformation.js +10 -0
  39. package/dist/resources/CallRecordings.js +22 -0
  40. package/dist/resources/Calls.js +64 -0
  41. package/dist/resources/Campaign.js +75 -0
  42. package/dist/resources/CampaignBuilder.js +35 -0
  43. package/dist/resources/CdrUsageReports.js +10 -0
  44. package/dist/resources/Channelzones.js +22 -0
  45. package/{src/resources/ClientStateUpdate.ts → dist/resources/ClientStateUpdate.js} +2 -3
  46. package/dist/resources/Conferences.js +46 -0
  47. package/{src/resources/Connections.ts → dist/resources/Connections.js} +2 -3
  48. package/{src/resources/CredentialConnections.ts → dist/resources/CredentialConnections.js} +2 -3
  49. package/dist/resources/Credentials.js +24 -0
  50. package/dist/resources/CsvDownloads.js +15 -0
  51. package/dist/resources/CustomerServiceRecord.js +18 -0
  52. package/dist/resources/Debugging.js +10 -0
  53. package/{src/resources/DetailRecords.ts → dist/resources/DetailRecords.js} +5 -7
  54. package/dist/resources/DialogflowIntegration.js +10 -0
  55. package/{src/resources/DocumentLinks.ts → dist/resources/DocumentLinks.js} +2 -3
  56. package/dist/resources/Documents.js +44 -0
  57. package/dist/resources/DynamicEmergency.js +9 -0
  58. package/{src/resources/DynamicEmergencyAddresses.ts → dist/resources/DynamicEmergencyAddresses.js} +2 -3
  59. package/{src/resources/DynamicEmergencyEndpoints.ts → dist/resources/DynamicEmergencyEndpoints.js} +2 -3
  60. package/{src/resources/Events.ts → dist/resources/Events.js} +2 -3
  61. package/dist/resources/ExternalConnections.js +71 -0
  62. package/dist/resources/FaxApplications.js +39 -0
  63. package/dist/resources/Faxes.js +36 -0
  64. package/dist/resources/FqdnConnections.js +39 -0
  65. package/dist/resources/Fqdns.js +39 -0
  66. package/dist/resources/GlobalIps.js +42 -0
  67. package/dist/resources/InboundChannels.js +10 -0
  68. package/{src/resources/InventoryCoverage.ts → dist/resources/InventoryCoverage.js} +5 -7
  69. package/dist/resources/InventoryLevel.js +10 -0
  70. package/dist/resources/IpAddresses.js +15 -0
  71. package/dist/resources/IpConnections.js +39 -0
  72. package/dist/resources/IpRanges.js +15 -0
  73. package/dist/resources/Ips.js +39 -0
  74. package/dist/resources/ManagedAccounts.js +48 -0
  75. package/dist/resources/MdrDetailReports.js +19 -0
  76. package/dist/resources/MdrUsageReports.js +19 -0
  77. package/dist/resources/MediaStorageApi.js +18 -0
  78. package/dist/resources/Messages.js +9 -0
  79. package/{src/resources/MessagesAlphanumericSenderId.ts → dist/resources/MessagesAlphanumericSenderId.js} +2 -3
  80. package/dist/resources/MessagingHostedNumber.js +25 -0
  81. package/{src/resources/MessagingHostedNumberOrders.ts → dist/resources/MessagingHostedNumberOrders.js} +2 -3
  82. package/{src/resources/MessagingHostedNumbers.ts → dist/resources/MessagingHostedNumbers.js} +2 -3
  83. package/{src/resources/MessagingPhoneNumbers.ts → dist/resources/MessagingPhoneNumbers.js} +2 -3
  84. package/{src/resources/MessagingProfileMetrics.ts → dist/resources/MessagingProfileMetrics.js} +2 -3
  85. package/dist/resources/MessagingProfiles.js +81 -0
  86. package/dist/resources/MessagingSenderIds.js +5 -0
  87. package/{src/resources/MessagingShortCodes.ts → dist/resources/MessagingShortCodes.js} +2 -3
  88. package/dist/resources/MessagingTollfreeVerification.js +15 -0
  89. package/dist/resources/MessagingUrlDomains.js +10 -0
  90. package/dist/resources/MobileNetworkOperators.js +10 -0
  91. package/{src/resources/MobileOperatorNetworks.ts → dist/resources/MobileOperatorNetworks.js} +2 -3
  92. package/dist/resources/Networks.js +22 -0
  93. package/dist/resources/NumberBackgroundJobs.js +18 -0
  94. package/{src/resources/NumberLookup.ts → dist/resources/NumberLookup.js} +2 -3
  95. package/dist/resources/NumberOrderDocuments.js +10 -0
  96. package/{src/resources/NumberOrders.ts → dist/resources/NumberOrders.js} +2 -3
  97. package/dist/resources/NumberPortouts.js +64 -0
  98. package/dist/resources/NumberReservations.js +22 -0
  99. package/dist/resources/NumbersFeatures.js +10 -0
  100. package/dist/resources/Object.js +16 -0
  101. package/dist/resources/OtaUpdates.js +14 -0
  102. package/dist/resources/OutboundVoiceProfiles.js +43 -0
  103. package/dist/resources/Payment.js +13 -0
  104. package/dist/resources/PhoneNumberAssignmentByProfile.js +52 -0
  105. package/dist/resources/PhoneNumberBlockOrders.js +15 -0
  106. package/dist/resources/PhoneNumberBlocksBackgroundJobs.js +19 -0
  107. package/dist/resources/PhoneNumberCampaigns.js +15 -0
  108. package/dist/resources/PhoneNumberOrderDocuments.js +15 -0
  109. package/{src/resources/PhoneNumberRegulatoryRequirements.ts → dist/resources/PhoneNumberRegulatoryRequirements.js} +2 -4
  110. package/dist/resources/PhoneNumberSearch.js +14 -0
  111. package/dist/resources/PhoneNumbers.js +41 -0
  112. package/dist/resources/PhoneNumbersInboundChannels.js +23 -0
  113. package/{src/resources/PhoneNumbersMessaging.ts → dist/resources/PhoneNumbersMessaging.js} +2 -3
  114. package/{src/resources/PhoneNumbersVoice.ts → dist/resources/PhoneNumbersVoice.js} +2 -3
  115. package/{src/resources/PortabilityChecks.ts → dist/resources/PortabilityChecks.js} +4 -6
  116. package/dist/resources/PortingOrders.js +85 -0
  117. package/{src/resources/PortingPhoneNumbers.ts → dist/resources/PortingPhoneNumbers.js} +2 -3
  118. package/dist/resources/PortoutRequests.js +47 -0
  119. package/dist/resources/PresignedObjectUrls.js +11 -0
  120. package/dist/resources/PrivateWirelessGateways.js +14 -0
  121. package/dist/resources/PublicInternetGateways.js +14 -0
  122. package/{src/resources/PublicKey.ts → dist/resources/PublicKey.js} +4 -6
  123. package/dist/resources/PushCredentials.js +15 -0
  124. package/dist/resources/Queues.js +48 -0
  125. package/dist/resources/RecordingsCommands.js +11 -0
  126. package/dist/resources/Regions.js +10 -0
  127. package/{src/resources/RegulatoryRequirements.ts → dist/resources/RegulatoryRequirements.js} +2 -4
  128. package/dist/resources/Reporting.js +14 -0
  129. package/dist/resources/Reports.js +14 -0
  130. package/{src/resources/ReportsMdrs.ts → dist/resources/ReportsMdrs.js} +2 -3
  131. package/dist/resources/RequirementTypes.js +14 -0
  132. package/dist/resources/Requirements.js +14 -0
  133. package/{src/resources/RoomCompositions.ts → dist/resources/RoomCompositions.js} +2 -3
  134. package/{src/resources/RoomParticipants.ts → dist/resources/RoomParticipants.js} +2 -3
  135. package/dist/resources/RoomRecordings.js +15 -0
  136. package/dist/resources/RoomSessions.js +38 -0
  137. package/{src/resources/Rooms.ts → dist/resources/Rooms.js} +2 -3
  138. package/dist/resources/RoomsClientToken.js +15 -0
  139. package/dist/resources/RoomsClientTokens.js +16 -0
  140. package/dist/resources/SharedCampaigns.js +15 -0
  141. package/dist/resources/ShortCodes.js +27 -0
  142. package/dist/resources/SimCardActions.js +22 -0
  143. package/dist/resources/SimCardGroupActions.js +14 -0
  144. package/dist/resources/SimCardGroups.js +39 -0
  145. package/{src/resources/SimCardOrders.ts → dist/resources/SimCardOrders.js} +2 -3
  146. package/dist/resources/SimCards.js +103 -0
  147. package/dist/resources/StorageBuckets.js +30 -0
  148. package/dist/resources/TelephonyCredentials.js +35 -0
  149. package/{src/resources/TexmlApplications.ts → dist/resources/TexmlApplications.js} +2 -3
  150. package/dist/resources/UpdateClientState.js +14 -0
  151. package/dist/resources/Verifications.js +53 -0
  152. package/{src/resources/VerifiedNumbers.ts → dist/resources/VerifiedNumbers.js} +2 -3
  153. package/dist/resources/Verify.js +50 -0
  154. package/dist/resources/VerifyProfiles.js +45 -0
  155. package/dist/resources/VirtualCrossConnects.js +26 -0
  156. package/dist/resources/WdrDetailReports.js +10 -0
  157. package/{src/resources/Webhooks.ts → dist/resources/Webhooks.js} +2 -3
  158. package/dist/resources/WireguardInterfaces.js +34 -0
  159. package/{src/resources/WirelessDetailRecordReports.ts → dist/resources/WirelessDetailRecordReports.js} +2 -3
  160. package/dist/telnyx.js +567 -0
  161. package/{types → dist/types}/AccessIpRangesResource.d.ts +1 -1
  162. package/{types → dist/types}/AddressesResource.d.ts +5 -5
  163. package/dist/types/AiAssistantsResource.d.ts +69 -0
  164. package/dist/types/AiAudioTranscriptionsResource.d.ts +18 -0
  165. package/dist/types/AiChatCompletionsResource.d.ts +18 -0
  166. package/dist/types/AiEmbeddingsBucketsResource.d.ts +46 -0
  167. package/dist/types/AiEmbeddingsResource.d.ts +43 -0
  168. package/dist/types/AiEmbeddingsSimilaritySearchResource.d.ts +20 -0
  169. package/dist/types/AiModelsResource.d.ts +17 -0
  170. package/dist/types/AiSummarizeResource.d.ts +18 -0
  171. package/{types → dist/types}/AutorespConfigsResource.d.ts +4 -4
  172. package/{types → dist/types}/AvailablePhoneNumbersResource.d.ts +1 -1
  173. package/{types → dist/types}/BalanceResource.d.ts +1 -1
  174. package/{types → dist/types}/BillingGroupsResource.d.ts +5 -5
  175. package/{types → dist/types}/CallsResource.d.ts +30 -30
  176. package/{types → dist/types}/MessagingProfileMetricsResource.d.ts +1 -1
  177. package/{types → dist/types}/MessagingProfilesResource.d.ts +8 -8
  178. package/{types → dist/types}/StorageBucketsResource.d.ts +5 -5
  179. package/{types → dist/types}/index.d.ts +17 -0
  180. package/{types → dist/types}/lib.d.ts +1 -1
  181. package/dist/utils.js +277 -0
  182. package/package.json +1 -1
  183. package/src/Error.ts +0 -196
  184. package/src/TelnyxResource.ts +0 -556
  185. package/src/Types.d.ts +0 -244
  186. package/src/Webhooks.ts +0 -98
  187. package/src/autoPagination.ts +0 -315
  188. package/src/makeRequest.ts +0 -163
  189. package/src/multipart.ts +0 -99
  190. package/src/resources/AI.ts +0 -43
  191. package/src/resources/Actions.ts +0 -9
  192. package/src/resources/ActionsSimCards.ts +0 -16
  193. package/src/resources/ActivateDeactivateBulkCredentials.ts +0 -22
  194. package/src/resources/Addresses.ts +0 -51
  195. package/src/resources/AutorespConfigs.ts +0 -13
  196. package/src/resources/Brands.ts +0 -68
  197. package/src/resources/BulkCredentials.ts +0 -17
  198. package/src/resources/BulkSoleProprietorCreation.ts +0 -22
  199. package/src/resources/BulkTelephonyCredentials.ts +0 -49
  200. package/src/resources/BusinessIdentity.ts +0 -17
  201. package/src/resources/CallControlApplications.ts +0 -57
  202. package/src/resources/CallInformation.ts +0 -12
  203. package/src/resources/CallRecordings.ts +0 -24
  204. package/src/resources/Calls.ts +0 -94
  205. package/src/resources/Campaign.ts +0 -87
  206. package/src/resources/CampaignBuilder.ts +0 -43
  207. package/src/resources/CdrUsageReports.ts +0 -12
  208. package/src/resources/Channelzones.ts +0 -24
  209. package/src/resources/Conferences.ts +0 -67
  210. package/src/resources/Credentials.ts +0 -26
  211. package/src/resources/CsvDownloads.ts +0 -17
  212. package/src/resources/CustomerServiceRecord.ts +0 -20
  213. package/src/resources/Debugging.ts +0 -12
  214. package/src/resources/DialogflowIntegration.ts +0 -12
  215. package/src/resources/Documents.ts +0 -53
  216. package/src/resources/DynamicEmergency.ts +0 -10
  217. package/src/resources/ExternalConnections.ts +0 -73
  218. package/src/resources/FaxApplications.ts +0 -53
  219. package/src/resources/Faxes.ts +0 -51
  220. package/src/resources/FqdnConnections.ts +0 -53
  221. package/src/resources/Fqdns.ts +0 -53
  222. package/src/resources/GlobalIps.ts +0 -44
  223. package/src/resources/InboundChannels.ts +0 -12
  224. package/src/resources/InventoryLevel.ts +0 -12
  225. package/src/resources/IpAddresses.ts +0 -17
  226. package/src/resources/IpConnections.ts +0 -53
  227. package/src/resources/IpRanges.ts +0 -17
  228. package/src/resources/Ips.ts +0 -53
  229. package/src/resources/ManagedAccounts.ts +0 -60
  230. package/src/resources/MdrDetailReports.ts +0 -21
  231. package/src/resources/MdrUsageReports.ts +0 -21
  232. package/src/resources/MediaStorageApi.ts +0 -20
  233. package/src/resources/Messages.ts +0 -11
  234. package/src/resources/MessagingHostedNumber.ts +0 -27
  235. package/src/resources/MessagingProfiles.ts +0 -112
  236. package/src/resources/MessagingSenderIds.ts +0 -6
  237. package/src/resources/MessagingTollfreeVerification.ts +0 -17
  238. package/src/resources/MessagingUrlDomains.ts +0 -12
  239. package/src/resources/MobileNetworkOperators.ts +0 -12
  240. package/src/resources/Networks.ts +0 -24
  241. package/src/resources/NumberBackgroundJobs.ts +0 -22
  242. package/src/resources/NumberOrderDocuments.ts +0 -12
  243. package/src/resources/NumberPortouts.ts +0 -74
  244. package/src/resources/NumberReservations.ts +0 -30
  245. package/src/resources/NumbersFeatures.ts +0 -12
  246. package/src/resources/Object.ts +0 -18
  247. package/src/resources/OtaUpdates.ts +0 -16
  248. package/src/resources/OutboundVoiceProfiles.ts +0 -63
  249. package/src/resources/Payment.ts +0 -16
  250. package/src/resources/PhoneNumberAssignmentByProfile.ts +0 -74
  251. package/src/resources/PhoneNumberBlockOrders.ts +0 -17
  252. package/src/resources/PhoneNumberBlocksBackgroundJobs.ts +0 -21
  253. package/src/resources/PhoneNumberCampaigns.ts +0 -17
  254. package/src/resources/PhoneNumberOrderDocuments.ts +0 -17
  255. package/src/resources/PhoneNumberSearch.ts +0 -16
  256. package/src/resources/PhoneNumbers.ts +0 -49
  257. package/src/resources/PhoneNumbersInboundChannels.ts +0 -37
  258. package/src/resources/PortingOrders.ts +0 -105
  259. package/src/resources/PortoutRequests.ts +0 -51
  260. package/src/resources/PresignedObjectUrls.ts +0 -13
  261. package/src/resources/PrivateWirelessGateways.ts +0 -16
  262. package/src/resources/PublicInternetGateways.ts +0 -16
  263. package/src/resources/PushCredentials.ts +0 -17
  264. package/src/resources/Queues.ts +0 -68
  265. package/src/resources/RecordingsCommands.ts +0 -13
  266. package/src/resources/Regions.ts +0 -12
  267. package/src/resources/Reporting.ts +0 -16
  268. package/src/resources/Reports.ts +0 -16
  269. package/src/resources/RequirementTypes.ts +0 -16
  270. package/src/resources/Requirements.ts +0 -16
  271. package/src/resources/RoomRecordings.ts +0 -17
  272. package/src/resources/RoomSessions.ts +0 -41
  273. package/src/resources/RoomsClientToken.ts +0 -16
  274. package/src/resources/RoomsClientTokens.ts +0 -18
  275. package/src/resources/SharedCampaigns.ts +0 -17
  276. package/src/resources/ShortCodes.ts +0 -37
  277. package/src/resources/SimCardActions.ts +0 -24
  278. package/src/resources/SimCardGroupActions.ts +0 -16
  279. package/src/resources/SimCardGroups.ts +0 -53
  280. package/src/resources/SimCards.ts +0 -126
  281. package/src/resources/StorageBuckets.ts +0 -36
  282. package/src/resources/TelephonyCredentials.ts +0 -57
  283. package/src/resources/UpdateClientState.ts +0 -25
  284. package/src/resources/Verifications.ts +0 -70
  285. package/src/resources/Verify.ts +0 -52
  286. package/src/resources/VerifyProfiles.ts +0 -62
  287. package/src/resources/VirtualCrossConnects.ts +0 -28
  288. package/src/resources/WdrDetailReports.ts +0 -12
  289. package/src/resources/WireguardInterfaces.ts +0 -36
  290. package/src/telnyx.node.ts +0 -5
  291. package/src/telnyx.ts +0 -636
  292. package/src/utils.ts +0 -383
  293. /package/{types → dist/types}/AccessIpAddressResource.d.ts +0 -0
  294. /package/{types → dist/types}/BrandsResource.d.ts +0 -0
  295. /package/{types → dist/types}/Errors.d.ts +0 -0
  296. /package/{types → dist/types}/PhoneNumberAssignmentByProfileResource.d.ts +0 -0
  297. /package/{types → dist/types}/TelnyxAPI.d.ts +0 -0
  298. /package/{types → dist/types}/Webhooks.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## v2
4
4
 
5
+ ### v2.0.0-alpha.2
6
+
7
+ - Fix `AI` resource methods and created nested structure
8
+
9
+ ### v2.0.0-alpha.1
10
+
11
+ - Update actions workflow versions to v4 and `.npmignore` to v2
12
+ - Update examples dependencies
13
+
5
14
  ### v2.0.0-alpha.0
6
15
 
7
16
  - Add Typescript default config, linter and dependencies
package/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Version](https://img.shields.io/npm/v/telnyx.svg)](https://www.npmjs.org/package/telnyx)
4
4
  [![Build Status](https://github.com/team-telnyx/telnyx-node/workflows/CI/badge.svg)](https://github.com/team-telnyx/telnyx-node/actions)
5
- Coverage Status: Pending
6
5
  [![Downloads](https://img.shields.io/npm/dm/telnyx.svg)](https://www.npmjs.com/package/telnyx)
7
6
  [![Try on RunKit](https://badge.runkitcdn.com/telnyx.svg)](https://runkit.com/npm/telnyx)
8
7
  [![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://joinslack.telnyx.com/)
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0-alpha.0
1
+ 2.0.0-alpha.2
package/dist/Error.js ADDED
@@ -0,0 +1,156 @@
1
+ export const generate = (rawTelnyxError) => {
2
+ switch (rawTelnyxError.statusCode) {
3
+ case 400:
4
+ return new TelnyxInvalidRequestError(rawTelnyxError);
5
+ case 401:
6
+ return new TelnyxAuthenticationError(rawTelnyxError);
7
+ case 403:
8
+ return new TelnyxPermissionError(rawTelnyxError);
9
+ case 404:
10
+ return new TelnyxResourceNotFoundError(rawTelnyxError);
11
+ case 405:
12
+ return new TelnyxMethodNotSupportedError(rawTelnyxError);
13
+ case 408:
14
+ return new TelnyxTimeoutError(rawTelnyxError);
15
+ case 415:
16
+ return new TelnyxUnsupportedMediaTypeError(rawTelnyxError);
17
+ case 422:
18
+ return new TelnyxInvalidParametersError(rawTelnyxError);
19
+ case 429:
20
+ return new TelnyxRateLimitError(rawTelnyxError);
21
+ case 500:
22
+ return new TelnyxAPIError(rawTelnyxError);
23
+ case 503:
24
+ return new TelnyxServiceUnavailableError(rawTelnyxError);
25
+ }
26
+ return new TelnyxError({ type: 'Generic', message: 'Unknown Error' });
27
+ };
28
+ /**
29
+ * TelnyxError is the base error from which all other more specific Telnyx errors derive.
30
+ * Specifically for errors returned from Telnyx's REST API.
31
+ */
32
+ export class TelnyxError extends Error {
33
+ message;
34
+ type;
35
+ raw;
36
+ headers;
37
+ requestId;
38
+ detail;
39
+ code;
40
+ statusCode;
41
+ responseBody;
42
+ constructor(raw = {}, type = null) {
43
+ super(raw.message);
44
+ this.type = type || this.constructor.name;
45
+ this.raw = raw;
46
+ this.code = raw.code;
47
+ this.detail = raw.detail;
48
+ this.headers = raw.headers;
49
+ this.requestId = raw.requestId;
50
+ this.statusCode = raw.statusCode;
51
+ this.responseBody = raw.responseBody;
52
+ // @ts-expect-error message needs to be required here
53
+ this.message = raw.message;
54
+ }
55
+ /**
56
+ * Helper factory which takes raw Telnyx errors and outputs wrapping instances
57
+ */
58
+ static generate = generate;
59
+ }
60
+ /**
61
+ * InvalidRequestError is raised when a request is initiated with invalid
62
+ * parameters.
63
+ */
64
+ export class TelnyxInvalidRequestError extends TelnyxError {
65
+ constructor(raw = {}) {
66
+ super(raw, 'TelnyxInvalidRequestError');
67
+ }
68
+ }
69
+ /**
70
+ * APIError is a generic error that may be raised in cases where none of the
71
+ * other named errors cover the problem. It could also be raised in the case
72
+ * that a new error has been introduced in the API, but this version of the
73
+ * Node.JS SDK doesn't know how to handle it.
74
+ */
75
+ export class TelnyxAPIError extends TelnyxError {
76
+ constructor(raw = {}) {
77
+ super(raw, 'TelnyxAPIError');
78
+ }
79
+ }
80
+ /**
81
+ * AuthenticationError is raised when invalid credentials are used to connect
82
+ * to Telnyx's servers.
83
+ */
84
+ export class TelnyxAuthenticationError extends TelnyxError {
85
+ constructor(raw = {}) {
86
+ super(raw, 'TelnyxAuthenticationError');
87
+ }
88
+ }
89
+ /**
90
+ * PermissionError is raised in cases where access was attempted on a resource
91
+ * that wasn't allowed.
92
+ */
93
+ export class TelnyxPermissionError extends TelnyxError {
94
+ constructor(raw = {}) {
95
+ super(raw, 'TelnyxPermissionError');
96
+ }
97
+ }
98
+ export class TelnyxResourceNotFoundError extends TelnyxError {
99
+ constructor(raw = {}) {
100
+ super(raw, 'TelnyxResourceNotFoundError');
101
+ }
102
+ }
103
+ export class TelnyxMethodNotSupportedError extends TelnyxError {
104
+ constructor(raw = {}) {
105
+ super(raw, 'TelnyxMethodNotSupportedError');
106
+ }
107
+ }
108
+ export class TelnyxTimeoutError extends TelnyxError {
109
+ constructor(raw = {}) {
110
+ super(raw, 'TelnyxTimeoutError');
111
+ }
112
+ }
113
+ export class TelnyxUnsupportedMediaTypeError extends TelnyxError {
114
+ constructor(raw = {}) {
115
+ super(raw, 'TelnyxUnsupportedMediaTypeError');
116
+ }
117
+ }
118
+ export class TelnyxInvalidParametersError extends TelnyxError {
119
+ constructor(raw = {}) {
120
+ super(raw, 'TelnyxInvalidParametersError');
121
+ }
122
+ }
123
+ /**
124
+ * RateLimitError is raised in cases where an account is putting too much load
125
+ * on Telnyx's API servers (usually by performing too many requests). Please
126
+ * back off on request rate.
127
+ */
128
+ export class TelnyxRateLimitError extends TelnyxError {
129
+ constructor(raw = {}) {
130
+ super(raw, 'TelnyxRateLimitError');
131
+ }
132
+ }
133
+ export class TelnyxServiceUnavailableError extends TelnyxError {
134
+ constructor(raw = {}) {
135
+ super(raw, 'TelnyxServiceUnavailableError');
136
+ }
137
+ }
138
+ /**
139
+ * TelnyxConnectionError is raised in the event that the SDK can't connect to
140
+ * Telnyx's servers. That can be for a variety of different reasons from a
141
+ * downed network to a bad TLS certificate.
142
+ */
143
+ export class TelnyxConnectionError extends TelnyxError {
144
+ constructor(raw = {}) {
145
+ super(raw, 'TelnyxConnectionError');
146
+ }
147
+ }
148
+ /**
149
+ * SignatureVerificationError is raised when the signature verification for a
150
+ * webhook fails
151
+ */
152
+ export class TelnyxSignatureVerificationError extends TelnyxError {
153
+ constructor(raw = {}) {
154
+ super(raw, 'TelnyxSignatureVerificationError');
155
+ }
156
+ }
@@ -1,29 +1,24 @@
1
1
  import telnyxMethod from './TelnyxMethod';
2
-
3
2
  export const create = telnyxMethod({
4
- method: 'POST',
3
+ method: 'POST',
5
4
  });
6
-
7
5
  export const list = telnyxMethod({
8
- method: 'GET',
9
- methodType: 'list',
6
+ method: 'GET',
7
+ methodType: 'list',
10
8
  });
11
-
12
9
  export const retrieve = telnyxMethod({
13
- method: 'GET',
14
- path: '/{id}',
15
- urlParams: ['id'],
10
+ method: 'GET',
11
+ path: '/{id}',
12
+ urlParams: ['id'],
16
13
  });
17
-
18
14
  export const update = telnyxMethod({
19
- method: 'PATCH',
20
- path: '{id}',
21
- urlParams: ['id'],
15
+ method: 'PATCH',
16
+ path: '{id}',
17
+ urlParams: ['id'],
22
18
  });
23
-
24
19
  // Avoid 'delete' keyword in JS
25
20
  export const del = telnyxMethod({
26
- method: 'DELETE',
27
- path: '{id}',
28
- urlParams: ['id'],
21
+ method: 'DELETE',
22
+ path: '{id}',
23
+ urlParams: ['id'],
29
24
  });
@@ -1,8 +1,6 @@
1
- import {MethodSpec, TelnyxResourceObject} from './Types';
2
1
  import * as utils from './utils';
3
2
  import makeRequest from './makeRequest';
4
- import {makeAutoPaginationMethods} from './autoPagination';
5
-
3
+ import { makeAutoPaginationMethods } from './autoPagination';
6
4
  /**
7
5
  * Create an API method from the declared spec.
8
6
  *
@@ -22,66 +20,42 @@ import {makeAutoPaginationMethods} from './autoPagination';
22
20
  * @param [spec.host] Hostname for the request.
23
21
  * @param [spec.transformResponseData] mutates response data to decorate with any util functions or info.
24
22
  */
25
- function telnyxMethod(
26
- spec: MethodSpec,
27
- ): (...args: unknown[]) => Promise<unknown> {
28
- return function (
29
- this: TelnyxResourceObject,
23
+ function telnyxMethod(spec) {
24
+ return function (
30
25
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- ...args: any[] // needs to be any since callback is extracted from these args and there's no easy way to type all args
32
- ): Promise<unknown> {
33
- if (spec.paramsValues) {
34
- populateUrlParamsWithResource(this, args, spec);
35
- }
36
-
37
- const callback = typeof args[args.length - 1] == 'function' && args.pop();
38
-
39
- const requestPromise = utils.callbackifyPromiseWithTimeout(
40
- makeRequest(this, args, spec, {}),
41
- callback,
42
- );
43
-
44
- if (spec.methodType === 'list') {
45
- const autoPaginationMethods = makeAutoPaginationMethods(
46
- this,
47
- args,
48
- spec,
49
- requestPromise,
50
- );
51
- Object.assign(requestPromise, autoPaginationMethods);
52
- }
53
-
54
- return requestPromise;
55
- };
26
+ ...args // needs to be any since callback is extracted from these args and there's no easy way to type all args
27
+ ) {
28
+ if (spec.paramsValues) {
29
+ populateUrlParamsWithResource(this, args, spec);
30
+ }
31
+ const callback = typeof args[args.length - 1] == 'function' && args.pop();
32
+ const requestPromise = utils.callbackifyPromiseWithTimeout(makeRequest(this, args, spec, {}), callback);
33
+ if (spec.methodType === 'list') {
34
+ const autoPaginationMethods = makeAutoPaginationMethods(this, args, spec, requestPromise);
35
+ Object.assign(requestPromise, autoPaginationMethods);
36
+ }
37
+ return requestPromise;
38
+ };
56
39
  }
57
-
58
40
  /**
59
41
  * Populate nested method URL params with resource object attributes that match the param name.
60
42
  * This allows you to do things like setting the `call_control_id` attribute from an existing call object on a new instance of `telnyx.calls`.
61
43
  */
62
- function populateUrlParamsWithResource(
63
- self: TelnyxResourceObject,
64
- args: unknown[],
65
- spec: MethodSpec,
66
- ) {
67
- // if url params is not in resource response data.
68
- if (spec.paramsValues && !spec.paramsValues[0]) {
69
- const paramsValues = (spec.paramsNames || []).reduce(function (
70
- result,
71
- name,
72
- ) {
73
- // @ts-expect-error TODO: cast name to index of self
74
- if (self[name]) {
75
- // @ts-expect-error TODO: cast name to index of self
76
- result.push(self[name]);
77
- }
78
- return result;
79
- }, []);
80
-
81
- args.unshift(paramsValues);
82
- } else {
83
- args.unshift(spec.paramsValues);
84
- }
44
+ function populateUrlParamsWithResource(self, args, spec) {
45
+ // if url params is not in resource response data.
46
+ if (spec.paramsValues && !spec.paramsValues[0]) {
47
+ const paramsValues = (spec.paramsNames || []).reduce(function (result, name) {
48
+ // @ts-expect-error TODO: cast name to index of self
49
+ if (self[name]) {
50
+ // @ts-expect-error TODO: cast name to index of self
51
+ result.push(self[name]);
52
+ }
53
+ return result;
54
+ }, []);
55
+ args.unshift(paramsValues);
56
+ }
57
+ else {
58
+ args.unshift(spec.paramsValues);
59
+ }
85
60
  }
86
-
87
61
  export default telnyxMethod;