UNPKG

ev-recharge-sdk

Version:

This API Product provides the option to manage charging at all public Shell Recharge locations. The end points provides control to start, stop and get status of the charging session.

91 lines 4.28 kB
/** * Shell EVLib * * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). */ import { createAuthProviderFromConfig } from './authProvider'; import { ClientCredentialsAuthManager } from './clientCredentialsAuthManager'; import { Environment } from './configuration'; import { DEFAULT_CONFIGURATION, DEFAULT_RETRY_CONFIG, } from './defaultConfiguration'; import { ApiError } from './core'; import { AbortError, createRequestBuilderFactory, } from './core'; import { HttpClient } from './clientAdapter'; const USER_AGENT = 'APIMATIC 3.0'; export class Client { constructor(config) { var _a, _b, _c, _d; 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; const clonedConfig = Object.assign(Object.assign({}, this._config), { clientCredentialsAuthCredentials: this._config .clientCredentialsAuthCredentials || { oAuthClientId: this._config.oAuthClientId || '', oAuthClientSecret: this._config.oAuthClientSecret || '', oAuthToken: this._config.oAuthToken, } }); this._requestBuilderFactory = createRequestHandlerFactory((server) => getBaseUri(server, this._config), createAuthProviderFromConfig(clonedConfig, () => this.clientCredentialsAuthManager), 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, }), [withErrorHandlers, withUserAgent, withAuthenticationByDefault], this._retryConfig); this.clientCredentialsAuthManager = new ClientCredentialsAuthManager(clonedConfig.clientCredentialsAuthCredentials, this); } 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 = 'default', config) { if (config.environment === Environment.Production) { if (server === 'default') { return 'https://api.shell.com/ev/v1'; } if (server === 'access token server') { return 'https://api.shell.com/v2/oauth'; } } if (config.environment === Environment.Environment2) { if (server === 'default') { return 'https://api-test.shell.com/ev/v1'; } if (server === 'access token server') { return 'https://api.shell.com/v2/oauth'; } } 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(rb) { rb.header('user-agent', USER_AGENT); } function withAuthenticationByDefault(rb) { rb.authenticate([{ bearerAuth: true }]); } //# sourceMappingURL=client.js.map