UNPKG

afrimomo-sdk

Version:

A unified SDK for African payment providers

101 lines 3.73 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.loadEnvFile = loadEnvFile; exports.loadEnvConfig = loadEnvConfig; exports.validatePSPConfig = validatePSPConfig; const dotenv = __importStar(require("dotenv")); const DEFAULT_CONFIG = { PAYCHANGU_ENVIRONMENT: "DEVELOPMENT", PAWAPAY_ENVIRONMENT: "DEVELOPMENT", }; function loadEnvFile(options = {}) { const { envPath = ".env", strict = false, silent = false } = options; try { const result = dotenv.config({ path: envPath }); if (result.error) { if (!silent) { console.warn(`Warning: Could not load environment file from ${envPath}`); console.warn("Falling back to process.env variables"); } } else if (!silent) { console.log(`✓ Loaded environment variables from ${envPath}`); } } catch (error) { if (!silent) { console.warn(`Warning: Error loading environment file: ${error instanceof Error ? error.message : "Unknown error"}`); console.warn("Falling back to process.env variables"); } } } function loadEnvConfig() { const config = { ...DEFAULT_CONFIG }; config.PAYCHANGU_SECRET_KEY = process.env.PAYCHANGU_SECRET_KEY || ""; config.PAYCHANGU_RETURN_URL = process.env.PAYCHANGU_RETURN_URL; config.PAYCHANGU_ENVIRONMENT = process.env.PAYCHANGU_ENVIRONMENT || DEFAULT_CONFIG.PAYCHANGU_ENVIRONMENT; config.PAWAPAY_JWT = process.env.PAWAPAY_JWT || ""; config.PAWAPAY_ENVIRONMENT = process.env.PAWAPAY_ENVIRONMENT || DEFAULT_CONFIG.PAWAPAY_ENVIRONMENT; return config; } function validatePSPConfig(config, psp) { const result = { isValid: true, missingFields: [], service: psp, }; switch (psp) { case "paychangu": if (!config.PAYCHANGU_SECRET_KEY) { result.missingFields.push("PAYCHANGU_SECRET_KEY"); } break; case "pawapay": if (!config.PAWAPAY_JWT) { result.missingFields.push("PAWAPAY_JWT"); } break; default: throw new Error(`Unknown PSP: ${psp}`); } result.isValid = result.missingFields.length === 0; return result; } //# sourceMappingURL=env.js.map