UNPKG

@adyen/api-library

Version:

The Adyen API Library for NodeJS enables you to work with Adyen APIs.

121 lines 4.99 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const config_1 = __importStar(require("./config")); const config_2 = require("./config"); const httpURLConnectionClient_1 = __importDefault(require("./httpClient/httpURLConnectionClient")); /** * Main Adyen API Client class. * Handles configuration, authentication, and HTTP client setup for API requests. */ class Client { /** * Constructs a new Client instance. * @param options - Configuration object */ constructor(options, httpClient) { this.config = options; if (!this.config.environment) { throw new Error("Environment must be defined"); } // set Terminal API endpoints if (this.config.environment === config_1.EnvironmentEnum.TEST) { // one TEST endpoint for all regions this.config.terminalApiCloudEndpoint = config_2.TERMINAL_API_ENDPOINT_TEST; } else if (this.config.environment === config_1.EnvironmentEnum.LIVE) { // region-based LIVE endpoints if (this.config.region) { if (!config_1.default.isRegionValid(this.config.region)) { throw new Error(`Invalid region provided: ${this.config.region}`); } this.config.terminalApiCloudEndpoint = config_1.default.getTerminalApiEndpoint(this.config.region); } } // legacy support for marketPayEndpoint if (this.config.environment === config_1.EnvironmentEnum.TEST) { this.config.marketPayEndpoint = Client.MARKETPAY_ENDPOINT_TEST; } else if (this.config.environment === config_1.EnvironmentEnum.LIVE) { this.config.marketPayEndpoint = Client.MARKETPAY_ENDPOINT_LIVE; } // Set application name if provided if (options.applicationName) { this.config.applicationName = options.applicationName; } // Set custom HTTP client if provided if (httpClient) { this._httpClient = httpClient; } } /** * Gets the HTTP client instance, creating a default one if not set. */ get httpClient() { if (!this._httpClient) { this._httpClient = new httpURLConnectionClient_1.default(); } return this._httpClient; } /** * Sets a custom HTTP client. * @param httpClient - The HTTP client to use. */ set httpClient(httpClient) { this._httpClient = httpClient; } /** * Sets the application name in the config. * @param applicationName - The application name. */ setApplicationName(applicationName) { this.config.applicationName = applicationName; } /** * Sets the connection timeout in milliseconds. * @param connectionTimeoutMillis - Timeout in milliseconds. */ setTimeouts(connectionTimeoutMillis) { this.config.connectionTimeoutMillis = connectionTimeoutMillis; } } // Static endpoints and API version constants // @deprecated: use Config.TERMINAL_API_ENDPOINT_TEST instead Client.TERMINAL_API_ENDPOINT_TEST = "https://terminal-api-test.adyen.com"; // @deprecated: use Config.TERMINAL_API_ENDPOINT_LIVE instead Client.TERMINAL_API_ENDPOINT_LIVE = "https://terminal-api-live.adyen.com"; // legacy support for marketPayEndpoint Client.MARKETPAY_ENDPOINT_TEST = "https://cal-test.adyen.com/cal/services"; Client.MARKETPAY_ENDPOINT_LIVE = "https://cal-live.adyen.com/cal/services"; Client.MARKETPAY_ACCOUNT_API_VERSION = "v6"; Client.MARKETPAY_FUND_API_VERSION = "v6"; Client.MARKETPAY_HOP_API_VERSION = "v6"; Client.MARKETPAY_NOTIFICATION_API_VERSION = "v5"; Client.MARKETPAY_NOTIFICATION_CONFIGURATION_API_VERSION = "v6"; exports.default = Client; //# sourceMappingURL=client.js.map