@goparrot/square-connect-plus v1.7.0
Square Connect Plus
Square Connect Plus is a Typescript library which extends the official Square Connect APIs library with additional functionality
Installation
$ npm i @goparrot/square-connect-plus square-connect
Usage
Simple example
import { SquareClient } from '@goparrot/square-connect-plus';
import { ListLocationsResponse } from 'square-connect';
const accessToken: string = `${process.env.SQUARE_ACCESS_TOKEN}`;
const squareClient: SquareClient = new SquareClient(accessToken);
(async () => {
try {
const listLocationsResponse: ListLocationsResponse = await squareClient.getLocationsApi().listLocations();
if (listLocationsResponse.errors) {
throw new Error(`cant fetch locations`);
}
console.info('locations', listLocationsResponse.locations);
} catch (err) {
console.error(err);
}
})();
Advanced example
import { SquareClient, exponentialDelay, ILogger } from '@goparrot/square-connect-plus';
import { ListLocationsResponse } from 'square-connect';
const accessToken: string = `${process.env.SQUARE_ACCESS_TOKEN}`;
const squareClient: SquareClient = new SquareClient(accessToken, {
retry: {
maxRetries: 6,
retryDelay: exponentialDelay,
},
originClient: {
timeout: 10000,
},
logger: console,
});
Available Options
retry
Options
Name | Type | Default | Description |
---|---|---|---|
maxRetries | Number | 3 | The number of times to retry before failing. |
retryDelay | Function | exponentialDelay | A callback to further control the delay between retried requests. By default, the built-in exponentialDelay function is used (Exponential Backoff). The function is passed retryCount and error . |
originClient
Options
A set of possible settings for the original library.
| --- | --- | --- | --- |
| basePath | String
| https://connect.squareup.com
| The base URL against which to resolve every API call's (relative) path. |
| defaultHeaders | Array
| { 'User-Agent': 'Square-Connect-Javascript/2.20191217.0' }
| The default HTTP headers to be included for all API calls. |
| timeout | Number
| 15000
| The default HTTP timeout for all API calls. |
| cache | Boolean
| true
| If set to false an additional timestamp parameter is added to all API GET calls to prevent browser caching. |
| enableCookies | Boolean
| false
| If set to true, the client will save the cookies from each server response, and return them in the next request. |
logger
Option
By default, the built-in NullLogger
class is used.
You can use any logger that fits the built-in ILogger
interface
Versioning
Square Connect Plus follows Semantic Versioning.
Contributing
See CONTRIBUTING
file.
Unit Tests
In order to run the test suite, install the development dependencies:
$ npm i
Then, run the following command:
$ npm run coverage
License
Square Connect Plus is MIT licensed.
10 months ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago