UNPKG

@sonatel-os/juf

Version:

The community SDK for Orange Money, SMS, Email & Sonatel APIs on the Orange Developer Platform.

62 lines (46 loc) 2.73 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _chunkW5WEVJMXcjs = require('./chunk-W5WEVJMX.cjs'); // src/core/urls.js var EMAIL_URI = "/api/communication/v1/emails"; var SMS_URI = "/api/communication/v1/messages"; var GENERATE_QR_URI = "/api/eWallet/v4/qrcode"; var GENERATE_PAYMENT_LINK_URI = "/api/v1/onlinePayment/prepare"; var DECODE_QR_URI = "/api/services/internal/v2/qrcodes/:id"; // src/core/validation.js var _superstruct = require('superstruct'); var validate = (data, structure, context) => { try { _superstruct.assert.call(void 0, data, structure); } catch (error) { throw new (0, _chunkW5WEVJMXcjs.ValidationError)(`Validation failed for ${context}: ${error.message}`, _optionalChain([error, 'access', _ => _.failures, 'optionalCall', _2 => _2()]) || null); } }; var ALLOWED_PROTOCOLS = /* @__PURE__ */ new Set(["https:", "http:"]); var validateUrl = (url, fieldName) => { try { const parsed = new URL(url); if (!ALLOWED_PROTOCOLS.has(parsed.protocol)) { throw new Error(`Disallowed protocol: ${parsed.protocol}`); } } catch (e) { throw new (0, _chunkW5WEVJMXcjs.ValidationError)(`Invalid URL for ${fieldName}: must be a valid HTTP or HTTPS URL`, { field: fieldName, value: url }); } }; var validateUrls = (urls) => { if (!urls) return; for (const [key, value] of Object.entries(urls)) { if (value !== null && value !== void 0) { validateUrl(value, `urls.${key}`); } } }; // src/core/authHeader.js var capitalizeTokenType = (tokenType) => tokenType.charAt(0).toUpperCase() + tokenType.slice(1).toLowerCase(); var buildAuthHeader = (accessToken, tokenType) => ({ Authorization: `${capitalizeTokenType(tokenType)} ${accessToken}` }); exports.EMAIL_URI = EMAIL_URI; exports.SMS_URI = SMS_URI; exports.GENERATE_QR_URI = GENERATE_QR_URI; exports.GENERATE_PAYMENT_LINK_URI = GENERATE_PAYMENT_LINK_URI; exports.DECODE_QR_URI = DECODE_QR_URI; exports.validate = validate; exports.validateUrl = validateUrl; exports.validateUrls = validateUrls; exports.capitalizeTokenType = capitalizeTokenType; exports.buildAuthHeader = buildAuthHeader; //# sourceMappingURL=chunk-TSJ7NWVT.cjs.map