card-management-sdk
Version:
The Shell Card Management API is REST-based and employs OAUTH 2.0,Basic and ApiKey authentication. The API endpoints accept JSON-encoded request bodies, return JSON-encoded responses and use standard HTTP response codes. All resources are located in the S
139 lines • 6.13 kB
JavaScript
/**
* Shell Card Management APIsLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
import { oAuthTokenSchema } from './models/oAuthToken.js';
import { anyOf, array, boolean, literal, number, object, optional, string, stringEnum, validateAndMap, } from './schema.js';
/** Environments available for API */
export var Environment;
(function (Environment) {
Environment["SIT"] = "SIT";
Environment["Production"] = "Production";
})(Environment || (Environment = {}));
export var Configuration;
(function (Configuration) {
function fromJsonConfig(jsonConfig) {
const configurationObject = JSON.parse(jsonConfig);
const result = validateAndMap(jsonConfig, configurationObject);
if (result.errors) {
throw new Error('Invalid configuration provided. Please check the following errors:\n' +
result.errors.map((e) => e.message).join('\n'));
}
return result.result;
}
Configuration.fromJsonConfig = fromJsonConfig;
function fromEnvironment(envVariables) {
var _a, _b;
const config = {};
config.timeout = envVariables.TIMEOUT;
config.environment = envVariables.ENVIRONMENT;
if (envVariables.O_AUTH_CLIENT_ID && envVariables.O_AUTH_CLIENT_SECRET) {
config.clientCredentialsAuthCredentials = {
oAuthClientId: envVariables.O_AUTH_CLIENT_ID,
oAuthClientSecret: envVariables.O_AUTH_CLIENT_SECRET,
oAuthToken: envVariables.O_AUTH_TOKEN,
oAuthClockSkew: envVariables.O_AUTH_CLOCK_SKEW,
};
}
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((s) => s.trim()),
httpMethodsToRetry: (_b = envVariables.HTTP_METHODS_TO_RETRY) === null || _b === void 0 ? void 0 : _b.split(',').map((s) => 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,
};
}
}
const result = validateAndMap(config, configurationSchema);
if (result.errors) {
throw new Error('Invalid configuration provided. Please check the following errors:\n' +
result.errors.map((e) => e.message).join('\n'));
}
return result.result;
}
Configuration.fromEnvironment = fromEnvironment;
})(Configuration || (Configuration = {}));
const configurationSchema = object({
timeout: ['timeout', optional(number())],
environment: ['environment', optional(stringEnum(Environment))],
oAuthClientId: ['oAuthClientId', optional(string())],
oAuthClientSecret: ['oAuthClientSecret', optional(string())],
oAuthToken: ['oAuthToken', optional(optional(oAuthTokenSchema))],
clientCredentialsAuthCredentials: [
'clientCredentialsAuthCredentials',
optional(object({
oAuthClientId: ['oAuthClientId', string()],
oAuthClientSecret: ['oAuthClientSecret', string()],
oAuthClockSkew: ['oAuthClockSkew', optional(number())],
})),
],
httpClientOptions: [
'httpClientOptions',
optional(object({
timeout: ['timeout', optional(number())],
retryConfig: [
'retryConfig',
optional(object({
maxNumberOfRetries: ['maxNumberOfRetries', optional(number())],
retryOnTimeout: ['retryOnTimeout', optional(boolean())],
retryInterval: ['retryInterval', optional(number())],
maximumRetryWaitTime: [
'maximumRetryWaitTime',
optional(number()),
],
backoffFactor: ['backoffFactor', optional(number())],
httpStatusCodesToRetry: [
'httpStatusCodesToRetry',
optional(array(number())),
],
httpMethodsToRetry: [
'httpMethodsToRetry',
optional(array(anyOf([
literal('GET'),
literal('DELETE'),
literal('HEAD'),
literal('OPTIONS'),
literal('POST'),
literal('PUT'),
literal('PATCH'),
literal('LINK'),
literal('UNLINK'),
]))),
],
})),
],
proxySettings: [
'proxySettings',
optional(object({
address: ['address', string()],
port: ['port', optional(number())],
auth: [
'auth',
optional(object({
username: ['username', string()],
password: ['password', string()],
})),
],
})),
],
})),
],
});
//# sourceMappingURL=configuration.js.map