UNPKG

expresscheckout-nodejs

Version:

Juspay's official expresscheckout-nodejs sdk

139 lines 4.64 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.JuspayEnvironment = void 0; const Juspay_js_1 = __importDefault(require("./Juspay.js")); const index_js_1 = __importDefault(require("./security/index.js")); class JuspayEnvironment { constructor(juspayConfig) { this.__base_url = Juspay_js_1.default.SANDBOX_BASE_URL; this.__timeout = Juspay_js_1.default.DEFAULT_REQUEST_TIMEOUT; this.__version = Juspay_js_1.default.API_VERSION; this.setJuspayConfig(juspayConfig); } override(overrideConfig) { if (overrideConfig == undefined) { return this; } const 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 */ setJuspayConfig(juspayConfig) { this.withApiKey(juspayConfig.apiKey); this.withMerchantId(juspayConfig.merchantId); this.withJweAuthConfig(juspayConfig.jweAuth); this.withTimeout(juspayConfig.timeout || Juspay_js_1.default.DEFAULT_REQUEST_TIMEOUT); this.withBaseUrl(juspayConfig.baseUrl || Juspay_js_1.default.SANDBOX_BASE_URL); this.withVersion(juspayConfig.version || Juspay_js_1.default.API_VERSION); this.withHeaders(juspayConfig.headers || {}); } getJuspayConfig() { const juspayConfig = { apiKey: this.getApiKey(), baseUrl: this.getBaseUrl(), timeout: this.getTimeout(), merchantId: this.getMerchantId(), version: this.getVersion(), }; return juspayConfig; } getBaseUrl() { return this.__base_url; } withBaseUrl(base_url) { this.__base_url = base_url; return this; } getTimeout() { return this.__timeout; } withTimeout(default_timeout) { this.__timeout = default_timeout; return this; } getApiKey() { return this.__api_key; } withApiKey(api_key) { this.__api_key = api_key; return this; } getMerchantId() { return this.__merchant_id; } withMerchantId(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; } withVersion(version) { this.__version = version; return this; } getVersion() { return this.__version; } getHeaders() { return this.__headers; } getHeadersFromKey(key) { return this.__headers.get(key); } withHeaders(headers) { this.__headers = headers; return this; } withKeyValueHeaders(key, value) { this.__headers.set(key, value); return this; } withJweAuthConfig(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; } readJWTKeys(jwe_auth_config) { this.__jwe_encryption = { keyId: jwe_auth_config.keyId, publicKey: index_js_1.default.Keys.readPublicKey(jwe_auth_config.publicKey), privateKey: index_js_1.default.Keys.readPrivateKey(jwe_auth_config.privateKey), }; } /** * @returns returns raw keys in string format */ getJweAuthConfig() { return this.__jwe_auth_config; } /** * @returns returns keys are crypto.KeyObject format */ getJweEncryption() { return this.__jwe_encryption; } } exports.JuspayEnvironment = JuspayEnvironment; //# sourceMappingURL=JuspayEnvironment.js.map