UNPKG

expresscheckout-nodejs

Version:

Juspay's official expresscheckout-nodejs sdk

134 lines 5.15 kB
import Juspay from './Juspay.js'; import security from './security/index.js'; var JuspayEnvironment = /** @class */ (function () { function JuspayEnvironment(juspayConfig) { this.__base_url = Juspay.SANDBOX_BASE_URL; this.__timeout = Juspay.DEFAULT_REQUEST_TIMEOUT; this.__version = Juspay.API_VERSION; this.setJuspayConfig(juspayConfig); } JuspayEnvironment.prototype.override = function (overrideConfig) { if (overrideConfig == undefined) { return this; } var juspayConfig = { apiKey: overrideConfig.apiKey || this.getApiKey(), merchantId: overrideConfig.merchantId || this.getMerchantId(), baseUrl: overrideConfig.baseUrl || this.getBaseUrl(), timeout: overrideConfig.timeout || this.getTimeout(), version: overrideConfig.version || this.getVersion(), headers: overrideConfig.headers || this.getHeaders(), jweAuth: overrideConfig.jweAuth || this.getJweAuthConfig() }; return new JuspayEnvironment(juspayConfig); }; /** Getters and Setters */ JuspayEnvironment.prototype.setJuspayConfig = function (juspayConfig) { this.withApiKey(juspayConfig.apiKey); this.withMerchantId(juspayConfig.merchantId); this.withJweAuthConfig(juspayConfig.jweAuth); this.withTimeout(juspayConfig.timeout || Juspay.DEFAULT_REQUEST_TIMEOUT); this.withBaseUrl(juspayConfig.baseUrl || Juspay.SANDBOX_BASE_URL); this.withVersion(juspayConfig.version || Juspay.API_VERSION); this.withHeaders(juspayConfig.headers || {}); }; JuspayEnvironment.prototype.getJuspayConfig = function () { var juspayConfig = { apiKey: this.getApiKey(), baseUrl: this.getBaseUrl(), timeout: this.getTimeout(), merchantId: this.getMerchantId(), version: this.getVersion() }; return juspayConfig; }; JuspayEnvironment.prototype.getBaseUrl = function () { return this.__base_url; }; JuspayEnvironment.prototype.withBaseUrl = function (base_url) { this.__base_url = base_url; return this; }; JuspayEnvironment.prototype.getTimeout = function () { return this.__timeout; }; JuspayEnvironment.prototype.withTimeout = function (default_timeout) { this.__timeout = default_timeout; return this; }; JuspayEnvironment.prototype.getApiKey = function () { return this.__api_key; }; JuspayEnvironment.prototype.withApiKey = function (api_key) { this.__api_key = api_key; return this; }; JuspayEnvironment.prototype.getMerchantId = function () { return this.__merchant_id; }; JuspayEnvironment.prototype.withMerchantId = function (merchant_id) { // guard for merchant_id, it should be validated if (merchant_id == undefined || merchant_id == null || merchant_id.length == 0) { throw new TypeError('Please pass valid merchant_id'); } this.__merchant_id = merchant_id; return this; }; JuspayEnvironment.prototype.withVersion = function (version) { this.__version = version; return this; }; JuspayEnvironment.prototype.getVersion = function () { return this.__version; }; JuspayEnvironment.prototype.getHeaders = function () { return this.__headers; }; JuspayEnvironment.prototype.getHeadersFromKey = function (key) { return this.__headers.get(key); }; JuspayEnvironment.prototype.withHeaders = function (headers) { this.__headers = headers; return this; }; JuspayEnvironment.prototype.withKeyValueHeaders = function (key, value) { this.__headers.set(key, value); return this; }; JuspayEnvironment.prototype.withJweAuthConfig = function (jwe_auth_config) { if (jwe_auth_config == undefined) { return this; } if (jwe_auth_config.keyId == undefined || jwe_auth_config.keyId.length == 0) { throw new TypeError("keyId should not be empty"); } this.__jwe_auth_config = jwe_auth_config; this.readJWTKeys(jwe_auth_config); return this; }; JuspayEnvironment.prototype.readJWTKeys = function (jwe_auth_config) { this.__jwe_encryption = { keyId: jwe_auth_config.keyId, publicKey: security.Keys.readPublicKey(jwe_auth_config.publicKey), privateKey: security.Keys.readPrivateKey(jwe_auth_config.privateKey) }; }; /** * @returns returns raw keys in string format */ JuspayEnvironment.prototype.getJweAuthConfig = function () { return this.__jwe_auth_config; }; /** * @returns returns keys are crypto.KeyObject format */ JuspayEnvironment.prototype.getJweEncryption = function () { return this.__jwe_encryption; }; return JuspayEnvironment; }()); export { JuspayEnvironment }; //# sourceMappingURL=JuspayEnvironment.js.map