1.8.0 • Published 1 year ago

@goparrot/square-connect-plus v1.8.0

Weekly downloads
94
License
MIT
Repository
github
Last release
1 year ago

Build Status Coverage Status NPM version Greenkeeper badge Commitizen friendly Conventional Commits

Square Connect Plus

Square Connect Plus is a Typescript library which extends the official Square Node.js SDK library with additional functionality. The library does not modify request and response payload.

Installation

$ npm i @goparrot/square-connect-plus square@17.0.0

Usage

Simple example

import { SquareClient } from '@goparrot/square-connect-plus';
import { ListLocationsResponse } from 'square';

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.length) {
            throw new Error(`cant fetch locations`);
        }

        console.info('locations', listLocationsResponse.locations);
    } catch (error) {
        console.error(error);
        // or error as string with stack + request and response payload
        // console.error(`${error.stack}\npayload: ${error.toString()}`);
    }
})();

Advanced example

import { SquareClient, exponentialDelay, retryCondition } from '@goparrot/square-connect-plus';

const accessToken: string = `${process.env.SQUARE_ACCESS_TOKEN}`;
const squareClient: SquareClient = new SquareClient(accessToken, {
    retry: {
        maxRetries: 10,
    },
    configuration: {
        timeout: 60_000,
    },
    logger: console,
});

Available Options

retry Options

NameTypeDefaultDescription
maxRetriesNumber6The number of times to retry before failing.
retryConditionFunctionretryConditionA callback to further control if a request should be retried. By default, the built-in retryCondition function is used.
retryDelayFunctionexponentialDelayA callback to further control the delay between retried requests. By default, the built-in exponentialDelay function is used (Exponential Backoff).

originClient Options

A set of possible settings for the original library.

NameTypeDefaultDescription
customUrlStringhttps://connect.squareup.comThe custom URL against which to resolve every API call's (relative) path.
additionalHeadersObject{}Record<string, string>
timeoutNumber60_000The default HTTP timeout for all API calls.
squareVersionString2021-12-15The default square api version for all API calls.
environmentEnumEnvironment.ProductionThe default square enviroment for all API calls.
accessTokenString''Scoped access token.

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.

1.8.0

1 year ago

1.7.0

3 years ago

1.6.0-dev.7277.2

3 years ago

1.6.1

3 years ago

1.2.0

3 years ago

1.5.2-dev-7252.0

3 years ago

1.6.0

3 years ago

1.4.0

3 years ago

1.3.0-dev.7073.0

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.2.0-dev-7201.3

3 years ago

1.5.0

3 years ago

1.2.0-dev-7201.1

3 years ago

1.3.0

3 years ago

1.2.0-dev-7201.0

3 years ago

1.1.0-dev.7073.0

3 years ago

1.1.0-dev.gc.0

3 years ago

1.1.0-dev.gc.1

3 years ago

1.1.0

3 years ago

1.0.0-dev.6755.0

3 years ago

1.0.0

4 years ago

0.4.0-dev-6205.0

4 years ago

0.4.0-dev-6205.1

4 years ago

0.5.0-dev-6619.2

4 years ago

0.5.0-dev-6619.3

4 years ago

0.5.0-dev-6619.4

4 years ago

0.5.0-dev-6619.5

4 years ago

0.5.0-dev-6619.6

4 years ago

0.5.0-dev-6619.7

4 years ago

0.5.0-dev-6619.8

4 years ago

0.5.0-dev-6619.0

4 years ago

0.5.0-dev-6619.1

4 years ago

0.4.0

4 years ago

0.3.1

4 years ago

0.2.0-dev-5420.0

4 years ago

0.3.0

4 years ago

0.2.0

5 years ago

0.1.0-dev-4397.5

5 years ago

0.1.0-dev-4397.4

5 years ago

0.1.0-dev-4397.2

5 years ago

0.1.0-dev-3201.1

5 years ago

0.1.0-dev-3201.0

5 years ago

0.1.0

5 years ago

0.1.0-dev.0

5 years ago

0.0.3

5 years ago

0.0.2

6 years ago

0.0.1

6 years ago

0.0.1-dev.4

6 years ago

0.0.1-dev.3

6 years ago

0.0.1-dev.2

6 years ago

0.0.1-dev.1

6 years ago

0.0.1-dev.0

6 years ago