Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bitly

Package Overview
Dependencies
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitly - npm Package Compare versions

Comparing version 6.1.0 to 7.0.0

33

package.json

@@ -12,6 +12,5 @@ {

"homepage": "https://github.com/tanepiper/node-bitly",
"version": "6.1.0",
"version": "7.0.0",
"author": {
"name": "Tane Piper",
"email": "piper.tane@gmail.com",
"url": "https://github.com/tanepiper"

@@ -41,2 +40,6 @@ },

"email": "specious@gmail.com"
},
{
"name": "Joshua Tzucker",
"url": "https://joshuatz.com/"
}

@@ -52,6 +55,6 @@ ],

"engines": {
"node": ">= 6.10.0"
"node": ">= 10.0.0"
},
"scripts": {
"test": "VCR_MODE=cache mocha -r ts-node/register --reporter list src/*.spec.ts",
"test": "mocha -r ts-node/register --reporter list src/*.spec.ts",
"build": "npx tsc",

@@ -61,19 +64,17 @@ "docs": "rm -rf ./docs && npx typedoc --readme ./README.md --out ./docs && touch ./docs/.nojekyll"

"devDependencies": {
"@types/chai": "^4.1.7",
"@types/node": "^12.0.8",
"@types/request-promise": "^4.1.44",
"@types/chai": "^4.2.10",
"@types/node": "^13.7.7",
"chai": "^4.2.0",
"jsdoc": "^3.6.2",
"jsdoc": "^3.6.3",
"minami": "^1.2.3",
"mocha": "^6.1.4",
"mocha": "^7.1.0",
"mocha-typescript": "^1.1.17",
"np": "^5.0.3",
"sepia": "^2.0.2",
"ts-node": "^8.2.0",
"typedoc": "^0.14.2",
"typescript": "^3.5.2"
"np": "^5.2.1",
"replay": "^2.4.0",
"ts-node": "^8.6.2",
"typedoc": "^0.16.11",
"typescript": "^3.8.3"
},
"dependencies": {
"request": "^2.88.0",
"request-promise": "^4.2.4",
"axios": "^0.19.2",
"valid-url": "^1.0.9"

@@ -80,0 +81,0 @@ },

@@ -5,11 +5,30 @@ # node-bitly - Unofficial Bitly API for nodejs

## Current Versions
### V6.x.x to V7.x.x transition - aka V3 of Bitly API to V4 - Breaking Changes
In March 2020, Bitly deprecated the v3 of their API, and switched to v4. Unfortunately, even with the changes to this package to make it compatible, there are several unavoidable breaking changes. These are summarized below:
- Endpoints no longer support bulk options (multiple hashes or URLs in a single request)
- Most importantly, this affects `expand()` and `shorten()`
- As a general rule of thumb, *none* of the v4 endpoints take bulk inputs
- Return types have changed, for multiple endpoints
- DEPRECATED: The `lookup` method and corresponding endpoint have been deprecated
With these changes all previous versions of this library are now full deprecated and there is only 1 version starting with v7.0.0
* [v6.0.x](https://github.com/tanepiper/node-bitly) - Support for Node >=6. Available on npm as `npm install bitly@latest`
* [v5.1.x](https://github.com/tanepiper/node-bitly/tree/v5.x.x) - Support for Node >=4. Available on npm as `npm install bitly@stable`
Here is a simple example of how you might have to update your use of node-bitly to account for the change:
```js
// Both versions
const BitlyClient = require('bitly').BitlyClient;
const bitly = new BitlyClient('<accessToken>');
Version 5 is end-of-life and will only recieve minor updates in the future and is considered stable. This will only ever support the **Bitly v3** API
// v6.1.0
async function example(url) {
const response = await bitly.shorten(url);
console.log(`Your shortened bitlink is ${response.url}`);
}
// v7.x.x
async function example(url) {
const response = await bitly.shorten(url);
console.log(`Your shortened bitlink is ${response.link}`);
}
```
Version 6 is the current in-development version, re-written in Typescript. This version currently only supports the **Bitly v3** API and will continue to do so in `v6.0.x`. Version `6.1.x` will introduce **Bitly v4** support.
## Module Features

@@ -19,8 +38,6 @@

For more information on the API request and responses visit the [Bitly API docs](https://dev.bitly.com/api.html)
For more information on the API request and responses visit the [Bitly API docs](https://dev.bitly.com/v4_documentation.html)
`node-bitly` is programmed with `TypeScript` but is compiled to JavaScript and supports `node 6, 8, 10`. When you import the client you get full type information. There maybe be some gaps in the information but this will be filled in, in future releases.
`node-bitly` is programmed with `TypeScript` but is compiled to JavaScript and supports `node >= 10.0.0`. When you import the client you get full type information. There maybe be some gaps in the information but this will be filled in, in future releases.
**Currently `node-bitly` only supports Bitly's `v3` API and has this hard coded in the parameter type. Support for version 4 will be added in a future release**
## Installation

@@ -45,3 +62,3 @@

```js
```ts
import { BitlyClient } from 'bitly';

@@ -63,2 +80,22 @@ const bitly = new BitlyClient('<accessToken>', {});

When the library throws an error, it should be the error object response from Bitly, but if something has gone wrong with your internet or intermediate requests, it is possible that a generic AxiosError might get returned. You can use an exported Type Guard to narrow the type:
```ts
import {BitlyClient, isBitlyErrResponse} from 'bitly';
const bitly = new BitlyClient(process.env.BITLY_API_KEY);
let data: BitlyLink;
try {
data = await bitly.shorten('http://bit.ly/38XaXKy');
} catch (error) {
if (isBitlyErrResponse(error)) {
// Inferred type by TS is `BitlyErrorResponse`
console.log(`Bitly error: ${error.description}`);
} else if (error.isAxiosError) {
// Infererred type is `any`, but you can cast to AxiosError safely
const axiosError = error as unknown as AxiosError;
console.log(`AxiosError:`, axiosError.toJSON());
}
}
```
#### JavaScript

@@ -115,9 +152,6 @@

To run tests type `npm test`. Please note one test will fail if you use your own API key, please update the string accordingly.
To run tests type `npm test`.
## Support This Project
This module is a side project of mine and I don't actively use the module except to completly over-engineer the CI pipeline and re-write it in Typescript all in the name of learning. But to add features like the v4 API would take a lot of work, so if you use this library a lot please consider donating using the links below. Or if you learned something useful from one of my blog posts talking about the changes I've done with this module please consider leaving a tip.
The tests use [`replay`](https://www.npmjs.com/package/replay), which caches the responses from Bitly under the `/fixtures` directory, until you edit a test's requests payload. This means you can run the test suite without having a Bitly API key, until you need to edit or add a new test.
[![Beerpay](https://beerpay.io/tanepiper/node-bitly/badge.svg?style=beer-square)](https://beerpay.io/tanepiper/node-bitly) [![Beerpay](https://beerpay.io/tanepiper/node-bitly/make-wish.svg?style=flat-square)](https://beerpay.io/tanepiper/node-bitly?focus=wish)
You can also [PayPal Me](https://paypal.me/tanepiper).
Once you need to run tests that can't use a cached response and actually hit Bitly's API, you will need to pass your API key to the tests by having an environment variable `BITLY_API_KEY` set to the value of your key.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc