trustpilot
Advanced tools
Comparing version
{ | ||
"name": "trustpilot", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"description": "HTTP client for Trustpilot", | ||
@@ -15,21 +15,39 @@ "homepage": "https://github.com/trustpilot/node-trustpilot", | ||
], | ||
"main": "./src/client.js", | ||
"main": "./dist/trustpilot-api.js", | ||
"scripts": { | ||
"start": "node src/client.js", | ||
"test": "gulp test" | ||
"tsc": "tsc -p tsconfig.build.json", | ||
"test": "mocha --compilers ts:ts-node/register ./spec/*.spec.ts", | ||
"lint": "tslint -c tslint.json --fix -e node_modules/** **/*.ts", | ||
"build": "npm run tsc && npm run test && npm run lint", | ||
"start": "node dist/client.js" | ||
}, | ||
"dependencies": { | ||
"request-promise": "1.0.2" | ||
"request": "^2.87.0", | ||
"request-promise-native": "^1.0.5" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "^7.2.1", | ||
"chai": "^3.2.0", | ||
"chai-as-promised": "^5.1.0", | ||
"eslint-config-trustpilot": "^1.7.0", | ||
"eslint-plugin-babel": "^4.1.1", | ||
"gulp": "^3.9.0", | ||
"gulp-eslint": "^3.0.1", | ||
"gulp-mocha": "^2.1.3", | ||
"mocha": "^2.3.2" | ||
"@semantic-release/changelog": "^3.0.1", | ||
"@semantic-release/git": "^7.0.5", | ||
"@semantic-release/npm": "^5.1.1", | ||
"@semantic-release/release-notes-generator": "^7.1.4", | ||
"@types/chai": "^4.1.4", | ||
"@types/chai-as-promised": "^7.1.0", | ||
"@types/mocha": "^5.2.3", | ||
"@types/request-promise-native": "^1.0.15", | ||
"chai": "^4.1.2", | ||
"chai-as-promised": "^7.1.1", | ||
"commitlint": "^7.2.1", | ||
"conventional-changelog-eslint": "^3.0.1", | ||
"husky": "^1.2.0", | ||
"mocha": "^5.2.0", | ||
"semantic-release": "^15.12.3", | ||
"ts-node": "^6.1.2", | ||
"tslint": "^5.10.0", | ||
"typescript": "^2.9.2" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS" | ||
} | ||
} | ||
} |
@@ -9,3 +9,3 @@ # trustpilot | ||
This module is built using Node.js `v4.0.x`. | ||
This module is built using Typescript and Node.js `v8.10.x`. | ||
@@ -18,25 +18,25 @@ If you are not using version 4 of Node, you'll have to transpile the code down to ES5 yourself. | ||
The trustpilot module is Promise based. It provides [request-promise](https://github.com/request/request-promise) objects with sane defaults. | ||
As of version 3, the project has been converted to Typescript. | ||
The trustpilot module is async/await based. It provides [request-promise-native](https://github.com/request/request-promise-native) objects with sane defaults. | ||
### Basic Usage | ||
```js | ||
let Trustpilot = require('trustpilot'); | ||
```ts | ||
import { TrustpilotApi } from "./trustpilot-api"; | ||
let client = new Trustpilot( | ||
{ | ||
apiKey: 'YOUR-API-KEY', | ||
secret: 'YOUR-SECRET', | ||
username: 'YOUR-TRUSTPILOT-B2B-USERNAME', | ||
password: 'YOUR-TRUSTPILOT-B2B-PASSWORD' | ||
}); | ||
async run() { | ||
const client = new TrustpilotApi({ | ||
key: 'YOUR-API-KEY', | ||
secret: 'YOUR-SECRET', | ||
username: 'YOUR-TRUSTPILOT-B2B-USERNAME', | ||
password: 'YOUR-TRUSTPILOT-B2B-PASSWORD' | ||
}); | ||
// For basic calls authentified by API key, use client.apiRequest | ||
client.apiRequest('/v1/resources/images') | ||
.then((response) => { | ||
// handle the response | ||
}) | ||
.catch((error) => { | ||
// For basic calls authentified by API key, use client.apiRequest | ||
try { | ||
const response = await client.apiRequest('/v1/resources/images'); | ||
} catch(error) { | ||
// handle the error | ||
}); | ||
} | ||
``` | ||
@@ -46,45 +46,44 @@ | ||
For calls authentified by OAuth token, use the `authenticate()` promise, which resolves with a `request-promise` | ||
For calls authentified by OAuth token, use the `authenticate()` promise, which resolves with a `request-promise-native` | ||
object with everything you need. | ||
```js | ||
client.authenticate() | ||
.then((rp) => { | ||
return rp(`/v1/private/business-units/${YOUR_BUSINESS_UNIT_ID}/reviews`) | ||
}) | ||
.then((response) => { | ||
// handle the response | ||
}) | ||
.catch((error) => { | ||
```ts | ||
import { TrustpilotApi } from "./trustpilot-api"; | ||
async run() { | ||
const client = await new TrustpilotApi({ | ||
key: 'YOUR-API-KEY', | ||
secret: 'YOUR-SECRET', | ||
username: 'YOUR-TRUSTPILOT-B2B-USERNAME', | ||
password: 'YOUR-TRUSTPILOT-B2B-PASSWORD' | ||
}).authenticate(); | ||
try { | ||
await client(`/v1/private/business-units/${YOUR_BUSINESS_UNIT_ID}/reviews`); | ||
// same as | ||
await client.get(`/v1/private/business-units/${YOUR_BUSINESS_UNIT_ID}/reviews`); | ||
} catch(error) { | ||
// handle the error | ||
}); | ||
} | ||
``` | ||
### Invitations API | ||
### Override API Base URL | ||
The Invitations API methods have a different base URL. Here are two ways you can access them. | ||
The Invitations API methods have a different base URL. To override it, simply pass the `baseUrl`. | ||
1. Knowing that `authenticate()` promises you a `request-promise` object, you can use `.defaults()` to override the base URL. | ||
```ts | ||
import { TrustpilotApi } from "./trustpilot-api"; | ||
```js | ||
client.authenticate() | ||
.then((rp) => { | ||
return rp.defaults({ | ||
async run() { | ||
const client = await new TrustpilotApi({ | ||
key: 'YOUR-API-KEY', | ||
secret: 'YOUR-SECRET', | ||
username: 'YOUR-TRUSTPILOT-B2B-USERNAME', | ||
password: 'YOUR-TRUSTPILOT-B2B-PASSWORD', | ||
baseUrl: 'https://invitations-api.trustpilot.com' | ||
})(AN-INVITATIONS-API-ENDPOINT) | ||
}); | ||
``` | ||
}).authenticate(); | ||
2. If you only need to access the Invitations API, just initialize your client with the Invitations API base URL. | ||
```js | ||
let Trustpilot = require('trustpilot'); | ||
let client = new Trustpilot( | ||
{ | ||
apiKey: 'YOUR-API-KEY', | ||
secret: 'YOUR-SECRET', | ||
username: 'YOUR-TRUSTPILOT-B2B-USERNAME', | ||
password: 'YOUR-TRUSTPILOT-B2B-PASSWORD' | ||
baseUrl: 'https://invitations-api.trustpilot.com' | ||
}); | ||
// Use client | ||
} | ||
``` |
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
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
18
157.14%266
91.37%1
-50%15105
-81.7%2
100%18
100%87
-1.14%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed