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
130 lines • 6.23 kB
JavaScript
;
/**
* Shell Card Management APIsLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Client = void 0;
var tslib_1 = require("tslib");
var authProvider_js_1 = require("./authProvider.js");
var clientCredentialsAuthManager_js_1 = require("./clientCredentialsAuthManager.js");
var configuration_js_1 = require("./configuration.js");
var defaultConfiguration_js_1 = require("./defaultConfiguration.js");
var core_js_1 = require("./core.js");
var core_js_2 = require("./core.js");
var clientAdapter_js_1 = require("./clientAdapter.js");
var USER_AGENT = 'APIMATIC 3.0';
var Client = /** @class */ (function () {
function Client(config) {
var _this = this;
var _a, _b, _c, _d, _e;
this._config = tslib_1.__assign(tslib_1.__assign({}, defaultConfiguration_js_1.DEFAULT_CONFIGURATION), config);
this._retryConfig = tslib_1.__assign(tslib_1.__assign({}, defaultConfiguration_js_1.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;
var clonedConfig = tslib_1.__assign(tslib_1.__assign({}, this._config), { clientCredentialsAuthCredentials: this._config
.clientCredentialsAuthCredentials || {
oAuthClientId: this._config.oAuthClientId || '',
oAuthClientSecret: this._config.oAuthClientSecret || '',
oAuthToken: this._config.oAuthToken,
} });
this._requestBuilderFactory = createRequestHandlerFactory(function (server) { return getBaseUri(server, _this._config); }, (0, authProvider_js_1.createAuthProviderFromConfig)(clonedConfig, function () { return _this.clientCredentialsAuthManager; }), new clientAdapter_js_1.HttpClient(core_js_2.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, withAuthenticationByDefault], this._retryConfig);
this.clientCredentialsAuthManager = new clientCredentialsAuthManager_js_1.ClientCredentialsAuthManager(clonedConfig.clientCredentialsAuthCredentials, this);
}
Client.prototype.getRequestBuilderFactory = function () {
return this._requestBuilderFactory;
};
/**
* Clone this client and override given configuration options
*/
Client.prototype.withConfiguration = function (config) {
return new Client(tslib_1.__assign(tslib_1.__assign({}, this._config), config));
};
/**
* Create a client instance from a JSON configuration string
* @param jsonConfig - JSON string containing the configuration
* @returns A new Client instance
*/
Client.fromJsonConfig = function (jsonConfig) {
return new Client(configuration_js_1.Configuration.fromJsonConfig(jsonConfig));
};
/**
* Create a client instance from environment variables
* @param envVariables - Optional object containing environment variables
* @returns A new Client instance
*/
Client.fromEnvironment = function (envVariables) {
return new Client(configuration_js_1.Configuration.fromEnvironment(envVariables || process.env));
};
return Client;
}());
exports.Client = Client;
function createHttpClientAdapter(client) {
var _this = this;
return function (request, requestOptions) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, client.executeRequest(request, requestOptions)];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
}
function getBaseUri(server, config) {
if (server === void 0) { server = 'Shell'; }
if (config.environment === configuration_js_1.Environment.SIT) {
if (server === 'OAuth Server') {
return 'https://api-test.shell.com';
}
if (server === 'Shell') {
return 'https://api-test.shell.com/test';
}
}
if (config.environment === configuration_js_1.Environment.Production) {
if (server === 'OAuth Server') {
return 'https://api.shell.com';
}
if (server === 'Shell') {
return 'https://api.shell.com';
}
}
throw new Error('Could not get Base URL. Invalid environment or server.');
}
function createRequestHandlerFactory(baseUrlProvider, authProvider, httpClient, addons, retryConfig) {
var requestBuilderFactory = (0, core_js_2.createRequestBuilderFactory)(createHttpClientAdapter(httpClient), baseUrlProvider, core_js_1.ApiError, authProvider, retryConfig);
return tap.apply(void 0, tslib_1.__spreadArray([requestBuilderFactory], addons, false));
}
function tap(requestBuilderFactory) {
var callback = [];
for (var _i = 1; _i < arguments.length; _i++) {
callback[_i - 1] = arguments[_i];
}
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var requestBuilder = requestBuilderFactory.apply(void 0, args);
callback.forEach(function (c) { return c(requestBuilder); });
return requestBuilder;
};
}
function withErrorHandlers(rb) {
rb.defaultToError(core_js_1.ApiError);
}
function withUserAgent(rb) {
rb.header('user-agent', USER_AGENT);
}
function withAuthenticationByDefault(rb) {
rb.authenticate([{ bearerToken: true }]);
}
//# sourceMappingURL=client.js.map