Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies and switch to axios #106

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/pushes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: build-and-release

"on":
push:
branches:
- master
pull_request:
types:
- opened
- synchronize

permissions:
contents: write
packages: write
pull-requests: write

jobs:
made-with-tpgha:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Setting up NodeJs
id: setup-node-js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: npm ci
run: npm ci
shell: bash

- name: npm run lint
run: npm run lint
shell: bash

- name: npm run test
run: npm run test
shell: bash

- name: npm run build
run: npm run build
shell: bash

- name: npm run release
run: npx semantic-release
shell: bash
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ src
.gitignore
.nvmrc
.releaserc
.travis.yml
.github
tsconfig.*
tslint.json
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v12.21.0
v20
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
output
7 changes: 7 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
trailingComma: 'all',
singleQuote: true,
printWidth: 120,
tabWidth: 2,
endOfLine: 'auto',
};
5 changes: 0 additions & 5 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
analyzeCommits:
preset: eslint
generateNotes:
preset: eslint
path: '@semantic-release/release-notes-generator'
prepare:
- "@semantic-release/changelog"
- "@semantic-release/npm"
Expand Down
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# trustpilot

[![Build Status](https://travis-ci.org/trustpilot/node-trustpilot.svg?branch=master)](https://travis-ci.org/trustpilot/node-trustpilot) [![npm](https://img.shields.io/npm/v/trustpilot.svg)](https://www.npmjs.com/package/trustpilot)

This a node API wrapper for accessing the Trustpilot APIs. You can learn all about the Trustpilot API at [https://developers.trustpilot.com/](https://developers.trustpilot.com/).
This a NodeJS API wrapper for accessing the Trustpilot APIs. You can learn all about the Trustpilot API at [https://developers.trustpilot.com/](https://developers.trustpilot.com/).

## Installation

This module is built using Typescript and Node.js `v12.21.x`.

If you are not using version 4 of Node, you'll have to transpile the code down to ES5 yourself.
This module is built using Typescript and NodeJS `v20.x`.

Install using `npm install trustpilot`

## Usage

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.
The trustpilot module is async/await based. It provides an [axios instance](https://github.com/axios/axios?tab=readme-ov-file#creating-an-instance) with sane defaults.

### Basic Usage

Expand All @@ -33,6 +29,7 @@ async run() {
// For basic calls authentified by API key, use client.apiRequest
try {
const response = await client.apiRequest('/v1/resources/images');
console.log(response.data);
} catch(error) {
// handle the error
});
Expand All @@ -41,7 +38,7 @@ async run() {

### Usage with OAuth

For calls authentified by OAuth token, use the `authenticate()` promise, which resolves with a `request-promise-native`
For calls authentified by OAuth token, use the `authenticate()` promise, which resolves with an `axiosInstance`
object with everything you need.

```ts
Expand All @@ -56,9 +53,8 @@ async run() {
}).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`);
const response = await client.get(`/v1/private/business-units/${YOUR_BUSINESS_UNIT_ID}/reviews`);
console.log(response.data);
} catch(error) {
// handle the error
});
Expand Down Expand Up @@ -102,3 +98,18 @@ async run() {
// Use client
}
```

### Migration from v3 to v4

As of version 4, [request-promise-native](https://github.com/request/request-promise-native) has been replaced by [axios](https://github.com/axios/axios)

This means all responses are now following [this response schema](https://github.com/axios/axios?tab=readme-ov-file#response-schema)
so code that previously used the response body directly, will need to add a `.data`

```ts
const json = await client.apiRequest('...');
```

```ts
const json = (await client.apiRequest('...')).data;
```
Loading