@maxio-com/advanced-billing-sdk
Version:
Ultimate billing and pricing flexibility for B2B SaaS. Maxio integrates directly into your product, so you can seamlessly manage your product catalog, bill customers, and collect payments.
98 lines • 4.45 kB
JavaScript
/**
* AdvancedBilling
*
* This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
import { createAuthProviderFromConfig } from './authProvider.js';
import { Environment } from './configuration.js';
import { DEFAULT_CONFIGURATION, DEFAULT_RETRY_CONFIG, } from './defaultConfiguration.js';
import { ApiError } from './core.js';
import { pathTemplate, SkipEncode } from './core.js';
import { setHeader } from './core.js';
import { updateUserAgent } from './core.js';
import { AbortError, createRequestBuilderFactory, } from './core.js';
import { HttpClient } from './clientAdapter.js';
export class Client {
constructor(config) {
var _a, _b, _c, _d, _e;
this._config = Object.assign(Object.assign({}, DEFAULT_CONFIGURATION), config);
this._retryConfig = Object.assign(Object.assign({}, DEFAULT_RETRY_CONFIG), (_a = this._config.httpClientOptions) === null || _a === void 0 ? void 0 : _a.retryConfig);
this._timeout =
typeof ((_b = this._config.httpClientOptions) === null || _b === void 0 ? void 0 : _b.timeout) != 'undefined'
? this._config.httpClientOptions.timeout
: this._config.timeout;
this._userAgent = updateUserAgent('AB SDK TypeScript:8.0.0 on OS {os-info}');
this._requestBuilderFactory = createRequestHandlerFactory((server) => getBaseUri(server, this._config), createAuthProviderFromConfig(this._config), new HttpClient(AbortError, {
timeout: this._timeout,
clientConfigOverrides: this._config.unstable_httpClientOptions,
httpAgent: (_c = this._config.httpClientOptions) === null || _c === void 0 ? void 0 : _c.httpAgent,
httpsAgent: (_d = this._config.httpClientOptions) === null || _d === void 0 ? void 0 : _d.httpsAgent,
proxySettings: (_e = this._config.httpClientOptions) === null || _e === void 0 ? void 0 : _e.proxySettings,
}), [
withErrorHandlers,
withUserAgent(this._userAgent),
withAuthenticationByDefault,
], this._retryConfig);
}
getRequestBuilderFactory() {
return this._requestBuilderFactory;
}
/**
* Clone this client and override given configuration options
*/
withConfiguration(config) {
return new Client(Object.assign(Object.assign({}, this._config), config));
}
}
function createHttpClientAdapter(client) {
return async (request, requestOptions) => {
return await client.executeRequest(request, requestOptions);
};
}
function getBaseUri(server = 'production', config) {
if (config.environment === Environment.US) {
if (server === 'production') {
return pathTemplate `https://${new SkipEncode(config.site)}.chargify.com`;
}
if (server === 'ebb') {
return pathTemplate `https://events.chargify.com/${new SkipEncode(config.site)}`;
}
}
if (config.environment === Environment.EU) {
if (server === 'production') {
return pathTemplate `https://${new SkipEncode(config.site)}.ebilling.maxio.com`;
}
if (server === 'ebb') {
return pathTemplate `https://events.chargify.com/${new SkipEncode(config.site)}`;
}
}
throw new Error('Could not get Base URL. Invalid environment or server.');
}
function createRequestHandlerFactory(baseUrlProvider, authProvider, httpClient, addons, retryConfig) {
const requestBuilderFactory = createRequestBuilderFactory(createHttpClientAdapter(httpClient), baseUrlProvider, ApiError, authProvider, retryConfig);
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 withUserAgent(userAgent) {
return (rb) => {
rb.interceptRequest((request) => {
var _a;
const headers = (_a = request.headers) !== null && _a !== void 0 ? _a : {};
setHeader(headers, 'user-agent', userAgent);
return Object.assign(Object.assign({}, request), { headers });
});
};
}
function withAuthenticationByDefault(rb) {
rb.authenticate([{ basicAuth: true }]);
}
//# sourceMappingURL=client.js.map