UNPKG

@sonatel-os/juf

Version:

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

62 lines (58 loc) 1.77 kB
import { ValidationError } from "./chunk-4T5F3RH2.js"; // 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 import { assert } from "superstruct"; var validate = (data, structure, context) => { try { assert(data, structure); } catch (error) { throw new ValidationError(`Validation failed for ${context}: ${error.message}`, error.failures?.() || 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 { throw new 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}` }); export { EMAIL_URI, SMS_URI, GENERATE_QR_URI, GENERATE_PAYMENT_LINK_URI, DECODE_QR_URI, validate, validateUrl, validateUrls, capitalizeTokenType, buildAuthHeader }; //# sourceMappingURL=chunk-BXTDSY5Z.js.map