telnyx 1.27.0 → 2.0.0-alpha.1

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 (336) hide show
  1. package/CHANGELOG.md +50 -1
  2. package/LICENSE +1 -1
  3. package/README.md +117 -100
  4. package/VERSION +1 -1
  5. package/dist/Error.js +156 -0
  6. package/dist/TelnyxMethod.basic.js +24 -0
  7. package/{lib → dist}/TelnyxMethod.js +34 -41
  8. package/dist/TelnyxResource.js +393 -0
  9. package/dist/Webhooks.js +52 -0
  10. package/dist/autoPagination.js +201 -0
  11. package/dist/makeRequest.js +108 -0
  12. package/dist/multipart.js +60 -0
  13. package/dist/resources/AI.js +40 -0
  14. package/dist/resources/AccessIpAddress.js +5 -0
  15. package/dist/resources/AccessIpRanges.js +5 -0
  16. package/dist/resources/Actions.js +8 -0
  17. package/dist/resources/ActionsSimCards.js +13 -0
  18. package/dist/resources/ActivateDeactivateBulkCredentials.js +15 -0
  19. package/dist/resources/Addresses.js +37 -0
  20. package/dist/resources/AuthenticationProviders.js +5 -0
  21. package/dist/resources/AutorespConfigs.js +11 -0
  22. package/dist/resources/AvailablePhoneNumbers.js +5 -0
  23. package/dist/resources/Balance.js +5 -0
  24. package/dist/resources/BillingGroups.js +5 -0
  25. package/dist/resources/Brands.js +57 -0
  26. package/dist/resources/BulkCredentials.js +15 -0
  27. package/dist/resources/BulkSoleProprietorCreation.js +20 -0
  28. package/dist/resources/BulkTelephonyCredentials.js +36 -0
  29. package/dist/resources/BusinessIdentity.js +15 -0
  30. package/dist/resources/CallControlApplications.js +39 -0
  31. package/dist/resources/CallEvents.js +5 -0
  32. package/dist/resources/CallInformation.js +10 -0
  33. package/dist/resources/CallRecordings.js +22 -0
  34. package/dist/resources/Calls.js +64 -0
  35. package/dist/resources/Campaign.js +75 -0
  36. package/dist/resources/CampaignBuilder.js +35 -0
  37. package/dist/resources/CdrUsageReports.js +10 -0
  38. package/dist/resources/Channelzones.js +22 -0
  39. package/dist/resources/ClientStateUpdate.js +5 -0
  40. package/dist/resources/Conferences.js +46 -0
  41. package/dist/resources/Connections.js +5 -0
  42. package/dist/resources/CredentialConnections.js +5 -0
  43. package/dist/resources/Credentials.js +24 -0
  44. package/dist/resources/CsvDownloads.js +15 -0
  45. package/dist/resources/CustomerServiceRecord.js +18 -0
  46. package/dist/resources/Debugging.js +10 -0
  47. package/dist/resources/DetailRecords.js +9 -0
  48. package/dist/resources/DialogflowIntegration.js +10 -0
  49. package/dist/resources/DocumentLinks.js +5 -0
  50. package/dist/resources/Documents.js +44 -0
  51. package/dist/resources/DynamicEmergency.js +9 -0
  52. package/dist/resources/DynamicEmergencyAddresses.js +5 -0
  53. package/dist/resources/DynamicEmergencyEndpoints.js +5 -0
  54. package/dist/resources/Events.js +5 -0
  55. package/dist/resources/ExternalConnections.js +71 -0
  56. package/dist/resources/FaxApplications.js +39 -0
  57. package/dist/resources/Faxes.js +36 -0
  58. package/dist/resources/FqdnConnections.js +39 -0
  59. package/dist/resources/Fqdns.js +39 -0
  60. package/dist/resources/GlobalIps.js +42 -0
  61. package/dist/resources/InboundChannels.js +10 -0
  62. package/dist/resources/InventoryCoverage.js +9 -0
  63. package/dist/resources/InventoryLevel.js +10 -0
  64. package/dist/resources/IpAddresses.js +15 -0
  65. package/dist/resources/IpConnections.js +39 -0
  66. package/dist/resources/IpRanges.js +15 -0
  67. package/dist/resources/Ips.js +39 -0
  68. package/dist/resources/ManagedAccounts.js +48 -0
  69. package/dist/resources/MdrDetailReports.js +19 -0
  70. package/dist/resources/MdrUsageReports.js +19 -0
  71. package/dist/resources/MediaStorageApi.js +18 -0
  72. package/dist/resources/Messages.js +9 -0
  73. package/dist/resources/MessagesAlphanumericSenderId.js +5 -0
  74. package/dist/resources/MessagingHostedNumber.js +25 -0
  75. package/dist/resources/MessagingHostedNumberOrders.js +5 -0
  76. package/dist/resources/MessagingHostedNumbers.js +5 -0
  77. package/dist/resources/MessagingPhoneNumbers.js +5 -0
  78. package/dist/resources/MessagingProfileMetrics.js +5 -0
  79. package/dist/resources/MessagingProfiles.js +81 -0
  80. package/dist/resources/MessagingSenderIds.js +5 -0
  81. package/dist/resources/MessagingShortCodes.js +5 -0
  82. package/dist/resources/MessagingTollfreeVerification.js +15 -0
  83. package/dist/resources/MessagingUrlDomains.js +10 -0
  84. package/dist/resources/MobileNetworkOperators.js +10 -0
  85. package/dist/resources/MobileOperatorNetworks.js +5 -0
  86. package/dist/resources/Networks.js +22 -0
  87. package/dist/resources/NumberBackgroundJobs.js +18 -0
  88. package/dist/resources/NumberLookup.js +5 -0
  89. package/dist/resources/NumberOrderDocuments.js +10 -0
  90. package/dist/resources/NumberOrders.js +5 -0
  91. package/dist/resources/NumberPortouts.js +64 -0
  92. package/dist/resources/NumberReservations.js +22 -0
  93. package/dist/resources/NumbersFeatures.js +10 -0
  94. package/dist/resources/Object.js +16 -0
  95. package/dist/resources/OtaUpdates.js +14 -0
  96. package/dist/resources/OutboundVoiceProfiles.js +43 -0
  97. package/dist/resources/Payment.js +13 -0
  98. package/dist/resources/PhoneNumberAssignmentByProfile.js +52 -0
  99. package/dist/resources/PhoneNumberBlockOrders.js +15 -0
  100. package/dist/resources/PhoneNumberBlocksBackgroundJobs.js +19 -0
  101. package/dist/resources/PhoneNumberCampaigns.js +15 -0
  102. package/dist/resources/PhoneNumberOrderDocuments.js +15 -0
  103. package/dist/resources/PhoneNumberRegulatoryRequirements.js +5 -0
  104. package/dist/resources/PhoneNumberSearch.js +14 -0
  105. package/dist/resources/PhoneNumbers.js +41 -0
  106. package/dist/resources/PhoneNumbersInboundChannels.js +23 -0
  107. package/dist/resources/PhoneNumbersMessaging.js +5 -0
  108. package/dist/resources/PhoneNumbersVoice.js +5 -0
  109. package/dist/resources/PortabilityChecks.js +8 -0
  110. package/dist/resources/PortingOrders.js +85 -0
  111. package/dist/resources/PortingPhoneNumbers.js +5 -0
  112. package/dist/resources/PortoutRequests.js +47 -0
  113. package/dist/resources/PresignedObjectUrls.js +11 -0
  114. package/dist/resources/PrivateWirelessGateways.js +14 -0
  115. package/dist/resources/PublicInternetGateways.js +14 -0
  116. package/dist/resources/PublicKey.js +8 -0
  117. package/dist/resources/PushCredentials.js +15 -0
  118. package/dist/resources/Queues.js +48 -0
  119. package/dist/resources/RecordingsCommands.js +11 -0
  120. package/dist/resources/Regions.js +10 -0
  121. package/dist/resources/RegulatoryRequirements.js +5 -0
  122. package/dist/resources/Reporting.js +14 -0
  123. package/dist/resources/Reports.js +14 -0
  124. package/dist/resources/ReportsMdrs.js +5 -0
  125. package/dist/resources/RequirementTypes.js +14 -0
  126. package/dist/resources/Requirements.js +14 -0
  127. package/dist/resources/RoomCompositions.js +5 -0
  128. package/dist/resources/RoomParticipants.js +5 -0
  129. package/dist/resources/RoomRecordings.js +15 -0
  130. package/dist/resources/RoomSessions.js +38 -0
  131. package/dist/resources/Rooms.js +5 -0
  132. package/dist/resources/RoomsClientToken.js +15 -0
  133. package/dist/resources/RoomsClientTokens.js +16 -0
  134. package/dist/resources/SharedCampaigns.js +15 -0
  135. package/dist/resources/ShortCodes.js +27 -0
  136. package/dist/resources/SimCardActions.js +22 -0
  137. package/dist/resources/SimCardGroupActions.js +14 -0
  138. package/dist/resources/SimCardGroups.js +39 -0
  139. package/dist/resources/SimCardOrders.js +5 -0
  140. package/dist/resources/SimCards.js +103 -0
  141. package/dist/resources/StorageBuckets.js +30 -0
  142. package/dist/resources/TelephonyCredentials.js +35 -0
  143. package/dist/resources/TexmlApplications.js +5 -0
  144. package/dist/resources/UpdateClientState.js +14 -0
  145. package/dist/resources/Verifications.js +53 -0
  146. package/dist/resources/VerifiedNumbers.js +5 -0
  147. package/dist/resources/Verify.js +50 -0
  148. package/dist/resources/VerifyProfiles.js +45 -0
  149. package/dist/resources/VirtualCrossConnects.js +26 -0
  150. package/dist/resources/WdrDetailReports.js +10 -0
  151. package/dist/resources/Webhooks.js +5 -0
  152. package/dist/resources/WireguardInterfaces.js +34 -0
  153. package/dist/resources/WirelessDetailRecordReports.js +5 -0
  154. package/dist/telnyx.js +553 -0
  155. package/dist/telnyx.node.js +3 -0
  156. package/dist/types/AccessIpAddressResource.d.ts +57 -0
  157. package/dist/types/AccessIpRangesResource.d.ts +43 -0
  158. package/dist/types/AddressesResource.d.ts +78 -0
  159. package/dist/types/AutorespConfigsResource.d.ts +74 -0
  160. package/dist/types/AvailablePhoneNumbersResource.d.ts +18 -0
  161. package/dist/types/BalanceResource.d.ts +19 -0
  162. package/dist/types/BillingGroupsResource.d.ts +72 -0
  163. package/dist/types/BrandsResource.d.ts +142 -0
  164. package/dist/types/CallsResource.d.ts +299 -0
  165. package/dist/types/Errors.d.ts +131 -0
  166. package/dist/types/MessagingProfileMetricsResource.d.ts +18 -0
  167. package/dist/types/MessagingProfilesResource.d.ts +132 -0
  168. package/dist/types/PhoneNumberAssignmentByProfileResource.d.ts +53 -0
  169. package/dist/types/StorageBucketsResource.d.ts +74 -0
  170. package/dist/types/TelnyxAPI.d.ts +65420 -0
  171. package/dist/types/Webhooks.d.ts +26 -0
  172. package/dist/types/index.d.ts +60 -0
  173. package/dist/types/lib.d.ts +44 -0
  174. package/dist/utils.js +277 -0
  175. package/package.json +40 -33
  176. package/lib/Error.js +0 -143
  177. package/lib/MultipartDataGenerator.js +0 -45
  178. package/lib/TelnyxMethod.basic.js +0 -112
  179. package/lib/TelnyxResource.js +0 -479
  180. package/lib/Webhooks.js +0 -72
  181. package/lib/autoPagination.js +0 -231
  182. package/lib/makeRequest.js +0 -144
  183. package/lib/resources/AI.js +0 -45
  184. package/lib/resources/AccessIpAddress.js +0 -6
  185. package/lib/resources/AccessIpRanges.js +0 -6
  186. package/lib/resources/AccessTokens.js +0 -6
  187. package/lib/resources/Actions.js +0 -9
  188. package/lib/resources/ActionsSimCards.js +0 -18
  189. package/lib/resources/ActivateDeactivateBulkCredentials.js +0 -20
  190. package/lib/resources/Addresses.js +0 -47
  191. package/lib/resources/AdvancedOptinoptout.js +0 -21
  192. package/lib/resources/AuthenticationProviders.js +0 -8
  193. package/lib/resources/Autorechargepreferences.js +0 -15
  194. package/lib/resources/AvailablePhoneNumbers.js +0 -7
  195. package/lib/resources/Balance.js +0 -11
  196. package/lib/resources/Billing.js +0 -15
  197. package/lib/resources/BillingGroups.js +0 -6
  198. package/lib/resources/Brands.js +0 -36
  199. package/lib/resources/Bucket.js +0 -16
  200. package/lib/resources/BucketUsage.js +0 -21
  201. package/lib/resources/BulkCreation.js +0 -52
  202. package/lib/resources/BulkCredentials.js +0 -20
  203. package/lib/resources/BulkPhoneNumberCampaigns.js +0 -25
  204. package/lib/resources/BulkPhoneNumberOperations.js +0 -32
  205. package/lib/resources/BulkSoleProprietorCreation.js +0 -25
  206. package/lib/resources/BulkTelephonyCredentials.js +0 -46
  207. package/lib/resources/BusinessIdentity.js +0 -20
  208. package/lib/resources/CallControlApplications.js +0 -54
  209. package/lib/resources/CallEvents.js +0 -7
  210. package/lib/resources/CallInformation.js +0 -15
  211. package/lib/resources/CallRecordings.js +0 -27
  212. package/lib/resources/Calls.js +0 -73
  213. package/lib/resources/Campaign.js +0 -84
  214. package/lib/resources/CampaignBuilder.js +0 -40
  215. package/lib/resources/CdrUsageReports.js +0 -15
  216. package/lib/resources/Channelzones.js +0 -27
  217. package/lib/resources/ClientStateUpdate.js +0 -6
  218. package/lib/resources/Conferences.js +0 -62
  219. package/lib/resources/Connections.js +0 -8
  220. package/lib/resources/CredentialConnections.js +0 -6
  221. package/lib/resources/Credentials.js +0 -29
  222. package/lib/resources/CsvDownloads.js +0 -20
  223. package/lib/resources/CustomerServiceRecord.js +0 -23
  224. package/lib/resources/Debugging.js +0 -15
  225. package/lib/resources/DetailRecords.js +0 -13
  226. package/lib/resources/DialogflowIntegration.js +0 -15
  227. package/lib/resources/DocumentLinks.js +0 -6
  228. package/lib/resources/Documents.js +0 -50
  229. package/lib/resources/DynamicEmergency.js +0 -10
  230. package/lib/resources/DynamicEmergencyAddresses.js +0 -8
  231. package/lib/resources/DynamicEmergencyEndpoints.js +0 -8
  232. package/lib/resources/Events.js +0 -7
  233. package/lib/resources/ExternalConnections.js +0 -76
  234. package/lib/resources/FaxApplications.js +0 -55
  235. package/lib/resources/Faxes.js +0 -53
  236. package/lib/resources/FqdnConnections.js +0 -55
  237. package/lib/resources/Fqdns.js +0 -55
  238. package/lib/resources/GlobalIps.js +0 -47
  239. package/lib/resources/InboundChannels.js +0 -15
  240. package/lib/resources/InventoryCoverage.js +0 -13
  241. package/lib/resources/InventoryLevel.js +0 -15
  242. package/lib/resources/IpAddresses.js +0 -20
  243. package/lib/resources/IpConnections.js +0 -55
  244. package/lib/resources/IpRanges.js +0 -20
  245. package/lib/resources/Ips.js +0 -55
  246. package/lib/resources/ManagedAccounts.js +0 -57
  247. package/lib/resources/MdrDetailReports.js +0 -24
  248. package/lib/resources/MdrUsageReports.js +0 -24
  249. package/lib/resources/MediaStorageApi.js +0 -23
  250. package/lib/resources/Messages.js +0 -10
  251. package/lib/resources/MessagesAlphanumericSenderId.js +0 -6
  252. package/lib/resources/MessagingHostedNumber.js +0 -30
  253. package/lib/resources/MessagingHostedNumberOrders.js +0 -6
  254. package/lib/resources/MessagingHostedNumbers.js +0 -6
  255. package/lib/resources/MessagingPhoneNumbers.js +0 -7
  256. package/lib/resources/MessagingProfileMetrics.js +0 -7
  257. package/lib/resources/MessagingProfiles.js +0 -112
  258. package/lib/resources/MessagingSenderIds.js +0 -7
  259. package/lib/resources/MessagingShortCodes.js +0 -7
  260. package/lib/resources/MessagingTollfreeVerification.js +0 -20
  261. package/lib/resources/MessagingUrlDomains.js +0 -15
  262. package/lib/resources/MobileNetworkOperators.js +0 -15
  263. package/lib/resources/MobileOperatorNetworks.js +0 -8
  264. package/lib/resources/Networks.js +0 -27
  265. package/lib/resources/NumberBackgroundJobs.js +0 -24
  266. package/lib/resources/NumberLookup.js +0 -8
  267. package/lib/resources/NumberOrderDocuments.js +0 -15
  268. package/lib/resources/NumberOrders.js +0 -7
  269. package/lib/resources/NumberPortouts.js +0 -71
  270. package/lib/resources/NumberReservations.js +0 -33
  271. package/lib/resources/NumbersFeatures.js +0 -15
  272. package/lib/resources/Object.js +0 -21
  273. package/lib/resources/OtaUpdates.js +0 -19
  274. package/lib/resources/Outbound.js +0 -55
  275. package/lib/resources/OutboundVoiceProfiles.js +0 -19
  276. package/lib/resources/PhoneNumberAssignmentByProfile.js +0 -55
  277. package/lib/resources/PhoneNumberBlockOrders.js +0 -20
  278. package/lib/resources/PhoneNumberBlocksBackgroundJobs.js +0 -24
  279. package/lib/resources/PhoneNumberCampaigns.js +0 -19
  280. package/lib/resources/PhoneNumberOrderDocuments.js +0 -20
  281. package/lib/resources/PhoneNumberRegulatoryRequirements.js +0 -9
  282. package/lib/resources/PhoneNumberSearch.js +0 -19
  283. package/lib/resources/PhoneNumbers.js +0 -48
  284. package/lib/resources/PhoneNumbersInboundChannels.js +0 -34
  285. package/lib/resources/PhoneNumbersMessaging.js +0 -6
  286. package/lib/resources/PhoneNumbersVoice.js +0 -6
  287. package/lib/resources/PortabilityChecks.js +0 -12
  288. package/lib/resources/PortingOrders.js +0 -107
  289. package/lib/resources/PortingPhoneNumbers.js +0 -8
  290. package/lib/resources/PortoutRequests.js +0 -53
  291. package/lib/resources/PresignedObjectUrls.js +0 -16
  292. package/lib/resources/PrivateWirelessGateways.js +0 -19
  293. package/lib/resources/PublicInternetGateways.js +0 -19
  294. package/lib/resources/PublicKey.js +0 -13
  295. package/lib/resources/PushCredentials.js +0 -20
  296. package/lib/resources/Queues.js +0 -41
  297. package/lib/resources/RecordingsCommands.js +0 -16
  298. package/lib/resources/Regions.js +0 -15
  299. package/lib/resources/RegisterCall.js +0 -6
  300. package/lib/resources/RegulatoryRequirements.js +0 -9
  301. package/lib/resources/Reporting.js +0 -19
  302. package/lib/resources/Reports.js +0 -19
  303. package/lib/resources/ReportsMdrs.js +0 -6
  304. package/lib/resources/RequirementTypes.js +0 -19
  305. package/lib/resources/Requirements.js +0 -19
  306. package/lib/resources/RoomCompositions.js +0 -8
  307. package/lib/resources/RoomParticipants.js +0 -8
  308. package/lib/resources/RoomRecordings.js +0 -20
  309. package/lib/resources/RoomSessions.js +0 -43
  310. package/lib/resources/Rooms.js +0 -6
  311. package/lib/resources/RoomsClientToken.js +0 -18
  312. package/lib/resources/RoomsClientTokens.js +0 -21
  313. package/lib/resources/SharedCampaigns.js +0 -20
  314. package/lib/resources/ShortCodes.js +0 -39
  315. package/lib/resources/SimCardActions.js +0 -27
  316. package/lib/resources/SimCardGroupActions.js +0 -19
  317. package/lib/resources/SimCardGroups.js +0 -55
  318. package/lib/resources/SimCardOrders.js +0 -6
  319. package/lib/resources/SimCards.js +0 -139
  320. package/lib/resources/SslCertificates.js +0 -20
  321. package/lib/resources/TeXMLApplication.js +0 -6
  322. package/lib/resources/TelephonyCredentials.js +0 -55
  323. package/lib/resources/UpdateClientState.js +0 -22
  324. package/lib/resources/Verifications.js +0 -68
  325. package/lib/resources/VerifiedCallsDisplayProfile.js +0 -25
  326. package/lib/resources/VerifiedCallsDisplayProfiles.js +0 -13
  327. package/lib/resources/VerifiedNumbers.js +0 -6
  328. package/lib/resources/Verify.js +0 -55
  329. package/lib/resources/VerifyProfiles.js +0 -61
  330. package/lib/resources/VirtualCrossConnects.js +0 -31
  331. package/lib/resources/WdrDetailReports.js +0 -15
  332. package/lib/resources/Webhooks.js +0 -6
  333. package/lib/resources/WireguardInterfaces.js +0 -39
  334. package/lib/resources/WirelessDetailRecordReports.js +0 -8
  335. package/lib/telnyx.js +0 -425
  336. package/lib/utils.js +0 -366
package/CHANGELOG.md CHANGED
@@ -1,23 +1,72 @@
1
1
  # CHANGELOG
2
2
 
3
- ##
3
+ ## v2
4
+
5
+ ### v2.0.0-alpha.1
6
+
7
+ - Update actions workflow versions to v4 and `.npmignore` to v2
8
+ - Update examples dependencies
9
+
10
+ ### v2.0.0-alpha.0
11
+
12
+ - Add Typescript default config, linter and dependencies
13
+ - Bump default Node version to `20`
14
+ - Update README on [Development](./README.md#development) instructions
15
+ - Remove `yarn` in favor of `npm` 10
16
+ - Convert SDK files to Typescript
17
+ - Convert Resources to Typescript
18
+ - Use ES Modules syntax
19
+ - Update package `main` entrypoint to be compiled version of [src telnyx.ts](./src/telnyx.ts)
20
+ - Added `Jest` and create tests in Typescript
21
+ - Update tests expect matchers according to limitations with `prism mock`
22
+ - Add `nock` cleanup setup
23
+ - Make `setApiKey` TelnyxObject prototype method private
24
+ - Moved to `moduleResolution` Bundler to support better imports and tests with `Jest`
25
+ - Enabled `esModuleInterop` for Jest
26
+ - Update files included when publishing
27
+ - Remove custom resource get `generateAccessTokenFromCredential` from `TelephonyCredentials`
28
+ - Update `AutoRechargePreferences` resource
29
+ - Remove `RegisterCall` resource
30
+ - Remove `ProgrammableFaxCommants` specs
31
+ - Remove `BulkCreation` resource
32
+ - Update `TexmlApplications` resource
33
+ - Remove `Conferences` `dial_participant` action
34
+ - Remove `SimCards` `deletePublicIp` and `setPublicIp`
35
+ - Update `Queues` method names to camelCase
36
+ - Remove `VerifiedCallsDisplayProfile` resource
37
+ - Update examples to Typescript
38
+ - Remove duplicated `AccessTokens` resource
39
+ - Move custom `AdvancedOptinoptout` resource to be `AutoRespConfigs` resource
40
+ - Remove `Billing` resource
41
+ - Remove inexistent `Bucket` resource
42
+ - Move `BucketUsage` resource to `StorageBuckets`
43
+ - Remove duplicated `BulkPhoneNumberCampaigns` resource
44
+ - Remove duplicated `BulkPhoneNumberOperations` resource
45
+
46
+
47
+ ## v1
4
48
 
5
49
  ### v1.26.2
50
+
6
51
  - Fix Brand and Campaign redirects
7
52
  - Update security
8
53
 
9
54
  ### v1.26.1
55
+
10
56
  - Fix porting comments
11
57
 
12
58
  ### v1.26.0
59
+
13
60
  - Endpoint additions
14
61
  - Package upgrades
15
62
  - Preparation for typescript migration/support
16
63
 
17
64
  ### v1.25.5
65
+
18
66
  - Security Updates + API Additions
19
67
 
20
68
  ### v1.23.0 (2021-10-19)
69
+
21
70
  - **Addresses** added `validate`
22
71
  - **AuthenticationProvider** added `list`, `create`, `retrieve`, `update`, `del`
23
72
  - **DynamicEmergency** (for `endpoints` and `addresses`) added `list`, `retrieve`, `create`, `del`
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  Copyright (C) 2011 Ask Bjørn Hansen
2
2
  Copyright (C) 2013 Stripe, Inc. (https://stripe.com)
3
- Copyright (C) 2019 Telnyx, Inc. (https://www.telnyx.com)
3
+ Copyright (C) 2019 Telnyx, Inc. (https://telnyx.com)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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](https://coveralls.io/repos/github/team-telnyx/telnyx-node/badge.svg?branch=master)](https://coveralls.io/github/team-telnyx/telnyx-node?branch=master)
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/)
@@ -26,62 +25,41 @@ The package needs to be configured with your account's API key which is
26
25
  available in your the [Telnyx Mission Control Portal][api-keys]. Require it with the key's
27
26
  value:
28
27
 
29
- ``` js
30
- const telnyx = require('telnyx')('KEY123456...');
28
+ ```typescript
29
+ import Telnyx from 'telnyx';
30
+
31
+ const telnyx = new Telnyx('KEY123456...');
31
32
 
32
33
  const messagingProfile = await telnyx.messagingProfiles.create({
33
- name: 'Summer Campaign'
34
+ name: 'Summer Campaign',
34
35
  });
35
36
  ```
36
37
 
37
- Or with versions of Node.js prior to v7.9:
38
-
39
- ``` js
40
- var telnyx = require('telnyx')('KEY123456...');
41
-
42
- telnyx.messagingProfiles.create(
43
- { name: 'Summer Campaign' },
44
- function(err, messagingProfile) {
45
- err; // null if no error occurred
46
- messagingProfile; // the created messaging profile object
47
- }
48
- );
49
- ```
50
-
51
- Or using ES modules, this looks more like:
52
-
53
- ```js
54
- import Telnyx from 'telnyx';
55
- const telnyx = Telnyx('KEY...');
56
- //…
57
- ```
58
-
59
38
  ### Using Promises
60
39
 
61
40
  Every method returns a chainable promise which can be used instead of a regular
62
41
  callback:
63
42
 
64
- ```js
43
+ ```typescript
65
44
  // Create a new messaging profile and then send a message using that profile:
66
- telnyx.MessagingProfiles.create({
67
- name: 'Summer Campaign'
68
- }).then((messagingProfile) => {
69
- return telnyx.MessagingPhoneNumbers.update(
70
- '+18005554000',
71
- {
72
- 'messaging_profile_id': messagingProfile.data.id
73
- }
74
- );
75
- }).catch((err) => {
76
- // Deal with an error
77
- });
45
+ telnyx.,essagingProfiles.create({
46
+ name: 'Summer Campaign',
47
+ })
48
+ .then((messagingProfile) => {
49
+ return telnyx.messagingPhoneNumbers.update('+18005554000', {
50
+ messaging_profile_id: messagingProfile.data.id,
51
+ });
52
+ })
53
+ .catch((err) => {
54
+ // Deal with an error
55
+ });
78
56
  ```
79
57
 
80
58
  ### Configuring Timeout
81
59
 
82
60
  Request timeout is configurable (the default is Node's default of 120 seconds):
83
61
 
84
- ``` js
62
+ ```typescript
85
63
  telnyx.setTimeout(20000); // in ms (this is 20 seconds)
86
64
  ```
87
65
 
@@ -90,11 +68,12 @@ telnyx.setTimeout(20000); // in ms (this is 20 seconds)
90
68
  An [https-proxy-agent][https-proxy-agent] can be configured with
91
69
  `setHttpAgent`.
92
70
 
93
- To use telnyx behind a proxy you can pass to sdk:
71
+ To use telnyx behind a proxy you can pass to sdk:
72
+
73
+ ```typescript
74
+ import ProxyAgent from 'https-proxy-agent';
94
75
 
95
- ```js
96
76
  if (process.env.http_proxy) {
97
- const ProxyAgent = require('https-proxy-agent');
98
77
  telnyx.setHttpAgent(new ProxyAgent(process.env.http_proxy));
99
78
  }
100
79
  ```
@@ -105,7 +84,7 @@ Automatic network retries can be enabled with `setMaxNetworkRetries`. This will
105
84
  retry requests `n` times with exponential backoff if they fail due to an
106
85
  intermittent network problem.
107
86
 
108
- ```js
87
+ ```typescript
109
88
  // Retry a request once before giving up
110
89
  telnyx.setMaxNetworkRetries(1);
111
90
  ```
@@ -115,21 +94,23 @@ telnyx.setMaxNetworkRetries(1);
115
94
  Some information about the response which generated a resource is available
116
95
  with the `lastResponse` property:
117
96
 
118
- ```js
119
- messagingProfile.lastResponse.requestId // see: https://telnyx.com/docs/api/node#request_ids
120
- messagingProfile.lastResponse.statusCode
97
+ ```typescript
98
+ messagingProfile.lastResponse.requestId; // see: https://telnyx.com/docs/api/node#request_ids
99
+ messagingProfile.lastResponse.statusCode;
121
100
  ```
122
101
 
123
102
  ### `request` and `response` events
124
103
 
125
- The Telnyx object emits `request` and `response` events. You can use them like this:
104
+ The Telnyx object emits `request` and `response` events. You can use them like this:
105
+
106
+ ```typescript
107
+ import Telnyx from 'telnyx';
126
108
 
127
- ```js
128
- const telnyx = require('telnyx')('KEY...');
109
+ const telnyx = new Telnyx('KEY...');
129
110
 
130
111
  const onRequest = (request) => {
131
112
  // Do something.
132
- }
113
+ };
133
114
 
134
115
  // Add the event handler function:
135
116
  telnyx.on('request', onRequest);
@@ -139,7 +120,8 @@ telnyx.off('request', onRequest);
139
120
  ```
140
121
 
141
122
  #### `request` object
142
- ```js
123
+
124
+ ```typescript
143
125
  {
144
126
  method: 'POST',
145
127
  path: '/v2/messaging_profiles'
@@ -147,7 +129,8 @@ telnyx.off('request', onRequest);
147
129
  ```
148
130
 
149
131
  #### `response` object
150
- ```js
132
+
133
+ ```typescript
151
134
  {
152
135
  method: 'POST',
153
136
  path: '/v2/messaging_profiles',
@@ -171,12 +154,12 @@ You can find an example of how to use this with [Express](https://expressjs.com/
171
154
  in the [`examples/webhook-signing`](examples/webhook-signing) folder, but here's
172
155
  what it looks like:
173
156
 
174
- ```js
157
+ ```typescript
175
158
  const event = telnyx.webhooks.constructEvent(
176
159
  webhookRawBody,
177
160
  webhookTelnyxSignatureHeader,
178
161
  webhookTelnyxTimestampHeader,
179
- publicKey
162
+ publicKey,
180
163
  );
181
164
  ```
182
165
 
@@ -186,7 +169,7 @@ TeXML sends webhooks as form-encoded payloads instead of JSON. To validate the s
186
169
 
187
170
  You can find an example of how to use this with [Express](https://expressjs.com/) in the [`examples/webhook-signing`](examples/webhook-signing) folder.
188
171
 
189
- ```js
172
+ ```typescript
190
173
  const timeToleranceInSeconds = 300; // Will validate signatures of webhooks up to 5 minutes after Telnyx sent the request
191
174
  try {
192
175
  telnyx.webhooks.signature.verifySignature(
@@ -194,20 +177,19 @@ try {
194
177
  webhookTelnyxSignatureHeader,
195
178
  webhookTelnyxTimestampHeader,
196
179
  publicKey,
197
- timeToleranceInSeconds
180
+ timeToleranceInSeconds,
198
181
  );
199
182
  } catch (e) {
200
- console.log("Failed to validate the signature")
183
+ console.log('Failed to validate the signature');
201
184
  console.log(e);
202
185
  }
203
-
204
186
  ```
205
187
 
206
188
  ### Writing a Plugin
207
189
 
208
190
  If you're writing a plugin that uses the library, we'd appreciate it if you identified using `telnyx.setAppInfo()`:
209
191
 
210
- ```js
192
+ ```typescript
211
193
  telnyx.setAppInfo({
212
194
  name: 'MyAwesomePlugin',
213
195
  version: '1.2.34', // Optional
@@ -222,14 +204,13 @@ This information is passed along when the library makes calls to the Telnyx API.
222
204
  You can auto-paginate list methods. We provide a few different APIs for this to
223
205
  aid with a variety of node versions and styles.
224
206
 
225
-
226
207
  #### Async iterators (`for-await-of`)
227
208
 
228
209
  If you are in a Node environment that has support for [async iteration](https://github.com/tc39/proposal-async-iteration#the-async-iteration-statement-for-await-of),
229
210
  such as Node 10+ or [babel](https://babeljs.io/docs/en/babel-plugin-transform-async-generator-functions),
230
211
  the following will auto-paginate:
231
212
 
232
- ```js
213
+ ```typescript
233
214
  for await (const messagingProfile of telnyx.messagingProfiles.list()) {
234
215
  doSomething(messagingProfile);
235
216
  if (shouldStop()) {
@@ -243,36 +224,42 @@ for await (const messagingProfile of telnyx.messagingProfiles.list()) {
243
224
  If you are in a Node environment that has support for `await`, such as Node 7.9 and greater,
244
225
  you may pass an async function to `.autoPagingEach`:
245
226
 
246
- ```js
247
- await telnyx.messagingProfiles.list().autoPagingEach(async (messagingProfile) => {
248
- await doSomething(messagingProfile);
249
- if (shouldBreak()) {
250
- return false;
251
- }
252
- })
227
+ ```typescript
228
+ await telnyx.messagingProfiles
229
+ .list()
230
+ .autoPagingEach(async (messagingProfile) => {
231
+ await doSomething(messagingProfile);
232
+ if (shouldBreak()) {
233
+ return false;
234
+ }
235
+ });
253
236
  console.log('Done iterating.');
254
237
  ```
255
238
 
256
239
  Equivalently, without `await`, you may return a Promise, which can resolve to `false` to break:
257
240
 
258
- ```js
259
- telnyx.messagingProfiles.list().autoPagingEach((messagingProfile) => {
260
- return doSomething(messagingProfile).then(() => {
261
- if (shouldBreak()) {
262
- return false;
263
- }
264
- });
265
- }).then(() => {
266
- console.log('Done iterating.');
267
- }).catch(handleError);
241
+ ```typescript
242
+ telnyx.messagingProfiles
243
+ .list()
244
+ .autoPagingEach((messagingProfile) => {
245
+ return doSomething(messagingProfile).then(() => {
246
+ if (shouldBreak()) {
247
+ return false;
248
+ }
249
+ });
250
+ })
251
+ .then(() => {
252
+ console.log('Done iterating.');
253
+ })
254
+ .catch(handleError);
268
255
  ```
269
256
 
270
257
  If you prefer callbacks to promises, you may also use a `next` callback and a second `onDone` callback:
271
258
 
272
- ```js
259
+ ```typescript
273
260
  telnyx.messagingProfiles.list().autoPagingEach(
274
261
  function onItem(messagingProfile, next) {
275
- doSomething(messagingProfile, function(err, result) {
262
+ doSomething(messagingProfile, function (err, result) {
276
263
  if (shouldStop(result)) {
277
264
  next(false); // Passing `false` breaks out of the loop.
278
265
  } else {
@@ -286,8 +273,8 @@ telnyx.messagingProfiles.list().autoPagingEach(
286
273
  } else {
287
274
  console.log('Done iterating.');
288
275
  }
289
- }
290
- )
276
+ },
277
+ );
291
278
  ```
292
279
 
293
280
  If your `onItem` function does not accept a `next` callback parameter _or_ return a Promise,
@@ -301,31 +288,41 @@ to prevent runaway list growth from consuming too much memory.
301
288
 
302
289
  Returns a promise of an array of all items across pages for a list request.
303
290
 
304
- ```js
305
- const allMessagingProfiles = await telnyx.messagingProfiles.list()
291
+ ```typescript
292
+ const allMessagingProfiles = await telnyx.messagingProfiles
293
+ .list()
306
294
  .autoPagingToArray({limit: 10000});
307
295
  ```
308
296
 
309
297
  ## Development
310
298
 
311
299
  ### Setup
312
- The test suite depends on the [Prism Mock Server](https://github.com/stoplightio/prism).
300
+
301
+ Run the following to create your env file
313
302
 
314
303
  ```bash
315
- npm install -g @stoplight/prism-cli
304
+ cp .env.local .env
305
+ ```
306
+
307
+ > Don't forget to update your `.env` values accordingly.
316
308
 
317
- # OR
309
+ Now inject envs into terminal:
318
310
 
319
- yarn global add @stoplight/prism-cli
311
+ ```bash
312
+ . ./setup_env.sh
320
313
  ```
321
314
 
322
- Once installed, start the prism mock service with the following command:
315
+ > Feel free to use Node `--env-file` parameter to [setup envs](https://nodejs.org/en/learn/command-line/how-to-read-environment-variables-from-nodejs) if you prefer
316
+
317
+ The test suite depends on the [Prism Mock Server](https://github.com/stoplightio/prism).
318
+
319
+ Start the prism mock service with the following command:
323
320
 
324
321
  ```bash
325
- prism mock https://raw.githubusercontent.com/team-telnyx/openapi/master/openapi/spec3.json
322
+ npx prism mock https://raw.githubusercontent.com/team-telnyx/openapi/master/openapi/spec3.json
326
323
  ```
327
324
 
328
- --------
325
+ ---
329
326
 
330
327
  One final step -- because the Node SDK originally expected to reach the legacy `telnyx-mock` service at port 12111 (in addition to providing a `/v2/` base path), we need to setup the [Telnyx mock proxy server](https://github.com/team-telnyx/telnyx-mock-server-proxy) to modify the request path and forward along to the prism mock server.
331
328
 
@@ -335,7 +332,7 @@ One final step -- because the Node SDK originally expected to reach the legacy `
335
332
  git clone git@github.com:team-telnyx/telnyx-prism-mock.git
336
333
  cd telnyx-prism-mock/proxy
337
334
 
338
- yarn install
335
+ npm install
339
336
  node index.js
340
337
  ```
341
338
 
@@ -349,22 +346,22 @@ $ npm test
349
346
  Run all tests with a custom `telnyx-mock` port:
350
347
 
351
348
  ```bash
352
- $ TELNYX_MOCK_PORT=12000 npm test
349
+ $ TELNYX_MOCK_PORT=12111 npm test
353
350
  ```
354
351
 
355
352
  Run a single test suite:
356
353
 
357
354
  ```bash
358
- $ npm run mocha -- test/Error.spec.js
355
+ $ npm test -- test/Error.test.ts
359
356
  ```
360
357
 
361
358
  Run a single test (case sensitive):
362
359
 
363
360
  ```bash
364
- $ npm run mocha -- test/Error.spec.js --grep 'Populates with type'
361
+ $ npm test -- test/Error.test.ts -t 'Populates with type'
365
362
  ```
366
363
 
367
- If you wish, you may run tests using your Telnyx *Test* API key by setting the
364
+ If you wish, you may run tests using your Telnyx _Test_ API key by setting the
368
365
  environment variable `TELNYX_TEST_API_KEY` before running the tests:
369
366
 
370
367
  ```bash
@@ -377,10 +374,12 @@ $ npm test
377
374
 
378
375
  To inspect values in tests first import debug:
379
376
 
380
- ```js
381
- var debug = require('debug')('foo');
377
+ ```typescript
378
+ import Debug from 'debug';
379
+
380
+ const debug = Debug('foo');
382
381
  //...
383
- debug(result)
382
+ debug(result);
384
383
  ```
385
384
 
386
385
  Then run the tests with:
@@ -395,6 +394,24 @@ To view verbose debugging for `nock` run the tests with:
395
394
  $ DEBUG=nock.* npm test
396
395
  ```
397
396
 
397
+ ### Typescript
398
+
399
+ Run:
400
+
401
+ ```bash
402
+ npm run build
403
+ ```
404
+
405
+ Then check output in [dist](./dist) folder
406
+
407
+ ### Linter (Prettier)
408
+
409
+ Add an [editor integration](https://prettier.io/docs/en/editors.html) or:
410
+
411
+ ```bash
412
+ $ npm run fix
413
+ ```
414
+
398
415
  ## Acknowledgements
399
416
 
400
417
  The contributors and maintainers of Telnyx Node would like to extend their deep gratitude to the
package/VERSION CHANGED
@@ -1 +1 @@
1
- 1.27.0
1
+ 2.0.0-alpha.1
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
+ }
@@ -0,0 +1,24 @@
1
+ import telnyxMethod from './TelnyxMethod';
2
+ export const create = telnyxMethod({
3
+ method: 'POST',
4
+ });
5
+ export const list = telnyxMethod({
6
+ method: 'GET',
7
+ methodType: 'list',
8
+ });
9
+ export const retrieve = telnyxMethod({
10
+ method: 'GET',
11
+ path: '/{id}',
12
+ urlParams: ['id'],
13
+ });
14
+ export const update = telnyxMethod({
15
+ method: 'PATCH',
16
+ path: '{id}',
17
+ urlParams: ['id'],
18
+ });
19
+ // Avoid 'delete' keyword in JS
20
+ export const del = telnyxMethod({
21
+ method: 'DELETE',
22
+ path: '{id}',
23
+ urlParams: ['id'],
24
+ });