UNPKG

@sonatel-os/juf

Version:

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

1 lines 4.51 kB
{"version":3,"sources":["/Users/JOHNSON028877/Documents/new-juf.js/dist/chunk-TSJ7NWVT.cjs","../src/core/urls.js","../src/core/validation.js","../src/core/authHeader.js"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJO,IAAM,UAAA,EAAY,8BAAA;AAClB,IAAM,QAAA,EAAU,gCAAA;AAChB,IAAM,gBAAA,EAAkB,wBAAA;AACxB,IAAM,0BAAA,EAA4B,+BAAA;AAClC,IAAM,cAAA,EAAgB,uCAAA;ADM7B;AACA;AENA,0CAAuB;AAYhB,IAAM,SAAA,EAAW,CAAC,IAAA,EAAM,SAAA,EAAW,OAAA,EAAA,GAAY;AACpD,EAAA,IAAI;AACF,IAAA,iCAAA,IAAO,EAAM,SAAS,CAAA;AAAA,EACxB,EAAA,MAAA,CAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,sCAAA,CAAgB,CAAA,sBAAA,EAAyB,OAAO,CAAA,EAAA,EAAK,KAAA,CAAM,OAAO,CAAA,CAAA;AAC9E,EAAA;AACF;AAGqD;AAUN;AACzC,EAAA;AACwB,IAAA;AACmB,IAAA;AACc,MAAA;AAC3D,IAAA;AACM,EAAA;AACgD,IAAA;AAC7C,MAAA;AACA,MAAA;AACR,IAAA;AACH,EAAA;AACF;AAQsC;AACzB,EAAA;AAEsC,EAAA;AACJ,IAAA;AACT,MAAA;AAClC,IAAA;AACF,EAAA;AACF;AFtBiF;AACA;AG/BK;AAS1B;AACK,EAAA;AACjE;AHyBiF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/JOHNSON028877/Documents/new-juf.js/dist/chunk-TSJ7NWVT.cjs","sourcesContent":[null,"export const EMAIL_URI = '/api/communication/v1/emails';\nexport const SMS_URI = '/api/communication/v1/messages';\nexport const GENERATE_QR_URI = '/api/eWallet/v4/qrcode';\nexport const GENERATE_PAYMENT_LINK_URI = '/api/v1/onlinePayment/prepare';\nexport const DECODE_QR_URI = '/api/services/internal/v2/qrcodes/:id';\nexport const GENERATE_TEST_MSISDN_URI = '/api/assignments/v1/partner/sim-cards';\n","/**\n * @namespace Validation\n * @description Input validation utilities for the JUF library.\n */\n\nimport { assert } from 'superstruct';\nimport { ValidationError } from './errors.js';\n\n/**\n * Validates input data against a Superstruct schema.\n * Throws a ValidationError on failure instead of silently returning undefined.\n *\n * @param {object} data - The data to validate.\n * @param {import('superstruct').Struct} structure - The Superstruct schema.\n * @param {string} context - Human-readable context for error messages (e.g. 'sendEmail').\n * @throws {ValidationError} When validation fails.\n */\nexport const validate = (data, structure, context) => {\n try {\n assert(data, structure);\n } catch (error) {\n throw new ValidationError(`Validation failed for ${context}: ${error.message}`, error.failures?.() || null);\n }\n};\n\n/** @type {Set<string>} Allowed URL protocols for redirect URLs. */\nconst ALLOWED_PROTOCOLS = new Set(['https:', 'http:']);\n\n/**\n * Validates that a URL string is a well-formed HTTP(S) URL.\n * Prevents open redirect attacks by rejecting javascript:, data:, etc.\n *\n * @param {string} url - The URL to validate.\n * @param {string} fieldName - Field name for error messages.\n * @throws {ValidationError} When the URL is malformed or uses a disallowed protocol.\n */\nexport const validateUrl = (url, fieldName) => {\n try {\n const parsed = new URL(url);\n if (!ALLOWED_PROTOCOLS.has(parsed.protocol)) {\n throw new Error(`Disallowed protocol: ${parsed.protocol}`);\n }\n } catch {\n throw new ValidationError(`Invalid URL for ${fieldName}: must be a valid HTTP or HTTPS URL`, {\n field: fieldName,\n value: url,\n });\n }\n};\n\n/**\n * Validates an object of optional URL fields.\n * Only validates URLs that are provided (non-nullish).\n *\n * @param {object} urls - Object with URL fields to validate.\n */\nexport const validateUrls = (urls) => {\n if (!urls) return;\n\n for (const [key, value] of Object.entries(urls)) {\n if (value !== null && value !== undefined) {\n validateUrl(value, `urls.${key}`);\n }\n }\n};\n","/**\n * @namespace AuthHeader\n * @description Shared utilities for building Authorization headers from OAuth tokens.\n */\n\n/**\n * Capitalizes the token type for use in Authorization headers.\n * Handles any casing of \"bearer\" properly.\n *\n * @param {string} tokenType - Raw token type from the auth response.\n * @returns {string} Properly capitalized token type.\n */\nexport const capitalizeTokenType = (tokenType) => tokenType.charAt(0).toUpperCase() + tokenType.slice(1).toLowerCase();\n\n/**\n * Builds an Authorization header from token credentials.\n *\n * @param {string} accessToken - The access token.\n * @param {string} tokenType - The token type (e.g. \"bearer\").\n * @returns {{ Authorization: string }} Authorization header object.\n */\nexport const buildAuthHeader = (accessToken, tokenType) => ({\n Authorization: `${capitalizeTokenType(tokenType)} ${accessToken}`,\n});\n"]}