Comparing version 1.27.0 to 2.0.0-alpha.0
# CHANGELOG | ||
## | ||
## v2 | ||
### v2.0.0-alpha.0 | ||
- Add Typescript default config, linter and dependencies | ||
- Bump default Node version to `20` | ||
- Update README on [Development](./README.md#development) instructions | ||
- Remove `yarn` in favor of `npm` 10 | ||
- Convert SDK files to Typescript | ||
- Convert Resources to Typescript | ||
- Use ES Modules syntax | ||
- Update package `main` entrypoint to be compiled version of [src telnyx.ts](./src/telnyx.ts) | ||
- Added `Jest` and create tests in Typescript | ||
- Update tests expect matchers according to limitations with `prism mock` | ||
- Add `nock` cleanup setup | ||
- Make `setApiKey` TelnyxObject prototype method private | ||
- Moved to `moduleResolution` Bundler to support better imports and tests with `Jest` | ||
- Enabled `esModuleInterop` for Jest | ||
- Update files included when publishing | ||
- Remove custom resource get `generateAccessTokenFromCredential` from `TelephonyCredentials` | ||
- Update `AutoRechargePreferences` resource | ||
- Remove `RegisterCall` resource | ||
- Remove `ProgrammableFaxCommants` specs | ||
- Remove `BulkCreation` resource | ||
- Update `TexmlApplications` resource | ||
- Remove `Conferences` `dial_participant` action | ||
- Remove `SimCards` `deletePublicIp` and `setPublicIp` | ||
- Update `Queues` method names to camelCase | ||
- Remove `VerifiedCallsDisplayProfile` resource | ||
- Update examples to Typescript | ||
- Remove duplicated `AccessTokens` resource | ||
- Move custom `AdvancedOptinoptout` resource to be `AutoRespConfigs` resource | ||
- Remove `Billing` resource | ||
- Remove inexistent `Bucket` resource | ||
- Move `BucketUsage` resource to `StorageBuckets` | ||
- Remove duplicated `BulkPhoneNumberCampaigns` resource | ||
- Remove duplicated `BulkPhoneNumberOperations` resource | ||
## v1 | ||
### v1.26.2 | ||
- Fix Brand and Campaign redirects | ||
@@ -10,5 +49,7 @@ - Update security | ||
### v1.26.1 | ||
- Fix porting comments | ||
### v1.26.0 | ||
- Endpoint additions | ||
@@ -19,5 +60,7 @@ - Package upgrades | ||
### v1.25.5 | ||
- Security Updates + API Additions | ||
### v1.23.0 (2021-10-19) | ||
- **Addresses** added `validate` | ||
@@ -24,0 +67,0 @@ - **AuthenticationProvider** added `list`, `create`, `retrieve`, `update`, `del` |
{ | ||
"name": "telnyx", | ||
"version": "1.27.0", | ||
"version": "2.0.0-alpha.0", | ||
"description": "Telnyx API Node SDK", | ||
@@ -14,8 +14,8 @@ "keywords": [ | ||
"homepage": "https://developers.telnyx.com", | ||
"author": "Telnyx <support@telnyx.com> (https://www.telnyx.com/)", | ||
"author": "Telnyx <support@telnyx.com> (https://telnyx.com)", | ||
"contributors": [ | ||
"Vlad Ionash <vladi@telnyx.com> (http://www.telnyx.com/)", | ||
"Gabriel Taylor Russ <gabriel@telnyx.com> (http://www.telnyx.com/)", | ||
"Lucas Rosa <lucas@telnyx.com> (http://www.telnyx.com/)", | ||
"Rômulo Garofalo <romulo@telnyx.com> (http://www.telnyx.com/)", | ||
"Vlad Ionash <vladi@telnyx.com> (http://telnyx.com)", | ||
"Gabriel Taylor Russ <gabriel@telnyx.com> (http://telnyx.com)", | ||
"Lucas Rosa <lucas@telnyx.com> (http://telnyx.com)", | ||
"Rômulo Garofalo <romulo@telnyx.com> (http://telnyx.com)", | ||
"Khalil Mohammad <khalilmohammadmirza@gmail.com> (https://khalilmohammadmirza.com)" | ||
@@ -27,43 +27,50 @@ ], | ||
}, | ||
"bugs:": "https://github.com/team-telnyx/telnyx-node/issues", | ||
"bugs": "https://github.com/team-telnyx/telnyx-node/issues", | ||
"engines": { | ||
"node": "^6 || >=8" | ||
"node": "^18 || >=20" | ||
}, | ||
"main": "lib/telnyx.js", | ||
"main": "dist/telnyx.node.js", | ||
"type": "module", | ||
"types": "dist/types/index.d.ts", | ||
"devDependencies": { | ||
"chai": "~4.4.1", | ||
"chai-as-promised": "~7.1.1", | ||
"coveralls": "^3.1.1", | ||
"@eslint/js": "^9.10.0", | ||
"@stoplight/prism-cli": "^5.10.0", | ||
"@types/eslint__js": "^8.42.3", | ||
"@types/jest": "^29.5.13", | ||
"@types/node": "^22.7.3", | ||
"@types/qs": "^6.9.15", | ||
"debug": "^4.3.4", | ||
"eslint": "^8.57.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-chai-friendly": "^0.7.4", | ||
"mocha": "^10.3.0", | ||
"eslint-plugin-prettier": "^5.2.1", | ||
"jest": "^29.7.0", | ||
"nock": "^13.5.4", | ||
"nyc": "^15.1.0" | ||
}, | ||
"dependencies": { | ||
"lodash.isplainobject": "^4.0.6", | ||
"nyc": "^15.1.0", | ||
"plop": "^4.0.1", | ||
"prettier": "^3.0.0", | ||
"qs": "^6.11.2", | ||
"safe-buffer": "^5.2.1", | ||
"telnyx": "^1.26.2", | ||
"ts-jest": "^29.2.5", | ||
"ts-node": "^10.9.2", | ||
"tweetnacl": "^1.0.3", | ||
"typescript": "^5.6.2", | ||
"typescript-eslint": "^8.8.0", | ||
"uuid": "^9.0.1" | ||
}, | ||
"overrides": { | ||
"node-plop": { | ||
"inquirer": "9.3.5" | ||
} | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"clean": "rm -rf ./.nyc_output ./node_modules/.cache ./coverage", | ||
"mocha": "nyc mocha", | ||
"test": "npm run lint && npm run mocha", | ||
"lint": "eslint . --fix", | ||
"report": "nyc -r text -r lcov report", | ||
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", | ||
"release": "telnyx-npm-release" | ||
}, | ||
"nyc": { | ||
"exclude": [ | ||
"testUtils/**/*", | ||
"test/**/*", | ||
"lib/TelnyxMethod.basic.js" | ||
] | ||
"prebuild": "rm -rf ./dist", | ||
"build": "tsc && cp -r types dist/types", | ||
"clean": "rm -rf ./.nyc_output ./node_modules/.cache ./coverage ./dist", | ||
"prepack": "npm install && npm run build", | ||
"test": "jest", | ||
"generate": "plop", | ||
"lint": "rm -rf ./dist && eslint .", | ||
"fix": "npm run lint --fix" | ||
} | ||
} |
218
README.md
@@ -5,3 +5,3 @@ # Telnyx Node.js Library | ||
[](https://github.com/team-telnyx/telnyx-node/actions) | ||
[](https://coveralls.io/github/team-telnyx/telnyx-node?branch=master) | ||
Coverage Status: Pending | ||
[](https://www.npmjs.com/package/telnyx) | ||
@@ -30,32 +30,12 @@ [](https://runkit.com/npm/telnyx) | ||
``` js | ||
const telnyx = require('telnyx')('KEY123456...'); | ||
```typescript | ||
import Telnyx from 'telnyx'; | ||
const telnyx = new Telnyx('KEY123456...'); | ||
const messagingProfile = await telnyx.messagingProfiles.create({ | ||
name: 'Summer Campaign' | ||
name: 'Summer Campaign', | ||
}); | ||
``` | ||
Or with versions of Node.js prior to v7.9: | ||
``` js | ||
var telnyx = require('telnyx')('KEY123456...'); | ||
telnyx.messagingProfiles.create( | ||
{ name: 'Summer Campaign' }, | ||
function(err, messagingProfile) { | ||
err; // null if no error occurred | ||
messagingProfile; // the created messaging profile object | ||
} | ||
); | ||
``` | ||
Or using ES modules, this looks more like: | ||
```js | ||
import Telnyx from 'telnyx'; | ||
const telnyx = Telnyx('KEY...'); | ||
//… | ||
``` | ||
### Using Promises | ||
@@ -66,16 +46,15 @@ | ||
```js | ||
```typescript | ||
// Create a new messaging profile and then send a message using that profile: | ||
telnyx.MessagingProfiles.create({ | ||
name: 'Summer Campaign' | ||
}).then((messagingProfile) => { | ||
return telnyx.MessagingPhoneNumbers.update( | ||
'+18005554000', | ||
{ | ||
'messaging_profile_id': messagingProfile.data.id | ||
} | ||
); | ||
}).catch((err) => { | ||
// Deal with an error | ||
}); | ||
telnyx.,essagingProfiles.create({ | ||
name: 'Summer Campaign', | ||
}) | ||
.then((messagingProfile) => { | ||
return telnyx.messagingPhoneNumbers.update('+18005554000', { | ||
messaging_profile_id: messagingProfile.data.id, | ||
}); | ||
}) | ||
.catch((err) => { | ||
// Deal with an error | ||
}); | ||
``` | ||
@@ -87,3 +66,3 @@ | ||
``` js | ||
```typescript | ||
telnyx.setTimeout(20000); // in ms (this is 20 seconds) | ||
@@ -97,7 +76,8 @@ ``` | ||
To use telnyx behind a proxy you can pass to sdk: | ||
To use telnyx behind a proxy you can pass to sdk: | ||
```js | ||
```typescript | ||
import ProxyAgent from 'https-proxy-agent'; | ||
if (process.env.http_proxy) { | ||
const ProxyAgent = require('https-proxy-agent'); | ||
telnyx.setHttpAgent(new ProxyAgent(process.env.http_proxy)); | ||
@@ -113,3 +93,3 @@ } | ||
```js | ||
```typescript | ||
// Retry a request once before giving up | ||
@@ -124,5 +104,5 @@ telnyx.setMaxNetworkRetries(1); | ||
```js | ||
messagingProfile.lastResponse.requestId // see: https://telnyx.com/docs/api/node#request_ids | ||
messagingProfile.lastResponse.statusCode | ||
```typescript | ||
messagingProfile.lastResponse.requestId; // see: https://telnyx.com/docs/api/node#request_ids | ||
messagingProfile.lastResponse.statusCode; | ||
``` | ||
@@ -132,10 +112,12 @@ | ||
The Telnyx object emits `request` and `response` events. You can use them like this: | ||
The Telnyx object emits `request` and `response` events. You can use them like this: | ||
```js | ||
const telnyx = require('telnyx')('KEY...'); | ||
```typescript | ||
import Telnyx from 'telnyx'; | ||
const telnyx = new Telnyx('KEY...'); | ||
const onRequest = (request) => { | ||
// Do something. | ||
} | ||
}; | ||
@@ -150,3 +132,4 @@ // Add the event handler function: | ||
#### `request` object | ||
```js | ||
```typescript | ||
{ | ||
@@ -159,3 +142,4 @@ method: 'POST', | ||
#### `response` object | ||
```js | ||
```typescript | ||
{ | ||
@@ -184,3 +168,3 @@ method: 'POST', | ||
```js | ||
```typescript | ||
const event = telnyx.webhooks.constructEvent( | ||
@@ -190,3 +174,3 @@ webhookRawBody, | ||
webhookTelnyxTimestampHeader, | ||
publicKey | ||
publicKey, | ||
); | ||
@@ -201,3 +185,3 @@ ``` | ||
```js | ||
```typescript | ||
const timeToleranceInSeconds = 300; // Will validate signatures of webhooks up to 5 minutes after Telnyx sent the request | ||
@@ -210,9 +194,8 @@ try { | ||
publicKey, | ||
timeToleranceInSeconds | ||
timeToleranceInSeconds, | ||
); | ||
} catch (e) { | ||
console.log("Failed to validate the signature") | ||
console.log('Failed to validate the signature'); | ||
console.log(e); | ||
} | ||
``` | ||
@@ -224,3 +207,3 @@ | ||
```js | ||
```typescript | ||
telnyx.setAppInfo({ | ||
@@ -240,3 +223,2 @@ name: 'MyAwesomePlugin', | ||
#### Async iterators (`for-await-of`) | ||
@@ -248,3 +230,3 @@ | ||
```js | ||
```typescript | ||
for await (const messagingProfile of telnyx.messagingProfiles.list()) { | ||
@@ -263,9 +245,11 @@ doSomething(messagingProfile); | ||
```js | ||
await telnyx.messagingProfiles.list().autoPagingEach(async (messagingProfile) => { | ||
await doSomething(messagingProfile); | ||
if (shouldBreak()) { | ||
return false; | ||
} | ||
}) | ||
```typescript | ||
await telnyx.messagingProfiles | ||
.list() | ||
.autoPagingEach(async (messagingProfile) => { | ||
await doSomething(messagingProfile); | ||
if (shouldBreak()) { | ||
return false; | ||
} | ||
}); | ||
console.log('Done iterating.'); | ||
@@ -276,12 +260,16 @@ ``` | ||
```js | ||
telnyx.messagingProfiles.list().autoPagingEach((messagingProfile) => { | ||
return doSomething(messagingProfile).then(() => { | ||
if (shouldBreak()) { | ||
return false; | ||
} | ||
}); | ||
}).then(() => { | ||
console.log('Done iterating.'); | ||
}).catch(handleError); | ||
```typescript | ||
telnyx.messagingProfiles | ||
.list() | ||
.autoPagingEach((messagingProfile) => { | ||
return doSomething(messagingProfile).then(() => { | ||
if (shouldBreak()) { | ||
return false; | ||
} | ||
}); | ||
}) | ||
.then(() => { | ||
console.log('Done iterating.'); | ||
}) | ||
.catch(handleError); | ||
``` | ||
@@ -291,6 +279,6 @@ | ||
```js | ||
```typescript | ||
telnyx.messagingProfiles.list().autoPagingEach( | ||
function onItem(messagingProfile, next) { | ||
doSomething(messagingProfile, function(err, result) { | ||
doSomething(messagingProfile, function (err, result) { | ||
if (shouldStop(result)) { | ||
@@ -309,4 +297,4 @@ next(false); // Passing `false` breaks out of the loop. | ||
} | ||
} | ||
) | ||
}, | ||
); | ||
``` | ||
@@ -325,4 +313,5 @@ | ||
```js | ||
const allMessagingProfiles = await telnyx.messagingProfiles.list() | ||
```typescript | ||
const allMessagingProfiles = await telnyx.messagingProfiles | ||
.list() | ||
.autoPagingToArray({limit: 10000}); | ||
@@ -334,19 +323,28 @@ ``` | ||
### Setup | ||
The test suite depends on the [Prism Mock Server](https://github.com/stoplightio/prism). | ||
Run the following to create your env file | ||
```bash | ||
npm install -g @stoplight/prism-cli | ||
cp .env.local .env | ||
``` | ||
# OR | ||
> Don't forget to update your `.env` values accordingly. | ||
yarn global add @stoplight/prism-cli | ||
Now inject envs into terminal: | ||
```bash | ||
. ./setup_env.sh | ||
``` | ||
Once installed, start the prism mock service with the following command: | ||
> 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 | ||
The test suite depends on the [Prism Mock Server](https://github.com/stoplightio/prism). | ||
Start the prism mock service with the following command: | ||
```bash | ||
prism mock https://raw.githubusercontent.com/team-telnyx/openapi/master/openapi/spec3.json | ||
npx prism mock https://raw.githubusercontent.com/team-telnyx/openapi/master/openapi/spec3.json | ||
``` | ||
-------- | ||
--- | ||
@@ -361,3 +359,3 @@ 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. | ||
yarn install | ||
npm install | ||
node index.js | ||
@@ -376,3 +374,3 @@ ``` | ||
```bash | ||
$ TELNYX_MOCK_PORT=12000 npm test | ||
$ TELNYX_MOCK_PORT=12111 npm test | ||
``` | ||
@@ -383,3 +381,3 @@ | ||
```bash | ||
$ npm run mocha -- test/Error.spec.js | ||
$ npm test -- test/Error.test.ts | ||
``` | ||
@@ -390,6 +388,6 @@ | ||
```bash | ||
$ npm run mocha -- test/Error.spec.js --grep 'Populates with type' | ||
$ npm test -- test/Error.test.ts -t 'Populates with type' | ||
``` | ||
If you wish, you may run tests using your Telnyx *Test* API key by setting the | ||
If you wish, you may run tests using your Telnyx _Test_ API key by setting the | ||
environment variable `TELNYX_TEST_API_KEY` before running the tests: | ||
@@ -407,6 +405,8 @@ | ||
```js | ||
var debug = require('debug')('foo'); | ||
```typescript | ||
import Debug from 'debug'; | ||
const debug = Debug('foo'); | ||
//... | ||
debug(result) | ||
debug(result); | ||
``` | ||
@@ -426,2 +426,20 @@ | ||
### Typescript | ||
Run: | ||
```bash | ||
npm run build | ||
``` | ||
Then check output in [dist](./dist) folder | ||
### Linter (Prettier) | ||
Add an [editor integration](https://prettier.io/docs/en/editors.html) or: | ||
```bash | ||
$ npm run fix | ||
``` | ||
## Acknowledgements | ||
@@ -428,0 +446,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
2347031
0
177
72300
429
0
1
Yes
23
1
- Removedlodash.isplainobject@^4.0.6
- Removedqs@^6.11.2
- Removedsafe-buffer@^5.2.1
- Removedtelnyx@^1.26.2
- Removedtweetnacl@^1.0.3
- Removeduuid@^9.0.1
- Removedcall-bind-apply-helpers@1.0.2(transitive)
- Removedcall-bound@1.0.4(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.3.0(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedlodash.isplainobject@4.0.6(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedobject-inspect@1.13.4(transitive)
- Removedqs@6.14.0(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedside-channel@1.1.0(transitive)
- Removedside-channel-list@1.0.0(transitive)
- Removedside-channel-map@1.0.1(transitive)
- Removedside-channel-weakmap@1.0.2(transitive)
- Removedtweetnacl@1.0.3(transitive)
- Removeduuid@9.0.1(transitive)