import { ApplePayApi } from './api/applePayApi' ; import { BankAccountsApi } from './api/bankAccountsApi' ; import { BookingsApi } from './api/bookingsApi' ; import { CardsApi } from './api/cardsApi' ; import { CashDrawersApi } from './api/cashDrawersApi' ; import { CatalogApi } from './api/catalogApi' ; import { CheckoutApi } from './api/checkoutApi' ; import { CustomerGroupsApi } from './api/customerGroupsApi' ; import { CustomersApi } from './api/customersApi' ; import { CustomerSegmentsApi } from './api/customerSegmentsApi' ; import { DevicesApi } from './api/devicesApi' ; import { DisputesApi } from './api/disputesApi' ; import { EmployeesApi } from './api/employeesApi' ; import { GiftCardActivitiesApi } from './api/giftCardActivitiesApi' ; import { GiftCardsApi } from './api/giftCardsApi' ; import { InventoryApi } from './api/inventoryApi' ; import { InvoicesApi } from './api/invoicesApi' ; import { LaborApi } from './api/laborApi' ; import { LocationsApi } from './api/locationsApi' ; import { LoyaltyApi } from './api/loyaltyApi' ; import { MerchantsApi } from './api/merchantsApi' ; import { MobileAuthorizationApi } from './api/mobileAuthorizationApi' ; import { OAuthApi } from './api/oAuthApi' ; import { OrdersApi } from './api/ordersApi' ; import { PaymentsApi } from './api/paymentsApi' ; import { RefundsApi } from './api/refundsApi' ; import { SitesApi } from './api/sitesApi' ; import { SnippetsApi } from './api/snippetsApi' ; import { SubscriptionsApi } from './api/subscriptionsApi' ; import { TeamApi } from './api/teamApi' ; import { TerminalApi } from './api/terminalApi' ; import { TransactionsApi } from './api/transactionsApi' ; import { V1TransactionsApi } from './api/v1TransactionsApi' ; import { accessTokenAuthenticationProvider } from './authentication' ; import { AuthParams , ClientInterface , SdkRequestBuilder , SdkRequestBuilderFactory , Server , } from './clientInterface' ; import { Configuration , Environment } from './configuration' ; import { DEFAULT_CONFIGURATION } from './defaultConfiguration' ; import { ApiError } from './errors/apiError' ; import { assertHeaders , mergeHeaders , setHeader } from './core' ; import { pathTemplate , SkipEncode } from './core' ; import { AuthenticatorInterface , createRequestBuilderFactory , HttpClient , HttpClientInterface , XmlSerializerInterface , } from './core' ; import { XmlSerialization } from './http/xmlSerialization' ; /** Current SDK version */ export const SDK_VERSION = '17.0.0' ; const USER_AGENT = 'Square-TypeScript-SDK/17.0.0' ; export class Client implements ClientInterface { private _config : Readonly < Configuration > ; private _requestBuilderFactory : SdkRequestBuilderFactory ; public readonly applePayApi : ApplePayApi ; public readonly bankAccountsApi : BankAccountsApi ; public readonly bookingsApi : BookingsApi ; public readonly cardsApi : CardsApi ; public readonly cashDrawersApi : CashDrawersApi ; public readonly catalogApi : CatalogApi ; public readonly checkoutApi : CheckoutApi ; public readonly customerGroupsApi : CustomerGroupsApi ; public readonly customersApi : CustomersApi ; public readonly customerSegmentsApi : CustomerSegmentsApi ; public readonly devicesApi : DevicesApi ; public readonly disputesApi : DisputesApi ; public readonly employeesApi : EmployeesApi ; public readonly giftCardActivitiesApi : GiftCardActivitiesApi ; public readonly giftCardsApi : GiftCardsApi ; public readonly inventoryApi : InventoryApi ; public readonly invoicesApi : InvoicesApi ; public readonly laborApi : LaborApi ; public readonly locationsApi : LocationsApi ; public readonly loyaltyApi : LoyaltyApi ; public readonly merchantsApi : MerchantsApi ; public readonly mobileAuthorizationApi : MobileAuthorizationApi ; public readonly oAuthApi : OAuthApi ; public readonly ordersApi : OrdersApi ; public readonly paymentsApi : PaymentsApi ; public readonly refundsApi : RefundsApi ; public readonly sitesApi : SitesApi ; public readonly snippetsApi : SnippetsApi ; public readonly subscriptionsApi : SubscriptionsApi ; public readonly teamApi : TeamApi ; public readonly terminalApi : TerminalApi ; public readonly transactionsApi : TransactionsApi ; public readonly v1TransactionsApi : V1TransactionsApi ; constructor ( config ? ) { this . _config = { ... DEFAULT_CONFIGURATION , ... config , } ; this . _requestBuilderFactory = createRequestHandlerFactory ( server => getBaseUri ( server , this . _config ) , accessTokenAuthenticationProvider ( this . _config ) , new HttpClient ( { timeout : this . _config . timeout , clientConfigOverrides : this . _config . unstable_httpClientOptions , } ) , [ withErrorHandlers , withUserAgent , withAdditionalHeaders ( this . _config ) , withAuthenticationByDefault , withSquareVersion ( this . _config ) , ] , new XmlSerialization ( ) ) ; this . applePayApi = new ApplePayApi ( this ) ; this . bankAccountsApi = new BankAccountsApi ( this ) ; this . bookingsApi = new BookingsApi ( this ) ; this . cardsApi = new CardsApi ( this ) ; this . cashDrawersApi = new CashDrawersApi ( this ) ; this . catalogApi = new CatalogApi ( this ) ; this . checkoutApi = new CheckoutApi ( this ) ; this . customerGroupsApi = new CustomerGroupsApi ( this ) ; this . customersApi = new CustomersApi ( this ) ; this . customerSegmentsApi = new CustomerSegmentsApi ( this ) ; this . devicesApi = new DevicesApi ( this ) ; this . disputesApi = new DisputesApi ( this ) ; this . employeesApi = new EmployeesApi ( this ) ; this . giftCardActivitiesApi = new GiftCardActivitiesApi ( this ) ; this . giftCardsApi = new GiftCardsApi ( this ) ; this . inventoryApi = new InventoryApi ( this ) ; this . invoicesApi = new InvoicesApi ( this ) ; this . laborApi = new LaborApi ( this ) ; this . locationsApi = new LocationsApi ( this ) ; this . loyaltyApi = new LoyaltyApi ( this ) ; this . merchantsApi = new MerchantsApi ( this ) ; this . mobileAuthorizationApi = new MobileAuthorizationApi ( this ) ; this . oAuthApi = new OAuthApi ( this ) ; this . ordersApi = new OrdersApi ( this ) ; this . paymentsApi = new PaymentsApi ( this ) ; this . refundsApi = new RefundsApi ( this ) ; this . sitesApi = new SitesApi ( this ) ; this . snippetsApi = new SnippetsApi ( this ) ; this . subscriptionsApi = new SubscriptionsApi ( this ) ; this . teamApi = new TeamApi ( this ) ; this . terminalApi = new TerminalApi ( this ) ; this . transactionsApi = new TransactionsApi ( this ) ; this . v1TransactionsApi = new V1TransactionsApi ( this ) ; } public getRequestBuilderFactory ( ) { return this . _requestBuilderFactory ; } /**
     * Clone this client and override given configuration options
     */ public withConfiguration ( config ) { return new Client ( { ... this . _config , ... config } ) ; } } function createHttpClientAdapter ( client ) { return async ( request , requestOptions ) => { return await client . executeRequest ( request , requestOptions ) ; } ; } function getBaseUri ( server = 'default' , config ) { if ( config . environment === Environment . Production ) { if ( server === 'default' ) { return 'https://connect.squareup.com' ; } } if ( config . environment === Environment . Sandbox ) { if ( server === 'default' ) { return 'https://connect.squareupsandbox.com' ; } } if ( config . environment === Environment . Custom ) { if ( server === 'default' ) { return pathTemplate `${ new SkipEncode ( config . customUrl ) }` ; } } throw new Error ( 'Could not get Base URL. Invalid environment or server.' ) ; } function createRequestHandlerFactory ( baseUrlProvider , authProvider , httpClient , addons , xmlSerializer ) { const requestBuilderFactory = createRequestBuilderFactory ( createHttpClientAdapter ( httpClient ) , baseUrlProvider , ApiError , authProvider , xmlSerializer ) ; return tap ( requestBuilderFactory , ... addons ) ; } function tap ( requestBuilderFactory , ... callback ) { return ( ... args ) => { const requestBuilder = requestBuilderFactory ( ... args ) ; callback . forEach ( c => c ( requestBuilder ) ) ; return requestBuilder ; } ; } function withErrorHandlers ( rb ) { rb . defaultToError ( ApiError ) ; } function withAdditionalHeaders ( { additionalHeaders , } ) { const clone = { ... additionalHeaders } ; assertHeaders ( clone ) ; return ( rb ) => { rb . interceptRequest ( request => { const headers = request . headers ?? { } ; mergeHeaders ( headers , clone ) ; return { ... request , headers } ; } ) ; } ; } function withUserAgent ( rb ) { rb . header ( 'user-agent' , USER_AGENT ) ; } function withSquareVersion ( { squareVersion } ) { return ( rb ) => { rb . interceptRequest ( request => { const headers = request . headers ?? { } ; setHeader ( headers , 'Square-Version' , squareVersion ) ; return { ... request , headers } ; } ) ; } ; } function withAuthenticationByDefault ( rb ) { rb . authenticate ( true ) ; }