@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.
137 lines • 6.67 kB
JavaScript
;
/**
* AdvancedBilling
*
* This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Configuration = exports.Environment = void 0;
var schema_js_1 = require("./schema.js");
/** Environments available for API */
var Environment;
(function (Environment) {
Environment["US"] = "US";
Environment["EU"] = "EU";
})(Environment || (exports.Environment = Environment = {}));
var Configuration;
(function (Configuration) {
function fromJsonConfig(jsonConfig) {
var configurationObject = JSON.parse(jsonConfig);
var result = (0, schema_js_1.validateAndMap)(jsonConfig, configurationObject);
if (result.errors) {
throw new Error('Invalid configuration provided. Please check the following errors:\n' +
result.errors.map(function (e) { return e.message; }).join('\n'));
}
return result.result;
}
Configuration.fromJsonConfig = fromJsonConfig;
function fromEnvironment(envVariables) {
var _a, _b;
var config = {};
config.timeout = envVariables.TIMEOUT;
config.environment = envVariables.ENVIRONMENT;
config.site = envVariables.SITE;
if (envVariables.USERNAME && envVariables.PASSWORD) {
config.basicAuthCredentials = {
username: envVariables.USERNAME,
password: envVariables.PASSWORD,
};
}
config.httpClientOptions = {
timeout: envVariables.TIMEOUT,
retryConfig: {
retryOnTimeout: envVariables.RETRY_ON_TIMEOUT,
retryInterval: envVariables.RETRY_INTERVAL,
maxNumberOfRetries: envVariables.MAX_NUMBER_OF_RETRIES,
maximumRetryWaitTime: envVariables.MAX_RETRY_WAIT_TIME,
backoffFactor: envVariables.RETRY_BACKOFF_FACTOR,
httpStatusCodesToRetry: (_a = envVariables.HTTP_STATUS_CODES_TO_RETRY) === null || _a === void 0 ? void 0 : _a.split(',').map(function (s) { return s.trim(); }),
httpMethodsToRetry: (_b = envVariables.HTTP_METHODS_TO_RETRY) === null || _b === void 0 ? void 0 : _b.split(',').map(function (s) { return s.trim(); }),
},
};
if (envVariables.PROXY_ADDRESS) {
config.httpClientOptions.proxySettings = {
address: envVariables.PROXY_ADDRESS,
port: envVariables.PROXY_PORT,
};
if (envVariables.PROXY_AUTH_USERNAME &&
envVariables.PROXY_AUTH_PASSWORD) {
config.httpClientOptions.proxySettings.auth = {
username: envVariables.PROXY_AUTH_USERNAME,
password: envVariables.PROXY_AUTH_PASSWORD,
};
}
}
var result = (0, schema_js_1.validateAndMap)(config, configurationSchema);
if (result.errors) {
throw new Error('Invalid configuration provided. Please check the following errors:\n' +
result.errors.map(function (e) { return e.message; }).join('\n'));
}
return result.result;
}
Configuration.fromEnvironment = fromEnvironment;
})(Configuration || (exports.Configuration = Configuration = {}));
var configurationSchema = (0, schema_js_1.object)({
timeout: ['timeout', (0, schema_js_1.optional)((0, schema_js_1.number)())],
environment: ['environment', (0, schema_js_1.optional)((0, schema_js_1.stringEnum)(Environment))],
basicAuthCredentials: [
'basicAuthCredentials',
(0, schema_js_1.optional)((0, schema_js_1.object)({
username: ['username', (0, schema_js_1.string)()],
password: ['password', (0, schema_js_1.string)()],
})),
],
httpClientOptions: [
'httpClientOptions',
(0, schema_js_1.optional)((0, schema_js_1.object)({
timeout: ['timeout', (0, schema_js_1.optional)((0, schema_js_1.number)())],
retryConfig: [
'retryConfig',
(0, schema_js_1.optional)((0, schema_js_1.object)({
maxNumberOfRetries: ['maxNumberOfRetries', (0, schema_js_1.optional)((0, schema_js_1.number)())],
retryOnTimeout: ['retryOnTimeout', (0, schema_js_1.optional)((0, schema_js_1.boolean)())],
retryInterval: ['retryInterval', (0, schema_js_1.optional)((0, schema_js_1.number)())],
maximumRetryWaitTime: [
'maximumRetryWaitTime',
(0, schema_js_1.optional)((0, schema_js_1.number)()),
],
backoffFactor: ['backoffFactor', (0, schema_js_1.optional)((0, schema_js_1.number)())],
httpStatusCodesToRetry: [
'httpStatusCodesToRetry',
(0, schema_js_1.optional)((0, schema_js_1.array)((0, schema_js_1.number)())),
],
httpMethodsToRetry: [
'httpMethodsToRetry',
(0, schema_js_1.optional)((0, schema_js_1.array)((0, schema_js_1.anyOf)([
(0, schema_js_1.literal)('GET'),
(0, schema_js_1.literal)('DELETE'),
(0, schema_js_1.literal)('HEAD'),
(0, schema_js_1.literal)('OPTIONS'),
(0, schema_js_1.literal)('POST'),
(0, schema_js_1.literal)('PUT'),
(0, schema_js_1.literal)('PATCH'),
(0, schema_js_1.literal)('LINK'),
(0, schema_js_1.literal)('UNLINK'),
]))),
],
})),
],
proxySettings: [
'proxySettings',
(0, schema_js_1.optional)((0, schema_js_1.object)({
address: ['address', (0, schema_js_1.string)()],
port: ['port', (0, schema_js_1.optional)((0, schema_js_1.number)())],
auth: [
'auth',
(0, schema_js_1.optional)((0, schema_js_1.object)({
username: ['username', (0, schema_js_1.string)()],
password: ['password', (0, schema_js_1.string)()],
})),
],
})),
],
})),
],
site: ['site', (0, schema_js_1.optional)((0, schema_js_1.string)())],
});
//# sourceMappingURL=configuration.js.map