Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 3x 3x 3x 3x 3x | // src/config/index.js
import { INTEGRATION_TYPE } from "../utils/constant";
/**
* @typedef {object} SDKConfig
* @property {string} apiUrl
* @property {string} secretKey
* @property {string} apiKey
* @property {string} verificationId
* @property {string} customerId
* @property {string} integrationType
* @property {object} [userData]
* @property {string} [token]
*/
const defaultConfig = {
apiUrl: "",
secretKey: "",
apiKey: "",
verificationId: "",
customerId: "",
integrationType: "",
userData: undefined,
token: undefined,
};
/** @type {SDKConfig} */
let config = { ...defaultConfig };
export const setConfig = (newConfig) => {
const { apiUrl, secretKey, apiKey, verificationId, integrationType } =
newConfig;
if (!apiUrl || !secretKey || !apiKey || !verificationId || !integrationType) {
throw new Error(
"Apacuana SDK: La configuración inicial debe incluir apiUrl, " +
"secretKey, apiKey, verificationId e integrationType."
);
}
// Nueva validación para el valor de integrationType
if (!Object.values(INTEGRATION_TYPE).includes(integrationType)) {
throw new Error(
`Apacuana SDK: El valor de integrationType ('${integrationType}') no es válido. ` +
`Valores permitidos: ${Object.values(INTEGRATION_TYPE).join(", ")}`
);
}
config = { ...config, ...newConfig };
// eslint-disable-next-line no-console
};
export const getConfig = () => ({ ...config });
export const close = () => {
config = { ...defaultConfig };
};
|