@begapp/sdk 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # @begaapp/sdk
2
+
3
+ Librería cliente para consumir los servicios de BegaApp desde cualquier aplicación externa. Permite configurar la API Key y consumir fácilmente endpoints.
4
+
5
+ ---
6
+
7
+ ## 🚀 Instalación
8
+
9
+ ```bash
10
+ npm install @begaapp/sdk
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import { configurarSDKBegaApp } from './src/client.js';
2
+ import { crearNotificacionBegaApp } from './src/notificaciones.js';
3
+
4
+ export {
5
+ configurarSDKBegaApp,
6
+ crearNotificacionBegaApp,
7
+ };
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@begapp/sdk",
3
+ "version": "1.0.6",
4
+ "description": "SDK para interactuar con el servicio de notificaciones de Bega App",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "keywords": [],
11
+ "author": "Bega App",
12
+ "license": "MIT",
13
+ "dependencies": {
14
+ "axios": "^1.9.0"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ }
19
+ }
package/src/client.js ADDED
@@ -0,0 +1,36 @@
1
+ import axios from 'axios';
2
+
3
+ var axiosInstance = null;
4
+ var claveSecreta = '';
5
+
6
+ export function configurarSDKBegaApp({ apiKey, urlApi, secretKey }) {
7
+ if (!key) throw new Error("Debes proporcionar una API key");
8
+ if (!url) throw new Error("Debes proporcionar la URL de la API Bega");
9
+ if (!secret) throw new Error("Debes proporcionar la URL de la API Bega");
10
+
11
+ claveSecreta = secretKey;
12
+
13
+ axiosInstance = axios.create({
14
+ baseURL: urlApi,
15
+ headers: {
16
+ 'bega-api-key': apiKey,
17
+ 'Content-Type': 'application/json',
18
+ },
19
+ });
20
+ }
21
+
22
+ export function getClient() {
23
+ if (!axiosInstance) {
24
+ throw new Error("El SDK no ha sido configurado. Debes declarar 'configurarSDKBegaApp' primero");
25
+ }
26
+
27
+ return axiosInstance;
28
+ }
29
+
30
+ export function getClaveSecreta() {
31
+ if (secretKey === '') {
32
+ throw new Error("No se ha configurado la Clave secreta para encriptar los mensajes");
33
+ }
34
+
35
+ return claveSecreta;
36
+ }
@@ -0,0 +1,24 @@
1
+ import CryptoJS from "crypto-js";
2
+
3
+ /**
4
+ * Cifra un objeto JSON como string
5
+ * @param {Object} data - El objeto con los datos (por ejemplo { cliente, estado })
6
+ * @param {string} claveSecreta - Clave AES
7
+ * @returns {string} - Texto cifrado
8
+ */
9
+ export function encryptMensaje(data, claveSecreta) {
10
+ const stringData = JSON.stringify(data);
11
+ return CryptoJS.AES.encrypt(stringData, claveSecreta).toString();
12
+ }
13
+
14
+ /**
15
+ * Descifra un string cifrado a objeto JSON
16
+ * @param {string} mensajeCifrado - Texto cifrado
17
+ * @param {string} claveSecreta - Clave AES
18
+ * @returns {Object} - Objeto original
19
+ */
20
+ export function decryptMensaje(mensajeCifrado, claveSecreta) {
21
+ const bytes = CryptoJS.AES.decrypt(mensajeCifrado, claveSecreta);
22
+ const textoPlano = bytes.toString(CryptoJS.enc.Utf8);
23
+ return JSON.parse(textoPlano);
24
+ }
@@ -0,0 +1,15 @@
1
+ import { getClient } from './client.js';
2
+
3
+ export async function crearNotificacionBegaApp(id, data) {
4
+ if (!id || typeof data !== 'object') {
5
+ throw new Error("crearNotificacion requiere un ID y un objeto data.");
6
+ }
7
+
8
+ const client = getClient();
9
+ const res = await client.post("/notification/create-notification", {
10
+ id,
11
+ data,
12
+ });
13
+
14
+ return res.data;
15
+ }